Skip to content

Commit

Permalink
Issue mozilla-mobile#7647: Add SessionFeature.release() to allow app …
Browse files Browse the repository at this point in the history
…to stop rendering engine sessions and release the current one.
  • Loading branch information
pocmo committed Jul 9, 2020
1 parent 1df4738 commit 5ba7914
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ class SessionFeature(
override fun stop() {
presenter.stop()
}

/**
* Stops the feature from rendering sessions on the [EngineView] (until explicitly started again)
* and releases an already rendering session from the [EngineView].
*/
fun release() {
// Once we fully migrated to BrowserStore we may be able to get rid of the need for cleanup().
// See https://github.com/mozilla-mobile/android-components/issues/7657
presenter.stop()
engineView.release()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,56 @@ class SessionFeatureTest {
verify(view).release()
}

@Test
fun `release() stops observing and releases session from view`() {
val store = BrowserStore(BrowserState(
tabs = listOf(
createTab("https://www.mozilla.org", id = "A"),
createTab("https://getpocket.com", id = "B"),
createTab("https://www.firefox.com", id = "C")
),
selectedTabId = "B"
))

val view: EngineView = mock()
val useCases: EngineSessionUseCases = mock()
val getOrCreateUseCase: EngineSessionUseCases.GetOrCreateUseCase = mock()
doReturn(getOrCreateUseCase).`when`(useCases).getOrCreateEngineSession

val engineSession: EngineSession = mock()
doReturn(engineSession).`when`(getOrCreateUseCase).invoke(ArgumentMatchers.anyString())

val feature = SessionFeature(store, mock(), useCases, view)

verify(getOrCreateUseCase, never()).invoke(anyString())
verify(view, never()).render(any())

feature.start()

testDispatcher.advanceUntilIdle()
store.waitUntilIdle()

verify(getOrCreateUseCase).invoke("B")
verify(view).render(engineSession)

reset(view)
reset(getOrCreateUseCase)

val newEngineSession: EngineSession = mock()
doReturn(newEngineSession).`when`(getOrCreateUseCase).invoke(ArgumentMatchers.anyString())

feature.release()

verify(view).release()

store.dispatch(
TabListAction.SelectTabAction("A")
).joinBlocking()

verify(getOrCreateUseCase, never()).invoke("A")
verify(view, never()).render(newEngineSession)
}

@Test
fun `Releases when custom tab gets removed`() {
val store = BrowserStore(BrowserState(
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt)

* **feature-session**
* Added `SessionFeature.release()`: Calling this method stops the feature from rendering sessions on the `EngineView` (until explicitly started again) and releases an already rendering session from the `EngineView`.

* **support-ktx**
* Adds `Bundle.contentEquals` function to check if two bundles are equal.

Expand Down

0 comments on commit 5ba7914

Please sign in to comment.