diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/AccessSettingsTest.kt b/app/src/androidTest/java/org/mozilla/focus/activity/AccessSettingsTest.kt deleted file mode 100644 index 5b545b4a5c7..00000000000 --- a/app/src/androidTest/java/org/mozilla/focus/activity/AccessSettingsTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- 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 androidx.test.uiautomator.UiSelector -import org.junit.Assert -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mozilla.focus.helpers.EspressoHelper.openSettings -import org.mozilla.focus.helpers.MainActivityFirstrunTestRule -import org.mozilla.focus.helpers.TestHelper -import org.mozilla.focus.helpers.TestHelper.waitingTime - -// This test checks all the headings in the Settings menu are there -// https://testrail.stage.mozaws.net/index.php?/cases/view/40064 -@RunWith(AndroidJUnit4ClassRunner::class) -class AccessSettingsTest { - @get: Rule - var mActivityTestRule = MainActivityFirstrunTestRule(showFirstRun = false) - - val generalHeading = TestHelper.mDevice.findObject( - UiSelector() - .text("General") - .resourceId("android:id/title") - ) - val privacyHeading = TestHelper.mDevice.findObject( - UiSelector() - .text("Privacy & Security") - .resourceId("android:id/title") - ) - val searchHeading = TestHelper.mDevice.findObject( - UiSelector() - .text("Search") - .resourceId("android:id/title") - ) - val mozHeading = TestHelper.mDevice.findObject( - UiSelector() - .text("Mozilla") - .resourceId("android:id/title") - ) - - @Test - fun AccessSettingsTest() { - /* Go to Settings */TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime) - openSettings() - generalHeading.waitForExists(waitingTime) - - /* Check the first element and other headings are present */ - Assert.assertTrue(generalHeading.exists()) - Assert.assertTrue(searchHeading.exists()) - Assert.assertTrue(privacyHeading.exists()) - Assert.assertTrue(mozHeading.exists()) - } -} diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/SettingsTest.kt b/app/src/androidTest/java/org/mozilla/focus/activity/SettingsTest.kt new file mode 100644 index 00000000000..b28d36d21ae --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/focus/activity/SettingsTest.kt @@ -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() + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsAdvancedMenuRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsAdvancedMenuRobot.kt new file mode 100644 index 00000000000..6c630536d20 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsAdvancedMenuRobot.kt @@ -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")) diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsGeneralMenuRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsGeneralMenuRobot.kt new file mode 100644 index 00000000000..9f37644c665 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsGeneralMenuRobot.kt @@ -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")) diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsMozillaMenuRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsMozillaMenuRobot.kt new file mode 100644 index 00000000000..c03c8396f0e --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsMozillaMenuRobot.kt @@ -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")) diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsPrivacyMenuRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsPrivacyMenuRobot.kt new file mode 100644 index 00000000000..1bb10f96aa0 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsPrivacyMenuRobot.kt @@ -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")) +} diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsRobot.kt index 8baa68c2553..2b0cd694931 100644 --- a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsRobot.kt @@ -6,11 +6,21 @@ package org.mozilla.focus.activity.robots import androidx.test.uiautomator.UiScrollable import androidx.test.uiautomator.UiSelector +import org.junit.Assert.assertTrue import org.mozilla.focus.helpers.TestHelper.appName import org.mozilla.focus.helpers.TestHelper.waitingTime class SettingsRobot { + fun verifySettingsMenuItems() { + settingsMenuList.waitForExists(waitingTime) + assertTrue(generalSettingsMenu.exists()) + assertTrue(searchSettingsMenu.exists()) + assertTrue(privacySettingsMenu.exists()) + assertTrue(advancedSettingsMenu.exists()) + assertTrue(mozillaSettingsMenu.exists()) + } + class Transition { fun openSearchSettingsMenu(interact: SearchSettingsRobot.() -> Unit): SearchSettingsRobot.Transition { searchSettingsMenu.waitForExists(waitingTime) @@ -19,14 +29,78 @@ class SettingsRobot { SearchSettingsRobot().interact() return SearchSettingsRobot.Transition() } + + fun openGeneralSettingsMenu( + interact: SettingsGeneralMenuRobot.() -> Unit + ): SettingsGeneralMenuRobot.Transition { + generalSettingsMenu.waitForExists(waitingTime) + generalSettingsMenu.click() + + SettingsGeneralMenuRobot().interact() + return SettingsGeneralMenuRobot.Transition() + } + + fun openPrivacySettingsMenu( + interact: SettingsPrivacyMenuRobot.() -> Unit + ): SettingsPrivacyMenuRobot.Transition { + privacySettingsMenu.waitForExists(waitingTime) + privacySettingsMenu.click() + + SettingsPrivacyMenuRobot().interact() + return SettingsPrivacyMenuRobot.Transition() + } + + fun openAdvancedSettingsMenu( + interact: SettingsAdvancedMenuRobot.() -> Unit + ): SettingsAdvancedMenuRobot.Transition { + advancedSettingsMenu.waitForExists(waitingTime) + advancedSettingsMenu.click() + + SettingsAdvancedMenuRobot().interact() + return SettingsAdvancedMenuRobot.Transition() + } + + fun openMozillaSettingsMenu( + interact: SettingsMozillaMenuRobot.() -> Unit + ): SettingsMozillaMenuRobot.Transition { + mozillaSettingsMenu.waitForExists(waitingTime) + mozillaSettingsMenu.click() + + SettingsMozillaMenuRobot().interact() + return SettingsMozillaMenuRobot.Transition() + } } } private val settingsMenuList = UiScrollable(UiSelector().resourceId("$appName:id/recycler_view")) +private val generalSettingsMenu = settingsMenuList.getChild( + UiSelector() + .resourceId("android:id/title") + .text("General") +) + private val searchSettingsMenu = settingsMenuList.getChild( UiSelector() .resourceId("android:id/title") .text("Search") .enabled(true) ) + +private val privacySettingsMenu = settingsMenuList.getChild( + UiSelector() + .resourceId("android:id/title") + .text("Privacy & Security") +) + +private val advancedSettingsMenu = settingsMenuList.getChild( + UiSelector() + .text("Advanced") + .resourceId("android:id/title") +) + +private val mozillaSettingsMenu = settingsMenuList.getChild( + UiSelector() + .text("Mozilla") + .resourceId("android:id/title") +) diff --git a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsSearchMenuRobot.kt b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsSearchMenuRobot.kt index 7b78ab2fc99..995d0211602 100644 --- a/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsSearchMenuRobot.kt +++ b/app/src/androidTest/java/org/mozilla/focus/activity/robots/SettingsSearchMenuRobot.kt @@ -7,12 +7,19 @@ package org.mozilla.focus.activity.robots import androidx.test.uiautomator.UiObject import androidx.test.uiautomator.UiScrollable import androidx.test.uiautomator.UiSelector +import org.junit.Assert.assertTrue import org.mozilla.focus.helpers.TestHelper.appName import org.mozilla.focus.helpers.TestHelper.mDevice import org.mozilla.focus.helpers.TestHelper.waitingTime class SearchSettingsRobot { + fun verifySearchSettingsItems() { + assertTrue(searchEngineSubMenu.exists()) + assertTrue(searchSuggestionsSwitch.exists()) + assertTrue(urlAutocompleteSubMenu.exists()) + } + fun openSearchEngineSubMenu() { searchEngineSubMenu.waitForExists(waitingTime) searchEngineSubMenu.click() @@ -47,3 +54,7 @@ private val searchSuggestionsSwitch: UiObject = UiSelector() .resourceId("$appName:id/switchWidget") ) + +private val urlAutocompleteSubMenu = + UiScrollable(UiSelector().resourceId("$appName:id/recycler_view")) + .getChild(UiSelector().text("URL Autocomplete"))