parent
ccb5b0b641
commit
d45af2a717
|
@ -10,6 +10,7 @@ import android.os.Bundle
|
|||
import android.os.StrictMode
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import mozilla.components.feature.intent.processing.IntentProcessor
|
||||
import org.mozilla.fenix.HomeActivity.Companion.PRIVATE_BROWSING_MODE
|
||||
import org.mozilla.fenix.components.IntentProcessorType
|
||||
import org.mozilla.fenix.components.getType
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
|
@ -43,7 +44,15 @@ class IntentReceiverActivity : Activity() {
|
|||
|
||||
fun processIntent(intent: Intent) {
|
||||
// Call process for side effects, short on the first that returns true
|
||||
val processor = getIntentProcessors().firstOrNull { it.process(intent) }
|
||||
val private = settings().openLinksInAPrivateTab
|
||||
intent.putExtra(PRIVATE_BROWSING_MODE, private)
|
||||
if (private) {
|
||||
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.PRIVATE))
|
||||
} else {
|
||||
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.NORMAL))
|
||||
}
|
||||
|
||||
val processor = getIntentProcessors(private).firstOrNull { it.process(intent) }
|
||||
val intentProcessorType = components.intentProcessors.getType(processor)
|
||||
|
||||
launch(intent, intentProcessorType)
|
||||
|
@ -65,17 +74,14 @@ class IntentReceiverActivity : Activity() {
|
|||
finish() // must finish() after starting the other activity
|
||||
}
|
||||
|
||||
private fun getIntentProcessors(): List<IntentProcessor> {
|
||||
val modeDependentProcessors = if (settings().openLinksInAPrivateTab) {
|
||||
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.PRIVATE))
|
||||
intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, true)
|
||||
private fun getIntentProcessors(private: Boolean): List<IntentProcessor> {
|
||||
val modeDependentProcessors = if (private) {
|
||||
listOf(
|
||||
components.intentProcessors.privateCustomTabIntentProcessor,
|
||||
components.intentProcessors.privateIntentProcessor
|
||||
)
|
||||
} else {
|
||||
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.NORMAL))
|
||||
intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, false)
|
||||
listOf(
|
||||
components.intentProcessors.customTabIntentProcessor,
|
||||
components.intentProcessors.intentProcessor
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.mockk.every
|
|||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import mozilla.components.feature.intent.processing.IntentProcessor
|
||||
|
@ -139,9 +140,14 @@ class IntentReceiverActivityTest {
|
|||
attachMocks(activity)
|
||||
activity.processIntent(intent)
|
||||
|
||||
val shadow = shadowOf(activity)
|
||||
val actualIntent = shadow.peekNextStartedActivity()
|
||||
|
||||
val normalProcessor = intentProcessors.intentProcessor
|
||||
coVerify(exactly = 0) { normalProcessor.process(intent) }
|
||||
coVerify { intentProcessors.privateIntentProcessor.process(intent) }
|
||||
verify(exactly = 0) { normalProcessor.process(intent) }
|
||||
verify { intentProcessors.privateIntentProcessor.process(intent) }
|
||||
assertEquals(HomeActivity::class.java.name, actualIntent.component?.className)
|
||||
assertTrue(actualIntent.getBooleanExtra(HomeActivity.PRIVATE_BROWSING_MODE, false))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue