For #5308: Display search shortcuts when going from browser to search
parent
063a3b268a
commit
e38bff8597
|
@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue