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

Commit

Permalink
Close #8354: Do not restart FAILED downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Sep 14, 2020
1 parent c0ad3ba commit 9a98bd2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.browser.state.state.content.DownloadState.Status.CANCELLED
import mozilla.components.browser.state.state.content.DownloadState.Status.COMPLETED
import mozilla.components.browser.state.state.content.DownloadState.Status.FAILED
import mozilla.components.lib.state.Middleware
import mozilla.components.lib.state.MiddlewareContext
import mozilla.components.lib.state.Store
Expand Down Expand Up @@ -110,8 +111,9 @@ class DownloadMiddleware(
}
}

private fun sendDownloadIntent(download: DownloadState) {
if (download.status !in arrayOf(COMPLETED, CANCELLED)) {
@VisibleForTesting
internal fun sendDownloadIntent(download: DownloadState) {
if (download.status !in arrayOf(COMPLETED, CANCELLED, FAILED)) {
val intent = Intent(applicationContext, downloadServiceClass)
intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, download.id)
startForegroundService(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.browser.state.state.content.DownloadState.Status.COMPLETED
import mozilla.components.browser.state.state.content.DownloadState.Status.INITIATED
import mozilla.components.browser.state.state.content.DownloadState.Status.FAILED
import mozilla.components.browser.state.state.content.DownloadState.Status.CANCELLED
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.test.any
import mozilla.components.support.test.argumentCaptor
Expand All @@ -38,6 +40,7 @@ import org.mockito.Mockito.verify
import org.mockito.Mockito.times
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.reset

@RunWith(AndroidJUnit4::class)
class DownloadMiddlewareTest {
Expand Down Expand Up @@ -222,4 +225,30 @@ class DownloadMiddlewareTest {

assertEquals(download, store.state.downloads.values.first())
}

@Test
fun `sendDownloadIntent MUST call startForegroundService WHEN downloads are NOT COMPLETED, CANCELLED and FAILED`() = runBlockingTest {
val applicationContext: Context = mock()
val downloadMiddleware = spy(DownloadMiddleware(
applicationContext,
AbstractFetchDownloadService::class.java
))

val ignoredStatus = listOf(COMPLETED, CANCELLED, FAILED)
ignoredStatus.forEach { status ->
val download = DownloadState("https://mozilla.org/download", status = status)
downloadMiddleware.sendDownloadIntent(download)
verify(downloadMiddleware, times(0)).startForegroundService(any())
}

reset(downloadMiddleware)

val allowedStatus = DownloadState.Status.values().filter { it !in ignoredStatus }

allowedStatus.forEachIndexed { index, status ->
val download = DownloadState("https://mozilla.org/download", status = status)
downloadMiddleware.sendDownloadIntent(download)
verify(downloadMiddleware, times(index + 1)).startForegroundService(any())
}
}
}
4 changes: 3 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/.config.yml)

* **feature-downloads**
* 🚒 Bug fixed [issue #8354](https://github.com/mozilla-mobile/android-components/issues/8354) Do not restart FAILED downloads.

* **browser-tabstray**
* Removed the `BrowserTabsTray` that was deprecated in previous releases.
* **service-telemetry**
Expand Down Expand Up @@ -92,7 +95,6 @@ permalink: /changelog/
* 🚒 Bug [issue #8190](https://github.com/mozilla-mobile/android-components/issues/8190) ArithmeticException: divide by zero in Download notification.
* 🚒 Bug [issue #8363](https://github.com/mozilla-mobile/android-components/issues/8363) IllegalStateException: Not allowed to start service Intent.


* **ui-widgets**
* 🆕 New VerticalSwipeRefreshLayout that comes to resolve many of the issues of the platform SwipeRefreshLayout and filters out other gestures than swipe down/up.

Expand Down

0 comments on commit 9a98bd2

Please sign in to comment.