From e38bff8597e1d966eac3f76ef6813078e2f81841 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Mon, 2 Mar 2020 16:11:40 -0800 Subject: [PATCH] For #5308: Display search shortcuts when going from browser to search --- .../org/mozilla/fenix/search/SearchController.kt | 11 +++++++---- .../fenix/search/DefaultSearchControllerTest.kt | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt index c5835d627..66a440a34 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt @@ -79,18 +79,21 @@ class DefaultSearchController( } override fun handleTextChanged(text: String) { + // Display the search shortcuts on each entry of the search fragment (see #5308) + val textMatchesCurrentUrl = store.state.session?.url ?: "" == text + store.dispatch(SearchFragmentAction.UpdateQuery(text)) store.dispatch( SearchFragmentAction.ShowSearchShortcutEnginePicker( - text.isEmpty() && context.settings().shouldShowSearchShortcuts + (textMatchesCurrentUrl || text.isEmpty()) && context.settings().shouldShowSearchShortcuts ) ) store.dispatch( SearchFragmentAction.AllowSearchSuggestionsInPrivateModePrompt( text.isNotEmpty() && - (context as HomeActivity).browsingModeManager.mode.isPrivate && - !context.settings().shouldShowSearchSuggestionsInPrivate && - !context.settings().showSearchSuggestionsInPrivateOnboardingFinished + (context as HomeActivity).browsingModeManager.mode.isPrivate && + !context.settings().shouldShowSearchSuggestionsInPrivate && + !context.settings().showSearchSuggestionsInPrivateOnboardingFinished ) ) } diff --git a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt index d641259a9..b466a184d 100644 --- a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt @@ -14,6 +14,7 @@ import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Before import org.junit.Test @@ -116,6 +117,18 @@ class DefaultSearchControllerTest { verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) } } + @Test + fun `show search shortcuts when setting enabled AND query equals url`() { + val text = "mozilla.org" + every { session?.url } returns "mozilla.org" + + assertEquals(text, session?.url) + + controller.handleTextChanged(text) + + verify { store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(true)) } + } + @Test fun `do not show search shortcuts when setting enabled AND query non-empty`() { val text = "mozilla" @@ -126,7 +139,7 @@ class DefaultSearchControllerTest { } @Test - fun `do not show search shortcuts when setting disabled AND query empty`() { + fun `do not show search shortcuts when setting disabled AND query empty AND url not matching query`() { testContext.settings().preferences .edit() .putBoolean(testContext.getString(R.string.pref_key_show_search_shortcuts), false)