|
|
@ -5,9 +5,11 @@
|
|
|
|
package org.mozilla.fenix
|
|
|
|
package org.mozilla.fenix
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import android.content.Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.test.runBlockingTest
|
|
|
|
import kotlinx.coroutines.test.runBlockingTest
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.mockito.Mockito.`when`
|
|
|
|
import org.mockito.Mockito.`when`
|
|
|
@ -15,8 +17,10 @@ import org.mockito.Mockito.never
|
|
|
|
import org.mockito.Mockito.verify
|
|
|
|
import org.mockito.Mockito.verify
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
|
|
|
|
import org.mozilla.fenix.shortcut.NewTabShortcutIntentProcessor
|
|
|
|
import org.robolectric.Robolectric
|
|
|
|
import org.robolectric.Robolectric
|
|
|
|
import org.robolectric.RobolectricTestRunner
|
|
|
|
import org.robolectric.RobolectricTestRunner
|
|
|
|
|
|
|
|
import org.robolectric.Shadows.shadowOf
|
|
|
|
import org.robolectric.annotation.Config
|
|
|
|
import org.robolectric.annotation.Config
|
|
|
|
|
|
|
|
|
|
|
|
@ExperimentalCoroutinesApi
|
|
|
|
@ExperimentalCoroutinesApi
|
|
|
@ -25,37 +29,106 @@ import org.robolectric.annotation.Config
|
|
|
|
class IntentReceiverActivityTest {
|
|
|
|
class IntentReceiverActivityTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun `process intent with launchLinksInPrivateTab set to true`() {
|
|
|
|
fun `process intent with flag launched from history`() = runBlockingTest {
|
|
|
|
runBlockingTest {
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
testContext.settings().openLinksInAPrivateTab = true
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
val intent = Intent()
|
|
|
|
intent.flags = FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
|
|
|
|
`when`(testContext.components.intentProcessors.privateIntentProcessor.process(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)
|
|
|
|
activity.processIntent(intent)
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.matches(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
// Not using mockk here because process is a suspend function
|
|
|
|
activity.processIntent(intent)
|
|
|
|
// and mockito makes this easier to read.
|
|
|
|
|
|
|
|
verify(testContext.components.intentProcessors.intentProcessor, never()).process(intent)
|
|
|
|
val shadow = shadowOf(activity)
|
|
|
|
verify(testContext.components.intentProcessors.privateIntentProcessor).process(intent)
|
|
|
|
val actualIntent = shadow.peekNextStartedActivity()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(HomeActivity::class.java.name, actualIntent.component?.className)
|
|
|
|
|
|
|
|
assertEquals(true, actualIntent.flags == FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `process intent with action OPEN_PRIVATE_TAB`() = runBlockingTest {
|
|
|
|
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
|
|
|
|
intent.action = NewTabShortcutIntentProcessor.ACTION_OPEN_PRIVATE_TAB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(false)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
|
|
|
|
activity.processIntent(intent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val shadow = shadowOf(activity)
|
|
|
|
|
|
|
|
val actualIntent = shadow.peekNextStartedActivity()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(HomeActivity::class.java.name, actualIntent.component?.className)
|
|
|
|
|
|
|
|
assertEquals(true, actualIntent.getBooleanExtra(HomeActivity.PRIVATE_BROWSING_MODE, false))
|
|
|
|
|
|
|
|
assertEquals(false, actualIntent.getBooleanExtra(HomeActivity.OPEN_TO_BROWSER, true))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `process intent with action OPEN_TAB`() = runBlockingTest {
|
|
|
|
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
|
|
|
|
intent.action = NewTabShortcutIntentProcessor.ACTION_OPEN_TAB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
|
|
|
|
activity.processIntent(intent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val shadow = shadowOf(activity)
|
|
|
|
|
|
|
|
val actualIntent = shadow.peekNextStartedActivity()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(HomeActivity::class.java.name, actualIntent.component?.className)
|
|
|
|
|
|
|
|
assertEquals(false, actualIntent.hasExtra(HomeActivity.PRIVATE_BROWSING_MODE))
|
|
|
|
|
|
|
|
assertEquals(false, actualIntent.getBooleanExtra(HomeActivity.OPEN_TO_BROWSER, true))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `process intent starts Activity`() = runBlockingTest {
|
|
|
|
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
|
|
|
|
activity.processIntent(intent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val shadow = shadowOf(activity)
|
|
|
|
|
|
|
|
val actualIntent = shadow.peekNextStartedActivity()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(HomeActivity::class.java.name, actualIntent.component?.className)
|
|
|
|
|
|
|
|
assertEquals(false, actualIntent.getBooleanExtra(HomeActivity.OPEN_TO_BROWSER, true))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `process intent with launchLinksInPrivateTab set to true`() = runBlockingTest {
|
|
|
|
|
|
|
|
testContext.settings().openLinksInAPrivateTab = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
|
|
|
|
`when`(testContext.components.intentProcessors.privateIntentProcessor.process(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
|
|
|
|
activity.processIntent(intent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Not using mockk here because process is a suspend function
|
|
|
|
|
|
|
|
// and mockito makes this easier to read.
|
|
|
|
|
|
|
|
verify(testContext.components.intentProcessors.intentProcessor, never()).process(intent)
|
|
|
|
|
|
|
|
verify(testContext.components.intentProcessors.privateIntentProcessor).process(intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun `process intent with launchLinksInPrivateTab set to false`() {
|
|
|
|
fun `process intent with launchLinksInPrivateTab set to false`() = runBlockingTest {
|
|
|
|
runBlockingTest {
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
testContext.settings().openLinksInAPrivateTab = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent()
|
|
|
|
val intent = Intent()
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)
|
|
|
|
`when`(testContext.components.intentProcessors.intentProcessor.process(intent)).thenReturn(true)
|
|
|
|
|
|
|
|
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
val activity = Robolectric.buildActivity(IntentReceiverActivity::class.java, intent).get()
|
|
|
|
activity.processIntent(intent)
|
|
|
|
activity.processIntent(intent)
|
|
|
|
|
|
|
|
|
|
|
|
// Not using mockk here because process is a suspend function
|
|
|
|
// Not using mockk here because process is a suspend function
|
|
|
|
// and mockito makes this easier to read.
|
|
|
|
// and mockito makes this easier to read.
|
|
|
|
verify(testContext.components.intentProcessors.privateIntentProcessor, never()).process(intent)
|
|
|
|
verify(testContext.components.intentProcessors.privateIntentProcessor, never()).process(intent)
|
|
|
|
verify(testContext.components.intentProcessors.intentProcessor).process(intent)
|
|
|
|
verify(testContext.components.intentProcessors.intentProcessor).process(intent)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|