mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Remove need to specify component names for new intents
This commit is contained in:
parent
98a33ea82b
commit
22689a9ff5
@ -9,6 +9,7 @@ import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.mozilla.fenix.BuildConfig.DEEP_LINK_SCHEME
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.ext.application
|
||||
|
||||
@ -17,10 +18,8 @@ class DeepLinkRobot {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
data = Uri.parse(url)
|
||||
data = Uri.parse("$DEEP_LINK_SCHEME://$url")
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
component =
|
||||
ComponentName(context.application.packageName, HomeActivity::class.java.name)
|
||||
addCategory(Intent.CATEGORY_BROWSABLE)
|
||||
}
|
||||
try {
|
||||
@ -32,7 +31,7 @@ class DeepLinkRobot {
|
||||
}
|
||||
|
||||
fun openURL(url: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
val deepLink = Uri.parse("fenix://open")
|
||||
val deepLink = Uri.parse("open")
|
||||
.buildUpon()
|
||||
.appendQueryParameter("url", url)
|
||||
.build()
|
||||
@ -42,42 +41,42 @@ class DeepLinkRobot {
|
||||
}
|
||||
|
||||
fun openHomeScreen(interact: HomeScreenRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home").run { homeScreen(interact) }
|
||||
openDeepLink("home").run { homeScreen(interact) }
|
||||
|
||||
fun openBookmarks(interact: BookmarksRobot.() -> Unit) =
|
||||
openDeepLink("fenix://urls_bookmarks").run { bookmarksMenu(interact) }
|
||||
openDeepLink("urls_bookmarks").run { bookmarksMenu(interact) }
|
||||
|
||||
fun openHistory(interact: HistoryRobot.() -> Unit) =
|
||||
openDeepLink("fenix://urls_history").run { historyMenu(interact) }
|
||||
openDeepLink("urls_history").run { historyMenu(interact) }
|
||||
|
||||
fun openCollections(interact: HomeScreenRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home_collections").run { homeScreen(interact) }
|
||||
openDeepLink("home_collections").run { homeScreen(interact) }
|
||||
|
||||
fun openSettings(interact: SettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings").run { settings(interact) }
|
||||
openDeepLink("settings").run { settings(interact) }
|
||||
|
||||
fun openSettingsPrivacy(interact: SettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_privacy").run { settings(interact) }
|
||||
openDeepLink("settings_privacy").run { settings(interact) }
|
||||
|
||||
fun openSettingsLogins(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_logins").run { settingsSubMenuLoginsAndPassword(interact) }
|
||||
openDeepLink("settings_logins").run { settingsSubMenuLoginsAndPassword(interact) }
|
||||
|
||||
fun openSettingsTrackingProtection(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_tracking_protection").run {
|
||||
openDeepLink("settings_tracking_protection").run {
|
||||
settingsSubMenuEnhancedTrackingProtection(interact)
|
||||
}
|
||||
|
||||
fun openSettingsSearchEngine(interact: SettingsSubMenuSearchRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_search_engine").run {
|
||||
openDeepLink("settings_search_engine").run {
|
||||
SettingsSubMenuSearchRobot().interact()
|
||||
SettingsSubMenuSearchRobot.Transition()
|
||||
}
|
||||
|
||||
fun openSettingsNotification(interact: SystemSettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_notifications").run { systemSettings(interact) }
|
||||
openDeepLink("settings_notifications").run { systemSettings(interact) }
|
||||
|
||||
fun openMakeDefaultBrowser(interact: SystemSettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://make_default_browser").run { systemSettings(interact) }
|
||||
openDeepLink("make_default_browser").run { systemSettings(interact) }
|
||||
}
|
||||
|
||||
private fun settings(interact: SettingsRobot.() -> Unit) =
|
||||
|
@ -79,24 +79,42 @@
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="enable_private_browsing"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="home"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings"/>
|
||||
android:host="home_collections"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="turn_on_sync"/>
|
||||
android:host="install_search_widget"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_search_engine"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_accessibility"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_delete_browsing_data"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="enable_private_browsing"/>
|
||||
android:host="make_default_browser"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="open"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="make_default_browser"/>
|
||||
android:host="settings"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_accessibility"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_addon_manager"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_delete_browsing_data"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_logins"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_notifications"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_privacy"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_search_engine"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="settings_tracking_protection"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="turn_on_sync"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="urls_bookmarks"/>
|
||||
<data android:scheme="${deepLinkScheme}"
|
||||
android:host="urls_history"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
@ -12,6 +12,7 @@ import android.os.Build.VERSION.SDK_INT
|
||||
import android.provider.Settings
|
||||
import androidx.navigation.NavController
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.GlobalDirections
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
@ -26,7 +27,7 @@ class DeepLinkIntentProcessor(
|
||||
) : HomeIntentProcessor {
|
||||
|
||||
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
|
||||
val scheme = intent.scheme?.contains("fenix") ?: return false
|
||||
val scheme = intent.scheme?.equals(BuildConfig.DEEP_LINK_SCHEME, ignoreCase = true) ?: return false
|
||||
return if (scheme) {
|
||||
intent.data?.let { handleDeepLink(it, navController) }
|
||||
true
|
||||
|
@ -19,6 +19,7 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.BuildConfig.DEEP_LINK_SCHEME
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.NavGraphDirections
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
@ -52,7 +53,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `return true if scheme is fenix`() {
|
||||
assertTrue(processor.process(testIntent("fenix://test"), navController, out))
|
||||
assertTrue(processor.process(testIntent("test"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController wasNot Called }
|
||||
@ -70,7 +71,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process home deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://home"), navController, out))
|
||||
assertTrue(processor.process(testIntent("home"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalHome()) }
|
||||
@ -79,7 +80,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process urls_bookmarks deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://urls_bookmarks"), navController, out))
|
||||
assertTrue(processor.process(testIntent("urls_bookmarks"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalBookmarkFragment(BookmarkRoot.Root.id)) }
|
||||
verify { out wasNot Called }
|
||||
@ -87,7 +88,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process urls_history deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://urls_history"), navController, out))
|
||||
assertTrue(processor.process(testIntent("urls_history"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalHistoryFragment()) }
|
||||
verify { out wasNot Called }
|
||||
@ -95,7 +96,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process home_collections deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://home_collections"), navController, out))
|
||||
assertTrue(processor.process(testIntent("home_collections"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalHome()) }
|
||||
verify { out wasNot Called }
|
||||
@ -103,7 +104,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalSettingsFragment()) }
|
||||
@ -112,7 +113,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process turn_on_sync deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://turn_on_sync"), navController, out))
|
||||
assertTrue(processor.process(testIntent("turn_on_sync"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalTurnOnSync()) }
|
||||
@ -121,7 +122,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_search_engine deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_search_engine"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_search_engine"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalSearchEngineFragment()) }
|
||||
@ -130,7 +131,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_accessibility deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_accessibility"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_accessibility"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalAccessibilityFragment()) }
|
||||
@ -139,7 +140,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_delete_browsing_data deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_delete_browsing_data"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_delete_browsing_data"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalDeleteBrowsingDataFragment()) }
|
||||
@ -148,7 +149,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_addon_manager deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_addon_manager"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_addon_manager"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalSettingsAddonsManagementFragment()) }
|
||||
verify { out wasNot Called }
|
||||
@ -156,7 +157,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_logins deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_logins"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_logins"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalSavedLoginsAuthFragment()) }
|
||||
verify { out wasNot Called }
|
||||
@ -164,7 +165,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_tracking_protection deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_tracking_protection"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_tracking_protection"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalTrackingProtectionFragment()) }
|
||||
verify { out wasNot Called }
|
||||
@ -172,7 +173,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_privacy deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_privacy"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_privacy"), navController, out))
|
||||
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalSettingsFragment()) }
|
||||
verify { out wasNot Called }
|
||||
@ -180,7 +181,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process enable_private_browsing deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://enable_private_browsing"), navController, out))
|
||||
assertTrue(processor.process(testIntent("enable_private_browsing"), navController, out))
|
||||
|
||||
verify { activity.browsingModeManager.mode = BrowsingMode.Private }
|
||||
verify { navController.navigate(NavGraphDirections.actionGlobalHome()) }
|
||||
@ -189,13 +190,13 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process open deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://open"), navController, out))
|
||||
assertTrue(processor.process(testIntent("open"), navController, out))
|
||||
|
||||
verify { activity wasNot Called }
|
||||
verify { navController wasNot Called }
|
||||
verify { out wasNot Called }
|
||||
|
||||
assertTrue(processor.process(testIntent("fenix://open?url=test"), navController, out))
|
||||
assertTrue(processor.process(testIntent("open?url=test"), navController, out))
|
||||
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
@ -210,7 +211,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process make_default_browser deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://make_default_browser"), navController, out))
|
||||
assertTrue(processor.process(testIntent("make_default_browser"), navController, out))
|
||||
|
||||
verify { navController wasNot Called }
|
||||
verify { out wasNot Called }
|
||||
@ -218,7 +219,7 @@ class DeepLinkIntentProcessorTest {
|
||||
|
||||
@Test
|
||||
fun `process settings_notifications deep link`() {
|
||||
assertTrue(processor.process(testIntent("fenix://settings_notifications"), navController, out))
|
||||
assertTrue(processor.process(testIntent("settings_notifications"), navController, out))
|
||||
|
||||
verify { navController wasNot Called }
|
||||
verify { out wasNot Called }
|
||||
@ -229,12 +230,12 @@ class DeepLinkIntentProcessorTest {
|
||||
fun `process install_search_widget deep link`() {
|
||||
mockkObject(SearchWidgetCreator)
|
||||
every { SearchWidgetCreator.createSearchWidget(any()) } returns true
|
||||
assertTrue(processor.process(testIntent("fenix://install_search_widget"), navController, out))
|
||||
assertTrue(processor.process(testIntent("install_search_widget"), navController, out))
|
||||
|
||||
verify { navController wasNot Called }
|
||||
verify { out wasNot Called }
|
||||
verify { activity wasNot Called }
|
||||
}
|
||||
|
||||
private fun testIntent(uri: String) = Intent("", uri.toUri())
|
||||
private fun testIntent(uri: String) = Intent("", "$DEEP_LINK_SCHEME://$uri".toUri())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user