ExternalAppBrowserActivity: Add additional test cases.
This commit is contained in:
parent
788a8309c2
commit
57ebc0cb99
|
@ -5,6 +5,7 @@
|
|||
package org.mozilla.fenix.customtabs
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.navigation.NavDestination
|
||||
import androidx.navigation.NavDirections
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
|
@ -111,16 +112,19 @@ open class ExternalAppBrowserActivity : HomeActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun hasExternalTab(): Boolean {
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal fun hasExternalTab(): Boolean {
|
||||
return getExternalTab() != null
|
||||
}
|
||||
|
||||
private fun getExternalTab(): SessionState? {
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal fun getExternalTab(): SessionState? {
|
||||
val id = getExternalTabId() ?: return null
|
||||
return components.core.store.state.findCustomTab(id)
|
||||
}
|
||||
|
||||
private fun getExternalTabId(): String? {
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal fun getExternalTabId(): String? {
|
||||
return getIntentSessionId(SafeIntent(intent))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -513,7 +513,7 @@ class DefaultBrowserToolbarMenuControllerTest {
|
|||
verify { currentSession.customTabConfig = null }
|
||||
verify { sessionManager.select(currentSession) }
|
||||
verify { activity.startActivity(openInFenixIntent) }
|
||||
verify { activity.finish() }
|
||||
verify { activity.finishAndRemoveTask() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user