Clear active profile downloads

This commit is contained in:
2026-05-07 21:59:43 -04:00
parent 7370ae14b9
commit 72b43974c3
2 changed files with 37 additions and 0 deletions
@@ -81,6 +81,13 @@ impl BrowserCore {
.ok_or_else(|| CoreError::DownloadTargetPathUnavailable { id: download_id.clone() })
}
pub fn clear_downloads_for_active_profile(&mut self) -> usize {
let active_profile_id = self.active_profile_id.clone();
let before_count = self.download_entries.len();
self.download_entries.retain(|entry| entry.profile_id() != &active_profile_id);
before_count - self.download_entries.len()
}
pub(super) fn visible_downloads(&self) -> Vec<DownloadEntry> {
self.download_entries
.iter()
@@ -110,6 +110,36 @@ fn returns_visible_download_target_file_path() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn clears_downloads_for_active_profile() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let default_profile_id = core.active_tab()?.profile_id().clone();
core.record_download_started(
UrlText::parse("https://example.com/report.pdf")?,
"report.pdf",
Some(2048),
)?;
core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
core.record_download_started(
UrlText::parse("https://example.com/archive.zip")?,
"archive.zip",
Some(4096),
)?;
assert_eq!(core.clear_downloads_for_active_profile(), 1);
assert!(core.snapshot()?.download_entries.is_empty());
core.select_profile(&default_profile_id)?;
let default_snapshot = core.snapshot()?;
assert_eq!(default_snapshot.download_entries.len(), 1);
assert_eq!(default_snapshot.download_entries[0].file_name(), "report.pdf");
assert_eq!(core.clear_downloads_for_active_profile(), 1);
assert!(core.snapshot()?.download_entries.is_empty());
assert_eq!(core.clear_downloads_for_active_profile(), 0);
Ok(())
}
#[test]
fn rejects_target_path_for_ask_every_time_download() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;