Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1876806 - Do not remove downloaded files in private tabs after de…
Browse files Browse the repository at this point in the history
…leting browsing data
  • Loading branch information
Amejia481 committed Feb 6, 2024
1 parent de5db98 commit 3021df8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ abstract class AbstractFetchDownloadService : Service() {
internal fun handleRemovePrivateDownloadIntent(download: DownloadState) {
if (download.private) {
downloadJobs[download.id]?.let {
cancelDownloadJob(it)
// Do not cancel already completed downloads.
if (it.status != COMPLETED) {
cancelDownloadJob(it)
}
removeDownloadJob(it)
}
store.dispatch(DownloadAction.RemoveDownloadAction(download.id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ class AbstractFetchDownloadServiceTest {

service.handleRemovePrivateDownloadIntent(downloadState)

verify(service, times(0)).cancelDownloadJob(downloadJobState)
verify(service).removeDownloadJob(downloadJobState)
verify(browserStore).dispatch(DownloadAction.RemoveDownloadAction(downloadState.id))
}

@Test
fun `WHEN handleRemovePrivateDownloadIntent is called with a private download AND not COMPLETED status THEN removeDownloadJob and cancelDownloadJob must be called`() {
val downloadState = DownloadState(url = "mozilla.org/mozilla.txt", private = true)
val downloadJobState = DownloadJobState(state = downloadState, status = DOWNLOADING)
val browserStore = mock<BrowserStore>()
val service = spy(
object : AbstractFetchDownloadService() {
override val httpClient = client
override val store = browserStore
override val notificationsDelegate = this@AbstractFetchDownloadServiceTest.notificationsDelegate
},
)

doAnswer { Unit }.`when`(service).removeDownloadJob(any())

service.downloadJobs[downloadState.id] = downloadJobState

service.handleRemovePrivateDownloadIntent(downloadState)

verify(service).cancelDownloadJob(downloadJobState)
verify(service).removeDownloadJob(downloadJobState)
verify(browserStore).dispatch(DownloadAction.RemoveDownloadAction(downloadState.id))
Expand Down

0 comments on commit 3021df8

Please sign in to comment.