For #14772: Crash in Downloads

upstream-sync
Kate Glazko 4 years ago committed by kglazko
parent 729f46ec1f
commit 6c68e79a22

@ -91,7 +91,7 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
it.id, it.id,
it.fileName, it.fileName,
it.filePath, it.filePath,
it.contentLength.toString(), it.contentLength?.toString() ?: "0",
it.contentType, it.contentType,
it.status it.status
) )

@ -48,7 +48,7 @@ class DownloadFragmentTest {
"3", "3",
"3.pdf", "3.pdf",
downloadedFile3.path, downloadedFile3.path,
"null", "0",
null, null,
DownloadState.Status.COMPLETED DownloadState.Status.COMPLETED
), ),
@ -56,7 +56,7 @@ class DownloadFragmentTest {
"2", "2",
"2.pdf", "2.pdf",
downloadedFile2.path, downloadedFile2.path,
"null", "0",
null, null,
DownloadState.Status.COMPLETED DownloadState.Status.COMPLETED
), ),
@ -64,7 +64,7 @@ class DownloadFragmentTest {
"1", "1",
"1.pdf", "1.pdf",
downloadedFile1.path, downloadedFile1.path,
"null", "0",
null, null,
DownloadState.Status.COMPLETED DownloadState.Status.COMPLETED
) )
@ -104,4 +104,43 @@ class DownloadFragmentTest {
downloadedFile2.delete() downloadedFile2.delete()
downloadedFile3.delete() downloadedFile3.delete()
} }
@Test
fun `downloads with null content length don't crash`() {
val downloadedFile0 = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"1.pdf"
)
downloadedFile0.createNewFile()
val fragment = DownloadFragment()
val expectedList = listOf(
DownloadItem(
"1",
"1.pdf",
downloadedFile0.path,
"0",
null,
DownloadState.Status.COMPLETED
)
)
val state: BrowserState = mockk(relaxed = true)
every { state.downloads } returns mapOf(
"1" to DownloadState(
id = "1",
createdTime = 1,
url = "url",
fileName = "1.pdf",
contentLength = null,
status = DownloadState.Status.COMPLETED
)
)
val list = fragment.provideDownloads(state)
assertEquals(expectedList[0].size, list[0].size)
}
} }

Loading…
Cancel
Save