Closes #17548: Remove SessionManager reference from TabTrayDialogFragment

upstream-sync
Christian Sadilek 3 years ago
parent 0de948e8ae
commit c34d68d915

@ -9,7 +9,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.selector.findTab import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.normalTabs import mozilla.components.browser.state.selector.normalTabs
@ -63,7 +62,6 @@ interface TabTrayController {
* *
* @param activity [Activity] the current activity. * @param activity [Activity] the current activity.
* @param profiler [Profiler] used for profiling. * @param profiler [Profiler] used for profiling.
* @param sessionManager [HomeActivity] used for retrieving a list of sessions.
* @param browserStore [BrowserStore] holds the global [BrowserState]. * @param browserStore [BrowserStore] holds the global [BrowserState].
* @param browsingModeManager [HomeActivity] used for registering browsing mode. * @param browsingModeManager [HomeActivity] used for registering browsing mode.
* @param tabCollectionStorage [TabCollectionStorage] storage for saving collections. * @param tabCollectionStorage [TabCollectionStorage] storage for saving collections.
@ -87,7 +85,6 @@ interface TabTrayController {
class DefaultTabTrayController( class DefaultTabTrayController(
private val activity: HomeActivity, private val activity: HomeActivity,
private val profiler: Profiler?, private val profiler: Profiler?,
private val sessionManager: SessionManager,
private val browserStore: BrowserStore, private val browserStore: BrowserStore,
private val browsingModeManager: BrowsingModeManager, private val browsingModeManager: BrowsingModeManager,
private val tabCollectionStorage: TabCollectionStorage, private val tabCollectionStorage: TabCollectionStorage,

@ -34,6 +34,8 @@ import kotlinx.coroutines.plus
import mozilla.appservices.places.BookmarkRoot import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.state.selector.findTab import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.normalTabs
import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.thumbnails.loader.ThumbnailLoader import mozilla.components.browser.thumbnails.loader.ThumbnailLoader
import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tab.collections.TabCollection
@ -53,7 +55,6 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getDefaultCollectionNumber import org.mozilla.fenix.ext.getDefaultCollectionNumber
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.normalSessionSize
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeScreenViewModel import org.mozilla.fenix.home.HomeScreenViewModel
@ -137,11 +138,12 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
private fun removeIfNotLastTab(sessionId: String) { private fun removeIfNotLastTab(sessionId: String) {
// We only want to *immediately* remove a tab if there are more than one in the tab tray // We only want to *immediately* remove a tab if there are more than one in the tab tray
// If there is only one, the HomeFragment handles deleting the tab (to better support snackbars) // If there is only one, the HomeFragment handles deleting the tab (to better support snackbars)
val sessionManager = view?.context?.components?.core?.sessionManager val browserStore = requireComponents.core.store
val sessionToRemove = sessionManager?.findSessionById(sessionId) val sessionToRemove = browserStore.state.findTab(sessionId)
sessionToRemove?.let {
if (sessionManager?.sessions?.filter { sessionToRemove?.private == it.private }?.size != 1) { if (browserStore.state.getNormalOrPrivateTabs(it.content.private).size != 1) {
requireComponents.useCases.tabsUseCases.removeTab(sessionId) requireComponents.useCases.tabsUseCases.removeTab(sessionId)
}
} }
} }
@ -204,7 +206,6 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
DefaultTabTrayController( DefaultTabTrayController(
activity = activity, activity = activity,
profiler = activity.components.core.engine.profiler, profiler = activity.components.core.engine.profiler,
sessionManager = activity.components.core.sessionManager,
browserStore = activity.components.core.store, browserStore = activity.components.core.store,
tabsUseCases = activity.components.useCases.tabsUseCases, tabsUseCases = activity.components.useCases.tabsUseCases,
ioScope = lifecycleScope + Dispatchers.IO, ioScope = lifecycleScope + Dispatchers.IO,
@ -444,7 +445,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
tabCollectionStorage.addTabsToCollection(collection, sessionList) tabCollectionStorage.addTabsToCollection(collection, sessionList)
it.metrics.track( it.metrics.track(
Event.CollectionTabsAdded( Event.CollectionTabsAdded(
it.components.core.sessionManager.normalSessionSize(), it.components.core.store.state.normalTabs.size,
sessionList.size sessionList.size
) )
) )
@ -490,7 +491,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
) )
it.metrics.track( it.metrics.track(
Event.CollectionSaved( Event.CollectionSaved(
it.components.core.sessionManager.normalSessionSize(), it.components.core.store.state.normalTabs.size,
sessionList.size sessionList.size
) )
) )

@ -18,8 +18,6 @@ import io.mockk.verify
import io.mockk.verifyOrder import io.mockk.verifyOrder
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.state.createTab
@ -41,14 +39,12 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.components.TabCollectionStorage import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.sessionsOfType
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
class DefaultTabTrayControllerTest { class DefaultTabTrayControllerTest {
private val activity: HomeActivity = mockk(relaxed = true) private val activity: HomeActivity = mockk(relaxed = true)
private val profiler: Profiler? = mockk(relaxed = true) private val profiler: Profiler? = mockk(relaxed = true)
private val navController: NavController = mockk() private val navController: NavController = mockk()
private val sessionManager: SessionManager = mockk(relaxed = true)
private val browsingModeManager: BrowsingModeManager = mockk(relaxed = true) private val browsingModeManager: BrowsingModeManager = mockk(relaxed = true)
private val dismissTabTray: (() -> Unit) = mockk(relaxed = true) private val dismissTabTray: (() -> Unit) = mockk(relaxed = true)
private val dismissTabTrayAndNavigateHome: ((String) -> Unit) = mockk(relaxed = true) private val dismissTabTrayAndNavigateHome: ((String) -> Unit) = mockk(relaxed = true)
@ -72,16 +68,6 @@ class DefaultTabTrayControllerTest {
private val tab1 = createTab(url = "http://firefox.com", id = "5678") private val tab1 = createTab(url = "http://firefox.com", id = "5678")
private val tab2 = createTab(url = "http://mozilla.org", id = "1234") private val tab2 = createTab(url = "http://mozilla.org", id = "1234")
private val session = Session(
"mozilla.org",
true
)
private val nonPrivateSession = Session(
"mozilla.org",
false
)
@Before @Before
fun setUp() { fun setUp() {
mockkStatic("org.mozilla.fenix.ext.SessionManagerKt") mockkStatic("org.mozilla.fenix.ext.SessionManagerKt")
@ -92,15 +78,7 @@ class DefaultTabTrayControllerTest {
) )
) )
every { sessionManager.sessionsOfType(private = true) } returns listOf(session).asSequence()
every { sessionManager.sessionsOfType(private = false) } returns listOf(nonPrivateSession).asSequence()
every { sessionManager.createSessionSnapshot(any()) } returns SessionManager.Snapshot.Item(
session
)
every { sessionManager.findSessionById("1234") } returns session
every { sessionManager.remove(any()) } just Runs
every { tabCollectionStorage.cachedTabCollections } returns cachedTabCollections every { tabCollectionStorage.cachedTabCollections } returns cachedTabCollections
every { sessionManager.selectedSession } returns nonPrivateSession
every { navController.navigate(any<NavDirections>()) } just Runs every { navController.navigate(any<NavDirections>()) } just Runs
every { navController.currentDestination } returns currentDestination every { navController.currentDestination } returns currentDestination
every { currentDestination.id } returns R.id.browserFragment every { currentDestination.id } returns R.id.browserFragment
@ -109,7 +87,6 @@ class DefaultTabTrayControllerTest {
controller = DefaultTabTrayController( controller = DefaultTabTrayController(
activity = activity, activity = activity,
profiler = profiler, profiler = profiler,
sessionManager = sessionManager,
browserStore = store, browserStore = store,
browsingModeManager = browsingModeManager, browsingModeManager = browsingModeManager,
tabCollectionStorage = tabCollectionStorage, tabCollectionStorage = tabCollectionStorage,

Loading…
Cancel
Save