mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/17548: Remove SessionManager reference from TabHistoryDialog
This commit is contained in:
parent
98865d66b0
commit
525bf428b4
@ -5,7 +5,6 @@
|
||||
package org.mozilla.fenix.tabhistory
|
||||
|
||||
import androidx.navigation.NavController
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.feature.session.SessionUseCases
|
||||
|
||||
interface TabHistoryController {
|
||||
@ -15,15 +14,16 @@ interface TabHistoryController {
|
||||
class DefaultTabHistoryController(
|
||||
private val navController: NavController,
|
||||
private val goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase,
|
||||
private val customTabId: String? = null,
|
||||
private val sessionManager: SessionManager
|
||||
private val customTabId: String? = null
|
||||
) : TabHistoryController {
|
||||
|
||||
override fun handleGoToHistoryItem(item: TabHistoryItem) {
|
||||
navController.navigateUp()
|
||||
goToHistoryIndexUseCase.invoke(
|
||||
item.index,
|
||||
session = customTabId?.let { sessionManager.findSessionById(customTabId) }
|
||||
?: sessionManager.selectedSession)
|
||||
|
||||
if (customTabId != null) {
|
||||
goToHistoryIndexUseCase.invoke(item.index, customTabId)
|
||||
} else {
|
||||
goToHistoryIndexUseCase.invoke(item.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
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.coroutines.ExperimentalCoroutinesApi
|
||||
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.kotlinx.coroutines.flow.ifChanged
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
|
||||
class TabHistoryDialogFragment : BottomSheetDialogFragment() {
|
||||
@ -46,8 +44,7 @@ class TabHistoryDialogFragment : BottomSheetDialogFragment() {
|
||||
val controller = DefaultTabHistoryController(
|
||||
navController = findNavController(),
|
||||
goToHistoryIndexUseCase = requireComponents.useCases.sessionUseCases.goToHistoryIndex,
|
||||
customTabId = customTabSessionId,
|
||||
sessionManager = container.requireContext().components.core.sessionManager
|
||||
customTabId = customTabSessionId
|
||||
)
|
||||
val tabHistoryView = TabHistoryView(
|
||||
container = tabHistoryLayout,
|
||||
|
@ -5,62 +5,53 @@
|
||||
package org.mozilla.fenix.tabhistory
|
||||
|
||||
import androidx.navigation.NavController
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
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 org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class TabHistoryControllerTest {
|
||||
|
||||
private val store: BrowserStore = mockk(relaxed = true)
|
||||
private val sessionManager: SessionManager = mockk(relaxed = true)
|
||||
private val navController: NavController = mockk(relaxed = true)
|
||||
private val sessionUseCases = SessionUseCases(store, sessionManager)
|
||||
private lateinit var navController: NavController
|
||||
private lateinit var goToHistoryIndexUseCase: SessionUseCases.GoToHistoryIndexUseCase
|
||||
private lateinit var currentItem: TabHistoryItem
|
||||
|
||||
private val goToHistoryIndexUseCase = sessionUseCases.goToHistoryIndex
|
||||
private val controller = DefaultTabHistoryController(
|
||||
navController = navController,
|
||||
goToHistoryIndexUseCase = goToHistoryIndexUseCase,
|
||||
sessionManager = sessionManager
|
||||
)
|
||||
|
||||
private val currentItem = TabHistoryItem(
|
||||
index = 0,
|
||||
title = "",
|
||||
url = "",
|
||||
isSelected = true
|
||||
)
|
||||
@Before
|
||||
fun setUp() {
|
||||
navController = mockk(relaxed = true)
|
||||
goToHistoryIndexUseCase = mockk(relaxed = true)
|
||||
currentItem = TabHistoryItem(
|
||||
index = 0,
|
||||
title = "",
|
||||
url = "",
|
||||
isSelected = true
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleGoToHistoryIndexNormalBrowsing() {
|
||||
val session: Session = mockk(relaxed = true)
|
||||
every { sessionManager.selectedSession } returns session
|
||||
val controller = DefaultTabHistoryController(
|
||||
navController = navController,
|
||||
goToHistoryIndexUseCase = goToHistoryIndexUseCase
|
||||
)
|
||||
|
||||
controller.handleGoToHistoryItem(currentItem)
|
||||
|
||||
verify { navController.navigateUp() }
|
||||
verify { goToHistoryIndexUseCase.invoke(currentItem.index, session) }
|
||||
verify { goToHistoryIndexUseCase.invoke(currentItem.index) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleGoToHistoryIndexCustomTab() {
|
||||
val customTabId = "customTabId"
|
||||
val customTabController = DefaultTabHistoryController(
|
||||
navController = navController,
|
||||
goToHistoryIndexUseCase = goToHistoryIndexUseCase,
|
||||
customTabId = "custom-id",
|
||||
sessionManager = sessionManager
|
||||
customTabId = customTabId
|
||||
)
|
||||
val customTabSession: Session = mockk(relaxed = true)
|
||||
|
||||
every { sessionManager.findSessionById(any()) } returns customTabSession
|
||||
|
||||
customTabController.handleGoToHistoryItem(currentItem)
|
||||
|
||||
verify { navController.navigateUp() }
|
||||
verify { goToHistoryIndexUseCase.invoke(currentItem.index, customTabSession) }
|
||||
verify { goToHistoryIndexUseCase.invoke(currentItem.index, customTabId) }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user