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

Commit

Permalink
For #20868, #18764: Update Tracking Protection UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Aug 23, 2021
1 parent 83b752a commit 11ab815
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 94 deletions.
10 changes: 6 additions & 4 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ class SmokeTest {
}

@Test
@Ignore("https://github.com/mozilla-mobile/fenix/issues/20868")
fun customTrackingProtectionSettingsTest() {
val genericWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val trackingPage = TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
Expand All @@ -409,15 +408,16 @@ class SmokeTest {
// browsing a basic page to allow GV to load on a fresh run
}.enterURLAndEnterToBrowser(genericWebPage.url) {
}.openNavigationToolbar {
}.openTrackingProtectionTestPage(trackingPage.url, true) {}
}.enterURLAndEnterToBrowser(trackingPage.url) {}

enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
}.openDetails {
verifyTrackingCookiesBlocked()
verifyCryptominersBlocked()
verifyFingerprintersBlocked()
verifyBasicLevelTrackingContentBlocked()
verifyTrackingContentBlocked()
viewTrackingContentBlockList()
}
}

Expand Down Expand Up @@ -634,7 +634,9 @@ class SmokeTest {
IdlingRegistry.getInstance().unregister(addonsListIdlingResource!!)
}.goBack {
}.openNavigationToolbar {
}.openTrackingProtectionTestPage(trackingProtectionPage.url, true) {}
}.enterURLAndEnterToBrowser(trackingProtectionPage.url) {
verifyPageContent(trackingProtectionPage.content)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.mozilla.fenix.ui

import androidx.test.platform.app.InstrumentationRegistry
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
Expand All @@ -14,7 +13,6 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.ui.robots.enhancedTrackingProtection
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
Expand Down Expand Up @@ -47,12 +45,6 @@ class StrictEnhancedTrackingProtectionTest {
}

activityTestRule.activity.settings().setStrictETP()

// Reset on-boarding notification for each test
TestHelper.setPreference(
InstrumentationRegistry.getInstrumentation().context,
"pref_key_tracking_protection_onboarding", 0
)
}

@After
Expand All @@ -78,49 +70,33 @@ class StrictEnhancedTrackingProtectionTest {

@Test
fun testStrictVisitProtectionSheet() {
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val trackingProtectionTest =
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)

// browsing a generic page to allow GV to load on a fresh run
navigationToolbar {
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}

enhancedTrackingProtection {}.openEnhancedTrackingProtectionSheet {
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
}
}

@Test
fun testStrictVisitDisable() {
val trackingProtectionTest =
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)

navigationToolbar {
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
}.enterURLAndEnterToBrowser(genericPage.url) {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}

enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
}.disableEnhancedTrackingProtectionFromSheet {
verifyEnhancedTrackingProtectionSheetStatus("OFF", false)
}.closeEnhancedTrackingProtectionSheet {}

// Verify that Enhanced Tracking Protection remains globally enabled
navigationToolbar {
}.openThreeDotMenu {
verifyThreeDotMenuExists()
}.openSettings {
verifyEnhancedTrackingProtectionButton()
verifyEnhancedTrackingProtectionValue("On")
}
}

@Test
fun testStrictVisitDisableExceptionToggle() {
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val trackingProtectionTest =
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)

// browsing a generic page to allow GV to load on a fresh run
navigationToolbar {
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
}.enterURLAndEnterToBrowser(genericPage.url) {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}

enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
Expand All @@ -143,17 +119,26 @@ class StrictEnhancedTrackingProtectionTest {

@Test
fun testStrictVisitSheetDetails() {
val genericPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val trackingProtectionTest =
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)

// browsing a generic page to allow GV to load on a fresh run
navigationToolbar {
}.openTrackingProtectionTestPage(trackingProtectionTest.url, true) {}
}.enterURLAndEnterToBrowser(genericPage.url) {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}

enhancedTrackingProtection {
}.openEnhancedTrackingProtectionSheet {
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
}.openDetails {
verifyEnhancedTrackingProtectionDetailsStatus("Blocked")
verifyTrackingCookiesBlocked()
verifyCryptominersBlocked()
verifyFingerprintersBlocked()
verifyTrackingContentBlocked()
viewTrackingContentBlockList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.mozilla.fenix.ui.robots

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
Expand All @@ -18,6 +17,7 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import junit.framework.TestCase.assertTrue
import org.hamcrest.Matchers.containsString
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
Expand Down Expand Up @@ -45,21 +45,41 @@ class EnhancedTrackingProtectionRobot {

fun verifyCryptominersBlocked() = assertCryptominersBlocked()

fun verifyBasicLevelTrackingContentBlocked() = assertBasicLevelTrackingContentBlocked()
fun verifyTrackingContentBlocked() = assertTrackingContentBlocked()

fun viewTrackingContentBlockList() {
trackingContentBlockListButton()
.check(matches(isDisplayed()))
.click()
onView(withId(R.id.blocking_text_list))
.check(
matches(
withText(
containsString(
"social-track-digest256.dummytracker.org\n" +
"ads-track-digest256.dummytracker.org\n" +
"analytics-track-digest256.dummytracker.org"
)
)
)
)
}

class Transition {
fun openEnhancedTrackingProtectionSheet(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
openEnhancedTrackingProtectionSheet().waitForExists(waitingTime)
openEnhancedTrackingProtectionSheet().click()

EnhancedTrackingProtectionRobot().interact()
return Transition()
}

fun closeEnhancedTrackingProtectionSheet(interact: BrowserRobot.() -> Unit): Transition {
fun closeEnhancedTrackingProtectionSheet(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
// Back out of the Enhanced Tracking Protection sheet
mDevice.pressBack()

BrowserRobot().interact()
return Transition()
return BrowserRobot.Transition()
}

fun disableEnhancedTrackingProtectionFromSheet(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
Expand All @@ -70,14 +90,16 @@ class EnhancedTrackingProtectionRobot {
}

fun openProtectionSettings(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): Transition {
onView(withId(R.id.trackingProtectionDetails)).click()
openEnhancedTrackingProtectionSettings().click()
openEnhancedTrackingProtectionDetails().waitForExists(waitingTime)
openEnhancedTrackingProtectionDetails().click()
trackingProtectionSettingsButton().click()

SettingsSubMenuEnhancedTrackingProtectionRobot().interact()
return Transition()
}

fun openDetails(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
openEnhancedTrackingProtectionDetails().waitForExists(waitingTime)
openEnhancedTrackingProtectionDetails().click()

EnhancedTrackingProtectionRobot().interact()
Expand All @@ -91,16 +113,10 @@ fun enhancedTrackingProtection(interact: EnhancedTrackingProtectionRobot.() -> U
return EnhancedTrackingProtectionRobot.Transition()
}

private fun assertEnhancedTrackingProtectionShield() {
mDevice.waitNotNull(
Until.findObjects(By.descContains("Tracking Protection has blocked trackers"))
)
}

private fun assertEnhancedTrackingProtectionSheetStatus(status: String, state: Boolean) {
mDevice.waitNotNull(Until.findObjects(By.textContains(status)))
onView(ViewMatchers.withResourceName("switch_widget")).check(
ViewAssertions.matches(
matches(
isChecked(
state
)
Expand All @@ -113,22 +129,22 @@ private fun assertEnhancedTrackingProtectionDetailsStatus(status: String) {
}

private fun openEnhancedTrackingProtectionSheet() =
onView(withId(R.id.mozac_browser_toolbar_security_indicator))
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_security_indicator"))

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

private fun openEnhancedTrackingProtectionSettings() =
onView(ViewMatchers.withId(R.id.protection_settings))
private fun trackingProtectionSettingsButton() =
onView(withId(R.id.protection_settings))

private fun openEnhancedTrackingProtectionDetails() =
onView(ViewMatchers.withId(R.id.trackingProtectionDetails))
mDevice.findObject(UiSelector().resourceId("$packageName:id/trackingProtectionDetails"))

private fun assertTrackingCookiesBlocked() {
mDevice.findObject(UiSelector().resourceId("$packageName:id/cross_site_tracking"))
.waitForExists(waitingTime)
onView(withId(R.id.blocking_header)).check(matches(isDisplayed()))
onView(withId(R.id.cross_site_tracking)).check(matches(isDisplayed()))
onView(withId(R.id.tracking_content)).check(matches(isDisplayed()))
}

private fun assertFingerprintersBlocked() {
Expand All @@ -145,23 +161,11 @@ private fun assertCryptominersBlocked() {
onView(withId(R.id.cryptominers)).check(matches(isDisplayed()))
}

private fun assertBasicLevelTrackingContentBlocked() {
mDevice.findObject(UiSelector().resourceId("$packageName:id/tracking_content"))
.waitForExists(waitingTime)

onView(withId(R.id.tracking_content))
.check(matches(isDisplayed()))
.click()
onView(withId(R.id.blocking_text_list))
.check(
matches(
withText(
containsString(
"social-track-digest256.dummytracker.org\n" +
"ads-track-digest256.dummytracker.org\n" +
"analytics-track-digest256.dummytracker.org"
)
)
)
)
private fun assertTrackingContentBlocked() {
assertTrue(
mDevice.findObject(UiSelector().resourceId("$packageName:id/tracking_content"))
.waitForExists(waitingTime)
)
}

private fun trackingContentBlockListButton() = onView(withId(R.id.tracking_content))
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -116,23 +115,6 @@ class NavigationToolbarRobot {
return BrowserRobot.Transition()
}

fun openTrackingProtectionTestPage(
url: Uri,
etpEnabled: Boolean,
interact: BrowserRobot.() -> Unit
): BrowserRobot.Transition {
openEditURLView()

awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())

if (!etpEnabled) {
onView(withResourceName("browserLayout")).check(matches(isDisplayed()))
}

BrowserRobot().interact()
return BrowserRobot.Transition()
}

fun openTabCrashReporter(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
val crashUrl = "about:crashcontent"

Expand Down

0 comments on commit 11ab815

Please sign in to comment.