Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #21002: Add testETPOffGlobally UI smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Dec 3, 2021
1 parent 4fe3d6d commit 2115285
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class FeatureSettingsHelper {
settings.showRecentTabsFeature = enabled
}

fun setStrictETPEnabled() {
settings.setStrictETP()
}

// Important:
// Use this after each test if you have modified these feature settings
// to make sure the app goes back to the default state
Expand Down
2 changes: 1 addition & 1 deletion app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class SmokeTest {
}.openThreeDotMenu {
}.openSettings {
}.openEnhancedTrackingProtectionSubMenu {
verifyEnhancedTrackingProtectionOptions()
verifyEnhancedTrackingProtectionOptionsEnabled()
selectTrackingProtectionOption("Custom")
verifyCustomTrackingProtectionSettings()
}.goBackToHomeScreen {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ 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.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.ui.robots.enhancedTrackingProtection
Expand All @@ -33,6 +34,7 @@ import org.mozilla.fenix.ui.robots.settingsSubMenuEnhancedTrackingProtection

class StrictEnhancedTrackingProtectionTest {
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()

@get:Rule
val activityTestRule = HomeActivityTestRule()
Expand All @@ -43,15 +45,14 @@ class StrictEnhancedTrackingProtectionTest {
dispatcher = AndroidAssetDispatcher()
start()
}

val settings = activityTestRule.activity.settings()
settings.setStrictETP()
settings.shouldShowJumpBackInCFR = false
featureSettingsHelper.setStrictETPEnabled()
featureSettingsHelper.setJumpBackCFREnabled(false)
}

@After
fun tearDown() {
mockWebServer.shutdown()
featureSettingsHelper.resetAllFeatureFlags()
}

@Test
Expand All @@ -63,13 +64,46 @@ class StrictEnhancedTrackingProtectionTest {
verifyEnhancedTrackingProtectionValue("On")
}.openEnhancedTrackingProtectionSubMenu {
verifyEnhancedTrackingProtectionHeader()
verifyEnhancedTrackingProtectionOptions()
verifyEnhancedTrackingProtectionOptionsEnabled()
verifyTrackingProtectionSwitchEnabled()
}.openExceptions {
verifyDefault()
}
}

@SmokeTest
@Test
fun testETPOffGlobally() {
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openEnhancedTrackingProtectionSubMenu {
switchEnhancedTrackingProtectionToggle()
verifyEnhancedTrackingProtectionOptionsEnabled(false)
}.goBack {
}.goBack { }

navigationToolbar {
}.enterURLAndEnterToBrowser(genericPage.url) { }
enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
verifyETPSwitchVisibility(false)
}.closeEnhancedTrackingProtectionSheet {
}.openThreeDotMenu {
}.openSettings {
}.openEnhancedTrackingProtectionSubMenu {
switchEnhancedTrackingProtectionToggle()
verifyEnhancedTrackingProtectionOptionsEnabled(true)
}.goBack {
}.goBackToBrowser { }
enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
verifyETPSwitchVisibility(true)
}
}

@Test
fun testStrictVisitProtectionSheet() {
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
Expand Down Expand Up @@ -113,7 +147,7 @@ class StrictEnhancedTrackingProtectionTest {
verifyEnhancedTrackingProtectionSheetStatus("OFF", false)
}.openProtectionSettings {
verifyEnhancedTrackingProtectionHeader()
verifyEnhancedTrackingProtectionOptions()
verifyEnhancedTrackingProtectionOptionsEnabled()
verifyTrackingProtectionSwitchEnabled()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,10 @@ class BrowserRobot {
)
}

fun verifyNavURLBar() = assertNavURLBar()

fun verifyNavURLBarHidden() = assertNavURLBarHidden()

fun verifySecureConnectionLockIcon() = assertSecureConnectionLockIcon()

fun verifyEnhancedTrackingProtectionSwitch() = assertEnhancedTrackingProtectionSwitch()

fun verifyEnhancedTrackingOptions() {
onView(withId(R.id.mozac_browser_toolbar_security_indicator)).click()
verifyEnhancedTrackingProtectionSwitch()
}

fun verifyMenuButton() = assertMenuButton()

fun verifyNavURLBarItems() {
Expand Down Expand Up @@ -674,16 +665,6 @@ private fun assertNavURLBar() = assertTrue(navURLBar().waitForExists(waitingTime

private fun assertNavURLBarHidden() = assertTrue(navURLBar().waitUntilGone(waitingTime))

private fun assertEnhancedTrackingProtectionSwitch() {
withText(R.id.trackingProtectionSwitch)
.matches(withEffectiveVisibility(Visibility.VISIBLE))
}

private fun assertProtectionSettingsButton() {
onView(withId(R.id.protection_settings))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertSecureConnectionLockIcon() {
onView(withId(R.id.mozac_browser_toolbar_security_indicator))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import junit.framework.TestCase.assertTrue
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.not
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
Expand All @@ -41,6 +42,8 @@ class EnhancedTrackingProtectionRobot {
fun verifyEnhancedTrackingProtectionDetailsStatus(status: String) =
assertEnhancedTrackingProtectionDetailsStatus(status)

fun verifyETPSwitchVisibility(visible: Boolean) = assertETPSwitchVisibility(visible)

fun verifyTrackingCookiesBlocked() = assertTrackingCookiesBlocked()

fun verifyFingerprintersBlocked() = assertFingerprintersBlocked()
Expand Down Expand Up @@ -86,7 +89,7 @@ class EnhancedTrackingProtectionRobot {
}

fun disableEnhancedTrackingProtectionFromSheet(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
disableEnhancedTrackingProtection().click()
enhancedTrackingProtectionSwitch().click()

EnhancedTrackingProtectionRobot().interact()
return Transition()
Expand Down Expand Up @@ -116,6 +119,16 @@ fun enhancedTrackingProtection(interact: EnhancedTrackingProtectionRobot.() -> U
return EnhancedTrackingProtectionRobot.Transition()
}

private fun assertETPSwitchVisibility(visible: Boolean) {
if (visible) {
enhancedTrackingProtectionSwitch()
.check(matches(isDisplayed()))
} else {
enhancedTrackingProtectionSwitch()
.check(matches(not(isDisplayed())))
}
}

private fun assertEnhancedTrackingProtectionSheetStatus(status: String, state: Boolean) {
mDevice.waitNotNull(Until.findObjects(By.textContains(status)))
onView(ViewMatchers.withResourceName("switch_widget")).check(
Expand All @@ -134,7 +147,7 @@ private fun assertEnhancedTrackingProtectionDetailsStatus(status: String) {
private fun openEnhancedTrackingProtectionSheet() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_security_indicator"))

private fun disableEnhancedTrackingProtection() =
private fun enhancedTrackingProtectionSwitch() =
onView(ViewMatchers.withResourceName("switch_widget"))

private fun trackingProtectionSettingsButton() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.not
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.assertIsChecked
Expand All @@ -48,7 +47,7 @@ class SettingsSubMenuEnhancedTrackingProtectionRobot {

fun verifyEnhancedTrackingProtectionTextWithSwitchWidget() = assertEnhancedTrackingProtectionTextWithSwitchWidget()

fun verifyEnhancedTrackingProtectionOptions() = assertEnhancedTrackingProtectionOptions()
fun verifyEnhancedTrackingProtectionOptionsEnabled(enabled: Boolean = true) = assertEnhancedTrackingProtectionOptionsState(enabled)

fun verifyTrackingProtectionSwitchEnabled() = assertTrackingProtectionSwitchEnabled()

Expand All @@ -63,7 +62,7 @@ class SettingsSubMenuEnhancedTrackingProtectionRobot {
verifyEnhancedTrackingProtectionTextWithSwitchWidget()
verifyTrackingProtectionSwitchEnabled()
verifyRadioButtonDefaults()
verifyEnhancedTrackingProtectionOptions()
verifyEnhancedTrackingProtectionOptionsEnabled()
}

fun verifyCustomTrackingProtectionSettings() = assertCustomTrackingProtectionSettings()
Expand Down Expand Up @@ -153,48 +152,24 @@ private fun assertEnhancedTrackingProtectionTextWithSwitchWidget() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertEnhancedTrackingProtectionOptions() {
private fun assertEnhancedTrackingProtectionOptionsState(enabled: Boolean) {
onView(withText("Standard (default)"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

onView(withText(org.mozilla.fenix.R.string.preference_enhanced_tracking_protection_standard_description_4))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

onView(withText("Strict"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

onView(withText(org.mozilla.fenix.R.string.preference_enhanced_tracking_protection_strict_description_3))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

onView(withText("Custom"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

val customText =
"Choose which trackers and scripts to block."
onView(withText(customText))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertEnhancedTrackingProtectionOptionsGrayedOut() {
onView(withText("Standard (default)"))
.check(matches(not(isEnabled(true))))
.check(matches(isEnabled(enabled)))

onView(withText(org.mozilla.fenix.R.string.preference_enhanced_tracking_protection_standard_description_4))
.check(matches(not(isEnabled(true))))
.check(matches(isEnabled(enabled)))

onView(withText("Strict"))
.check(matches(not(isEnabled(true))))
.check(matches(isEnabled(enabled)))

onView(withText(org.mozilla.fenix.R.string.preference_enhanced_tracking_protection_strict_description_3))
.check(matches(not(isEnabled(true))))
.check(matches(isEnabled(enabled)))

onView(withText("Custom"))
.check(matches(not(isEnabled(true))))
.check(matches(isEnabled(enabled)))

val customText =
"Choose which trackers and scripts to block."
onView(withText(customText))
.check(matches(not(isEnabled(true))))
onView(withText(org.mozilla.fenix.R.string.preference_enhanced_tracking_protection_custom_description_2))
.check(matches(isEnabled(enabled)))
}

private fun assertTrackingProtectionSwitchEnabled() {
Expand Down

0 comments on commit 2115285

Please sign in to comment.