diff --git a/crates/ely_browser_core/src/state/downloads.rs b/crates/ely_browser_core/src/state/downloads.rs index a90c66b..44367b6 100644 --- a/crates/ely_browser_core/src/state/downloads.rs +++ b/crates/ely_browser_core/src/state/downloads.rs @@ -122,6 +122,7 @@ impl BrowserCore { ) -> Result<&mut DownloadEntry, CoreError> { self.download_entries .iter_mut() + .filter(|entry| entry.profile_id() == &self.active_profile_id) .find(|entry| entry.id() == download_id) .ok_or_else(|| CoreError::DownloadNotFound { id: download_id.clone() }) } diff --git a/crates/ely_browser_core/tests/downloads.rs b/crates/ely_browser_core/tests/downloads.rs index 35ff467..25baa00 100644 --- a/crates/ely_browser_core/tests/downloads.rs +++ b/crates/ely_browser_core/tests/downloads.rs @@ -43,6 +43,29 @@ fn download_entries_stay_with_active_profile() -> Result<(), Box> { Ok(()) } +#[test] +fn download_controls_stay_with_active_profile() -> Result<(), Box> { + let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let default_profile_id = core.active_tab()?.profile_id().clone(); + let default_download_id = core.record_download_started( + UrlText::parse("https://example.com/report.pdf")?, + "report.pdf", + Some(2048), + )?; + + core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?; + let error = match core.cancel_download(&default_download_id) { + Ok(()) => return Err("hidden profile download should stay out of scope".into()), + Err(error) => error, + }; + + assert_eq!(error, CoreError::DownloadNotFound { id: default_download_id.clone() }); + core.select_profile(&default_profile_id)?; + core.cancel_download(&default_download_id)?; + assert_eq!(active_download(&core)?.state(), &DownloadState::Cancelled); + Ok(()) +} + #[test] fn controls_download_lifecycle() -> Result<(), Box> { let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;