No issue: Adds TCP & jump back in contextual hints UI tests

This commit is contained in:
sv-ohorvath 2022-10-12 12:05:32 +03:00 committed by mergify[bot]
parent 832e832ec7
commit 881d761d4f
5 changed files with 112 additions and 12 deletions

View File

@ -0,0 +1,70 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
package org.mozilla.fenix.ui
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.ui.robots.navigationToolbar
/**
* Tests for verifying the new Cookie protection & homescreen feature hints.
* Note: This involves setting the feature flags On for CFRs which are disabled elsewhere.
*
*/
class ContextualHintsTest {
private lateinit var mockWebServer: MockWebServer
@get:Rule
val activityTestRule = HomeActivityTestRule(
isJumpBackInCFREnabled = true,
isTCPCFREnabled = true,
isPocketEnabled = false,
isRecentlyVisitedFeatureEnabled = false,
)
@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
@Test
fun jumpBackInCFRTest() {
val genericPage = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericPage.url) {
verifyCookiesProtectionHint()
// One back press to dismiss the TCP hint
mDevice.pressBack()
}.goToHomescreen {
verifyJumpBackInMessage()
}
}
@Test
fun cookieProtectionHintTest() {
val genericPage = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericPage.url) {
verifyCookiesProtectionHint()
}
}
}

View File

@ -9,12 +9,12 @@ import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.ui.robots.homeScreen
/**
* Tests for verifying the new onboarding features.
* Note: This involves setting the feature flags on for the onboarding dialog and
* other CFRs which are disabled elsewhere.
* Note: This involves setting the feature flag On for the onboarding dialog
*
*/
class OnboardingFeaturesTest {
@ -36,7 +36,6 @@ class OnboardingFeaturesTest {
}
}
@SmokeTest
@Test
fun upgradingUsersOnboardingSignInButtonTest() {
homeScreen {
@ -45,6 +44,10 @@ class OnboardingFeaturesTest {
verifyUpgradingUserOnboardingSecondScreen(activityTestRule)
}.clickUpgradingUserOnboardingSignInButton(activityTestRule) {
verifyTurnOnSyncMenu()
mDevice.pressBack()
}
homeScreen {
verifyHomeScreen()
}
}
}

View File

@ -43,6 +43,7 @@ import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeLong
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
@ -816,6 +817,15 @@ class BrowserRobot {
setCookiesButton.click()
}
fun verifyCookiesProtectionHint() {
val hintMessage =
mDevice.findObject(
UiSelector()
.textContains(getStringResource(R.string.tcp_cfr_message)),
)
assertTrue(hintMessage.waitForExists(waitingTime))
}
class Transition {
private fun threeDotButton() = onView(
allOf(
@ -881,7 +891,12 @@ class BrowserRobot {
assertTrue(
mDevice.findObject(UiSelector().resourceId("$packageName:id/homeLayout"))
.waitForExists(waitingTime),
.waitForExists(waitingTime) ||
mDevice.findObject(
UiSelector().text(
getStringResource(R.string.onboarding_home_screen_jump_back_contextual_hint_2),
),
).waitForExists(waitingTime),
)
HomeScreenRobot().interact()

View File

@ -343,6 +343,16 @@ class HomeScreenRobot {
return sponsoredShortcut
}
fun verifyJumpBackInMessage() {
assertTrue(
mDevice.findObject(
UiSelector().text(
getStringResource(R.string.onboarding_home_screen_jump_back_contextual_hint_2),
),
).waitForExists(waitingTime),
)
}
class Transition {
fun openTabDrawer(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition {

View File

@ -22,18 +22,17 @@ import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withResourceName
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.anyOf
import org.hamcrest.CoreMatchers.not
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
@ -98,12 +97,15 @@ class NavigationToolbarRobot {
mDevice.pressEnter()
runWithIdleRes(sessionLoadedIdlingResource) {
onView(
anyOf(
withResourceName("browserLayout"),
withResourceName("download_button"),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
assertTrue(
mDevice.findObject(
UiSelector().resourceId("$packageName:id/browserLayout"),
).waitForExists(waitingTime) || mDevice.findObject(
UiSelector().resourceId("$packageName:id/download_button"),
).waitForExists(waitingTime) || mDevice.findObject(
UiSelector().text(getStringResource(R.string.tcp_cfr_message)),
).waitForExists(waitingTime),
)
}
BrowserRobot().interact()