Commit 432c0a58 authored by MozLando's avatar MozLando
Browse files

Merge #7650



7650: Issue #7647: Add SessionFeature.release() to allow app to stop rendering engine sessions and release the current one. r=Amejia481,csadilek a=pocmo

Previously Fenix just called `engineView.release()`. However since `EnginePresenter` is now listening to `BrowserStore` it may re-render the session that we just released. This new methods stops the presenter from updating and releases the current session.
Co-authored-by: default avatarSebastian Kaspari <s.kaspari@gmail.com>
parents 1df47382 5ba7914f
......@@ -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()
}
}
......@@ -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(
......
......@@ -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.
......
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