2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Issue #17548: Remove SessionManager reference from TabHistoryDialog

This commit is contained in:
Christian Sadilek 2021-01-20 13:18:05 -05:00
parent 7358a313bf
commit 0de948e8ae
3 changed files with 31 additions and 43 deletions

View File

@ -5,7 +5,6 @@
package org.mozilla.fenix.tabhistory package org.mozilla.fenix.tabhistory
import androidx.navigation.NavController import androidx.navigation.NavController
import mozilla.components.browser.session.SessionManager
import mozilla.components.feature.session.SessionUseCases import mozilla.components.feature.session.SessionUseCases
interface TabHistoryController { interface TabHistoryController {
@ -15,15 +14,16 @@ interface TabHistoryController {
class DefaultTabHistoryController( class DefaultTabHistoryController(
private val navController: NavController, private val navController: NavController,
private val goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase, private val goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase,
private val customTabId: String? = null, private val customTabId: String? = null
private val sessionManager: SessionManager
) : TabHistoryController { ) : TabHistoryController {
override fun handleGoToHistoryItem(item: TabHistoryItem) { override fun handleGoToHistoryItem(item: TabHistoryItem) {
navController.navigateUp() navController.navigateUp()
goToHistoryIndexUseCase.invoke(
item.index, if (customTabId != null) {
session = customTabId?.let { sessionManager.findSessionById(customTabId) } goToHistoryIndexUseCase.invoke(item.index, customTabId)
?: sessionManager.selectedSession) } else {
goToHistoryIndexUseCase.invoke(item.index)
}
} }
} }

View File

@ -12,7 +12,6 @@ import androidx.navigation.fragment.findNavController
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.android.synthetic.main.fragment_tab_history_dialog.* import kotlinx.android.synthetic.main.fragment_tab_history_dialog.*
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
@ -22,7 +21,6 @@ import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
class TabHistoryDialogFragment : BottomSheetDialogFragment() { class TabHistoryDialogFragment : BottomSheetDialogFragment() {
@ -46,8 +44,7 @@ class TabHistoryDialogFragment : BottomSheetDialogFragment() {
val controller = DefaultTabHistoryController( val controller = DefaultTabHistoryController(
navController = findNavController(), navController = findNavController(),
goToHistoryIndexUseCase = requireComponents.useCases.sessionUseCases.goToHistoryIndex, goToHistoryIndexUseCase = requireComponents.useCases.sessionUseCases.goToHistoryIndex,
customTabId = customTabSessionId, customTabId = customTabSessionId
sessionManager = container.requireContext().components.core.sessionManager
) )
val tabHistoryView = TabHistoryView( val tabHistoryView = TabHistoryView(
container = tabHistoryLayout, container = tabHistoryLayout,

View File

@ -5,62 +5,53 @@
package org.mozilla.fenix.tabhistory package org.mozilla.fenix.tabhistory
import androidx.navigation.NavController import androidx.navigation.NavController
import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.session.SessionUseCases import mozilla.components.feature.session.SessionUseCases
import org.junit.Before
import org.junit.Test import org.junit.Test
class TabHistoryControllerTest { class TabHistoryControllerTest {
private val store: BrowserStore = mockk(relaxed = true) private lateinit var navController: NavController
private val sessionManager: SessionManager = mockk(relaxed = true) private lateinit var goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase
private val navController: NavController = mockk(relaxed = true) private lateinit var currentItem: TabHistoryItem
private val sessionUseCases = SessionUseCases(store, sessionManager)
private val goToHistoryIndexUseCase = sessionUseCases.goToHistoryIndex @Before
private val controller = DefaultTabHistoryController( fun setUp() {
navController = navController, navController = mockk(relaxed = true)
goToHistoryIndexUseCase = goToHistoryIndexUseCase, goToHistoryIndexUseCase = mockk(relaxed = true)
sessionManager = sessionManager currentItem = TabHistoryItem(
) index = 0,
title = "",
private val currentItem = TabHistoryItem( url = "",
index = 0, isSelected = true
title = "", )
url = "", }
isSelected = true
)
@Test @Test
fun handleGoToHistoryIndexNormalBrowsing() { fun handleGoToHistoryIndexNormalBrowsing() {
val session: Session = mockk(relaxed = true) val controller = DefaultTabHistoryController(
every { sessionManager.selectedSession } returns session navController = navController,
goToHistoryIndexUseCase = goToHistoryIndexUseCase
)
controller.handleGoToHistoryItem(currentItem) controller.handleGoToHistoryItem(currentItem)
verify { navController.navigateUp() } verify { navController.navigateUp() }
verify { goToHistoryIndexUseCase.invoke(currentItem.index, session) } verify { goToHistoryIndexUseCase.invoke(currentItem.index) }
} }
@Test @Test
fun handleGoToHistoryIndexCustomTab() { fun handleGoToHistoryIndexCustomTab() {
val customTabId = "customTabId"
val customTabController = DefaultTabHistoryController( val customTabController = DefaultTabHistoryController(
navController = navController, navController = navController,
goToHistoryIndexUseCase = goToHistoryIndexUseCase, goToHistoryIndexUseCase = goToHistoryIndexUseCase,
customTabId = "custom-id", customTabId = customTabId
sessionManager = sessionManager
) )
val customTabSession: Session = mockk(relaxed = true)
every { sessionManager.findSessionById(any()) } returns customTabSession
customTabController.handleGoToHistoryItem(currentItem) customTabController.handleGoToHistoryItem(currentItem)
verify { navController.navigateUp() } verify { navController.navigateUp() }
verify { goToHistoryIndexUseCase.invoke(currentItem.index, customTabSession) } verify { goToHistoryIndexUseCase.invoke(currentItem.index, customTabId) }
} }
} }