mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/20533: Fix intermittent failures of DefaultSessionControlControllerTest
This commit is contained in:
parent
f3027746bf
commit
fb66b53852
@ -34,6 +34,7 @@ import mozilla.components.feature.top.sites.TopSite
|
||||
import mozilla.components.support.test.ext.joinBlocking
|
||||
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
@ -71,10 +72,6 @@ class DefaultSessionControlControllerTest {
|
||||
private val tabsUseCases: TabsUseCases = mockk(relaxed = true)
|
||||
private val reloadUrlUseCase: SessionUseCases = mockk(relaxed = true)
|
||||
private val selectTabUseCase: TabsUseCases = mockk(relaxed = true)
|
||||
private val hideOnboarding: () -> Unit = mockk(relaxed = true)
|
||||
private val registerCollectionStorageObserver: () -> Unit = mockk(relaxed = true)
|
||||
private val showTabTray: () -> Unit = mockk(relaxed = true)
|
||||
private val handleSwipedItemDeletionCancel: () -> Unit = mockk(relaxed = true)
|
||||
private val showDeleteCollectionPrompt: (
|
||||
tabCollection: TabCollection,
|
||||
title: String?,
|
||||
@ -112,7 +109,6 @@ class DefaultSessionControlControllerTest {
|
||||
)
|
||||
|
||||
private lateinit var store: BrowserStore
|
||||
private lateinit var controller: DefaultSessionControlController
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
@ -142,31 +138,6 @@ class DefaultSessionControlControllerTest {
|
||||
every { activity.settings() } returns settings
|
||||
every { activity.components.analytics } returns analytics
|
||||
every { analytics.metrics } returns metrics
|
||||
|
||||
val restoreUseCase: TabsUseCases.RestoreUseCase = mockk(relaxed = true)
|
||||
|
||||
controller = spyk(
|
||||
DefaultSessionControlController(
|
||||
activity = activity,
|
||||
store = store,
|
||||
settings = settings,
|
||||
engine = engine,
|
||||
metrics = metrics,
|
||||
tabCollectionStorage = tabCollectionStorage,
|
||||
addTabUseCase = tabsUseCases.addTab,
|
||||
reloadUrlUseCase = reloadUrlUseCase.reload,
|
||||
selectTabUseCase = selectTabUseCase.selectTab,
|
||||
restoreUseCase = restoreUseCase,
|
||||
fragmentStore = fragmentStore,
|
||||
navController = navController,
|
||||
viewLifecycleScope = scope,
|
||||
hideOnboarding = hideOnboarding,
|
||||
registerCollectionStorageObserver = registerCollectionStorageObserver,
|
||||
showDeleteCollectionPrompt = showDeleteCollectionPrompt,
|
||||
showTabTray = showTabTray,
|
||||
handleSwipedItemDeletionCancel = handleSwipedItemDeletionCancel
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@After
|
||||
@ -180,7 +151,7 @@ class DefaultSessionControlControllerTest {
|
||||
val collection = mockk<TabCollection> {
|
||||
every { id } returns 12L
|
||||
}
|
||||
controller.handleCollectionAddTabTapped(collection)
|
||||
createController().handleCollectionAddTabTapped(collection)
|
||||
|
||||
verify { metrics.track(Event.CollectionAddTabPressed) }
|
||||
verify {
|
||||
@ -199,7 +170,7 @@ class DefaultSessionControlControllerTest {
|
||||
every { url } returns "https://mozilla.org"
|
||||
every { restore(activity, engine, restoreSessionId = false) } returns null
|
||||
}
|
||||
controller.handleCollectionOpenTabClicked(tab)
|
||||
createController().handleCollectionOpenTabClicked(tab)
|
||||
|
||||
verify { metrics.track(Event.CollectionTabRestored) }
|
||||
verify {
|
||||
@ -235,7 +206,7 @@ class DefaultSessionControlControllerTest {
|
||||
store.dispatch(TabListAction.SelectTabAction(otherTab.id)).joinBlocking()
|
||||
store.dispatch(TabListAction.AddTabAction(restoredTab)).joinBlocking()
|
||||
|
||||
controller.handleCollectionOpenTabClicked(tab)
|
||||
createController().handleCollectionOpenTabClicked(tab)
|
||||
verify { metrics.track(Event.CollectionTabRestored) }
|
||||
verify { activity.openToBrowser(BrowserDirection.FromHome) }
|
||||
verify { selectTabUseCase.selectTab.invoke(restoredTab.id) }
|
||||
@ -263,7 +234,7 @@ class DefaultSessionControlControllerTest {
|
||||
val restoredTab = createTab(id = recoverableTab.id, url = recoverableTab.url)
|
||||
store.dispatch(TabListAction.AddTabAction(restoredTab)).joinBlocking()
|
||||
|
||||
controller.handleCollectionOpenTabClicked(tab)
|
||||
createController().handleCollectionOpenTabClicked(tab)
|
||||
verify { metrics.track(Event.CollectionTabRestored) }
|
||||
verify { activity.openToBrowser(BrowserDirection.FromHome) }
|
||||
verify { selectTabUseCase.selectTab.invoke(restoredTab.id) }
|
||||
@ -275,7 +246,7 @@ class DefaultSessionControlControllerTest {
|
||||
val collection = mockk<TabCollection> {
|
||||
every { tabs } returns emptyList()
|
||||
}
|
||||
controller.handleCollectionOpenTabsTapped(collection)
|
||||
createController().handleCollectionOpenTabsTapped(collection)
|
||||
|
||||
verify { metrics.track(Event.CollectionAllTabsRestored) }
|
||||
}
|
||||
@ -297,7 +268,7 @@ class DefaultSessionControlControllerTest {
|
||||
activity.resources.getString(R.string.delete_tab_and_collection_dialog_message)
|
||||
} returns "Deleting this tab will delete everything."
|
||||
|
||||
controller.handleCollectionRemoveTab(collection, tab, false)
|
||||
createController().handleCollectionRemoveTab(collection, tab, false)
|
||||
|
||||
verify { metrics.track(Event.CollectionTabRemoved) }
|
||||
verify {
|
||||
@ -306,7 +277,7 @@ class DefaultSessionControlControllerTest {
|
||||
"Delete Collection?",
|
||||
"Deleting this tab will delete everything.",
|
||||
false,
|
||||
handleSwipedItemDeletionCancel
|
||||
any()
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -315,7 +286,7 @@ class DefaultSessionControlControllerTest {
|
||||
fun `handleCollectionRemoveTab multiple tabs`() {
|
||||
val collection: TabCollection = mockk(relaxed = true)
|
||||
val tab: ComponentTab = mockk(relaxed = true)
|
||||
controller.handleCollectionRemoveTab(collection, tab, false)
|
||||
createController().handleCollectionRemoveTab(collection, tab, false)
|
||||
verify { metrics.track(Event.CollectionTabRemoved) }
|
||||
}
|
||||
|
||||
@ -325,7 +296,7 @@ class DefaultSessionControlControllerTest {
|
||||
every { tabs } returns emptyList()
|
||||
every { title } returns ""
|
||||
}
|
||||
controller.handleCollectionShareTabsClicked(collection)
|
||||
createController().handleCollectionShareTabsClicked(collection)
|
||||
|
||||
verify { metrics.track(Event.CollectionShared) }
|
||||
verify {
|
||||
@ -345,21 +316,21 @@ class DefaultSessionControlControllerTest {
|
||||
activity.resources.getString(R.string.tab_collection_dialog_message, "Collection")
|
||||
} returns "Are you sure you want to delete Collection?"
|
||||
|
||||
controller.handleDeleteCollectionTapped(collection)
|
||||
createController().handleDeleteCollectionTapped(collection)
|
||||
verify {
|
||||
showDeleteCollectionPrompt(
|
||||
collection,
|
||||
null,
|
||||
"Are you sure you want to delete Collection?",
|
||||
false,
|
||||
handleSwipedItemDeletionCancel
|
||||
any()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handlePrivateBrowsingLearnMoreClicked() {
|
||||
controller.handlePrivateBrowsingLearnMoreClicked()
|
||||
createController().handlePrivateBrowsingLearnMoreClicked()
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = SupportUtils.getGenericSumoURLForTopic
|
||||
@ -375,7 +346,7 @@ class DefaultSessionControlControllerTest {
|
||||
val collection = mockk<TabCollection> {
|
||||
every { id } returns 3L
|
||||
}
|
||||
controller.handleRenameCollectionTapped(collection)
|
||||
createController().handleRenameCollectionTapped(collection)
|
||||
|
||||
verify { metrics.track(Event.CollectionRenamePressed) }
|
||||
verify {
|
||||
@ -389,6 +360,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectDefaultTopSite() {
|
||||
val topSiteUrl = "mozilla.org"
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
controller.handleSelectTopSite(topSiteUrl, TopSite.Type.DEFAULT)
|
||||
@ -407,6 +379,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectNonDefaultTopSite() {
|
||||
val topSiteUrl = "mozilla.org"
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
controller.handleSelectTopSite(topSiteUrl, TopSite.Type.FRECENT)
|
||||
@ -424,6 +397,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGoogleDefaultTopSiteUS() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("US", "US"))).joinBlocking()
|
||||
@ -445,6 +419,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGoogleDefaultTopSiteXX() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("DE", "FR"))).joinBlocking()
|
||||
@ -467,6 +442,7 @@ class DefaultSessionControlControllerTest {
|
||||
fun handleSelectGoogleDefaultTopSite_EventPerformedSearchTopSite() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val engineSource = EngineSource.Default(googleSearchEngine, false)
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(googleSearchEngine)
|
||||
try {
|
||||
mockkStatic("mozilla.components.browser.state.state.SearchStateKt")
|
||||
@ -495,6 +471,7 @@ class DefaultSessionControlControllerTest {
|
||||
fun handleSelectDuckDuckGoTopSite_EventPerformedSearchTopSite() {
|
||||
val topSiteUrl = "https://duckduckgo.com"
|
||||
val engineSource = EngineSource.Shortcut(duckDuckGoSearchEngine, false)
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(googleSearchEngine, duckDuckGoSearchEngine)
|
||||
try {
|
||||
mockkStatic("mozilla.components.browser.state.state.SearchStateKt")
|
||||
@ -522,6 +499,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGooglePinnedTopSiteUS() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("US", "US"))).joinBlocking()
|
||||
@ -543,6 +521,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGooglePinnedTopSiteXX() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("DE", "FR"))).joinBlocking()
|
||||
@ -564,6 +543,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGoogleFrecentTopSiteUS() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("US", "US"))).joinBlocking()
|
||||
@ -585,6 +565,7 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleSelectGoogleFrecentTopSiteXX() {
|
||||
val topSiteUrl = SupportUtils.GOOGLE_URL
|
||||
val controller = spyk(createController())
|
||||
every { controller.getAvailableSearchEngines() } returns listOf(searchEngine)
|
||||
|
||||
store.dispatch(SearchAction.SetRegionAction(RegionState("DE", "FR"))).joinBlocking()
|
||||
@ -605,13 +586,15 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handleStartBrowsingClicked() {
|
||||
controller.handleStartBrowsingClicked()
|
||||
verify { hideOnboarding() }
|
||||
var hideOnboardingInvoked = false
|
||||
createController(hideOnboarding = { hideOnboardingInvoked = true }).handleStartBrowsingClicked()
|
||||
|
||||
assertTrue(hideOnboardingInvoked)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleOpenSettingsClicked() {
|
||||
controller.handleOpenSettingsClicked()
|
||||
createController().handleOpenSettingsClicked()
|
||||
verify {
|
||||
navController.navigate(
|
||||
match<NavDirections> { it.actionId == R.id.action_global_privateBrowsingFragment },
|
||||
@ -622,7 +605,7 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handleWhatsNewGetAnswersClicked() {
|
||||
controller.handleWhatsNewGetAnswersClicked()
|
||||
createController().handleWhatsNewGetAnswersClicked()
|
||||
val whatsNewUrl = SupportUtils.getWhatsNewUrl(activity)
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
@ -635,7 +618,7 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handleReadPrivacyNoticeClicked() {
|
||||
controller.handleReadPrivacyNoticeClicked()
|
||||
createController().handleReadPrivacyNoticeClicked()
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.PRIVATE_NOTICE),
|
||||
@ -648,20 +631,20 @@ class DefaultSessionControlControllerTest {
|
||||
@Test
|
||||
fun handleToggleCollectionExpanded() {
|
||||
val collection = mockk<TabCollection>()
|
||||
controller.handleToggleCollectionExpanded(collection, true)
|
||||
createController().handleToggleCollectionExpanded(collection, true)
|
||||
verify { fragmentStore.dispatch(HomeFragmentAction.CollectionExpanded(collection, true)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleCloseTip() {
|
||||
val tip = mockk<Tip>()
|
||||
controller.handleCloseTip(tip)
|
||||
createController().handleCloseTip(tip)
|
||||
verify { fragmentStore.dispatch(HomeFragmentAction.RemoveTip(tip)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleCreateCollection() {
|
||||
controller.handleCreateCollection()
|
||||
createController().handleCreateCollection()
|
||||
|
||||
verify {
|
||||
navController.navigate(
|
||||
@ -673,7 +656,7 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handlePasteAndGo() {
|
||||
controller.handlePasteAndGo("text")
|
||||
createController().handlePasteAndGo("text")
|
||||
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
@ -685,7 +668,7 @@ class DefaultSessionControlControllerTest {
|
||||
metrics.track(any<Event.PerformedSearch>())
|
||||
}
|
||||
|
||||
controller.handlePasteAndGo("https://mozilla.org")
|
||||
createController().handlePasteAndGo("https://mozilla.org")
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = "https://mozilla.org",
|
||||
@ -699,7 +682,7 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handlePaste() {
|
||||
controller.handlePaste("text")
|
||||
createController().handlePaste("text")
|
||||
|
||||
verify {
|
||||
navController.navigate(
|
||||
@ -711,7 +694,7 @@ class DefaultSessionControlControllerTest {
|
||||
|
||||
@Test
|
||||
fun handleRemoveCollectionsPlaceholder() {
|
||||
controller.handleRemoveCollectionsPlaceholder()
|
||||
createController().handleRemoveCollectionsPlaceholder()
|
||||
|
||||
verify {
|
||||
settings.showCollectionsPlaceholderOnHome = false
|
||||
@ -726,7 +709,7 @@ class DefaultSessionControlControllerTest {
|
||||
every { id } returns R.id.searchDialogFragment
|
||||
}
|
||||
|
||||
controller.handleMenuOpened()
|
||||
createController().handleMenuOpened()
|
||||
|
||||
verify {
|
||||
navController.navigateUp()
|
||||
@ -739,10 +722,38 @@ class DefaultSessionControlControllerTest {
|
||||
every { id } returns R.id.homeFragment
|
||||
}
|
||||
|
||||
controller.handleMenuOpened()
|
||||
createController().handleMenuOpened()
|
||||
|
||||
verify(exactly = 0) {
|
||||
navController.navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createController(
|
||||
hideOnboarding: () -> Unit = { },
|
||||
registerCollectionStorageObserver: () -> Unit = { },
|
||||
showTabTray: () -> Unit = { },
|
||||
handleSwipedItemDeletionCancel: () -> Unit = { }
|
||||
): DefaultSessionControlController {
|
||||
return DefaultSessionControlController(
|
||||
activity = activity,
|
||||
store = store,
|
||||
settings = settings,
|
||||
engine = engine,
|
||||
metrics = metrics,
|
||||
tabCollectionStorage = tabCollectionStorage,
|
||||
addTabUseCase = tabsUseCases.addTab,
|
||||
reloadUrlUseCase = reloadUrlUseCase.reload,
|
||||
selectTabUseCase = selectTabUseCase.selectTab,
|
||||
restoreUseCase = mockk(relaxed = true),
|
||||
fragmentStore = fragmentStore,
|
||||
navController = navController,
|
||||
viewLifecycleScope = scope,
|
||||
hideOnboarding = hideOnboarding,
|
||||
registerCollectionStorageObserver = registerCollectionStorageObserver,
|
||||
showDeleteCollectionPrompt = showDeleteCollectionPrompt,
|
||||
showTabTray = showTabTray,
|
||||
handleSwipedItemDeletionCancel = handleSwipedItemDeletionCancel
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user