2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Closes #17473: Intermittent failues of PwaOnboardingObserver

This commit is contained in:
Christian Sadilek 2021-01-22 16:17:11 -05:00
parent 70dc975299
commit 7001fa1735
2 changed files with 18 additions and 20 deletions

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.shortcut package org.mozilla.fenix.shortcut
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController import androidx.navigation.NavController
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -47,9 +48,7 @@ class PwaOnboardingObserver(
if (webAppUseCases.isInstallable() && !settings.userKnowsAboutPwas) { if (webAppUseCases.isInstallable() && !settings.userKnowsAboutPwas) {
settings.incrementVisitedInstallableCount() settings.incrementVisitedInstallableCount()
if (settings.shouldShowPwaCfr) { if (settings.shouldShowPwaCfr) {
val directions = navigateToPwaOnboarding()
BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment()
navController.nav(R.id.browserFragment, directions)
settings.lastCfrShownTimeInMillis = System.currentTimeMillis() settings.lastCfrShownTimeInMillis = System.currentTimeMillis()
settings.userKnowsAboutPwas = true settings.userKnowsAboutPwas = true
} }
@ -61,4 +60,12 @@ class PwaOnboardingObserver(
fun stop() { fun stop() {
scope?.cancel() scope?.cancel()
} }
@VisibleForTesting
internal fun navigateToPwaOnboarding() {
navController.nav(
R.id.browserFragment,
BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment()
)
}
} }

View File

@ -10,6 +10,7 @@ import androidx.lifecycle.LifecycleRegistry
import androidx.navigation.NavController import androidx.navigation.NavController
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineDispatcher
@ -24,9 +25,6 @@ import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@ -54,17 +52,19 @@ class PwaOnboardingObserverTest {
) )
) )
lifecycleOwner = MockedLifecycleOwner(Lifecycle.State.STARTED) lifecycleOwner = MockedLifecycleOwner(Lifecycle.State.STARTED)
navigationController = mockk(relaxed = true) navigationController = mockk(relaxed = true)
settings = mockk(relaxed = true) settings = mockk(relaxed = true)
webAppUseCases = mockk(relaxed = true) webAppUseCases = mockk(relaxed = true)
pwaOnboardingObserver = PwaOnboardingObserver( pwaOnboardingObserver = spyk(PwaOnboardingObserver(
store = store, store = store,
lifecycleOwner = lifecycleOwner, lifecycleOwner = lifecycleOwner,
navController = navigationController, navController = navigationController,
settings = settings, settings = settings,
webAppUseCases = webAppUseCases webAppUseCases = webAppUseCases
) ))
every { pwaOnboardingObserver.navigateToPwaOnboarding() } returns Unit
} }
@After @After
@ -81,10 +81,7 @@ class PwaOnboardingObserverTest {
store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking() store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking()
verify { settings.incrementVisitedInstallableCount() } verify { settings.incrementVisitedInstallableCount() }
verify(exactly = 0) { navigationController.nav( verify(exactly = 0) { pwaOnboardingObserver.navigateToPwaOnboarding() }
R.id.browserFragment,
BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment())
}
} }
@Test @Test
@ -96,10 +93,7 @@ class PwaOnboardingObserverTest {
store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking() store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking()
verify { settings.incrementVisitedInstallableCount() } verify { settings.incrementVisitedInstallableCount() }
verify { navigationController.nav( verify { pwaOnboardingObserver.navigateToPwaOnboarding() }
R.id.browserFragment,
BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment())
}
} }
@Test @Test
@ -111,10 +105,7 @@ class PwaOnboardingObserverTest {
store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking() store.dispatch(ContentAction.UpdateWebAppManifestAction("1", mockk())).joinBlocking()
verify(exactly = 0) { settings.incrementVisitedInstallableCount() } verify(exactly = 0) { settings.incrementVisitedInstallableCount() }
verify(exactly = 0) { navigationController.nav( verify(exactly = 0) { pwaOnboardingObserver.navigateToPwaOnboarding() }
R.id.browserFragment,
BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment())
}
} }
internal class MockedLifecycleOwner(initialState: Lifecycle.State) : LifecycleOwner { internal class MockedLifecycleOwner(initialState: Lifecycle.State) : LifecycleOwner {