Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BrowserActivityTestRule : ExternalResource() {
get() {
var result: BrowserActivity? = null
scenario.onActivity { result = it }
return result!!
return checkNotNull(result) { "Activity unavailable — scenario may be in a terminal state" }
}

override fun before() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package org.mozilla.reference.browser.ui

import android.content.ComponentName
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import mockwebserver3.MockWebServer
import org.junit.After
import org.junit.Before
Expand All @@ -28,6 +30,19 @@ class CustomTabsTest {
@JvmField
val retryTestRule = RetryTestRule(3)

// ActivityScenario.launch resolves intents via normal Android routing, so an ACTION_VIEW
// intent with an HTTP URL would resolve to the browser rather than IntentReceiverActivity.
// Setting the component explicitly forces it to launch within the test process.
private fun launchCustomTab(pageUrl: String) =
ActivityScenario.launch<IntentReceiverActivity>(
createCustomTabIntent(pageUrl).apply {
component = ComponentName(
InstrumentationRegistry.getInstrumentation().targetContext,
IntentReceiverActivity::class.java,
)
},
)

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
Expand All @@ -45,10 +60,7 @@ class CustomTabsTest {
fun openCustomTabTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
launchCustomTab(customTabPage.url.toString()).use {
customTabScreen {
verifyCloseButton()
verifyTrackingProtectionIcon()
Expand All @@ -65,10 +77,7 @@ class CustomTabsTest {
fun verifyCustomTabMenuItemsTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
launchCustomTab(customTabPage.url.toString()).use {
customTabScreen {
}.openMainMenu {
verifyForwardButton()
Expand All @@ -87,10 +96,7 @@ class CustomTabsTest {
val pageLinks = TestAssetHelper.getGenericAsset(mockWebServer, 4)
val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(pageLinks.url.toString()),
).use {
launchCustomTab(pageLinks.url.toString()).use {
customTabScreen {
clickGenericLink("Link 1")
verifyPageTitle(genericURL.title)
Expand All @@ -110,10 +116,7 @@ class CustomTabsTest {
fun customTabShareTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
launchCustomTab(customTabPage.url.toString()).use {
customTabScreen {
}.openMainMenu {
}.clickShareButton {
Expand All @@ -126,10 +129,7 @@ class CustomTabsTest {
fun customTabRequestDesktopSiteTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
launchCustomTab(customTabPage.url.toString()).use {
customTabScreen {
}.openMainMenu {
switchRequestDesktopSiteToggle()
Expand All @@ -146,10 +146,7 @@ class CustomTabsTest {
fun customTabOpenInBrowserTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
launchCustomTab(customTabPage.url.toString()).use {
customTabScreen {
}.openMainMenu {
}.clickOpenInBrowserButton {
Expand Down