Bug 1812461 - Migrate TCP CFR Tests to compose

Two new tests have been added to check the TCP cfr
and the review checker cfr has been made sticky as well
fenix/119.0
DreVla 10 months ago committed by mergify[bot]
parent b7db4a7875
commit 2807157d2c

@ -12,16 +12,11 @@ import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.runWithSystemLocaleChanged
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
import java.util.Locale
@ -177,39 +172,4 @@ class NavigationToolbarTest {
verifyHomeScreen()
}
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2260552
@SmokeTest
@Test
fun totalCookieProtectionLearnMoreLinkTest() {
activityTestRule.applySettingsExceptions {
it.isTCPCFREnabled = true
}
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericPage.url) {
verifyCookiesProtectionHintIsDisplayed(true)
clickPageObject(itemContainingText(getStringResource(R.string.tcp_cfr_learn_more)))
verifyUrl("support.mozilla.org/en-US/kb/enhanced-tracking-protection-firefox-android")
}
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1913589
@Test
fun totalCookieProtectionHintTest() {
activityTestRule.applySettingsExceptions {
it.isTCPCFREnabled = true
}
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericPage.url) {
verifyCookiesProtectionHintIsDisplayed(true)
clickPageObject(itemWithDescription(getStringResource(R.string.mozac_cfr_dismiss_button_content_description)))
verifyCookiesProtectionHintIsDisplayed(false)
}
}
}

@ -0,0 +1,77 @@
/* 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.compose.ui.test.junit4.AndroidComposeTestRule
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
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 TotalCookieProtectionTest {
private lateinit var mockWebServer: MockWebServer
@get:Rule
val composeTestRule = AndroidComposeTestRule(
HomeActivityTestRule(
isTCPCFREnabled = true,
isCookieBannerReductionDialogEnabled = false,
),
) { it.activity }
@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2260552
@Test
fun openTotalCookieProtectionLearnMoreLinkTest() {
val genericPage = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowserForTCPCFR(genericPage.url) {
waitForPageToLoad()
verifyCookiesProtectionHintIsDisplayed(composeTestRule, true)
clickTCPCFRLearnMore(composeTestRule)
verifyUrl("support.mozilla.org/en-US/kb/enhanced-tracking-protection-firefox-android")
verifyShouldShowCFRTCP(false, composeTestRule.activity.settings())
}
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1913589
@Test
fun dismissTotalCookieProtectionHintTest() {
val genericPage = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowserForTCPCFR(genericPage.url) {
waitForPageToLoad()
verifyCookiesProtectionHintIsDisplayed(composeTestRule, true)
dismissTCPCFRPopup(composeTestRule)
verifyCookiesProtectionHintIsDisplayed(composeTestRule, false)
verifyShouldShowCFRTCP(false, composeTestRule.activity.settings())
}
}
}

@ -27,11 +27,14 @@ import java.util.regex.Pattern
*/
class AddToHomeScreenRobot {
fun verifyAddPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) = assertAddPrivateBrowsingShortcutButton(composeTestRule)
fun verifyAddPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) =
composeTestRule.onNodeWithTag("private.add").assertIsDisplayed()
fun verifyNoThanksPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) = assertNoThanksPrivateBrowsingShortcutButton(composeTestRule)
fun verifyNoThanksPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) =
composeTestRule.onNodeWithTag("private.cancel").assertIsDisplayed()
fun clickAddPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) = composeTestRule.onNodeWithTag("private.add").performClick()
fun clickAddPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) =
composeTestRule.onNodeWithTag("private.add").performClick()
fun addShortcutName(title: String) = shortcutTextField.setText(title)
@ -102,12 +105,6 @@ fun addToHomeScreen(interact: AddToHomeScreenRobot.() -> Unit): AddToHomeScreenR
private fun addAutomaticallyButton() =
mDevice.findObject(UiSelector().textContains("add automatically"))
private fun assertAddPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) =
composeTestRule.onNodeWithTag("private.add").assertIsDisplayed()
private fun assertNoThanksPrivateBrowsingShortcutButton(composeTestRule: ComposeTestRule) =
composeTestRule.onNodeWithTag("private.cancel").assertIsDisplayed()
private val cancelAddToHomeScreenButton =
itemWithResId("$packageName:id/cancel_button")
private val confirmAddToHomeScreenButton =

@ -11,7 +11,9 @@ import android.net.Uri
import android.os.SystemClock
import android.util.Log
import android.widget.TimePicker
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
@ -41,7 +43,6 @@ import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
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
@ -60,6 +61,7 @@ import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.tabstray.TabsTrayTestTag
import org.mozilla.fenix.utils.Settings
import java.time.LocalDate
class BrowserRobot {
@ -581,16 +583,32 @@ class BrowserRobot {
}
}
fun verifyCookiesProtectionHintIsDisplayed(isDisplayed: Boolean) {
assertItemContainingTextExists(
totalCookieProtectionHintMessage,
totalCookieProtectionHintLearnMoreLink,
exists = isDisplayed,
)
assertItemWithDescriptionExists(
totalCookieProtectionHintCloseButton,
exists = isDisplayed,
)
fun verifyCookiesProtectionHintIsDisplayed(composeTestRule: HomeActivityComposeTestRule, isDisplayed: Boolean) {
if (isDisplayed) {
composeTestRule.onNodeWithTag("tcp_cfr.message").assertIsDisplayed()
composeTestRule.onNodeWithTag("tcp_cfr.action").assertIsDisplayed()
composeTestRule.onNodeWithTag("cfr.dismiss").assertIsDisplayed()
} else {
composeTestRule.onNodeWithTag("tcp_cfr.message").assertDoesNotExist()
composeTestRule.onNodeWithTag("tcp_cfr.action").assertDoesNotExist()
composeTestRule.onNodeWithTag("cfr.dismiss").assertDoesNotExist()
}
}
fun clickTCPCFRLearnMore(composeTestRule: HomeActivityComposeTestRule) {
composeTestRule.onNodeWithTag("tcp_cfr.action").performClick()
}
fun dismissTCPCFRPopup(composeTestRule: HomeActivityComposeTestRule) {
composeTestRule.onNodeWithTag("cfr.dismiss").performClick()
}
fun verifyShouldShowCFRTCP(shouldShow: Boolean, settings: Settings) {
if (shouldShow) {
assertTrue(settings.shouldShowTotalCookieProtectionCFR)
} else {
assertFalse(settings.shouldShowTotalCookieProtectionCFR)
}
}
fun selectTime(hour: Int, minute: Int) =
@ -1337,12 +1355,6 @@ private val currentDay = currentDate.dayOfMonth
private val currentMonth = currentDate.month
private val currentYear = currentDate.year
private val cookieBanner = itemWithResId("startsiden-gdpr-disclaimer")
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))
// Context menu items
// Link URL

@ -191,6 +191,19 @@ class NavigationToolbarRobot {
return BrowserRobot.Transition()
}
fun enterURLAndEnterToBrowserForTCPCFR(
url: Uri,
interact: BrowserRobot.() -> Unit,
): BrowserRobot.Transition {
openEditURLView()
awesomeBar().setText(url.toString())
mDevice.pressEnter()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun openTabCrashReporter(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
val crashUrl = "about:crashcontent"

@ -217,6 +217,7 @@ class BrowserToolbarCFRPresenter(
@OptIn(ExperimentalComposeUiApi::class)
@VisibleForTesting
@Suppress("LongMethod")
internal fun showTcpCfr() {
CFRPopup(
anchor = toolbar.findViewById(
@ -277,6 +278,7 @@ class BrowserToolbarCFRPresenter(
),
)
TrackingProtection.tcpSumoLinkClicked.record(NoExtras())
settings.shouldShowTotalCookieProtectionCFR = false
popup?.dismiss()
},
style = FirefoxTheme.typography.body2.copy(
@ -315,7 +317,14 @@ class BrowserToolbarCFRPresenter(
dismissOnBackPress = false,
dismissOnClickOutside = false,
),
onDismiss = {},
onDismiss = {
when (it) {
true -> {
settings.shouldShowReviewQualityCheckCFR = false
}
false -> {}
}
},
text = {
FirefoxTheme {
Text(
@ -330,7 +339,6 @@ class BrowserToolbarCFRPresenter(
}
},
).run {
settings.shouldShowReviewQualityCheckCFR = false
popup = this
show()
}

@ -193,7 +193,7 @@ class BrowserToolbarCFRPresenterTest {
}
@Test
fun `WHEN the TCP CFR is to be shown THEN instantiate a new one and remember to not show it again`() {
fun `WHEN the TCP CFR is to be shown THEN instantiate a new one and remember show it again unless explicitly dismissed`() {
val settings: Settings = mockk(relaxed = true)
val presenter = createPresenter(
anchor = mockk(relaxed = true),
@ -202,7 +202,7 @@ class BrowserToolbarCFRPresenterTest {
presenter.showTcpCfr()
verify { settings.shouldShowTotalCookieProtectionCFR = false }
verify(exactly = 0) { settings.shouldShowTotalCookieProtectionCFR = false }
assertNotNull(presenter.popup)
}

Loading…
Cancel
Save