Commit 7739ea98 authored by Arturo Mejia's avatar Arturo Mejia
Browse files

Closes issue #8202: Increase downloadJobState.currentBytesCopied

parent 16343bb7
......@@ -621,7 +621,8 @@ abstract class AbstractFetchDownloadService : Service() {
}
}
private fun copyInChunks(downloadJobState: DownloadJobState, inStream: InputStream, outStream: OutputStream) {
@VisibleForTesting
internal fun copyInChunks(downloadJobState: DownloadJobState, inStream: InputStream, outStream: OutputStream) {
val data = ByteArray(CHUNK_SIZE)
logger.debug("starting copyInChunks ${downloadJobState.state.url}" +
" currentBytesCopied ${downloadJobState.currentBytesCopied}")
......@@ -632,9 +633,10 @@ abstract class AbstractFetchDownloadService : Service() {
// If bytesRead is -1, there's no data left to read from the stream
if (bytesRead == -1) { break }
downloadJobState.currentBytesCopied += bytesRead
val newState = downloadJobState.state.copy(
currentBytesCopied = downloadJobState.currentBytesCopied + bytesRead
currentBytesCopied = downloadJobState.currentBytesCopied
)
updateDownloadState(newState)
......
......@@ -1375,4 +1375,19 @@ class AbstractFetchDownloadServiceTest {
assertTrue(downloadJobState.canUpdateNotification())
}
@Test
fun `copyInChunks must alter download currentBytesCopied`() = runBlocking {
val downloadJobState = DownloadJobState(state = mock(), status = DOWNLOADING)
val inputStream = mock<InputStream>()
assertEquals(0, downloadJobState.currentBytesCopied)
doReturn(15, -1).`when`(inputStream).read(any())
doNothing().`when`(service).updateDownloadState(any())
service.copyInChunks(downloadJobState, inputStream, mock())
assertEquals(15, downloadJobState.currentBytesCopied)
}
}
......@@ -45,6 +45,9 @@ permalink: /changelog/
* **browser-icons**
* Expose `BrowserIcons.clear()` as a public API to remove all saved data from disk and memory caches.
* **feature-downloads**
* 🚒 Fix [issue #8202](https://github.com/mozilla-mobile/android-components/issues/8202) Download's ui were always showing failed status.
# 55.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v54.0.0...v55.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