diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/MatcherHelper.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/MatcherHelper.kt index 38ab7bb5aa..1c86eaa82e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/MatcherHelper.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/MatcherHelper.kt @@ -57,9 +57,13 @@ object MatcherHelper { } } - fun assertItemContainingTextExists(vararg appItems: UiObject) { + fun assertItemContainingTextExists(vararg appItems: UiObject, exists: Boolean = true) { for (appItem in appItems) { - assertTrue(appItem.waitForExists(waitingTime)) + if (exists) { + assertTrue(appItem.waitForExists(waitingTime)) + } else { + assertFalse(appItem.waitForExists(waitingTime)) + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/ContextualHintsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/ContextualHintsTest.kt index 42398d95d5..86493e49a6 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/ContextualHintsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/ContextualHintsTest.kt @@ -9,6 +9,7 @@ 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.HomeActivityTestRule import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset @@ -51,7 +52,7 @@ class ContextualHintsTest { navigationToolbar { }.enterURLAndEnterToBrowser(genericPage.url) { - verifyCookiesProtectionHint() + verifyCookiesProtectionHintIsDisplayed(true) // One back press to dismiss the TCP hint mDevice.pressBack() }.goToHomescreen { @@ -59,13 +60,29 @@ class ContextualHintsTest { } } + @SmokeTest @Test - fun cookieProtectionHintTest() { + fun openTotalCookieProtectionLearnMoreLinkTest() { val genericPage = getGenericAsset(mockWebServer, 1) navigationToolbar { }.enterURLAndEnterToBrowser(genericPage.url) { - verifyCookiesProtectionHint() + verifyCookiesProtectionHintIsDisplayed(true) + clickTotalCookieProtectionLearnMoreLink() + verifyUrl("support.mozilla.org/en-US/kb/enhanced-tracking-protection-firefox-android") + } + } + + @SmokeTest + @Test + fun dismissTotalCookieProtectionHintTest() { + val genericPage = getGenericAsset(mockWebServer, 1) + + navigationToolbar { + }.enterURLAndEnterToBrowser(genericPage.url) { + verifyCookiesProtectionHintIsDisplayed(true) + clickTotalCookieProtectionCloseButton() + verifyCookiesProtectionHintIsDisplayed(false) } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt index 8e11f56d48..a8ba8df9c5 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt @@ -46,9 +46,11 @@ import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION import org.mozilla.fenix.helpers.Constants.RETRY_COUNT import org.mozilla.fenix.helpers.MatcherHelper import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists +import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText +import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText import org.mozilla.fenix.helpers.SessionLoadedIdlingResource @@ -762,15 +764,34 @@ class BrowserRobot { fun clickSetCookiesButton() = clickPageObject(webPageItemWithResourceId("setCookies")) - fun verifyCookiesProtectionHint() { - val hintMessage = - mDevice.findObject( - UiSelector() - .textContains(getStringResource(R.string.tcp_cfr_message)), + fun verifyCookiesProtectionHintIsDisplayed(isDisplayed: Boolean) { + if (isDisplayed) { + assertItemContainingTextExists( + totalCookieProtectionHintMessage, + totalCookieProtectionHintLearnMoreLink, ) - assertTrue(hintMessage.waitForExists(waitingTime)) + assertItemWithDescriptionExists( + totalCookieProtectionHintCloseButton, + ) + } else { + assertItemContainingTextExists( + totalCookieProtectionHintMessage, + totalCookieProtectionHintLearnMoreLink, + exists = isDisplayed, + ) + assertItemWithDescriptionExists( + totalCookieProtectionHintCloseButton, + exists = isDisplayed, + ) + } } + fun clickTotalCookieProtectionLearnMoreLink() = + totalCookieProtectionHintLearnMoreLink.clickAndWaitForNewWindow(waitingTime) + + fun clickTotalCookieProtectionCloseButton() = + totalCookieProtectionHintCloseButton.click() + fun clickForm(formType: String) { when (formType) { "Calendar Form" -> { @@ -1424,3 +1445,9 @@ private val currentDay = currentDate.dayOfMonth private val currentMonth = currentDate.month private val currentYear = currentDate.year private val cookieBanner = itemWithResId("CybotCookiebotDialog") +private val totalCookieProtectionHintMessage = + itemContainingText(getStringResource(R.string.tcp_cfr_message)) +private val totalCookieProtectionHintLearnMoreLink = + itemContainingText(getStringResource(R.string.tcp_cfr_learn_more)) +private val totalCookieProtectionHintCloseButton = + itemWithDescription(getStringResource(R.string.mozac_cfr_dismiss_button_content_description))