For #6812 - Navigate via openToBrowser to selected session from search
parent
e1722b95b3
commit
7adb5b6084
|
@ -12,7 +12,6 @@ import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.support.ktx.kotlin.isUrl
|
import mozilla.components.support.ktx.kotlin.isUrl
|
||||||
import org.mozilla.fenix.BrowserDirection
|
import org.mozilla.fenix.BrowserDirection
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.ACTION
|
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.ACTION
|
||||||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.NONE
|
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.NONE
|
||||||
|
@ -21,7 +20,6 @@ import org.mozilla.fenix.components.metrics.MetricsUtils
|
||||||
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore
|
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,15 +80,19 @@ class DefaultSearchController(
|
||||||
|
|
||||||
override fun handleTextChanged(text: String) {
|
override fun handleTextChanged(text: String) {
|
||||||
store.dispatch(SearchFragmentAction.UpdateQuery(text))
|
store.dispatch(SearchFragmentAction.UpdateQuery(text))
|
||||||
store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(
|
store.dispatch(
|
||||||
|
SearchFragmentAction.ShowSearchShortcutEnginePicker(
|
||||||
text.isEmpty() && context.settings().shouldShowSearchShortcuts
|
text.isEmpty() && context.settings().shouldShowSearchShortcuts
|
||||||
))
|
)
|
||||||
store.dispatch(SearchFragmentAction.ShowSearchSuggestionsHint(
|
)
|
||||||
|
store.dispatch(
|
||||||
|
SearchFragmentAction.ShowSearchSuggestionsHint(
|
||||||
text.isNotEmpty() &&
|
text.isNotEmpty() &&
|
||||||
(context as HomeActivity).browsingModeManager.mode.isPrivate &&
|
(context as HomeActivity).browsingModeManager.mode.isPrivate &&
|
||||||
!context.settings().shouldShowSearchSuggestionsInPrivate &&
|
!context.settings().shouldShowSearchSuggestionsInPrivate &&
|
||||||
!context.settings().showSearchSuggestionsInPrivateOnboardingFinished
|
!context.settings().showSearchSuggestionsInPrivateOnboardingFinished
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleUrlTapped(url: String) {
|
override fun handleUrlTapped(url: String) {
|
||||||
|
@ -129,7 +131,8 @@ class DefaultSearchController(
|
||||||
|
|
||||||
override fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine) {
|
override fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine) {
|
||||||
store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine))
|
store.dispatch(SearchFragmentAction.SearchShortcutEngineSelected(searchEngine))
|
||||||
val isCustom = CustomSearchEngineStore.isCustomSearchEngine(context, searchEngine.identifier)
|
val isCustom =
|
||||||
|
CustomSearchEngineStore.isCustomSearchEngine(context, searchEngine.identifier)
|
||||||
context.metrics.track(Event.SearchShortcutSelected(searchEngine, isCustom))
|
context.metrics.track(Event.SearchShortcutSelected(searchEngine, isCustom))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,8 +147,9 @@ class DefaultSearchController(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleExistingSessionSelected(session: Session) {
|
override fun handleExistingSessionSelected(session: Session) {
|
||||||
val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null)
|
|
||||||
navController.nav(R.id.searchFragment, directions)
|
|
||||||
context.components.core.sessionManager.select(session)
|
context.components.core.sessionManager.select(session)
|
||||||
|
(context as HomeActivity).openToBrowser(
|
||||||
|
from = BrowserDirection.FromSearch
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.MetricController
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
|
||||||
import org.mozilla.fenix.ext.searchEngineManager
|
import org.mozilla.fenix.ext.searchEngineManager
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.utils.Settings
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
@ -72,12 +71,14 @@ class DefaultSearchControllerTest {
|
||||||
|
|
||||||
controller.handleUrlCommitted(url)
|
controller.handleUrlCommitted(url)
|
||||||
|
|
||||||
verify { context.openToBrowserAndLoad(
|
verify {
|
||||||
|
context.openToBrowserAndLoad(
|
||||||
searchTermOrURL = url,
|
searchTermOrURL = url,
|
||||||
newTab = session == null,
|
newTab = session == null,
|
||||||
from = BrowserDirection.FromSearch,
|
from = BrowserDirection.FromSearch,
|
||||||
engine = searchEngine
|
engine = searchEngine
|
||||||
) }
|
)
|
||||||
|
}
|
||||||
verify { metrics.track(Event.EnteredUrl(false)) }
|
verify { metrics.track(Event.EnteredUrl(false)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,11 +163,13 @@ class DefaultSearchControllerTest {
|
||||||
|
|
||||||
controller.handleUrlTapped(url)
|
controller.handleUrlTapped(url)
|
||||||
|
|
||||||
verify { context.openToBrowserAndLoad(
|
verify {
|
||||||
|
context.openToBrowserAndLoad(
|
||||||
searchTermOrURL = url,
|
searchTermOrURL = url,
|
||||||
newTab = session == null,
|
newTab = session == null,
|
||||||
from = BrowserDirection.FromSearch
|
from = BrowserDirection.FromSearch
|
||||||
) }
|
)
|
||||||
|
}
|
||||||
verify { metrics.track(Event.EnteredUrl(false)) }
|
verify { metrics.track(Event.EnteredUrl(false)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,13 +179,15 @@ class DefaultSearchControllerTest {
|
||||||
|
|
||||||
controller.handleSearchTermsTapped(searchTerms)
|
controller.handleSearchTermsTapped(searchTerms)
|
||||||
|
|
||||||
verify { context.openToBrowserAndLoad(
|
verify {
|
||||||
|
context.openToBrowserAndLoad(
|
||||||
searchTermOrURL = searchTerms,
|
searchTermOrURL = searchTerms,
|
||||||
newTab = session == null,
|
newTab = session == null,
|
||||||
from = BrowserDirection.FromSearch,
|
from = BrowserDirection.FromSearch,
|
||||||
engine = searchEngine,
|
engine = searchEngine,
|
||||||
forceSearch = true
|
forceSearch = true
|
||||||
) }
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -197,7 +202,8 @@ class DefaultSearchControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun handleClickSearchEngineSettings() {
|
fun handleClickSearchEngineSettings() {
|
||||||
val directions: NavDirections = SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment()
|
val directions: NavDirections =
|
||||||
|
SearchFragmentDirections.actionSearchFragmentToSearchEngineFragment()
|
||||||
|
|
||||||
controller.handleClickSearchEngineSettings()
|
controller.handleClickSearchEngineSettings()
|
||||||
|
|
||||||
|
@ -225,11 +231,10 @@ class DefaultSearchControllerTest {
|
||||||
@Test
|
@Test
|
||||||
fun handleExistingSessionSelected() {
|
fun handleExistingSessionSelected() {
|
||||||
val session: Session = mockk(relaxed = true)
|
val session: Session = mockk(relaxed = true)
|
||||||
val directions = SearchFragmentDirections.actionSearchFragmentToBrowserFragment(null)
|
|
||||||
|
|
||||||
controller.handleExistingSessionSelected(session)
|
controller.handleExistingSessionSelected(session)
|
||||||
|
|
||||||
verify { navController.nav(R.id.searchFragment, directions) }
|
|
||||||
verify { sessionManager.select(session) }
|
verify { sessionManager.select(session) }
|
||||||
|
verify { context.openToBrowser(from = BrowserDirection.FromSearch) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ package org.mozilla.fenix.search
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDestination
|
|
||||||
import androidx.navigation.NavDirections
|
import androidx.navigation.NavDirections
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import io.mockk.Runs
|
import io.mockk.Runs
|
||||||
|
@ -24,7 +23,6 @@ import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.BrowserDirection
|
import org.mozilla.fenix.BrowserDirection
|
||||||
import org.mozilla.fenix.FenixApplication
|
import org.mozilla.fenix.FenixApplication
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.TestApplication
|
import org.mozilla.fenix.TestApplication
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES
|
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES
|
||||||
|
@ -272,13 +270,12 @@ class SearchInteractorTest {
|
||||||
@Test
|
@Test
|
||||||
fun onExistingSessionSelected() {
|
fun onExistingSessionSelected() {
|
||||||
val navController: NavController = mockk(relaxed = true)
|
val navController: NavController = mockk(relaxed = true)
|
||||||
every { navController.currentDestination } returns NavDestination("").apply {
|
val context: HomeActivity = mockk(relaxed = true)
|
||||||
id = R.id.searchFragment
|
|
||||||
}
|
|
||||||
val context: Context = mockk(relaxed = true)
|
|
||||||
val applicationContext: FenixApplication = mockk(relaxed = true)
|
val applicationContext: FenixApplication = mockk(relaxed = true)
|
||||||
every { context.applicationContext } returns applicationContext
|
every { context.applicationContext } returns applicationContext
|
||||||
val store: SearchFragmentStore = mockk()
|
val store: SearchFragmentStore = mockk()
|
||||||
|
every { context.openToBrowser(any(), any()) } just Runs
|
||||||
|
|
||||||
every { store.state } returns mockk(relaxed = true)
|
every { store.state } returns mockk(relaxed = true)
|
||||||
|
|
||||||
val searchController: SearchController = DefaultSearchController(
|
val searchController: SearchController = DefaultSearchController(
|
||||||
|
@ -292,12 +289,7 @@ class SearchInteractorTest {
|
||||||
interactor.onExistingSessionSelected(session)
|
interactor.onExistingSessionSelected(session)
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
navController.navigate(
|
context.openToBrowser(BrowserDirection.FromSearch)
|
||||||
SearchFragmentDirections.actionSearchFragmentToBrowserFragment(
|
|
||||||
activeSessionId = null
|
|
||||||
),
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue