From b2a9e730519928ee74a02bfbc96ccca72659b13d Mon Sep 17 00:00:00 2001 From: ekager Date: Wed, 9 Sep 2020 14:39:04 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/13467 For https://github.com/mozilla-mobile/fenix/issues/14910 - Dismiss dialog on blank URL commit --- .../fenix/searchdialog/SearchDialogController.kt | 6 +++++- .../fenix/searchdialog/SearchDialogFragment.kt | 1 + .../searchdialog/SearchDialogControllerTest.kt | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt index c4e81c0410..8f210124a3 100644 --- a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt +++ b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt @@ -33,6 +33,7 @@ class SearchDialogController( private val navController: NavController, private val settings: Settings, private val metrics: MetricController, + private val dismissDialog: () -> Unit, private val clearToolbarFocus: () -> Unit ) : SearchController { @@ -45,12 +46,15 @@ class SearchDialogController( activity.startActivity(Intent(activity, CrashListActivity::class.java)) } "about:addons" -> { - val directions = SearchDialogFragmentDirections.actionGlobalAddonsManagementFragment() + val directions = + SearchDialogFragmentDirections.actionGlobalAddonsManagementFragment() navController.navigateSafe(R.id.searchDialogFragment, directions) } "moz://a" -> openSearchOrUrl(SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.MANIFESTO)) else -> if (url.isNotBlank()) { openSearchOrUrl(url) + } else { + dismissDialog() } } } diff --git a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt index f87bbc9837..9a1d1d0b83 100644 --- a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt @@ -140,6 +140,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { navController = findNavController(), settings = requireContext().settings(), metrics = requireComponents.analytics.metrics, + dismissDialog = { dismissAllowingStateLoss() }, clearToolbarFocus = { toolbarView.view.hideKeyboard() toolbarView.view.clearFocus() diff --git a/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt b/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt index 762f5e8668..0aaed6fe8c 100644 --- a/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt @@ -44,6 +44,7 @@ class SearchDialogControllerTest { @MockK(relaxed = true) private lateinit var settings: Settings @MockK private lateinit var sessionManager: SessionManager @MockK(relaxed = true) private lateinit var clearToolbarFocus: () -> Unit + @MockK(relaxed = true) private lateinit var dismissDialog: () -> Unit private lateinit var controller: SearchDialogController @@ -67,6 +68,7 @@ class SearchDialogControllerTest { navController = navController, settings = settings, metrics = metrics, + dismissDialog = dismissDialog, clearToolbarFocus = clearToolbarFocus ) } @@ -93,6 +95,17 @@ class SearchDialogControllerTest { verify { metrics.track(Event.EnteredUrl(false)) } } + @Test + fun handleBlankUrlCommitted() { + val url = "" + + controller.handleUrlCommitted(url) + + verify { + dismissDialog() + } + } + @Test fun handleSearchCommitted() { val searchTerm = "Firefox"