Commit ce0d5a1a authored by ValentinTimisica's avatar ValentinTimisica
Browse files

For #11365: Fixes UI tests for Settings

parent bc532966
......@@ -68,6 +68,7 @@ class SettingsBasicsTest {
}.openSettings {
verifyBasicsHeading()
verifySearchEngineButton()
verifyDefaultBrowserItem()
// drill down to submenu
}.openSearchSubMenu {
verifyDefaultSearchEngineHeader()
......@@ -86,10 +87,6 @@ class SettingsBasicsTest {
verifyAutomaticFontSizingMenuItems()
}.goBack {
// drill down to submenu
}.openDefaultBrowserSubMenu {
// verify item: set as default browser (duplicates, verify child of recyclerview)
// Verify label: Open links in private tab
}.goBack {
}
}
......@@ -213,11 +210,9 @@ class SettingsBasicsTest {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openDefaultBrowserSubMenu {
verifyDefaultBrowserIsDisabled()
verifyDefaultBrowserIsDisaled()
clickDefaultBrowserSwitch()
verifyAndroidDefaultAppsMenuAppears()
}
}
}
......@@ -14,6 +14,7 @@ import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.intent.matcher.IntentMatchers.toPackage
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
......@@ -34,6 +35,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.assertIsEnabled
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.ui.robots.SettingsRobot.Companion.DEFAULT_APPS_SETTINGS_ACTION
/**
* Implementation of Robot Pattern for the settings menu.
......@@ -48,6 +50,10 @@ class SettingsRobot {
fun verifyThemeSelected() = assertThemeSelected()
fun verifyAccessibilityButton() = assertAccessibilityButton()
fun verifySetAsDefaultBrowserButton() = assertSetAsDefaultBrowserButton()
fun verifyDefaultBrowserItem() = assertDefaultBrowserItem()
fun verifyDefaultBrowserIsDisaled() = assertDefaultBrowserIsDisabled()
fun clickDefaultBrowserSwitch() = toggleDefaultBrowserSwitch()
fun verifyAndroidDefaultAppsMenuAppears() = assertAndroidDefaultAppsMenuAppears()
// PRIVACY SECTION
fun verifyPrivacyHeading() = assertPrivacyHeading()
......@@ -128,15 +134,6 @@ class SettingsRobot {
return SettingsSubMenuAccessibilityRobot.Transition()
}
fun openDefaultBrowserSubMenu(interact: SettingsSubMenuDefaultBrowserRobot.() -> Unit): SettingsSubMenuDefaultBrowserRobot.Transition {
fun defaultBrowserButton() = onView(withText("Set as default browser"))
defaultBrowserButton().click()
SettingsSubMenuDefaultBrowserRobot().interact()
return SettingsSubMenuDefaultBrowserRobot.Transition()
}
fun openEnhancedTrackingProtectionSubMenu(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit): SettingsSubMenuEnhancedTrackingProtectionRobot.Transition {
fun enhancedTrackingProtectionButton() =
onView(withText("Enhanced Tracking Protection"))
......@@ -208,6 +205,10 @@ class SettingsRobot {
return SettingsSubMenuDataCollectionRobot.Transition()
}
}
companion object {
const val DEFAULT_APPS_SETTINGS_ACTION = "android.settings.MANAGE_DEFAULT_APPS_SETTINGS"
}
}
private fun assertSettingsView() {
......@@ -241,6 +242,31 @@ private fun assertSetAsDefaultBrowserButton() =
onView(withText("Set as default browser"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertDefaultBrowserIsDisabled() {
onView(withId(R.id.switch_widget))
.check(matches(ViewMatchers.isNotChecked()))
}
private fun toggleDefaultBrowserSwitch() {
onView(
CoreMatchers.allOf(
ViewMatchers.withParent(CoreMatchers.not(withId(R.id.navigationToolbar))),
withText("Set as default browser")
)
)
.perform(ViewActions.click())
}
private fun assertAndroidDefaultAppsMenuAppears() {
intended(IntentMatchers.hasAction(DEFAULT_APPS_SETTINGS_ACTION))
}
private fun assertDefaultBrowserItem() {
mDevice.wait(Until.findObject(By.text("Set as default browser")), waitingTime)
onView(withText("Set as default browser"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
// PRIVACY SECTION
private fun assertPrivacyHeading() {
onView(withText("Privacy and security"))
......
/* 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.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
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.R
import org.mozilla.fenix.ui.robots.SettingsSubMenuDefaultBrowserRobot.Companion.DEFAULT_APPS_SETTINGS_ACTION
/**
* Implementation of Robot Pattern for the settings DefaultBrowser sub menu.
*/
class SettingsSubMenuDefaultBrowserRobot {
companion object {
const val DEFAULT_APPS_SETTINGS_ACTION = "android.settings.MANAGE_DEFAULT_APPS_SETTINGS"
}
fun verifyDefaultBrowserIsDisabled() = assertDefaultBrowserIsDisabled()
fun clickDefaultBrowserSwitch() = toggleDefaultBrowserSwitch()
fun verifyAndroidDefaultAppsMenuAppears() = assertAndroidDefaultAppsMenuAppears()
class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
mDevice.waitForIdle()
goBackButton().perform(click())
SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}
fun assertDefaultBrowserIsDisabled() {
onView(withId(R.id.switch_widget))
.check(matches(isNotChecked()))
}
fun toggleDefaultBrowserSwitch() {
onView(
allOf(
withParent(not(withId(R.id.navigationToolbar))),
withText("Set as default browser")
)
)
.perform(click())
}
private fun assertAndroidDefaultAppsMenuAppears() {
intended(hasAction(DEFAULT_APPS_SETTINGS_ACTION))
}
private fun goBackButton() =
onView(allOf(withContentDescription("Navigate up")))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment