Commit 87d6f323 authored by Christian Sadilek's avatar Christian Sadilek Committed by Sebastian Kaspari
Browse files

Refactor HomeFragment to use browser store

parent 527ba161
......@@ -63,7 +63,6 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.menu.view.MenuButton
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.normalTabs
import mozilla.components.browser.state.selector.privateTabs
......@@ -145,8 +144,6 @@ class HomeFragment : Fragment() {
}
}
private val sessionManager: SessionManager
get() = requireComponents.core.sessionManager
private val store: BrowserStore
get() = requireComponents.core.store
......@@ -235,7 +232,6 @@ class HomeFragment : Fragment() {
engine = components.core.engine,
metrics = components.analytics.metrics,
store = store,
sessionManager = sessionManager,
tabCollectionStorage = components.core.tabCollectionStorage,
addTabUseCase = components.useCases.tabsUseCases.addTab,
restoreUseCase = components.useCases.tabsUseCases.restore,
......@@ -474,9 +470,9 @@ class HomeFragment : Fragment() {
private fun removeAllTabsAndShowSnackbar(sessionCode: String) {
if (sessionCode == ALL_PRIVATE_TABS) {
sessionManager.removePrivateSessions()
requireComponents.useCases.tabsUseCases.removePrivateTabs()
} else {
sessionManager.removeNormalSessions()
requireComponents.useCases.tabsUseCases.removeNormalTabs()
}
val snackbarMessage = if (sessionCode == ALL_PRIVATE_TABS) {
......
......@@ -11,7 +11,7 @@ import androidx.navigation.NavController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
......@@ -36,7 +36,6 @@ import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.home.HomeFragment
import org.mozilla.fenix.home.HomeFragmentAction
import org.mozilla.fenix.home.HomeFragmentDirections
......@@ -173,7 +172,6 @@ class DefaultSessionControlController(
private val settings: Settings,
private val engine: Engine,
private val metrics: MetricController,
private val sessionManager: SessionManager,
private val store: BrowserStore,
private val tabCollectionStorage: TabCollectionStorage,
private val addTabUseCase: TabsUseCases.AddNewTabUseCase,
......@@ -217,8 +215,10 @@ class DefaultSessionControlController(
tab,
onTabRestored = {
activity.openToBrowser(BrowserDirection.FromHome)
sessionManager.selectedSession?.let { selectTabUseCase.invoke(it) }
reloadUrlUseCase.invoke(sessionManager.selectedSession)
store.state.selectedTabId?.let {
selectTabUseCase.invoke(it)
reloadUrlUseCase.invoke(it)
}
},
onFailure = {
activity.openToBrowserAndLoad(
......@@ -457,8 +457,8 @@ class DefaultSessionControlController(
// Only register the observer right before moving to collection creation
registerCollectionStorageObserver()
val tabIds = sessionManager
.sessionsOfType(private = activity.browsingModeManager.mode.isPrivate)
val tabIds = store.state
.getNormalOrPrivateTabs(private = activity.browsingModeManager.mode.isPrivate)
.map { session -> session.id }
.toList()
.toTypedArray()
......
......@@ -12,14 +12,14 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.action.SearchAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.search.RegionState
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ReaderState
import mozilla.components.browser.state.state.SearchState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
......@@ -60,7 +60,6 @@ class DefaultSessionControlControllerTest {
private val fragmentStore: HomeFragmentStore = mockk(relaxed = true)
private val navController: NavController = mockk(relaxed = true)
private val metrics: MetricController = mockk(relaxed = true)
private val sessionManager: SessionManager = mockk(relaxed = true)
private val engine: Engine = mockk(relaxed = true)
private val tabCollectionStorage: TabCollectionStorage = mockk(relaxed = true)
private val tabsUseCases: TabsUseCases = mockk(relaxed = true)
......@@ -108,7 +107,6 @@ class DefaultSessionControlControllerTest {
showCollectionPlaceholder = true
)
every { sessionManager.sessions } returns emptyList()
every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment
}
......@@ -125,7 +123,6 @@ class DefaultSessionControlControllerTest {
settings = settings,
engine = engine,
metrics = metrics,
sessionManager = sessionManager,
tabCollectionStorage = tabCollectionStorage,
addTabUseCase = tabsUseCases.addTab,
reloadUrlUseCase = reloadUrlUseCase.reload,
......@@ -202,15 +199,16 @@ class DefaultSessionControlControllerTest {
every { restore(activity, engine, restoreSessionId = false) } returns restoredTab
}
val session = mockk<Session>()
every { sessionManager.selectedSession } returns session
store.dispatch(TabListAction.AddTabAction(
createTab(id = restoredTab.id, url = restoredTab.url))
).joinBlocking()
store.dispatch(TabListAction.SelectTabAction(restoredTab.id)).joinBlocking()
controller.handleCollectionOpenTabClicked(tab)
verify { metrics.track(Event.CollectionTabRestored) }
verify { activity.openToBrowser(BrowserDirection.FromHome) }
verify { selectTabUseCase.selectTab.invoke(session) }
verify { reloadUrlUseCase.reload.invoke(session) }
verify { selectTabUseCase.selectTab.invoke(restoredTab.id) }
verify { reloadUrlUseCase.reload.invoke(restoredTab.id) }
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment