From 6e97ac25275ff308b00a329583c7ac202bc42232 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Tue, 2 Mar 2021 17:59:00 +0200 Subject: [PATCH] Closes #9805 - Add support for opening links from ACTION_MAIN Intents This kind of Intents could get to the app following calls to `Intent .makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)`. --- .../intent/processing/TabIntentProcessor.kt | 3 +- .../processing/TabIntentProcessorTest.kt | 38 +++++++++++++++++++ docs/changelog.md | 3 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/components/feature/intent/src/main/java/mozilla/components/feature/intent/processing/TabIntentProcessor.kt b/components/feature/intent/src/main/java/mozilla/components/feature/intent/processing/TabIntentProcessor.kt index 4a35cad6c26..323af79ad3f 100644 --- a/components/feature/intent/src/main/java/mozilla/components/feature/intent/processing/TabIntentProcessor.kt +++ b/components/feature/intent/src/main/java/mozilla/components/feature/intent/processing/TabIntentProcessor.kt @@ -6,6 +6,7 @@ package mozilla.components.feature.intent.processing import android.app.SearchManager import android.content.Intent +import android.content.Intent.ACTION_MAIN import android.content.Intent.ACTION_SEND import android.content.Intent.ACTION_VIEW import android.content.Intent.ACTION_SEARCH @@ -108,7 +109,7 @@ class TabIntentProcessor( override fun process(intent: Intent): Boolean { val safeIntent = SafeIntent(intent) return when (safeIntent.action) { - ACTION_VIEW, ACTION_NDEF_DISCOVERED -> processViewIntent(safeIntent) + ACTION_VIEW, ACTION_MAIN, ACTION_NDEF_DISCOVERED -> processViewIntent(safeIntent) ACTION_SEND -> processSendIntent(safeIntent) ACTION_SEARCH, ACTION_WEB_SEARCH -> processSearchIntent(safeIntent) else -> false diff --git a/components/feature/intent/src/test/java/mozilla/components/feature/intent/processing/TabIntentProcessorTest.kt b/components/feature/intent/src/test/java/mozilla/components/feature/intent/processing/TabIntentProcessorTest.kt index c29b17c3c19..1b1909bacef 100644 --- a/components/feature/intent/src/test/java/mozilla/components/feature/intent/processing/TabIntentProcessorTest.kt +++ b/components/feature/intent/src/test/java/mozilla/components/feature/intent/processing/TabIntentProcessorTest.kt @@ -102,6 +102,44 @@ class TabIntentProcessorTest { assertEquals(Source.ACTION_VIEW, session.source) } + @Test + fun `process ACTION MAIN Intent`() { + val engine = mock() + val sessionManager = spy(SessionManager(engine)) + val useCases = SessionUseCases(store, sessionManager) + val handler = + TabIntentProcessor(TabsUseCases(store, sessionManager), useCases.loadUrl, searchUseCases.newTabSearch) + val intent = mock() + whenever(intent.action).thenReturn(Intent.ACTION_MAIN) + + val engineSession = mock() + whenever(intent.dataString).thenReturn("") + handler.process(intent) + verify(engineSession, never()).loadUrl("") + + whenever(intent.dataString).thenReturn("http://mozilla.org") + handler.process(intent) + + val sessionCaptor = argumentCaptor() + verify(sessionManager).add(sessionCaptor.capture(), eq(true), eq(null), eq(null), eq(null)) + verify(store).dispatch(EngineAction.LoadUrlAction( + sessionCaptor.value.id, "http://mozilla.org", LoadUrlFlags.external()) + ) + + // try to send a request to open a tab with the same url as before + whenever(intent.dataString).thenReturn("http://mozilla.org") + handler.process(intent) + verify(sessionManager).select(any()) + verify(sessionManager, never()).add(anyList()) + + assertEquals(sessionManager.sessions.size, 1) + + val session = sessionManager.all[0] + assertNotNull(session) + assertEquals("http://mozilla.org", session.url) + assertEquals(Source.ACTION_VIEW, session.source) + } + @Test fun processNfcIntent() { val engine = mock() diff --git a/docs/changelog.md b/docs/changelog.md index 7f27740150f..bcabcacecdb 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/.config.yml) +* **intent-processing** + * 🌟️ Added support for opening links from ACTION_MAIN Intents. This Intents could the result of `Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)` calls. + * **browser-toolbar** * 🌟️ Added `ToolbarBehaviorController` to automatically block the `BrowserToolbar` being animated by the `BrowserToolbarBehavior` while the tab is loading. This new class just has to be initialized by AC clients, similar to `ToolbarPresenter`.