From ce22838e4ce64c82c64223797a12c40de1b6c437 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Thu, 27 Aug 2020 09:49:32 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/8157: Redirect about:addons search (https://github.com/mozilla-mobile/fenix/pull/13990) --- .../java/org/mozilla/fenix/GlobalDirections.kt | 2 +- .../org/mozilla/fenix/search/SearchController.kt | 4 ++++ .../fenix/searchdialog/SearchDialogController.kt | 4 ++++ app/src/main/res/navigation/nav_graph.xml | 3 --- .../home/intent/DeepLinkIntentProcessorTest.kt | 2 +- .../fenix/search/DefaultSearchControllerTest.kt | 16 ++++++++++++++-- .../searchdialog/SearchDialogControllerTest.kt | 16 ++++++++++++++-- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/GlobalDirections.kt b/app/src/main/java/org/mozilla/fenix/GlobalDirections.kt index eb64e044b6..0e31e5d936 100644 --- a/app/src/main/java/org/mozilla/fenix/GlobalDirections.kt +++ b/app/src/main/java/org/mozilla/fenix/GlobalDirections.kt @@ -44,7 +44,7 @@ enum class GlobalDirections(val navDirections: NavDirections, val destinationId: R.id.deleteBrowsingDataFragment ), SettingsAddonManager( - NavGraphDirections.actionGlobalSettingsAddonsManagementFragment(), + NavGraphDirections.actionGlobalAddonsManagementFragment(), R.id.addonsManagementFragment ), SettingsLogins( 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 b2fe99221f..8e668c7eac 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt @@ -61,6 +61,10 @@ class DefaultSearchController( // and open the crash list activity instead. activity.startActivity(Intent(activity, CrashListActivity::class.java)) } + "about:addons" -> { + val directions = SearchFragmentDirections.actionGlobalAddonsManagementFragment() + navController.navigateSafe(R.id.searchFragment, directions) + } "moz://a" -> openSearchOrUrl(SupportUtils.getMozillaPageUrl(MANIFESTO)) else -> if (url.isNotBlank()) { openSearchOrUrl(url) 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 a28c81ce50..c4e81c0410 100644 --- a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt +++ b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogController.kt @@ -44,6 +44,10 @@ class SearchDialogController( // and open the crash list activity instead. activity.startActivity(Intent(activity, CrashListActivity::class.java)) } + "about:addons" -> { + val directions = SearchDialogFragmentDirections.actionGlobalAddonsManagementFragment() + navController.navigateSafe(R.id.searchDialogFragment, directions) + } "moz://a" -> openSearchOrUrl(SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.MANIFESTO)) else -> if (url.isNotBlank()) { openSearchOrUrl(url) diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 8231494319..2c14fb3921 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -40,9 +40,6 @@ - diff --git a/app/src/test/java/org/mozilla/fenix/home/intent/DeepLinkIntentProcessorTest.kt b/app/src/test/java/org/mozilla/fenix/home/intent/DeepLinkIntentProcessorTest.kt index 19b959b2ef..959200d5e5 100644 --- a/app/src/test/java/org/mozilla/fenix/home/intent/DeepLinkIntentProcessorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/intent/DeepLinkIntentProcessorTest.kt @@ -157,7 +157,7 @@ class DeepLinkIntentProcessorTest { fun `process settings_addon_manager deep link`() { assertTrue(processor.process(testIntent("settings_addon_manager"), navController, out)) - verify { navController.navigate(NavGraphDirections.actionGlobalSettingsAddonsManagementFragment()) } + verify { navController.navigate(NavGraphDirections.actionGlobalAddonsManagementFragment()) } verify { out wasNot Called } } 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 6a8a25c81b..d6a2233428 100644 --- a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt @@ -29,7 +29,6 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.components.metrics.MetricsUtils -import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.settings.SupportUtils import org.mozilla.fenix.utils.Settings @@ -55,6 +54,9 @@ class DefaultSearchControllerTest { every { store.state.tabId } returns "test-tab-id" every { store.state.searchEngineSource.searchEngine } returns searchEngine every { sessionManager.select(any()) } just Runs + every { navController.currentDestination } returns mockk { + every { id } returns R.id.searchFragment + } every { MetricsUtils.createSearchEvent(searchEngine, activity, any()) } returns null controller = DefaultSearchController( @@ -119,6 +121,16 @@ class DefaultSearchControllerTest { } } + @Test + fun handleAddonsUrlCommitted() { + val url = "about:addons" + val directions = SearchFragmentDirections.actionGlobalAddonsManagementFragment() + + controller.handleUrlCommitted(url) + + verify { navController.navigate(directions) } + } + @Test fun handleMozillaUrlCommitted() { val url = "moz://a" @@ -265,7 +277,7 @@ class DefaultSearchControllerTest { controller.handleClickSearchEngineSettings() - verify { navController.navigateSafe(R.id.searchEngineFragment, directions) } + verify { navController.navigate(directions) } } @Test 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 cfa3649c67..762f5e8668 100644 --- a/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/searchdialog/SearchDialogControllerTest.kt @@ -29,7 +29,6 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.components.metrics.MetricsUtils -import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.search.SearchFragmentAction import org.mozilla.fenix.settings.SupportUtils import org.mozilla.fenix.utils.Settings @@ -56,6 +55,9 @@ class SearchDialogControllerTest { every { store.state.tabId } returns "test-tab-id" every { store.state.searchEngineSource.searchEngine } returns searchEngine every { sessionManager.select(any()) } just Runs + every { navController.currentDestination } returns mockk { + every { id } returns R.id.searchDialogFragment + } every { MetricsUtils.createSearchEvent(searchEngine, activity, any()) } returns null controller = SearchDialogController( @@ -120,6 +122,16 @@ class SearchDialogControllerTest { } } + @Test + fun handleAddonsUrlCommitted() { + val url = "about:addons" + val directions = SearchDialogFragmentDirections.actionGlobalAddonsManagementFragment() + + controller.handleUrlCommitted(url) + + verify { navController.navigate(directions) } + } + @Test fun handleMozillaUrlCommitted() { val url = "moz://a" @@ -266,7 +278,7 @@ class SearchDialogControllerTest { controller.handleClickSearchEngineSettings() - verify { navController.navigateSafe(R.id.searchEngineFragment, directions) } + verify { navController.navigate(directions) } } @Test