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 002d2da9671..6f74bebdc97 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`.