Skip to content

Commit

Permalink
Issue mozilla-mobile#6097: Remove IntentProcessor.matches().
Browse files Browse the repository at this point in the history
IntentProcessor.process() already checks whether the Intent matches and returns true or
false. Another call to matches() is not necessary. Fenix was already refactored and we
removed the matches() call.
  • Loading branch information
pocmo committed Mar 3, 2020
1 parent 9257f15 commit ddef382
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomTabIntentProcessor(
private val isPrivate: Boolean = false
) : IntentProcessor {

override fun matches(intent: Intent): Boolean {
private fun matches(intent: Intent): Boolean {
val safeIntent = intent.toSafeIntent()
return safeIntent.action == ACTION_VIEW && isCustomTabIntent(safeIntent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import android.content.Intent
* Processor for Android intents which should trigger session-related actions.
*/
interface IntentProcessor {

/**
* Returns true if this intent processor will handle the intent.
*/
fun matches(intent: Intent): Boolean

/**
* Processes the given [Intent].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ class TabIntentProcessor(
}
}

override fun matches(intent: Intent): Boolean {
val safeIntent = SafeIntent(intent)
return safeIntent.action == ACTION_VIEW ||
safeIntent.action == ACTION_SEND ||
safeIntent.action == ACTION_NDEF_DISCOVERED ||
safeIntent.action == ACTION_SEARCH ||
safeIntent.action == ACTION_WEB_SEARCH
}

/**
* Processes the given intent by invoking the registered handler.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TrustedWebActivityIntentProcessor(
private val verifier = OriginVerifierFeature(httpClient, packageManager, apiKey) { store.dispatch(it) }
private val scope = MainScope()

override fun matches(intent: Intent): Boolean {
private fun matches(intent: Intent): Boolean {
val safeIntent = intent.toSafeIntent()
return safeIntent.action == ACTION_VIEW && isTrustedWebActivityIntent(safeIntent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WebAppIntentProcessor(
/**
* Returns true if this intent should launch a progressive web app.
*/
override fun matches(intent: Intent) =
private fun matches(intent: Intent) =
intent.toSafeIntent().action == ACTION_VIEW_PWA

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@ class TrustedWebActivityIntentProcessorTest {
sessionManager = SessionManager(mock(), store)
}

@Test
fun `matches checks if intent is a trusted web activity intent`() {
val processor = TrustedWebActivityIntentProcessor(mock(), mock(), mock(), mock(), apiKey, mock())

assertFalse(processor.matches(Intent(ACTION_VIEW_PWA)))
assertFalse(processor.matches(Intent(ACTION_VIEW)))
assertFalse(processor.matches(
Intent(ACTION_VIEW).apply { putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true) }
))
assertFalse(processor.matches(
Intent(ACTION_VIEW).apply {
putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false)
putExtra(EXTRA_SESSION, null as Bundle?)
}
))
assertTrue(processor.matches(
Intent(ACTION_VIEW).apply {
putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true)
putExtra(EXTRA_SESSION, null as Bundle?)
}
))
}

@Test
fun `process checks if intent action is not valid`() = runBlockingTest {
val processor = TrustedWebActivityIntentProcessor(mock(), mock(), mock(), mock(), apiKey, mock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ import org.mockito.Mockito.`when`
@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class WebAppIntentProcessorTest {

@Test
fun `matches checks if intent action is ACTION_VIEW_PWA`() {
val processor = WebAppIntentProcessor(mock(), mock(), mock())

assertTrue(processor.matches(Intent(ACTION_VIEW_PWA)))
assertFalse(processor.matches(Intent(ACTION_VIEW)))
}

@Test
fun `process checks if intent action is not valid`() = runBlockingTest {
val processor = WebAppIntentProcessor(mock(), mock(), mock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import mozilla.components.support.migration.state.MigrationStore
* ⚠️ When using this processor, ensure this is the first processor to be invoked if there are multiple.
*/
class MigrationIntentProcessor(private val store: MigrationStore) : IntentProcessor {

/**
* Matches itself with all intents in order to ensure processing all of incoming intents.
*/
override fun matches(intent: Intent): Boolean = store.state.progress == MigrationProgress.MIGRATING

/**
* Processes all incoming intents if a migration is in progress.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ import org.junit.Assert.assertTrue
import org.junit.Test

class MigrationIntentProcessorTest {
@Test
fun `matches against all view action intents`() = runBlockingTest {
val store = MigrationStore()
val processor = MigrationIntentProcessor(store)
val intent: Intent = mock()

assertFalse(processor.matches(intent))

store.dispatch(MigrationAction.Started).joinBlocking()

assertTrue(processor.matches(intent))
}

@Test
fun `process updates intent`() = runBlockingTest {
val store = MigrationStore()
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permalink: /changelog/
* **feature-awesomebar**
* ⚠️ **This is a breaking change**: Refactored component to use `browser-state` instead of `browser-session`. Feature and `SuggestionProvider` implementations may require a `BrowserStore` instance instead of a `SessionManager` now.

* **feature-intent**
* ⚠️ **This is a breaking change**: Removed `IntentProcessor.matches()` method from interface. Calling `process()` and examining the boolean return value is enough to know whether an `Intent` matched.

* **feature-downloads**
* Fixed APK downloads not prompting to install when the notification is clicked.

Expand Down

0 comments on commit ddef382

Please sign in to comment.