Skip to content

Commit

Permalink
Bug 1873200 - New cookie banner blocker UI smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ authored and mergify[bot] committed Jan 8, 2024
1 parent e58472c commit 486d24a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* 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 androidx.core.net.toUri
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithCondition
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for verifying the new Cookie banner blocker option and functionality.
*/
class CookieBannerBlockerTest {
@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2419260
@SmokeTest
@Test
fun verifyCookieBannerBlockerSettingsOptionTest() {
runWithCondition(appContext.settings().shouldUseCookieBannerPrivateMode) {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
verifyCookieBannerBlockerButton(enabled = true)
}
}
}

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2419273
@SmokeTest
@Test
fun verifyCFRAfterBlockingTheCookieBanner() {
runWithCondition(appContext.settings().shouldUseCookieBannerPrivateMode) {
homeScreen {
}.togglePrivateBrowsingMode()

navigationToolbar {
}.enterURLAndEnterToBrowser("voetbal24.be".toUri()) {
waitForPageToLoad()
verifyCookieBannerExists(exists = false)
verifyCookieBannerBlockerCFRExists(exists = true)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -686,24 +686,29 @@ class BrowserRobot {

fun verifyCookieBannerExists(exists: Boolean) {
for (i in 1..RETRY_COUNT) {
Log.i(TAG, "verifyCookieBannerExists: For loop: $i")
try {
assertUIObjectExists(cookieBanner(), exists = exists)
// Wait for the blocker to kick-in and make the cookie banner disappear
itemWithResId("CybotCookiebotDialog").waitUntilGone(waitingTime)
Log.i(TAG, "verifyCookieBannerExists: Waiting for window update")
// Assert that the blocker properly dismissed the cookie banner
assertUIObjectExists(itemWithResId("CybotCookiebotDialog"), exists = exists)

break
} catch (e: AssertionError) {
if (i == RETRY_COUNT) {
throw e
} else {
browserScreen {
}.openThreeDotMenu {
}.refreshPage {
waitForPageToLoad()
}
}
}
}
assertUIObjectExists(cookieBanner(), exists = exists)
}

fun verifyCookieBannerBlockerCFRExists(exists: Boolean) =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.cookie_banner_cfr_message)),
exists = exists,
)

fun verifyOpenLinkInAnotherAppPrompt() {
assertUIObjectExists(
itemWithResId("$packageName:id/parentPanel"),
Expand Down Expand Up @@ -1302,8 +1307,6 @@ fun clearTextFieldItem(item: UiObject) {
item.clearTextField()
}

private fun cookieBanner() = itemWithResId("startsiden-gdpr-disclaimer")

// Context menu items
// Link URL
private fun contextMenuLinkUrl(linkUrl: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
Expand Down Expand Up @@ -150,7 +149,7 @@ class NavigationToolbarRobot {
assertTrue(
itemWithResId("$packageName:id/browserLayout").waitForExists(waitingTime) ||
itemWithResId("$packageName:id/download_button").waitForExists(waitingTime) ||
itemWithText(getStringResource(R.string.tcp_cfr_message)).waitForExists(waitingTime),
itemWithResId("cfr.dismiss").waitForExists(waitingTime),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ class SettingsRobot {
fun verifyPrivacyHeading() = assertPrivacyHeading()

fun verifyHTTPSOnlyModeButton() = assertHTTPSOnlyModeButton()

fun verifyCookieBannerBlockerButton(enabled: Boolean) {
scrollToElementByText(getStringResource(R.string.preferences_cookie_banner_reduction_private_mode))
onView(withText(R.string.preferences_cookie_banner_reduction_private_mode))
.check(
matches(
hasCousin(
CoreMatchers.allOf(
withClassName(endsWith("Switch")),
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
Log.i(TAG, "verifyCookieBannerBlockerButton: Verified if cookie banner blocker toggle is enabled: $enabled")
}

fun verifyEnhancedTrackingProtectionButton() = assertEnhancedTrackingProtectionButton()
fun verifyLoginsAndPasswordsButton() = assertLoginsAndPasswordsButton()
fun verifyPrivateBrowsingButton() = assertPrivateBrowsingButton()
Expand Down

0 comments on commit 486d24a

Please sign in to comment.