Add current page download pipeline

This commit is contained in:
2026-05-09 12:54:24 -04:00
parent 1faa7423c1
commit 189b9b8b89
17 changed files with 842 additions and 13 deletions
@@ -259,6 +259,12 @@ impl BrowserCore {
self.open_tab(downloads_url()?);
Ok(true)
}
"download-current-page"
| "download current page"
| "save-page"
| "save page"
| "save-current-page"
| "save current page" => Ok(true),
"bookmarks" | "open-bookmarks" | "open bookmarks" => {
self.open_tab(bookmarks_url()?);
Ok(true)
@@ -27,6 +27,26 @@ impl BrowserCore {
Ok(download_id)
}
pub fn record_download_started_at_path(
&mut self,
source_url: UrlText,
target_file_path: impl Into<PathBuf>,
total_bytes: Option<u64>,
) -> Result<DownloadId, CoreError> {
let destination = self.active_profile()?.download_policy().destination().clone();
let entry = DownloadEntry::started_at_path(
self.active_profile_id.clone(),
source_url,
destination,
target_file_path,
total_bytes,
SystemTime::now(),
)?;
let download_id = entry.id().clone();
self.download_entries.push(entry);
Ok(download_id)
}
pub fn pause_download(&mut self, download_id: &DownloadId) -> Result<(), CoreError> {
self.download_entry_mut(download_id)?.pause()?;
Ok(())
+16
View File
@@ -66,6 +66,22 @@ fn open_downloads_command_opens_downloads_page() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn download_current_page_command_keeps_active_tab_for_shell_download() -> Result<(), Box<dyn Error>>
{
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let active_tab_id = core.active_tab()?.id().clone();
core.set_command_query(">download-current-page");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("download-current-page".to_string())));
assert_eq!(snapshot.active_tab_id, active_tab_id);
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn open_history_command_opens_history_page() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
@@ -91,6 +91,25 @@ fn controls_download_lifecycle() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn records_prompted_download_target_path() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let target_path = Path::new("/tmp/ely-prompted-download/report.pdf");
let download_id = core.record_download_started_at_path(
UrlText::parse("https://example.com/report.pdf")?,
target_path,
None,
)?;
let entry = active_download(&core)?;
assert_eq!(entry.id(), &download_id);
assert_eq!(entry.file_name(), "report.pdf");
assert_eq!(entry.destination(), &DownloadDestination::AskEveryTime);
assert_eq!(entry.target_file_path(), Some(target_path));
Ok(())
}
#[test]
fn records_checksum_after_download_completion() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;