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

Commit

Permalink
For #7364 - Adds sessionId to DownloadState and populates it in Conte…
Browse files Browse the repository at this point in the history
…ntStateReducer
  • Loading branch information
codrut.topliceanu committed Jun 15, 2020
1 parent 7cb2889 commit 0f9d037
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal object ContentStateReducer {
it.copy(thumbnail = action.thumbnail)
}
is ContentAction.UpdateDownloadAction -> updateContentState(state, action.sessionId) {
it.copy(download = action.download)
it.copy(download = action.download.copy(sessionId = action.sessionId))
}
is ContentAction.ConsumeDownloadAction -> updateContentState(state, action.sessionId) {
if (it.download != null && it.download.id == action.downloadId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import kotlin.random.Random
* @property referrerUrl The site that linked to this download.
* @property skipConfirmation Whether or not the confirmation dialog should be shown before the download begins.
* @property id The unique identifier of this download.
* @property sessionId Identifier of the session that spawned the download.
* @
*/
@Suppress("Deprecation")
@Parcelize
Expand All @@ -34,7 +36,8 @@ data class DownloadState(
val destinationDirectory: String = Environment.DIRECTORY_DOWNLOADS,
val referrerUrl: String? = null,
val skipConfirmation: Boolean = false,
val id: Long = Random.nextLong()
val id: Long = Random.nextLong(),
val sessionId: String? = null
) : Parcelable {
val filePath: String get() =
Environment.getExternalStoragePublicDirectory(destinationDirectory).path + "/" + fileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ class DownloadsFeature(
flow.mapNotNull { state -> state.findTabOrCustomTabOrSelectedTab(tabId) }
.ifChanged { it.content.download }
.collect { state ->
val download = state.content.download
if (download != null) {
processDownload(state, download)
state.content.download?.let { downloadState ->
processDownload(state, downloadState)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ class DownloadsFeatureTest {
feature.start()

verify(fragmentManager, never()).beginTransaction()
val download = DownloadState(url = "https://www.mozilla.org", sessionId = "test-tab")

store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download = mock()))
store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
.joinBlocking()

testDispatcher.advanceUntilIdle()
Expand Down Expand Up @@ -166,7 +167,7 @@ class DownloadsFeatureTest {

verify(downloadManager, never()).download(any(), anyString())

val download = DownloadState(url = "https://www.mozilla.org")
val download = DownloadState(url = "https://www.mozilla.org", sessionId = "test-tab")
store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
.joinBlocking()

Expand Down Expand Up @@ -200,7 +201,8 @@ class DownloadsFeatureTest {

val download = DownloadState(
url = "https://www.mozilla.org",
skipConfirmation = true
skipConfirmation = true,
sessionId = "test-tab"
)

store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
Expand All @@ -218,7 +220,8 @@ class DownloadsFeatureTest {
fun `When starting the feature will reattach to already existing dialog`() {
grantPermissions()

store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download = mock()))
val download = DownloadState(url = "https://www.mozilla.org", sessionId = "test-tab")
store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
.joinBlocking()

val dialogFragment: DownloadDialogFragment = mock()
Expand Down Expand Up @@ -364,7 +367,7 @@ class DownloadsFeatureTest {
verify(downloadManager, never()).download(any(), anyString())
verify(feature, never()).showDownloadNotSupportedError()

val download = DownloadState(url = "https://www.mozilla.org")
val download = DownloadState(url = "https://www.mozilla.org", sessionId = "test-tab")
store.dispatch(ContentAction.UpdateDownloadAction("test-tab", download))
.joinBlocking()

Expand Down

0 comments on commit 0f9d037

Please sign in to comment.