Add tests for verifying basic UI functionality of Enhanced Tracking Protectionmaster
parent
71880705df
commit
4a2cb91ad9
|
@ -0,0 +1,41 @@
|
||||||
|
<!-- https://github.com/mozilla/dummytracker -->
|
||||||
|
<!-- https://github.com/englehardt/englehardt.github.io/tree/master/test/trackingprotection/test_pages -->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Test for each list will say "Blocked" if Firefox is blocking resources from that list.</p>
|
||||||
|
<p>Fingerprinting (base-fingerprinting-track-digest256):</p>
|
||||||
|
<img
|
||||||
|
src="https://base-fingerprinting-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<br/>
|
||||||
|
<p>Cryptomining (base-cryptomining-track-digest256):</p>
|
||||||
|
<img
|
||||||
|
src="https://base-cryptomining-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<br/>
|
||||||
|
<p>Basic Tracking Protection List (base-track-digest256):</p>
|
||||||
|
<img
|
||||||
|
src="https://base-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<p>STP Tracker blocking (social-tracking-protection-digest256)</p>
|
||||||
|
<img
|
||||||
|
src="https://social-tracking-protection-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<p>social-track-digest256:</p>
|
||||||
|
<img
|
||||||
|
src="https://social-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<br/>
|
||||||
|
<p>ads-track-digest256:</p>
|
||||||
|
<img
|
||||||
|
src="https://ads-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
<br/>
|
||||||
|
<p>analytics-track-digest256:</p>
|
||||||
|
<img
|
||||||
|
src="https://analytics-track-digest256.dummytracker.org/test_not_blocked.png"
|
||||||
|
onerror="this.onerror=null;this.src='https://not-a-tracker.dummytracker.org/test_blocked.png'">
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -17,6 +17,7 @@ object TestAssetHelper {
|
||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
val waitingTime: Long = TimeUnit.SECONDS.toMillis(15)
|
val waitingTime: Long = TimeUnit.SECONDS.toMillis(15)
|
||||||
val waitingTimeShort: Long = TimeUnit.SECONDS.toMillis(1)
|
val waitingTimeShort: Long = TimeUnit.SECONDS.toMillis(1)
|
||||||
|
|
||||||
data class TestAsset(val url: Uri, val content: String)
|
data class TestAsset(val url: Uri, val content: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,4 +71,10 @@ object TestAssetHelper {
|
||||||
|
|
||||||
return TestAsset(url, content)
|
return TestAsset(url, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getEnhancedTrackingProtectionAsset(server: MockWebServer): TestAsset {
|
||||||
|
val url = server.url("pages/etp.html").toString().toUri()!!
|
||||||
|
|
||||||
|
return TestAsset(url, "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import org.hamcrest.CoreMatchers.allOf
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.helpers.ext.waitNotNull
|
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||||
import org.mozilla.fenix.ui.robots.mDevice
|
import org.mozilla.fenix.ui.robots.mDevice
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
object TestHelper {
|
object TestHelper {
|
||||||
fun scrollToElementByText(text: String): UiScrollable {
|
fun scrollToElementByText(text: String): UiScrollable {
|
||||||
|
@ -37,4 +39,11 @@ object TestHelper {
|
||||||
)
|
)
|
||||||
).perform(longClick())
|
).perform(longClick())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setPreference(context: Context, pref: String, value: Int) {
|
||||||
|
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
val editor = preferences.edit()
|
||||||
|
editor.putInt(pref, value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,205 @@
|
||||||
|
/* 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.test.platform.app.InstrumentationRegistry
|
||||||
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
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
|
||||||
|
import org.mozilla.fenix.ui.robots.settingsSubMenuEnhancedTrackingProtection
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for verifying basic UI functionality of Enhanced Tracking Protection
|
||||||
|
*
|
||||||
|
* Including
|
||||||
|
* - Verifying default states
|
||||||
|
* - Verifying Enhanced Tracking Protection notification bubble
|
||||||
|
* - Verifying Enhanced Tracking Protection notification shield
|
||||||
|
* - Verifying Enhanced Tracking Protection content sheet
|
||||||
|
* - Verifying Enhanced Tracking Protection content sheet details
|
||||||
|
* - Verifying Enhanced Tracking Protection toggle
|
||||||
|
* - Verifying Enhanced Tracking Protection site exceptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
class EnhancedTrackingProtectionTest {
|
||||||
|
private lateinit var mockWebServer: MockWebServer
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val activityTestRule = HomeActivityTestRule()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
mockWebServer = MockWebServer().apply {
|
||||||
|
setDispatcher(AndroidAssetDispatcher())
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset on-boarding notification for each test
|
||||||
|
TestHelper.setPreference(
|
||||||
|
InstrumentationRegistry.getInstrumentation().context,
|
||||||
|
"pref_key_tracking_protection_onboarding", 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() {
|
||||||
|
mockWebServer.shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSettingsDefaults() {
|
||||||
|
homeScreen {
|
||||||
|
}.openThreeDotMenu {
|
||||||
|
}.openSettings {
|
||||||
|
verifyEnhancedTrackingProtectionButton()
|
||||||
|
verifyEnhancedTrackingProtectionValue("On")
|
||||||
|
}.openEnhancedTrackingProtectionSubMenu {
|
||||||
|
verifyEnhancedTrackingProtectionHeader()
|
||||||
|
verifyEnhancedTrackingProtectionOptions()
|
||||||
|
verifyEnhancedTrackingProtectionDefaults()
|
||||||
|
}.openExceptions {
|
||||||
|
verifyDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitContentNotification() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitContentShield() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionShield()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitProtectionSheet() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionShield()
|
||||||
|
}.openEnhancedTrackingProtectionSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitDisable() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionShield()
|
||||||
|
}.openEnhancedTrackingProtectionSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
|
||||||
|
}.disableEnhancedTrackingProtectionFromSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("OFF", false)
|
||||||
|
}.closeEnhancedTrackingProtectionSheet {}
|
||||||
|
|
||||||
|
// Verify that Enhanced Tracking Protection remains globally enabled
|
||||||
|
navigationToolbar {
|
||||||
|
}.openThreeDotMenu {
|
||||||
|
}.openSettings {
|
||||||
|
verifyEnhancedTrackingProtectionValue("On")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitDisableExceptionToggle() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionShield()
|
||||||
|
}.openEnhancedTrackingProtectionSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
|
||||||
|
}.disableEnhancedTrackingProtectionFromSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("OFF", false)
|
||||||
|
}.openProtectionSettings {
|
||||||
|
verifyEnhancedTrackingProtectionHeader()
|
||||||
|
verifyEnhancedTrackingProtectionOptions()
|
||||||
|
verifyEnhancedTrackingProtectionDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsSubMenuEnhancedTrackingProtection {
|
||||||
|
}.openExceptions {
|
||||||
|
verifyListedURL(trackingProtectionTest.url.toString())
|
||||||
|
}.disableExceptions {
|
||||||
|
verifyDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStrictVisitSheetDetails() {
|
||||||
|
val trackingProtectionTest =
|
||||||
|
TestAssetHelper.getEnhancedTrackingProtectionAsset(mockWebServer)
|
||||||
|
|
||||||
|
navigationToolbar {
|
||||||
|
}.enterURLAndEnterToBrowser(trackingProtectionTest.url) {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionNotice()
|
||||||
|
}.closeNotificationPopup {}
|
||||||
|
|
||||||
|
enhancedTrackingProtection {
|
||||||
|
verifyEnhancedTrackingProtectionShield()
|
||||||
|
}.openEnhancedTrackingProtectionSheet {
|
||||||
|
verifyEnhancedTrackingProtectionSheetStatus("ON", true)
|
||||||
|
}.openDetails {
|
||||||
|
verifyEnhancedTrackingProtectionDetailsStatus("Blocked")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,7 +93,7 @@ class SettingsPrivacyTest {
|
||||||
// PRIVACY
|
// PRIVACY
|
||||||
verifyPrivacyHeading()
|
verifyPrivacyHeading()
|
||||||
verifyEnhancedTrackingProtectionButton()
|
verifyEnhancedTrackingProtectionButton()
|
||||||
verifyEnhancedTrackingProtectionValue()
|
verifyEnhancedTrackingProtectionValue("On")
|
||||||
// Logins
|
// Logins
|
||||||
verifyLoginsButton()
|
verifyLoginsButton()
|
||||||
// drill down to submenu
|
// drill down to submenu
|
||||||
|
|
|
@ -0,0 +1,130 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
@file:Suppress("TooManyFunctions")
|
||||||
|
|
||||||
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
|
import androidx.test.espresso.Espresso.onView
|
||||||
|
import androidx.test.espresso.assertion.ViewAssertions
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.uiautomator.By
|
||||||
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import androidx.test.uiautomator.Until
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||||
|
import org.mozilla.fenix.helpers.click
|
||||||
|
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||||
|
import org.mozilla.fenix.helpers.isChecked
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Robot Pattern for Enhanced Tracking Protection UI.
|
||||||
|
*/
|
||||||
|
class EnhancedTrackingProtectionRobot {
|
||||||
|
|
||||||
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!!
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionNotice() = assertEnhancedTrackingProtectionNotice()
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionShield() = assertEnhancedTrackingProtectionShield()
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionSheetStatus(status: String, state: Boolean) =
|
||||||
|
assertEnhancedTrackingProtectionSheetStatus(status, state)
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionDetailsStatus(status: String) =
|
||||||
|
assertEnhancedTrackingProtectionDetailsStatus(status)
|
||||||
|
|
||||||
|
class Transition {
|
||||||
|
fun openEnhancedTrackingProtectionSheet(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
|
||||||
|
openEnhancedTrackingProtectionSheet().click()
|
||||||
|
|
||||||
|
EnhancedTrackingProtectionRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeNotificationPopup(interact: BrowserRobot.() -> Unit): Transition {
|
||||||
|
closeButton().click()
|
||||||
|
|
||||||
|
BrowserRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeEnhancedTrackingProtectionSheet(interact: BrowserRobot.() -> Unit): Transition {
|
||||||
|
// Back out of the Enhanced Tracking Protection sheet
|
||||||
|
mDevice.pressBack()
|
||||||
|
|
||||||
|
BrowserRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disableEnhancedTrackingProtectionFromSheet(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
|
||||||
|
disableEnhancedTrackingProtection().click()
|
||||||
|
|
||||||
|
EnhancedTrackingProtectionRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openProtectionSettings(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): Transition {
|
||||||
|
openEnhancedTrackingProtectionSettings().click()
|
||||||
|
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openDetails(interact: EnhancedTrackingProtectionRobot.() -> Unit): Transition {
|
||||||
|
openEnhancedTrackingProtectionDetails().click()
|
||||||
|
|
||||||
|
EnhancedTrackingProtectionRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enhancedTrackingProtection(interact: EnhancedTrackingProtectionRobot.() -> Unit): EnhancedTrackingProtectionRobot.Transition {
|
||||||
|
EnhancedTrackingProtectionRobot().interact()
|
||||||
|
return EnhancedTrackingProtectionRobot.Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEnhancedTrackingProtectionNotice() {
|
||||||
|
mDevice.waitNotNull(
|
||||||
|
Until.findObject(By.res("org.mozilla.fenix.debug:id/onboarding_message")),
|
||||||
|
TestAssetHelper.waitingTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
isChecked(
|
||||||
|
state
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEnhancedTrackingProtectionDetailsStatus(status: String) {
|
||||||
|
mDevice.waitNotNull(Until.findObjects(By.textContains(status)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeButton() = onView(ViewMatchers.withId(R.id.close_onboarding))
|
||||||
|
|
||||||
|
private fun openEnhancedTrackingProtectionSheet() =
|
||||||
|
onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_tracking_protection_indicator))
|
||||||
|
|
||||||
|
private fun disableEnhancedTrackingProtection() =
|
||||||
|
onView(ViewMatchers.withResourceName("switch_widget"))
|
||||||
|
|
||||||
|
private fun openEnhancedTrackingProtectionSettings() =
|
||||||
|
onView(ViewMatchers.withId(R.id.protection_settings))
|
||||||
|
|
||||||
|
private fun openEnhancedTrackingProtectionDetails() =
|
||||||
|
onView(ViewMatchers.withId(R.id.tracking_content))
|
|
@ -6,15 +6,18 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.ui.robots
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
|
import androidx.preference.R
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.action.ViewActions
|
import androidx.test.espresso.action.ViewActions
|
||||||
|
import androidx.test.espresso.contrib.RecyclerViewActions
|
||||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.UiDevice
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
|
||||||
import androidx.test.uiautomator.By
|
import androidx.test.uiautomator.By
|
||||||
|
import androidx.test.uiautomator.UiDevice
|
||||||
import androidx.test.uiautomator.Until
|
import androidx.test.uiautomator.Until
|
||||||
import org.hamcrest.CoreMatchers
|
import org.hamcrest.CoreMatchers
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
@ -41,7 +44,9 @@ class SettingsRobot {
|
||||||
|
|
||||||
fun verifyEnhancedTrackingProtectionButton() = assertEnhancedTrackingProtectionButton()
|
fun verifyEnhancedTrackingProtectionButton() = assertEnhancedTrackingProtectionButton()
|
||||||
fun verifyLoginsButton() = assertLoginsButton()
|
fun verifyLoginsButton() = assertLoginsButton()
|
||||||
fun verifyEnhancedTrackingProtectionValue() = assertEnhancedTrackingProtectionValue()
|
fun verifyEnhancedTrackingProtectionValue(state: String) =
|
||||||
|
assertEnhancedTrackingProtectionValue(state)
|
||||||
|
|
||||||
fun verifyAddPrivateBrowsingShortcutButton() = assertAddPrivateBrowsingShortcutButton()
|
fun verifyAddPrivateBrowsingShortcutButton() = assertAddPrivateBrowsingShortcutButton()
|
||||||
fun verifySitePermissionsButton() = assertSitePermissionsButton()
|
fun verifySitePermissionsButton() = assertSitePermissionsButton()
|
||||||
fun verifyDeleteBrowsingDataButton() = assertDeleteBrowsingDataButton()
|
fun verifyDeleteBrowsingDataButton() = assertDeleteBrowsingDataButton()
|
||||||
|
@ -108,6 +113,15 @@ class SettingsRobot {
|
||||||
SettingsSubMenuDefaultBrowserRobot().interact()
|
SettingsSubMenuDefaultBrowserRobot().interact()
|
||||||
return SettingsSubMenuDefaultBrowserRobot.Transition()
|
return SettingsSubMenuDefaultBrowserRobot.Transition()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun openEnhancedTrackingProtectionSubMenu(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionRobot.Transition {
|
||||||
|
mDevice.waitForIdle()
|
||||||
|
fun enhancedTrackingProtectionButton() = onView(ViewMatchers.withText("Enhanced Tracking Protection"))
|
||||||
|
enhancedTrackingProtectionButton().click()
|
||||||
|
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionRobot().interact()
|
||||||
|
return SettingsSubMenuEnhancedTrackingProtectionRobot.Transition()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,12 +162,16 @@ private fun assertPrivacyHeading() {
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertEnhancedTrackingProtectionButton() =
|
private fun assertEnhancedTrackingProtectionButton() {
|
||||||
onView(ViewMatchers.withText("Enhanced Tracking Protection"))
|
onView(ViewMatchers.withId(R.id.recycler_view)).perform(
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||||
|
ViewMatchers.hasDescendant(ViewMatchers.withText("Enhanced Tracking Protection"))
|
||||||
|
)
|
||||||
|
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
|
}
|
||||||
|
|
||||||
private fun assertEnhancedTrackingProtectionValue() = onView(ViewMatchers.withText("On"))
|
private fun assertEnhancedTrackingProtectionValue(state: String) =
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
onView(ViewMatchers.withText(state)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
|
|
||||||
private fun assertLoginsButton() {
|
private fun assertLoginsButton() {
|
||||||
TestHelper.scrollToElementByText("Logins and passwords")
|
TestHelper.scrollToElementByText("Logins and passwords")
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
@file:Suppress("TooManyFunctions")
|
||||||
|
|
||||||
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
|
import androidx.test.espresso.Espresso
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import org.hamcrest.CoreMatchers
|
||||||
|
import org.mozilla.fenix.helpers.click
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Robot Pattern for the settings Enhanced Tracking Protection Exceptions sub menu.
|
||||||
|
*/
|
||||||
|
class SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot {
|
||||||
|
|
||||||
|
fun verifyDefault() = assertExceptionDefault()!!
|
||||||
|
|
||||||
|
fun verifyListedURL(url: String) = assertExceptionURL(url)!!
|
||||||
|
|
||||||
|
class Transition {
|
||||||
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!!
|
||||||
|
|
||||||
|
fun goBack(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionRobot.Transition {
|
||||||
|
mDevice.waitForIdle()
|
||||||
|
goBackButton().click()
|
||||||
|
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionRobot().interact()
|
||||||
|
return SettingsSubMenuEnhancedTrackingProtectionRobot.Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disableExceptions(interact: SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot.() -> Unit): Transition {
|
||||||
|
disableExceptionsButton().click()
|
||||||
|
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot().interact()
|
||||||
|
return Transition()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun goBackButton() =
|
||||||
|
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
|
||||||
|
|
||||||
|
private fun assertExceptionDefault() =
|
||||||
|
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText("Exceptions let you disable tracking protection for selected sites.")))
|
||||||
|
|
||||||
|
private fun assertExceptionURL(url: String) =
|
||||||
|
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText(url)))
|
||||||
|
|
||||||
|
private fun disableExceptionsButton() =
|
||||||
|
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.removeAllExceptions)))
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
@file:Suppress("TooManyFunctions")
|
||||||
|
|
||||||
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
|
import androidx.test.espresso.Espresso.onView
|
||||||
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers.withResourceName
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import org.hamcrest.CoreMatchers
|
||||||
|
import org.mozilla.fenix.helpers.click
|
||||||
|
import org.mozilla.fenix.helpers.isChecked
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Robot Pattern for the settings Enhanced Tracking Protection sub menu.
|
||||||
|
*/
|
||||||
|
class SettingsSubMenuEnhancedTrackingProtectionRobot {
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionHeader() = assertEnhancedTrackingProtectionHeader()
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionOptions() = assertEnhancedTrackingProtectionOptions()
|
||||||
|
|
||||||
|
fun verifyEnhancedTrackingProtectionDefaults() = assertEnhancedTrackingProtectionDefaults()
|
||||||
|
|
||||||
|
class Transition {
|
||||||
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!!
|
||||||
|
|
||||||
|
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
|
||||||
|
mDevice.waitForIdle()
|
||||||
|
goBackButton().click()
|
||||||
|
|
||||||
|
SettingsRobot().interact()
|
||||||
|
return SettingsRobot.Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openExceptions(interact: SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot.Transition {
|
||||||
|
openExceptions().click()
|
||||||
|
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot().interact()
|
||||||
|
return SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot.Transition()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEnhancedTrackingProtectionHeader() {
|
||||||
|
onView(ViewMatchers.withText("Browse without being followed"))
|
||||||
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEnhancedTrackingProtectionOptions() {
|
||||||
|
onView(ViewMatchers.withText("Standard"))
|
||||||
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
|
val stdText = "Pages will load normally, but block fewer trackers."
|
||||||
|
onView(ViewMatchers.withText(stdText))
|
||||||
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
|
|
||||||
|
onView(ViewMatchers.withText("Strict (Default)"))
|
||||||
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
|
val summaryText =
|
||||||
|
"Stronger tracking protection and faster performance, but some sites may not work properly."
|
||||||
|
onView(ViewMatchers.withText(summaryText))
|
||||||
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEnhancedTrackingProtectionDefaults() {
|
||||||
|
onView(withResourceName("switch_widget")).check(
|
||||||
|
matches(
|
||||||
|
isChecked(
|
||||||
|
true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun settingsSubMenuEnhancedTrackingProtection(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionRobot.Transition {
|
||||||
|
SettingsSubMenuEnhancedTrackingProtectionRobot().interact()
|
||||||
|
return SettingsSubMenuEnhancedTrackingProtectionRobot.Transition()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun goBackButton() =
|
||||||
|
onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
|
||||||
|
|
||||||
|
private fun openExceptions() =
|
||||||
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Exceptions")))
|
Loading…
Reference in New Issue