2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/17548: Remove SessionManager reference from TabTrayDialogFragment

This commit is contained in:
Christian Sadilek 2021-01-20 15:34:30 -05:00
parent 525bf428b4
commit 73abe98ba7
3 changed files with 10 additions and 35 deletions

View File

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

View File

@ -34,6 +34,8 @@ import kotlinx.coroutines.plus
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session
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.thumbnails.loader.ThumbnailLoader
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.getDefaultCollectionNumber
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.normalSessionSize
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeScreenViewModel
@ -137,11 +138,12 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
private fun removeIfNotLastTab(sessionId: String) {
// 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)
val sessionManager = view?.context?.components?.core?.sessionManager
val sessionToRemove = sessionManager?.findSessionById(sessionId)
if (sessionManager?.sessions?.filter { sessionToRemove?.private == it.private }?.size != 1) {
requireComponents.useCases.tabsUseCases.removeTab(sessionId)
val browserStore = requireComponents.core.store
val sessionToRemove = browserStore.state.findTab(sessionId)
sessionToRemove?.let {
if (browserStore.state.getNormalOrPrivateTabs(it.content.private).size != 1) {
requireComponents.useCases.tabsUseCases.removeTab(sessionId)
}
}
}
@ -204,7 +206,6 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
DefaultTabTrayController(
activity = activity,
profiler = activity.components.core.engine.profiler,
sessionManager = activity.components.core.sessionManager,
browserStore = activity.components.core.store,
tabsUseCases = activity.components.useCases.tabsUseCases,
ioScope = lifecycleScope + Dispatchers.IO,
@ -444,7 +445,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
tabCollectionStorage.addTabsToCollection(collection, sessionList)
it.metrics.track(
Event.CollectionTabsAdded(
it.components.core.sessionManager.normalSessionSize(),
it.components.core.store.state.normalTabs.size,
sessionList.size
)
)
@ -490,7 +491,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
)
it.metrics.track(
Event.CollectionSaved(
it.components.core.sessionManager.normalSessionSize(),
it.components.core.store.state.normalTabs.size,
sessionList.size
)
)

View File

@ -18,8 +18,6 @@ import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.ExperimentalCoroutinesApi
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.TabSessionState
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.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.sessionsOfType
@OptIn(ExperimentalCoroutinesApi::class)
class DefaultTabTrayControllerTest {
private val activity: HomeActivity = mockk(relaxed = true)
private val profiler: Profiler? = mockk(relaxed = true)
private val navController: NavController = mockk()
private val sessionManager: SessionManager = mockk(relaxed = true)
private val browsingModeManager: BrowsingModeManager = mockk(relaxed = true)
private val dismissTabTray: (() -> 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 tab2 = createTab(url = "http://mozilla.org", id = "1234")
private val session = Session(
"mozilla.org",
true
)
private val nonPrivateSession = Session(
"mozilla.org",
false
)
@Before
fun setUp() {
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 { sessionManager.selectedSession } returns nonPrivateSession
every { navController.navigate(any<NavDirections>()) } just Runs
every { navController.currentDestination } returns currentDestination
every { currentDestination.id } returns R.id.browserFragment
@ -109,7 +87,6 @@ class DefaultTabTrayControllerTest {
controller = DefaultTabTrayController(
activity = activity,
profiler = profiler,
sessionManager = sessionManager,
browserStore = store,
browsingModeManager = browsingModeManager,
tabCollectionStorage = tabCollectionStorage,