Commit c487a6c4 authored by Sebastian Kaspari's avatar Sebastian Kaspari
Browse files

feature-contextmenu: Do not show download confirmation dialog for "save image".

parent 22c0e34d
......@@ -26,5 +26,6 @@ data class DownloadState(
val userAgent: String? = null,
val destinationDirectory: String = Environment.DIRECTORY_DOWNLOADS,
val referrerUrl: String? = null,
val skipConfirmation: Boolean = false,
val id: String = UUID.randomUUID().toString()
)
......@@ -151,7 +151,7 @@ data class ContextMenuCandidate(
action = { tab, hitResult ->
contextMenuUseCases.injectDownload(
tab.id,
DownloadState(hitResult.src)
DownloadState(hitResult.src, skipConfirmation = true)
)
}
)
......
......@@ -382,6 +382,8 @@ class ContextMenuCandidateTest {
assertEquals(
"https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png",
store.state.tabs.first().content.download!!.url)
assertTrue(
store.state.tabs.first().content.download!!.skipConfirmation)
}
@Test
......
......@@ -107,7 +107,7 @@ class DownloadsFeature(
*/
private fun processDownload(tab: SessionState, download: DownloadState): Boolean {
return if (applicationContext.isPermissionGranted(downloadManager.permissions.asIterable())) {
if (fragmentManager != null) {
if (fragmentManager != null && !download.skipConfirmation) {
showDialog(tab, download)
false
} else {
......
......@@ -152,6 +152,43 @@ class DownloadsFeatureTest {
verify(downloadManager).download(eq(download), anyString())
}
@Test
fun `Adding a Download with skipConfirmation flag will start download immediately`() {
val fragmentManager: FragmentManager = mockFragmentManager()
grantPermissions()
val downloadManager: DownloadManager = mock()
doReturn(
arrayOf(INTERNET, WRITE_EXTERNAL_STORAGE)
).`when`(downloadManager).permissions
val feature = DownloadsFeature(
testContext,
store,
useCases = mock(),
fragmentManager = fragmentManager,
downloadManager = downloadManager
)
feature.start()
verify(fragmentManager, never()).beginTransaction()
val download = DownloadState(
url = "https://www.mozilla.org",
skipConfirmation = true
)
store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
.joinBlocking()
testDispatcher.advanceUntilIdle()
verify(fragmentManager, never()).beginTransaction()
verify(downloadManager).download(eq(download), anyString())
}
@Test
fun `When starting the feature will reattach to already existing dialog`() {
grantPermissions()
......
......@@ -12,6 +12,9 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt)
* **feature-contextmenu**
* The "Save Image" context menu item will no longer prompt before downloading the image.
# 16.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v15.0.0...v16.0.0)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment