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

Bug 1876806 - Do not remove downloaded files in private tabs after deleting browsing data (backport #5461) #5525

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [email protected]
},
)

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
Loading