Skip to content
Open
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ dependencies {
implementation libs.mozilla.ui.tabcounter
implementation libs.mozilla.ui.widgets

androidTestImplementation libs.androidx.test.core
androidTestImplementation libs.androidx.test.espresso.core
androidTestImplementation libs.androidx.test.espresso.idling.resources
constraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@file:Suppress("DEPRECATION")

package org.mozilla.reference.browser.helpers

import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.IdlingRegistry
import androidx.test.rule.ActivityTestRule
import org.junit.rules.ExternalResource
import org.mozilla.reference.browser.BrowserActivity

/**
* A [org.junit.Rule] to handle shared test set up for tests on [BrowserActivity].
*
* @param initialTouchMode See [ActivityTestRule]
* @param launchActivity See [ActivityTestRule]
*/
class BrowserActivityTestRule(
initialTouchMode: Boolean = false,
launchActivity: Boolean = true,
) : ActivityTestRule<BrowserActivity>(BrowserActivity::class.java, initialTouchMode, launchActivity) {
class BrowserActivityTestRule : ExternalResource() {
/**
* Ensures the test doesn't advance until session page load is completed.
*
Expand All @@ -29,16 +22,25 @@ class BrowserActivityTestRule(
* implementation changes and the tests break. In that case, this code might be
* broken because it's not used, and thus tested, at present.
*/

private lateinit var loadingIdlingResource: SessionLoadedIdlingResource
private lateinit var scenario: ActivityScenario<BrowserActivity>

val activity: BrowserActivity
get() {
var result: BrowserActivity? = null
scenario.onActivity { result = it }
return result!!
}

override fun beforeActivityLaunched() {
override fun before() {
loadingIdlingResource = SessionLoadedIdlingResource().also {
IdlingRegistry.getInstance().register(it)
}
scenario = ActivityScenario.launch(BrowserActivity::class.java)
}

override fun afterActivityFinished() {
override fun after() {
scenario.close()
IdlingRegistry.getInstance().unregister(loadingIdlingResource)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@file:Suppress("DEPRECATION")

package org.mozilla.reference.browser.ui

import androidx.test.rule.ActivityTestRule
import androidx.test.core.app.ActivityScenario
import mockwebserver3.MockWebServer
import org.junit.After
import org.junit.Before
Expand All @@ -26,13 +24,6 @@ class CustomTabsTest {
@get:Rule
val activityTestRule = BrowserActivityTestRule()

@get:Rule
val intentReceiverActivityTestRule = ActivityTestRule(
IntentReceiverActivity::class.java,
true,
false,
)

@Rule
@JvmField
val retryTestRule = RetryTestRule(3)
Expand All @@ -54,42 +45,40 @@ class CustomTabsTest {
fun openCustomTabTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)

customTabScreen {
verifyCloseButton()
verifyTrackingProtectionIcon()
verifySecurityIndicator()
verifyPageTitle(customTabPage.title)
verifyPageUrl(customTabPage.url.toString())
verifyActionButton()
verifyMenuButton()
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
customTabScreen {
verifyCloseButton()
verifyTrackingProtectionIcon()
verifySecurityIndicator()
verifyPageTitle(customTabPage.title)
verifyPageUrl(customTabPage.url.toString())
verifyActionButton()
verifyMenuButton()
}
}
}

@Test
fun verifyCustomTabMenuItemsTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)

customTabScreen {
}.openMainMenu {
verifyForwardButton()
verifyRefreshButton()
verifyStopButton()
verifyShareButton()
verifyRequestDesktopButton()
verifyFindInPageButton()
verifyOpenInBrowserButton()
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
customTabScreen {
}.openMainMenu {
verifyForwardButton()
verifyRefreshButton()
verifyStopButton()
verifyShareButton()
verifyRequestDesktopButton()
verifyFindInPageButton()
verifyOpenInBrowserButton()
}
}
}

Expand All @@ -98,78 +87,74 @@ class CustomTabsTest {
val pageLinks = TestAssetHelper.getGenericAsset(mockWebServer, 4)
val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
pageLinks.url.toString(),
),
)

customTabScreen {
clickGenericLink("Link 1")
verifyPageTitle(genericURL.title)
verifyPageUrl(genericURL.url.toString())
}.goBack {
verifyPageTitle(pageLinks.title)
verifyPageUrl(pageLinks.url.toString())
}.openMainMenu {
clickForwardButton()
verifyPageTitle(genericURL.title)
verifyPageUrl(genericURL.url.toString())
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(pageLinks.url.toString()),
).use {
customTabScreen {
clickGenericLink("Link 1")
verifyPageTitle(genericURL.title)
verifyPageUrl(genericURL.url.toString())
}.goBack {
verifyPageTitle(pageLinks.title)
verifyPageUrl(pageLinks.url.toString())
}.openMainMenu {
clickForwardButton()
verifyPageTitle(genericURL.title)
verifyPageUrl(genericURL.url.toString())
}
}
}

@Test
fun customTabShareTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)

customTabScreen {
}.openMainMenu {
}.clickShareButton {
verifyShareContentPanel()
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
customTabScreen {
}.openMainMenu {
}.clickShareButton {
verifyShareContentPanel()
}
}
}

@Test
fun customTabRequestDesktopSiteTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)

customTabScreen {
}.openMainMenu {
switchRequestDesktopSiteToggle()
}.openMainMenu {
verifyRequestDesktopSiteIsTurnedOn()
switchRequestDesktopSiteToggle()
}.openMainMenu {
verifyRequestDesktopSiteIsTurnedOff()
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
customTabScreen {
}.openMainMenu {
switchRequestDesktopSiteToggle()
}.openMainMenu {
verifyRequestDesktopSiteIsTurnedOn()
switchRequestDesktopSiteToggle()
}.openMainMenu {
verifyRequestDesktopSiteIsTurnedOff()
}
}
}

@Test
fun customTabOpenInBrowserTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)

customTabScreen {
}.openMainMenu {
}.clickOpenInBrowserButton {
verifyUrl(customTabPage.url.toString())
ActivityScenario
.launch<IntentReceiverActivity>(
createCustomTabIntent(customTabPage.url.toString()),
).use {
customTabScreen {
}.openMainMenu {
}.clickOpenInBrowserButton {
verifyUrl(customTabPage.url.toString())
}
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ androidx-compose-ui-text = { group = "androidx.compose.ui", name = "ui-text" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }

# AndroidX Testing
androidx-test-core = { group = "androidx.test", name = "core", version.ref = "androidx-test-core" }
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-test-espresso" }
androidx-test-espresso-idling-resources = { group = "androidx.test.espresso", name = "espresso-idling-resource", version.ref = "androidx-test-espresso" }
androidx-test-monitor = { group = "androidx.test", name = "monitor", version.ref = "androidx-test-monitor" }
Expand Down