|
|
|
@ -12,18 +12,28 @@ import io.mockk.every
|
|
|
|
|
import io.mockk.mockk
|
|
|
|
|
import io.mockk.spyk
|
|
|
|
|
import io.mockk.verify
|
|
|
|
|
import mozilla.components.browser.state.state.BrowserState
|
|
|
|
|
import mozilla.components.browser.state.state.createCustomTab
|
|
|
|
|
import mozilla.components.browser.state.state.createTab
|
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
|
import mozilla.components.feature.intent.ext.putSessionId
|
|
|
|
|
import mozilla.components.support.utils.toSafeIntent
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.mozilla.fenix.BrowserDirection
|
|
|
|
|
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
|
|
|
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
|
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|
|
|
|
import org.mozilla.fenix.utils.Settings
|
|
|
|
|
|
|
|
|
|
@RunWith(FenixRobolectricTestRunner::class)
|
|
|
|
|
class ExternalAppBrowserActivityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -95,4 +105,68 @@ class ExternalAppBrowserActivityTest {
|
|
|
|
|
assertNull(directions)
|
|
|
|
|
verify { activity.finishAndRemoveTask() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `ExternalAppBrowserActivity with matching external tab`() {
|
|
|
|
|
val store = BrowserStore(BrowserState(
|
|
|
|
|
customTabs = listOf(
|
|
|
|
|
createCustomTab(
|
|
|
|
|
url = "https://www.mozilla.org",
|
|
|
|
|
id = "mozilla"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW).apply { putSessionId("mozilla") }
|
|
|
|
|
|
|
|
|
|
val activity = spyk(ExternalAppBrowserActivity())
|
|
|
|
|
every { activity.components.core.store } returns store
|
|
|
|
|
every { activity.intent } returns intent
|
|
|
|
|
|
|
|
|
|
assertTrue(activity.hasExternalTab())
|
|
|
|
|
|
|
|
|
|
assertEquals("mozilla", activity.getExternalTabId())
|
|
|
|
|
|
|
|
|
|
val tab = activity.getExternalTab()
|
|
|
|
|
assertNotNull(tab!!)
|
|
|
|
|
assertEquals("https://www.mozilla.org", tab.content.url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `ExternalAppBrowserActivity without matching external tab`() {
|
|
|
|
|
val store = BrowserStore()
|
|
|
|
|
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW).apply { putSessionId("mozilla") }
|
|
|
|
|
|
|
|
|
|
val activity = spyk(ExternalAppBrowserActivity())
|
|
|
|
|
every { activity.components.core.store } returns store
|
|
|
|
|
every { activity.intent } returns intent
|
|
|
|
|
|
|
|
|
|
assertFalse(activity.hasExternalTab())
|
|
|
|
|
assertEquals("mozilla", activity.getExternalTabId())
|
|
|
|
|
assertNull(activity.getExternalTab())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `ExternalAppBrowserActivity with matching regular tab`() {
|
|
|
|
|
val store = BrowserStore(BrowserState(
|
|
|
|
|
tabs = listOf(
|
|
|
|
|
createTab(
|
|
|
|
|
url = "https://www.mozilla.org",
|
|
|
|
|
id = "mozilla"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW).apply { putSessionId("mozilla") }
|
|
|
|
|
|
|
|
|
|
val activity = spyk(ExternalAppBrowserActivity())
|
|
|
|
|
every { activity.components.core.store } returns store
|
|
|
|
|
every { activity.intent } returns intent
|
|
|
|
|
|
|
|
|
|
// Even though we have a matching regular tab we do not care about it in ExternalAppBrowserActivity
|
|
|
|
|
assertFalse(activity.hasExternalTab())
|
|
|
|
|
assertEquals("mozilla", activity.getExternalTabId())
|
|
|
|
|
assertNull(activity.getExternalTab())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|