Bug 1820211 - Adds `tabKilled` event to track when a tab was killed with form data. (#1343)
* Bug 1820211 - Adds `tabKilled` event to track when a tab was killed with form data. - Also includes if the tab was the active tab and whether the app was in the foreground. * Bug 1820211 - Adds tests for TelemetryMiddleware and StoreLifecycleObserver * Bug 1820211 - Renames CheckFormDataAction to UpdateHasFormData - Removes @property hasFormData comment from sessionState - Moves checking formdata from TabContentMiddleware to SessionPrioritizationMiddleware --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>fenix/113.0
parent
ade756f899
commit
70d4b7cd46
@ -0,0 +1,33 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.lifecycle
|
||||
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import mozilla.components.browser.state.action.AppLifecycleAction
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import org.mozilla.fenix.components.AppStore
|
||||
import org.mozilla.fenix.components.appstate.AppAction
|
||||
|
||||
/**
|
||||
* [LifecycleObserver] to dispatch app lifecycle actions to the [AppStore] and [BrowserStore].
|
||||
*/
|
||||
class StoreLifecycleObserver(
|
||||
private val appStore: AppStore,
|
||||
private val browserStore: BrowserStore,
|
||||
) : DefaultLifecycleObserver {
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
super.onPause(owner)
|
||||
appStore.dispatch(AppAction.AppLifecycleAction.PauseAction)
|
||||
browserStore.dispatch(AppLifecycleAction.PauseAction)
|
||||
}
|
||||
|
||||
override fun onResume(owner: LifecycleOwner) {
|
||||
super.onResume(owner)
|
||||
appStore.dispatch(AppAction.AppLifecycleAction.ResumeAction)
|
||||
browserStore.dispatch(AppLifecycleAction.ResumeAction)
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.lifecycle
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verifySequence
|
||||
import mozilla.components.browser.state.action.AppLifecycleAction
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.service.glean.testing.GleanTestRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.components.AppStore
|
||||
import org.mozilla.fenix.components.appstate.AppAction
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class StoreLifecycleObserverTest {
|
||||
@get:Rule
|
||||
val gleanRule = GleanTestRule(ApplicationProvider.getApplicationContext())
|
||||
|
||||
@Test
|
||||
fun `WHEN onPause is called THEN dispatch PauseAction`() {
|
||||
val appStore: AppStore = mockk(relaxed = true)
|
||||
val browserStore: BrowserStore = mockk(relaxed = true)
|
||||
val observer = StoreLifecycleObserver(appStore, browserStore)
|
||||
|
||||
observer.onPause(mockk())
|
||||
|
||||
verifySequence {
|
||||
appStore.dispatch(AppAction.AppLifecycleAction.PauseAction)
|
||||
browserStore.dispatch(AppLifecycleAction.PauseAction)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN onResume is called THEN dispatch ResumeAction`() {
|
||||
val appStore: AppStore = mockk(relaxed = true)
|
||||
val browserStore: BrowserStore = mockk(relaxed = true)
|
||||
val observer = StoreLifecycleObserver(appStore, browserStore)
|
||||
|
||||
observer.onResume(mockk())
|
||||
|
||||
verifySequence {
|
||||
appStore.dispatch(AppAction.AppLifecycleAction.ResumeAction)
|
||||
browserStore.dispatch(AppLifecycleAction.ResumeAction)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue