mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] For issue https://github.com/mozilla-mobile/fenix/issues/18049 Download complete dialog is not showing in custom tab.
This commit is contained in:
parent
34c1fa575c
commit
99393c2d84
@ -458,9 +458,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
|
||||
downloadFeature.onDownloadStopped = { downloadState, _, downloadJobStatus ->
|
||||
// If the download is just paused, don't show any in-app notification
|
||||
if (downloadJobStatus == DownloadState.Status.COMPLETED ||
|
||||
downloadJobStatus == DownloadState.Status.FAILED
|
||||
) {
|
||||
if (shouldShowCompletedDownloadDialog(downloadState, downloadJobStatus)) {
|
||||
|
||||
saveDownloadDialogState(
|
||||
downloadState.sessionId,
|
||||
@ -488,16 +486,13 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
onDismiss = { sharedViewModel.downloadDialogState.remove(downloadState.sessionId) }
|
||||
)
|
||||
|
||||
// Don't show the dialog if we aren't in the tab that started the download
|
||||
if (downloadState.sessionId == sessionManager.selectedSession?.id) {
|
||||
dynamicDownloadDialog.show()
|
||||
browserToolbarView.expand()
|
||||
}
|
||||
dynamicDownloadDialog.show()
|
||||
browserToolbarView.expand()
|
||||
}
|
||||
}
|
||||
|
||||
resumeDownloadDialogState(
|
||||
sessionManager.selectedSession?.id,
|
||||
getCurrentTab()?.id,
|
||||
store, view, context, toolbarHeight
|
||||
)
|
||||
|
||||
@ -1152,7 +1147,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentTab(): SessionState? {
|
||||
@VisibleForTesting
|
||||
internal fun getCurrentTab(): SessionState? {
|
||||
return requireComponents.core.store.state.findCustomTabOrSelectedTab(customTabSessionId)
|
||||
}
|
||||
|
||||
@ -1358,4 +1354,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
*/
|
||||
@VisibleForTesting
|
||||
internal fun getSwipeRefreshLayout() = swipeRefresh
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun shouldShowCompletedDownloadDialog(
|
||||
downloadState: DownloadState,
|
||||
status: DownloadState.Status
|
||||
): Boolean {
|
||||
|
||||
val isValidStatus = status in listOf(DownloadState.Status.COMPLETED, DownloadState.Status.FAILED)
|
||||
val isSameTab = downloadState.sessionId == getCurrentTab()?.id ?: false
|
||||
|
||||
return isValidStatus && isSameTab
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,12 @@ import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import junit.framework.TestCase.assertFalse
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import mozilla.components.browser.state.state.SessionState
|
||||
import mozilla.components.browser.state.state.content.DownloadState
|
||||
import mozilla.components.browser.state.state.createTab
|
||||
import mozilla.components.concept.engine.EngineView
|
||||
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
||||
import mozilla.components.feature.session.behavior.EngineViewBrowserToolbarBehavior
|
||||
@ -111,6 +115,66 @@ class BaseBrowserFragmentTest {
|
||||
|
||||
verify { (swipeRefreshLayout.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = 13 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN status is equals to FAILED or COMPLETED and it is the same tab then shouldShowCompletedDownloadDialog will be true`() {
|
||||
every { fragment.getCurrentTab() } returns createTab(id = "1", url = "")
|
||||
|
||||
val download = DownloadState(
|
||||
url = "",
|
||||
sessionId = "1"
|
||||
)
|
||||
|
||||
val status = DownloadState.Status.values()
|
||||
.filter { it == DownloadState.Status.COMPLETED && it == DownloadState.Status.FAILED }
|
||||
|
||||
status.forEach {
|
||||
val result =
|
||||
fragment.shouldShowCompletedDownloadDialog(download, it)
|
||||
|
||||
assertTrue(result)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN status is different from FAILED or COMPLETED then shouldShowCompletedDownloadDialog will be false`() {
|
||||
every { fragment.getCurrentTab() } returns createTab(id = "1", url = "")
|
||||
|
||||
val download = DownloadState(
|
||||
url = "",
|
||||
sessionId = "1"
|
||||
)
|
||||
|
||||
val status = DownloadState.Status.values()
|
||||
.filter { it != DownloadState.Status.COMPLETED && it != DownloadState.Status.FAILED }
|
||||
|
||||
status.forEach {
|
||||
val result =
|
||||
fragment.shouldShowCompletedDownloadDialog(download, it)
|
||||
|
||||
assertFalse(result)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the tab is different from the initial one then shouldShowCompletedDownloadDialog will be false`() {
|
||||
every { fragment.getCurrentTab() } returns createTab(id = "1", url = "")
|
||||
|
||||
val download = DownloadState(
|
||||
url = "",
|
||||
sessionId = "2"
|
||||
)
|
||||
|
||||
val status = DownloadState.Status.values()
|
||||
.filter { it != DownloadState.Status.COMPLETED && it != DownloadState.Status.FAILED }
|
||||
|
||||
status.forEach {
|
||||
val result =
|
||||
fragment.shouldShowCompletedDownloadDialog(download, it)
|
||||
|
||||
assertFalse(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
|
Loading…
Reference in New Issue
Block a user