Skip to content

Commit 486d24a

Browse files
AndiAJmergify[bot]
authored andcommitted
Bug 1873200 - New cookie banner blocker UI smoke tests
1 parent e58472c commit 486d24a

File tree

4 files changed

+89
-12
lines changed

4 files changed

+89
-12
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package org.mozilla.fenix.ui
6+
7+
import androidx.core.net.toUri
8+
import org.junit.Rule
9+
import org.junit.Test
10+
import org.mozilla.fenix.customannotations.SmokeTest
11+
import org.mozilla.fenix.ext.settings
12+
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithCondition
13+
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
14+
import org.mozilla.fenix.helpers.TestHelper.appContext
15+
import org.mozilla.fenix.ui.robots.homeScreen
16+
import org.mozilla.fenix.ui.robots.navigationToolbar
17+
18+
/**
19+
* Tests for verifying the new Cookie banner blocker option and functionality.
20+
*/
21+
class CookieBannerBlockerTest {
22+
@get:Rule
23+
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)
24+
25+
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2419260
26+
@SmokeTest
27+
@Test
28+
fun verifyCookieBannerBlockerSettingsOptionTest() {
29+
runWithCondition(appContext.settings().shouldUseCookieBannerPrivateMode) {
30+
homeScreen {
31+
}.openThreeDotMenu {
32+
}.openSettings {
33+
verifyCookieBannerBlockerButton(enabled = true)
34+
}
35+
}
36+
}
37+
38+
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2419273
39+
@SmokeTest
40+
@Test
41+
fun verifyCFRAfterBlockingTheCookieBanner() {
42+
runWithCondition(appContext.settings().shouldUseCookieBannerPrivateMode) {
43+
homeScreen {
44+
}.togglePrivateBrowsingMode()
45+
46+
navigationToolbar {
47+
}.enterURLAndEnterToBrowser("voetbal24.be".toUri()) {
48+
waitForPageToLoad()
49+
verifyCookieBannerExists(exists = false)
50+
verifyCookieBannerBlockerCFRExists(exists = true)
51+
}
52+
}
53+
}
54+
}

fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,24 +686,29 @@ class BrowserRobot {
686686

687687
fun verifyCookieBannerExists(exists: Boolean) {
688688
for (i in 1..RETRY_COUNT) {
689+
Log.i(TAG, "verifyCookieBannerExists: For loop: $i")
689690
try {
690-
assertUIObjectExists(cookieBanner(), exists = exists)
691+
// Wait for the blocker to kick-in and make the cookie banner disappear
692+
itemWithResId("CybotCookiebotDialog").waitUntilGone(waitingTime)
693+
Log.i(TAG, "verifyCookieBannerExists: Waiting for window update")
694+
// Assert that the blocker properly dismissed the cookie banner
695+
assertUIObjectExists(itemWithResId("CybotCookiebotDialog"), exists = exists)
696+
691697
break
692698
} catch (e: AssertionError) {
693699
if (i == RETRY_COUNT) {
694700
throw e
695-
} else {
696-
browserScreen {
697-
}.openThreeDotMenu {
698-
}.refreshPage {
699-
waitForPageToLoad()
700-
}
701701
}
702702
}
703703
}
704-
assertUIObjectExists(cookieBanner(), exists = exists)
705704
}
706705

706+
fun verifyCookieBannerBlockerCFRExists(exists: Boolean) =
707+
assertUIObjectExists(
708+
itemContainingText(getStringResource(R.string.cookie_banner_cfr_message)),
709+
exists = exists,
710+
)
711+
707712
fun verifyOpenLinkInAnotherAppPrompt() {
708713
assertUIObjectExists(
709714
itemWithResId("$packageName:id/parentPanel"),
@@ -1302,8 +1307,6 @@ fun clearTextFieldItem(item: UiObject) {
13021307
item.clearTextField()
13031308
}
13041309

1305-
private fun cookieBanner() = itemWithResId("startsiden-gdpr-disclaimer")
1306-
13071310
// Context menu items
13081311
// Link URL
13091312
private fun contextMenuLinkUrl(linkUrl: String) =

fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
4444
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
4545
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
4646
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
47-
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
4847
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
4948
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
5049
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
@@ -150,7 +149,7 @@ class NavigationToolbarRobot {
150149
assertTrue(
151150
itemWithResId("$packageName:id/browserLayout").waitForExists(waitingTime) ||
152151
itemWithResId("$packageName:id/download_button").waitForExists(waitingTime) ||
153-
itemWithText(getStringResource(R.string.tcp_cfr_message)).waitForExists(waitingTime),
152+
itemWithResId("cfr.dismiss").waitForExists(waitingTime),
154153
)
155154
}
156155

fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ class SettingsRobot {
107107
fun verifyPrivacyHeading() = assertPrivacyHeading()
108108

109109
fun verifyHTTPSOnlyModeButton() = assertHTTPSOnlyModeButton()
110+
111+
fun verifyCookieBannerBlockerButton(enabled: Boolean) {
112+
scrollToElementByText(getStringResource(R.string.preferences_cookie_banner_reduction_private_mode))
113+
onView(withText(R.string.preferences_cookie_banner_reduction_private_mode))
114+
.check(
115+
matches(
116+
hasCousin(
117+
CoreMatchers.allOf(
118+
withClassName(endsWith("Switch")),
119+
if (enabled) {
120+
isChecked()
121+
} else {
122+
isNotChecked()
123+
},
124+
),
125+
),
126+
),
127+
)
128+
Log.i(TAG, "verifyCookieBannerBlockerButton: Verified if cookie banner blocker toggle is enabled: $enabled")
129+
}
130+
110131
fun verifyEnhancedTrackingProtectionButton() = assertEnhancedTrackingProtectionButton()
111132
fun verifyLoginsAndPasswordsButton() = assertLoginsAndPasswordsButton()
112133
fun verifyPrivateBrowsingButton() = assertPrivateBrowsingButton()

0 commit comments

Comments
 (0)