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

Close #6421: Download try again should not crash when download does not exist #6746

Merged
merged 1 commit into from
Apr 24, 2020
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 @@ -76,7 +76,7 @@ class FetchDownloadManager<T : AbstractFetchDownloadService>(
}

override fun tryAgain(downloadId: Long) {
val download = queuedDownloads[downloadId]
val download = queuedDownloads[downloadId] ?: return
Amejia481 marked this conversation as resolved.
Show resolved Hide resolved

val intent = Intent(applicationContext, service.java)
intent.putDownloadExtra(download)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.verify
import mozilla.components.feature.downloads.AbstractFetchDownloadService.DownloadJobStatus
import org.junit.Assert.assertFalse
import org.mockito.Mockito.times

@RunWith(AndroidJUnit4::class)
Expand Down Expand Up @@ -101,6 +102,28 @@ class FetchDownloadManagerTest {
assertTrue(downloadCompleted)
}

@Test
fun `try again should not crash when download does not exist`() {
val context: Context = mock()
downloadManager = FetchDownloadManager(context, MockDownloadService::class, broadcastManager)
var downloadCompleted = false

downloadManager.onDownloadStopped = { _, _, _ -> downloadCompleted = true }

grantPermissions()

val id = downloadManager.download(download)!!

verify(context).startService(any())
notifyDownloadCompleted(id)
assertTrue(downloadCompleted)

downloadCompleted = false
downloadManager.tryAgain(id + 1)
assertFalse(downloadCompleted)
verify(context, times(1)).startService(any())
}

@Test
fun `trying to download a file with invalid protocol must NOT triggered a download`() {

Expand Down