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

Commit

Permalink
Refactor AddSettingsTest, added new tests based on the manual test ca…
Browse files Browse the repository at this point in the history
…ses.

Added new test robots.
  • Loading branch information
Oana Horvath authored and mergify[bot] committed Mar 29, 2021
1 parent 09ea191 commit 9436242
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* 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.focus.activity

import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.focus.activity.robots.homeScreen
import org.mozilla.focus.helpers.MainActivityFirstrunTestRule

// This test checks all the headings in the Settings menu are there
@RunWith(AndroidJUnit4ClassRunner::class)
class SettingsTest {
@get: Rule
var mActivityTestRule = MainActivityFirstrunTestRule(showFirstRun = false)

@Test
fun accessSettingsMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
verifySettingsMenuItems()
}
}

@Test
fun verifyGeneralSettingsMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openGeneralSettingsMenu {
verifyGeneralSettingsItems()
}
}

@Test
fun verifyPrivacySettingsMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openPrivacySettingsMenu {
verifyPrivacySettingsItems()
}
}

@Test
fun verifySearchSettingsMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openSearchSettingsMenu {
verifySearchSettingsItems()
}
}

@Test
fun verifyAdvancedSettingsMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openAdvancedSettingsMenu {
verifyAdvancedSettingsItems()
}
}

@Test
fun verifyMozillaMenuTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openMozillaSettingsMenu {
verifyMozillaMenuItems()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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.focus.activity.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.isDisplayed
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.mozilla.focus.helpers.TestHelper.appName
import org.mozilla.focus.helpers.TestHelper.waitingTime

class SettingsAdvancedMenuRobot {
fun verifyAdvancedSettingsItems() {
advancedSettingsList.waitForExists(waitingTime)
remoteDebuggingSwitch.check(matches(isDisplayed()))
}

class Transition
}

private val advancedSettingsList =
UiScrollable(UiSelector().resourceId("$appName:id/recycler_view"))

private val remoteDebuggingSwitch = onView(ViewMatchers.withText("Remote debugging via USB/Wi-Fi"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 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.focus.activity.robots

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.mozilla.focus.helpers.TestHelper.pressBackKey

class SettingsGeneralMenuRobot {

fun verifyGeneralSettingsItems() {
defaultBrowserSwitch.check(matches(isDisplayed()))
switchToLinkToggleButton.check(matches(isDisplayed()))
}

class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
pressBackKey()

SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}

private val defaultBrowserSwitch = onView(withText("Make Firefox Focus default browser"))

private val switchToLinkToggleButton = onView(withText("Switch to link in new tab immediately"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* 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.focus.activity.robots

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.mozilla.focus.helpers.TestHelper
import org.mozilla.focus.helpers.TestHelper.waitingTime

class SettingsMozillaMenuRobot {
fun verifyMozillaMenuItems() {
mozillaSettingsList.waitForExists(waitingTime)
showTipsSwitch.check(matches(isDisplayed()))
aboutFocusPageLink.check(matches(isDisplayed()))
helpPageLink.check(matches(isDisplayed()))
rightsPageLink.check(matches(isDisplayed()))
privacyNoticeLink.check(matches(isDisplayed()))
}

class Transition
}

private val mozillaSettingsList =
UiScrollable(UiSelector().resourceId("${TestHelper.appName}:id/recycler_view"))

private val showTipsSwitch = onView(withText("Show home screen tips"))

private val aboutFocusPageLink = onView(withText("About Firefox Focus"))

private val helpPageLink = onView(withText("Help"))

private val rightsPageLink = onView(withText("Your Rights"))

private val privacyNoticeLink = onView(withText("Privacy Notice"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* 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.focus.activity.robots

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.mozilla.focus.helpers.TestHelper.appName
import org.mozilla.focus.helpers.TestHelper.waitingTime

class SettingsPrivacyMenuRobot {

fun verifyPrivacySettingsItems() {
privacySettingsList.waitForExists(waitingTime)
adTrackersBlockSwitch().check(matches(isDisplayed()))
analyticTrackersBlockSwitch().check(matches(isDisplayed()))
socialTrackersBlockSwitch().check(matches(isDisplayed()))
otherContentTrackersBlockSwitch().check(matches(isDisplayed()))
blockWebFontsSwitch().check(matches(isDisplayed()))
blockJavaScriptSwitch().check(matches(isDisplayed()))
blockCookiesMenu().check(matches(isDisplayed()))
useFingerprintSwitch().check(matches(isDisplayed()))
stealthModeSwitch().check(matches(isDisplayed()))
safeBrowsingSwitch().check(matches(isDisplayed()))
sendDataSwitch().check(matches(isDisplayed()))
}

class Transition
}

private val privacySettingsList =
UiScrollable(UiSelector().resourceId("$appName:id/recycler_view"))

private fun adTrackersBlockSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block ad trackers")
return onView(withText("Block ad trackers"))
}

private fun analyticTrackersBlockSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block analytic trackers")
return onView(withText("Block analytic trackers"))
}

private fun socialTrackersBlockSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block social trackers")
return onView(withText("Block social trackers"))
}

private fun otherContentTrackersBlockSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block other content trackers")
return onView(withText("Block other content trackers"))
}

private fun blockWebFontsSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block Web fonts")
return onView(withText("Block Web fonts"))
}

private fun blockJavaScriptSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block JavaScript")
return onView(withText("Block JavaScript"))
}

private fun blockCookiesMenu(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block cookies")
return onView(withText("Block cookies"))
}

private fun useFingerprintSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Use fingerprint to unlock app")
return onView(withText("Use fingerprint to unlock app"))
}

private fun stealthModeSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Stealth")
return onView(withText("Stealth"))
}

private fun safeBrowsingSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Block potentially dangerous and deceptive sites")
return onView(withText("Block potentially dangerous and deceptive sites"))
}

private fun sendDataSwitch(): ViewInteraction {
privacySettingsList
.scrollTextIntoView("Send usage data")
return onView(withText("Send usage data"))
}
Loading

0 comments on commit 9436242

Please sign in to comment.