Skip to content

Commit

Permalink
Closes issue mozilla-mobile#8202: Increase downloadJobState.currentBy…
Browse files Browse the repository at this point in the history
…tesCopied
  • Loading branch information
Amejia481 committed Aug 24, 2020
1 parent 3d47143 commit fb3585b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ permalink: /changelog/
* **feature-app-links**
* Fixed [issue #8169](https://github.com/mozilla-mobile/android-components/issues/8169) App links dialog will now call `showNow` to immediately show the dialog.

* **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)
Expand Down

0 comments on commit fb3585b

Please sign in to comment.