Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Close #8847 Do not show download dialogs when
Browse files Browse the repository at this point in the history
the fragmentManager is destroyed.
  • Loading branch information
Amejia481 authored and mergify[bot] committed Oct 30, 2020
1 parent 234a3a3 commit 3e7cee0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class DownloadsFeature(
useCases.consumeDownload.invoke(tab.id, download.id)
}

if (!isAlreadyADownloadDialog() && fragmentManager != null) {
if (!isAlreadyADownloadDialog() && fragmentManager != null && !fragmentManager.isDestroyed) {
dialog.showNow(fragmentManager, FRAGMENT_TAG)
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ class DownloadsFeature(
useCases.consumeDownload.invoke(tab.id, download.id)
}

if (!isAlreadyAppDownloaderDialog() && fragmentManager != null) {
if (!isAlreadyAppDownloaderDialog() && fragmentManager != null && !fragmentManager.isDestroyed) {
appChooserDialog.showNow(fragmentManager, DownloadAppChooserDialog.FRAGMENT_TAG)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,46 @@ class DownloadsFeatureTest {
verify(dialog, times(1)).showNow(fragmentManager, DownloadDialogFragment.FRAGMENT_TAG)
}

@Test
fun `download dialog must NOT be shown WHEN the fragmentManager isDestroyed`() {
val fragmentManager = mockFragmentManager()
val dialog = mock<DownloadDialogFragment>()
val feature = spy(DownloadsFeature(
testContext,
store,
useCases = mock(),
downloadManager = mock(),
fragmentManager = fragmentManager
))

doReturn(false).`when`(feature).isAlreadyADownloadDialog()
doReturn(true).`when`(fragmentManager).isDestroyed

feature.showDownloadDialog(mock(), mock(), dialog)

verify(dialog, never()).showNow(fragmentManager, DownloadDialogFragment.FRAGMENT_TAG)
}

@Test
fun `app downloader dialog must NOT be shown WHEN the fragmentManager isDestroyed`() {
val fragmentManager = mockFragmentManager()
val dialog = mock<DownloadAppChooserDialog>()
val feature = spy(DownloadsFeature(
testContext,
store,
useCases = mock(),
downloadManager = mock(),
fragmentManager = fragmentManager
))

doReturn(false).`when`(feature).isAlreadyADownloadDialog()
doReturn(true).`when`(fragmentManager).isDestroyed

feature.showAppDownloaderDialog(mock(), mock(), emptyList(), dialog)

verify(dialog, never()).showNow(fragmentManager, DownloadDialogFragment.FRAGMENT_TAG)
}

@Test
fun `processDownload only forward downloads when shouldForwardToThirdParties is true`() {
val tab = createTab("https://www.mozilla.org", id = "test-tab")
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ permalink: /changelog/

* **feature-downloads**
* 🚒 Bug fixed [issue #8585](https://github.com/mozilla-mobile/android-components/issues/8784) create download directory when it doesn't exists for more information see [mozilla-mobile/fenix#15527](https://github.com/mozilla-mobile/fenix/issues/5829).
* 🚒 Bug fixed [issue #8847](https://github.com/mozilla-mobile/android-components/issues/8847) crash when trying to download a file and switching from a normal to a private mode.

* **feature-top-sites**
* Added `RenameTopSiteUseCase` to rename pinned site entries. [#8751](https://github.com/mozilla-mobile/android-components/issues/8751)
Expand Down

0 comments on commit 3e7cee0

Please sign in to comment.