2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/24300 - Add Tabs to the search engine menu

This commit is contained in:
Gabriel Luong 2022-05-27 00:42:57 -04:00 committed by mergify[bot]
parent 9bdc88cfb3
commit 397f1ffbb2
7 changed files with 85 additions and 0 deletions

View File

@ -205,6 +205,12 @@ class Core(
url = "", url = "",
icon = getDrawable(context, R.drawable.ic_bookmarks_search)?.toBitmap()!!, icon = getDrawable(context, R.drawable.ic_bookmarks_search)?.toBitmap()!!,
), ),
createApplicationSearchEngine(
id = TABS_SEARCH_ENGINE_ID,
name = context.getString(R.string.preferences_tabs),
url = "",
icon = getDrawable(context, R.drawable.ic_tabs_search)?.toBitmap()!!,
),
createApplicationSearchEngine( createApplicationSearchEngine(
id = HISTORY_SEARCH_ENGINE_ID, id = HISTORY_SEARCH_ENGINE_ID,
name = context.getString(R.string.library_history), name = context.getString(R.string.library_history),
@ -521,6 +527,7 @@ class Core(
private const val CONTILE_MAX_CACHE_AGE = 60L // 60 minutes private const val CONTILE_MAX_CACHE_AGE = 60L // 60 minutes
const val HISTORY_SEARCH_ENGINE_ID = "history_search_engine_id" const val HISTORY_SEARCH_ENGINE_ID = "history_search_engine_id"
const val BOOKMARKS_SEARCH_ENGINE_ID = "bookmarks_search_engine_id" const val BOOKMARKS_SEARCH_ENGINE_ID = "bookmarks_search_engine_id"
const val TABS_SEARCH_ENGINE_ID = "tabs_search_engine_id"
// Maximum number of suggestions returned from the history search engine source. // Maximum number of suggestions returned from the history search engine source.
const val METADATA_HISTORY_SUGGESTION_LIMIT = 100 const val METADATA_HISTORY_SUGGESTION_LIMIT = 100

View File

@ -205,6 +205,9 @@ class SearchDialogController(
&& searchEngine.id == Core.BOOKMARKS_SEARCH_ENGINE_ID -> { && searchEngine.id == Core.BOOKMARKS_SEARCH_ENGINE_ID -> {
fragmentStore.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine)) fragmentStore.dispatch(SearchFragmentAction.SearchBookmarksEngineSelected(searchEngine))
} }
searchEngine.type == SearchEngine.Type.APPLICATION && searchEngine.id == Core.TABS_SEARCH_ENGINE_ID -> {
fragmentStore.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine))
}
searchEngine == store.state.search.selectedOrDefaultSearchEngine -> { searchEngine == store.state.search.selectedOrDefaultSearchEngine -> {
fragmentStore.dispatch(SearchFragmentAction.SearchDefaultEngineSelected(searchEngine, settings)) fragmentStore.dispatch(SearchFragmentAction.SearchDefaultEngineSelected(searchEngine, settings))
} }

View File

@ -61,6 +61,11 @@ sealed class SearchEngineSource {
* Search engine for bookmarks * Search engine for bookmarks
*/ */
data class Bookmarks(override val searchEngine: SearchEngine) : SearchEngineSource() data class Bookmarks(override val searchEngine: SearchEngine) : SearchEngineSource()
/**
* Search engine for tabs
*/
data class Tabs(override val searchEngine: SearchEngine) : SearchEngineSource()
} }
/** /**
@ -180,6 +185,11 @@ sealed class SearchFragmentAction : Action {
*/ */
data class SearchBookmarksEngineSelected(val engine: SearchEngine) : SearchFragmentAction() data class SearchBookmarksEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
/**
* Action when tabs search engine is selected.
*/
data class SearchTabsEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
/** /**
* Action when search engine picker is selected. * Action when search engine picker is selected.
*/ */
@ -271,6 +281,17 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
showSyncedTabsSuggestions = false, showSyncedTabsSuggestions = false,
showSessionSuggestions = false, showSessionSuggestions = false,
) )
is SearchFragmentAction.SearchTabsEngineSelected ->
state.copy(
searchEngineSource = SearchEngineSource.Tabs(action.engine),
showSearchSuggestions = false,
showSearchShortcuts = false,
showClipboardSuggestions = false,
showHistorySuggestions = false,
showBookmarkSuggestions = false,
showSyncedTabsSuggestions = true,
showSessionSuggestions = true,
)
is SearchFragmentAction.ShowSearchShortcutEnginePicker -> is SearchFragmentAction.ShowSearchShortcutEnginePicker ->
state.copy(showSearchShortcuts = action.show && state.areShortcutsAvailable) state.copy(showSearchShortcuts = action.show && state.areShortcutsAvailable)
is SearchFragmentAction.UpdateQuery -> is SearchFragmentAction.UpdateQuery ->

View File

@ -285,6 +285,7 @@ class AwesomeBarView(
) )
is SearchEngineSource.History -> emptyList() is SearchEngineSource.History -> emptyList()
is SearchEngineSource.Bookmarks -> emptyList() is SearchEngineSource.Bookmarks -> emptyList()
is SearchEngineSource.Tabs -> emptyList()
is SearchEngineSource.None -> emptyList() is SearchEngineSource.None -> emptyList()
} }
} }

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:fillColor="@color/photonWhite"
android:pathData="M 2 0 L 22 0 C 22.53 0 23.039 0.211 23.414 0.586 C 23.789 0.961 24 1.47 24 2 L 24 22 C 24 22.53 23.789 23.039 23.414 23.414 C 23.039 23.789 22.53 24 22 24 L 2 24 C 1.47 24 0.961 23.789 0.586 23.414 C 0.211 23.039 0 22.53 0 22 L 0 2 C 0 1.47 0.211 0.961 0.586 0.586 C 0.961 0.211 1.47 0 2 0"
android:strokeWidth="1" />
<path
android:pathData="M4.5,4C3.119,4 2,5.119 2,6.5V17.5C2,18.881 3.119,20 4.5,20H19.5C20.881,20 22,18.881 22,17.5V6.5C22,5.119 20.881,4 19.5,4H4.5ZM20.5,17.7L19.7,18.5H4.3L3.5,17.7V6.3L4.3,5.5H19.7L20.5,6.3V17.7Z"
android:fillColor="@color/photonBlack"/>
</vector>

View File

@ -407,6 +407,31 @@ class SearchDialogControllerTest {
assertEquals("application", eventExtra["engine"]) assertEquals("application", eventExtra["engine"])
} }
@Test
fun `WHEN tabs search engine is selected THEN dispatch correct action`() {
val searchEngine: SearchEngine = mockk(relaxed = true)
every { searchEngine.type } returns SearchEngine.Type.APPLICATION
every { searchEngine.id } returns Core.TABS_SEARCH_ENGINE_ID
var focusToolbarInvoked = false
createController(
focusToolbar = {
focusToolbarInvoked = true
}
).handleSearchShortcutEngineSelected(searchEngine)
assertTrue(focusToolbarInvoked)
verify { store.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine)) }
assertTrue(SearchShortcuts.selected.testHasValue())
val recordedEvents = SearchShortcuts.selected.testGetValue()
assertEquals(1, recordedEvents.size)
val eventExtra = recordedEvents.single().extra
assertNotNull(eventExtra)
assertTrue(eventExtra!!.containsKey("engine"))
assertEquals("application", eventExtra["engine"])
}
@Test @Test
fun handleClickSearchEngineSettings() { fun handleClickSearchEngineSettings() {
val directions: NavDirections = actionGlobalSearchEngineFragment() val directions: NavDirections = actionGlobalSearchEngineFragment()

View File

@ -185,6 +185,16 @@ class SearchFragmentStoreTest {
assertEquals(SearchEngineSource.Bookmarks(searchEngine), store.state.searchEngineSource) assertEquals(SearchEngineSource.Bookmarks(searchEngine), store.state.searchEngineSource)
} }
@Test
fun `WHEN tabs engine selected action dispatched THEN update search engine source`() = runTest {
val initialState = emptyDefaultState()
val store = SearchFragmentStore(initialState)
store.dispatch(SearchFragmentAction.SearchTabsEngineSelected(searchEngine)).join()
assertNotSame(initialState, store.state)
assertEquals(SearchEngineSource.Tabs(searchEngine), store.state.searchEngineSource)
}
@Test @Test
fun showSearchShortcutEnginePicker() = runTest { fun showSearchShortcutEnginePicker() = runTest {
val initialState = emptyDefaultState() val initialState = emptyDefaultState()