Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Closes #9805 - Add support for opening links from ACTION_MAIN Intents #9811

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ class TabIntentProcessorTest {
assertEquals(Source.ACTION_VIEW, session.source)
}

@Test
fun `process ACTION MAIN Intent`() {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
val useCases = SessionUseCases(store, sessionManager)
val handler =
TabIntentProcessor(TabsUseCases(store, sessionManager), useCases.loadUrl, searchUseCases.newTabSearch)
val intent = mock<Intent>()
whenever(intent.action).thenReturn(Intent.ACTION_MAIN)

val engineSession = mock<EngineSession>()
whenever(intent.dataString).thenReturn("")
handler.process(intent)
verify(engineSession, never()).loadUrl("")

whenever(intent.dataString).thenReturn("http://mozilla.org")
handler.process(intent)

val sessionCaptor = argumentCaptor<Session>()
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<Engine>()
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down