Open links in apps UI test

upstream-sync
AndiAJ 3 years ago committed by mergify[bot]
parent 05594c48a0
commit a7e12a4dae

@ -5,6 +5,9 @@
<body>
<h1>
<p id="testContent">Page content: 3</p>
<p>
<a href="https://play.google.com/store/apps/details?id=org.mozilla.fenix">Mozilla Playstore link</a>
</p>
</h1>
</body>
</html>

@ -15,6 +15,7 @@ import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.view.View
import androidx.browser.customtabs.CustomTabsIntent
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
@ -22,8 +23,13 @@ import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.intent.matcher.IntentMatchers.toPackage
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
@ -32,17 +38,19 @@ import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import java.io.File
import kotlinx.coroutines.runBlocking
import mozilla.components.support.ktx.android.content.appName
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Matcher
import org.junit.Assert
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.helpers.idlingresource.NetworkConnectionIdlingResource
import org.mozilla.fenix.ui.robots.BrowserRobot
import org.mozilla.fenix.ui.robots.mDevice
import java.io.File
object TestHelper {
@ -209,6 +217,14 @@ object TestHelper {
}
}
fun assertNativeAppOpens(appPackageName: String, url: String) {
if (isPackageInstalled(appPackageName)) {
intended(toPackage(appPackageName))
} else {
BrowserRobot().verifyUrl(url)
}
}
fun returnToBrowser() {
val urlBar =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_url_view"))
@ -223,4 +239,14 @@ object TestHelper {
this.waitForIdle()
Assert.assertNotNull(obj.waitForExists(waitingTime))
}
fun hasCousin(matcher: Matcher<View>): Matcher<View> {
return withParent(
hasSibling(
withChild(
matcher
)
)
)
}
}

@ -7,13 +7,19 @@ package org.mozilla.fenix.ui
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Before
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.assertNativeAppOpens
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
/**
* Tests for verifying the advanced section in Settings
@ -25,6 +31,7 @@ class SettingsAdvancedTest {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()
@get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule()
@ -35,11 +42,14 @@ class SettingsAdvancedTest {
dispatcher = AndroidAssetDispatcher()
start()
}
featureSettingsHelper.setPocketEnabled(false)
}
@After
fun tearDown() {
mockWebServer.shutdown()
featureSettingsHelper.resetAllFeatureFlags()
}
@Test
@ -53,9 +63,32 @@ class SettingsAdvancedTest {
verifyAdvancedHeading()
verifyAddons()
verifyOpenLinksInAppsButton()
verifyOpenLinksInAppsSwitchDefault()
verifyOpenLinksInAppsSwitchState(false)
verifyRemoteDebug()
verifyLeakCanaryButton()
}
}
@SmokeTest
@Test
fun openLinkInAppTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 3)
val playStoreUrl = "play.google.com/store/apps/details?id=org.mozilla.fenix"
homeScreen {
}.openThreeDotMenu {
}.openSettings {
verifyOpenLinksInAppsSwitchState(false)
clickOpenLinksInAppsSwitch()
verifyOpenLinksInAppsSwitchState(true)
}.goBack {}
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
mDevice.waitForIdle()
clickLinkMatchingText("Mozilla Playstore link")
mDevice.waitForIdle()
assertNativeAppOpens(GOOGLE_PLAY_SERVICES, playStoreUrl)
}
}
}

@ -306,6 +306,15 @@ class BrowserRobot {
}.bookmarkPage { }
}
fun clickLinkMatchingText(expectedText: String) {
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
.waitForExists(waitingTime)
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
val element = mDevice.findObject(UiSelector().textContains(expectedText))
element.click()
}
fun longClickMatchingText(expectedText: String) {
try {
mDevice.waitForWindowUpdate(packageName, waitingTime)

@ -18,8 +18,11 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.toPackage
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
@ -32,15 +35,17 @@ import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.endsWith
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.hasCousin
import org.mozilla.fenix.helpers.TestHelper.isPackageInstalled
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.assertIsEnabled
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.ui.robots.SettingsRobot.Companion.DEFAULT_APPS_SETTINGS_ACTION
@ -81,7 +86,8 @@ class SettingsRobot {
fun verifyNotificationsButton() = assertNotificationsButton()
fun verifyDataCollectionButton() = assertDataCollectionButton()
fun verifyOpenLinksInAppsButton() = assertOpenLinksInAppsButton()
fun verifyOpenLinksInAppsSwitchDefault() = assertOpenLinksInAppsValue()
fun verifyOpenLinksInAppsSwitchState(enabled: Boolean) = assertOpenLinksInAppsSwitchState(enabled)
fun clickOpenLinksInAppsSwitch() = openLinksInAppsButton().click()
fun verifySettingsView() = assertSettingsView()
fun verifySettingsToolbar() = assertSettingsToolbar()
@ -439,7 +445,7 @@ private fun assertDataCollectionButton() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun openLinksInAppsButton() = onView(withText("Open links in apps"))
private fun openLinksInAppsButton() = onView(withText(R.string.preferences_open_links_in_apps))
private fun assertOpenLinksInAppsButton() {
scrollToElementByText("Open links in apps")
@ -447,9 +453,33 @@ private fun assertOpenLinksInAppsButton() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertOpenLinksInAppsValue() {
fun assertOpenLinksInAppsSwitchState(enabled: Boolean) {
scrollToElementByText("Open links in apps")
openLinksInAppsButton().assertIsEnabled(isEnabled = true)
if (enabled) {
openLinksInAppsButton()
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
isChecked()
)
)
)
)
} else {
openLinksInAppsButton()
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
isNotChecked()
)
)
)
)
}
}
// DEVELOPER TOOLS SECTION

Loading…
Cancel
Save