|
|
|
@ -24,11 +24,16 @@ import mozilla.components.browser.state.state.createTab
|
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
|
import mozilla.components.concept.base.profiler.Profiler
|
|
|
|
|
import mozilla.components.feature.tabs.TabsUseCases
|
|
|
|
|
import mozilla.components.service.glean.testing.GleanTestRule
|
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.mozilla.fenix.GleanMetrics.TabsTray
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
|
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
|
|
@ -36,7 +41,9 @@ import org.mozilla.fenix.components.metrics.MetricController
|
|
|
|
|
import org.mozilla.fenix.home.HomeFragment
|
|
|
|
|
import org.mozilla.fenix.ext.maxActiveTime
|
|
|
|
|
import org.mozilla.fenix.ext.potentialInactiveTabs
|
|
|
|
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|
|
|
|
|
|
|
|
|
@RunWith(FenixRobolectricTestRunner::class) // for gleanTestRule
|
|
|
|
|
class DefaultTabsTrayControllerTest {
|
|
|
|
|
@MockK(relaxed = true)
|
|
|
|
|
private lateinit var trayStore: TabsTrayStore
|
|
|
|
@ -62,6 +69,9 @@ class DefaultTabsTrayControllerTest {
|
|
|
|
|
@MockK(relaxed = true)
|
|
|
|
|
private lateinit var tabsUseCases: TabsUseCases
|
|
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
|
val gleanTestRule = GleanTestRule(testContext)
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setup() {
|
|
|
|
|
MockKAnnotations.init(this)
|
|
|
|
@ -327,6 +337,11 @@ class DefaultTabsTrayControllerTest {
|
|
|
|
|
|
|
|
|
|
controller.handleMultipleTabsDeletion(listOf(privateTab, mockk()))
|
|
|
|
|
|
|
|
|
|
assertTrue(TabsTray.closeSelectedTabs.testHasValue())
|
|
|
|
|
val snapshot = TabsTray.closeSelectedTabs.testGetValue()
|
|
|
|
|
assertEquals(1, snapshot.size)
|
|
|
|
|
assertEquals("2", snapshot.single().extra?.getValue("tab_count"))
|
|
|
|
|
|
|
|
|
|
verify { controller.dismissTabsTrayAndNavigateHome(HomeFragment.ALL_PRIVATE_TABS) }
|
|
|
|
|
assertTrue(showUndoSnackbarForTabInvoked)
|
|
|
|
|
verify(exactly = 0) { tabsUseCases.removeTabs(any()) }
|
|
|
|
@ -356,6 +371,11 @@ class DefaultTabsTrayControllerTest {
|
|
|
|
|
|
|
|
|
|
controller.handleMultipleTabsDeletion(listOf(normalTab, normalTab))
|
|
|
|
|
|
|
|
|
|
assertTrue(TabsTray.closeSelectedTabs.testHasValue())
|
|
|
|
|
val snapshot = TabsTray.closeSelectedTabs.testGetValue()
|
|
|
|
|
assertEquals(1, snapshot.size)
|
|
|
|
|
assertEquals("2", snapshot.single().extra?.getValue("tab_count"))
|
|
|
|
|
|
|
|
|
|
verify { controller.dismissTabsTrayAndNavigateHome(HomeFragment.ALL_NORMAL_TABS) }
|
|
|
|
|
verify(exactly = 0) { tabsUseCases.removeTabs(any()) }
|
|
|
|
|
assertTrue(showUndoSnackbarForTabInvoked)
|
|
|
|
@ -377,6 +397,11 @@ class DefaultTabsTrayControllerTest {
|
|
|
|
|
|
|
|
|
|
controller.handleMultipleTabsDeletion(listOf(privateTab))
|
|
|
|
|
|
|
|
|
|
assertTrue(TabsTray.closeSelectedTabs.testHasValue())
|
|
|
|
|
val snapshot = TabsTray.closeSelectedTabs.testGetValue()
|
|
|
|
|
assertEquals(1, snapshot.size)
|
|
|
|
|
assertEquals("1", snapshot.single().extra?.getValue("tab_count"))
|
|
|
|
|
|
|
|
|
|
verify { tabsUseCases.removeTabs(listOf("42")) }
|
|
|
|
|
verify(exactly = 0) { controller.dismissTabsTrayAndNavigateHome(any()) }
|
|
|
|
|
assertTrue(showUndoSnackbarForTabInvoked)
|
|
|
|
@ -398,6 +423,11 @@ class DefaultTabsTrayControllerTest {
|
|
|
|
|
|
|
|
|
|
controller.handleMultipleTabsDeletion(listOf(privateTab))
|
|
|
|
|
|
|
|
|
|
assertTrue(TabsTray.closeSelectedTabs.testHasValue())
|
|
|
|
|
val snapshot = TabsTray.closeSelectedTabs.testGetValue()
|
|
|
|
|
assertEquals(1, snapshot.size)
|
|
|
|
|
assertEquals("1", snapshot.single().extra?.getValue("tab_count"))
|
|
|
|
|
|
|
|
|
|
verify { tabsUseCases.removeTabs(listOf("24")) }
|
|
|
|
|
verify(exactly = 0) { controller.dismissTabsTrayAndNavigateHome(any()) }
|
|
|
|
|
assertTrue(showUndoSnackbarForTabInvoked)
|
|
|
|
|