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

[fenix] SearchDialogController: Pass tab ID instead of Session instance.

This commit is contained in:
Sebastian Kaspari 2021-01-18 11:59:35 +01:00 committed by Christian Sadilek
parent 0dc93ba95f
commit 4e676267b7
7 changed files with 18 additions and 31 deletions

View File

@ -12,10 +12,9 @@ import android.text.SpannableString
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.navigation.NavController
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.ktx.kotlin.isUrl
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
@ -40,7 +39,6 @@ interface SearchController {
fun handleSearchTermsTapped(searchTerms: String)
fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine)
fun handleClickSearchEngineSettings()
fun handleExistingSessionSelected(session: Session)
fun handleExistingSessionSelected(tabId: String)
fun handleSearchShortcutsButtonClicked()
fun handleCameraPermissionsNeeded()
@ -49,8 +47,8 @@ interface SearchController {
@Suppress("TooManyFunctions", "LongParameterList")
class SearchDialogController(
private val activity: HomeActivity,
private val sessionManager: SessionManager,
private val store: BrowserStore,
private val tabsUseCases: TabsUseCases,
private val fragmentStore: SearchFragmentStore,
private val navController: NavController,
private val settings: Settings,
@ -199,21 +197,16 @@ class SearchDialogController(
navController.navigateSafe(R.id.searchDialogFragment, directions)
}
override fun handleExistingSessionSelected(session: Session) {
override fun handleExistingSessionSelected(tabId: String) {
clearToolbarFocus()
sessionManager.select(session)
tabsUseCases.selectTab(tabId)
activity.openToBrowser(
from = BrowserDirection.FromSearchDialog
)
}
override fun handleExistingSessionSelected(tabId: String) {
val session = sessionManager.findSessionById(tabId)
if (session != null) {
handleExistingSessionSelected(session)
}
}
/**
* Creates and shows an [AlertDialog] when camera permissions are needed.
*

View File

@ -141,8 +141,8 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
interactor = SearchDialogInteractor(
SearchDialogController(
activity = activity,
sessionManager = requireComponents.core.sessionManager,
store = requireComponents.core.store,
tabsUseCases = requireComponents.useCases.tabsUseCases,
fragmentStore = store,
navController = findNavController(),
settings = requireContext().settings(),

View File

@ -4,7 +4,6 @@
package org.mozilla.fenix.search
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.search.SearchEngine
import org.mozilla.fenix.search.awesomebar.AwesomeBarInteractor
import org.mozilla.fenix.search.toolbar.ToolbarInteractor
@ -50,10 +49,6 @@ class SearchDialogInteractor(
searchController.handleClickSearchEngineSettings()
}
override fun onExistingSessionSelected(session: Session) {
searchController.handleExistingSessionSelected(session)
}
override fun onExistingSessionSelected(tabId: String) {
searchController.handleExistingSessionSelected(tabId)
}

View File

@ -4,7 +4,6 @@
package org.mozilla.fenix.search.awesomebar
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.search.SearchEngine
/**
@ -36,11 +35,6 @@ interface AwesomeBarInteractor {
*/
fun onClickSearchEngineSettings()
/**
* Called whenever an existing session is selected from the sessionSuggestionProvider
*/
fun onExistingSessionSelected(session: Session)
/**
* Called whenever an existing session is selected from the sessionSuggestionProvider
*/

View File

@ -86,7 +86,7 @@ class AwesomeBarView(
private val selectTabUseCase = object : TabsUseCases.SelectTabUseCase {
override fun invoke(session: Session) {
interactor.onExistingSessionSelected(session)
interactor.onExistingSessionSelected(session.id)
}
override fun invoke(tabId: String) {

View File

@ -23,6 +23,7 @@ import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tabs.TabsUseCases
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -68,10 +69,12 @@ class SearchDialogControllerTest {
}
every { MetricsUtils.createSearchEvent(searchEngine, browserStore, any()) } returns null
val tabsUseCases = TabsUseCases(browserStore, sessionManager)
controller = SearchDialogController(
activity = activity,
sessionManager = sessionManager,
store = browserStore,
tabsUseCases = tabsUseCases,
fragmentStore = store,
navController = navController,
settings = settings,
@ -324,7 +327,9 @@ class SearchDialogControllerTest {
fun handleExistingSessionSelected() {
val session = mockk<Session>()
controller.handleExistingSessionSelected(session)
every { sessionManager.findSessionById("selected") } returns session
controller.handleExistingSessionSelected("selected")
verify { sessionManager.select(session) }
verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
@ -337,7 +342,7 @@ class SearchDialogControllerTest {
controller.handleExistingSessionSelected("tab-id")
verify(inverse = true) { sessionManager.select(any()) }
verify(inverse = true) { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
verify { activity.openToBrowser(from = BrowserDirection.FromSearchDialog) }
}
@Test

View File

@ -100,10 +100,10 @@ class SearchDialogInteractorTest {
fun onExistingSessionSelected() {
val session = Session("http://mozilla.org", false)
interactor.onExistingSessionSelected(session)
interactor.onExistingSessionSelected(session.id)
verify {
searchController.handleExistingSessionSelected(session)
searchController.handleExistingSessionSelected(session.id)
}
}