diff --git a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py index 3114304859..0998cbb49d 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py +++ b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/generate_smoke_tests.py @@ -1,5 +1,5 @@ -from pathlib import Path import subprocess +from pathlib import Path import yaml diff --git a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/gradlewbuild.py b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/gradlewbuild.py index 721d4ff3fa..43ac14a64c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/gradlewbuild.py +++ b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/gradlewbuild.py @@ -24,7 +24,7 @@ class GradlewBuild(object): test_type = "ui" if smoke else "experimentintegration" cmd = f"adb shell am instrument -w -e class org.mozilla.fenix.{test_type}.{identifier} org.mozilla.fenix.debug.test/androidx.test.runner.AndroidJUnitRunner" # if smoke: - # cmd = f"adb shell am instrument -w -e class org.mozilla.fenix.ui.{identifier} org.mozilla.fenix.debug.test/androidx.test.runner.AndroidJUnitRunner" + # cmd = f"adb shell am instrument -w -e class org.mozilla.fenix.ui.{identifier} org.mozilla.fenix.debug.test/androidx.test.runner.AndroidJUnitRunner" # else: # cmd = f"adb shell am instrument -w -e class org.mozilla.fenix.experimentintegration.{identifier} org.mozilla.fenix.debug.test/androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/tests/test_generic_scenarios.py b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/tests/test_generic_scenarios.py index bcc841fefd..b203970278 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/tests/test_generic_scenarios.py +++ b/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/tests/test_generic_scenarios.py @@ -1,17 +1,25 @@ import pytest + @pytest.mark.parametrize("load_branches", [("branch")], indirect=True) -def test_experiment_unenrolls_via_studies_toggle(setup_experiment, gradlewbuild, load_branches, check_ping_for_experiment): +def test_experiment_unenrolls_via_studies_toggle( + setup_experiment, gradlewbuild, load_branches, check_ping_for_experiment +): setup_experiment(load_branches) gradlewbuild.test("GenericExperimentIntegrationTest#disableStudiesViaStudiesToggle") assert check_ping_for_experiment(reason="enrollment", branch=load_branches[0]) gradlewbuild.test("GenericExperimentIntegrationTest#testExperimentUnenrolled") assert check_ping_for_experiment(reason="unenrollment", branch=load_branches[0]) + @pytest.mark.parametrize("load_branches", [("branch")], indirect=True) -def test_experiment_unenrolls_via_secret_menu(setup_experiment, gradlewbuild, load_branches, check_ping_for_experiment): +def test_experiment_unenrolls_via_secret_menu( + setup_experiment, gradlewbuild, load_branches, check_ping_for_experiment +): setup_experiment(load_branches) - gradlewbuild.test("GenericExperimentIntegrationTest#testExperimentUnenrolledViaSecretMenu") + gradlewbuild.test( + "GenericExperimentIntegrationTest#testExperimentUnenrolledViaSecretMenu" + ) assert check_ping_for_experiment(reason="enrollment", branch=load_branches[0]) gradlewbuild.test("GenericExperimentIntegrationTest#testExperimentUnenrolled") assert check_ping_for_experiment(reason="unenrollment", branch=load_branches[0]) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/ViewVisibilityIdlingResource.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/ViewVisibilityIdlingResource.kt index c029bac0d7..a817c691de 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/ViewVisibilityIdlingResource.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/ViewVisibilityIdlingResource.kt @@ -1,36 +1,36 @@ -/* 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.helpers - -import android.view.View -import androidx.test.espresso.IdlingResource - -class ViewVisibilityIdlingResource( - private val view: View, - private val expectedVisibility: Int, -) : IdlingResource { - private var resourceCallback: IdlingResource.ResourceCallback? = null - private var isIdle: Boolean = false - - override fun getName(): String { - return ViewVisibilityIdlingResource::class.java.name + ":" + view.id + ":" + expectedVisibility - } - - override fun isIdleNow(): Boolean { - if (isIdle) return true - - isIdle = view.visibility == expectedVisibility - - if (isIdle) { - resourceCallback?.onTransitionToIdle() - } - - return isIdle - } - - override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) { - this.resourceCallback = callback - } -} +/* 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.helpers + +import android.view.View +import androidx.test.espresso.IdlingResource + +class ViewVisibilityIdlingResource( + private val view: View, + private val expectedVisibility: Int, +) : IdlingResource { + private var resourceCallback: IdlingResource.ResourceCallback? = null + private var isIdle: Boolean = false + + override fun getName(): String { + return ViewVisibilityIdlingResource::class.java.name + ":" + view.id + ":" + expectedVisibility + } + + override fun isIdleNow(): Boolean { + if (isIdle) return true + + isIdle = view.visibility == expectedVisibility + + if (isIdle) { + resourceCallback?.onTransitionToIdle() + } + + return isIdle + } + + override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) { + this.resourceCallback = callback + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDeleteBrowsingDataOnQuitRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDeleteBrowsingDataOnQuitRobot.kt index 976e6777c8..a818ef487f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDeleteBrowsingDataOnQuitRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuDeleteBrowsingDataOnQuitRobot.kt @@ -1,119 +1,119 @@ -/* 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.robots - -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.Visibility -import androidx.test.espresso.matcher.ViewMatchers.hasDescendant -import androidx.test.espresso.matcher.ViewMatchers.withChild -import androidx.test.espresso.matcher.ViewMatchers.withClassName -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withResourceName -import androidx.test.espresso.matcher.ViewMatchers.withText -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.CoreMatchers.containsString -import org.mozilla.fenix.R -import org.mozilla.fenix.helpers.assertIsChecked -import org.mozilla.fenix.helpers.atPosition -import org.mozilla.fenix.helpers.click -import org.mozilla.fenix.helpers.isChecked - -/** - * Implementation of Robot Pattern for the settings Delete Browsing Data On Quit sub menu. - */ -class SettingsSubMenuDeleteBrowsingDataOnQuitRobot { - - fun verifyNavigationToolBarHeader() = - onView( - allOf( - withId(R.id.navigationToolbar), - withChild(withText(R.string.preferences_delete_browsing_data_on_quit)), - ), - ) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - fun verifyDeleteBrowsingOnQuitEnabled(enabled: Boolean) = - deleteBrowsingOnQuitButton.assertIsChecked(enabled) - - fun verifyDeleteBrowsingOnQuitButtonSummary() = - onView( - withText(R.string.preference_summary_delete_browsing_data_on_quit_2), - ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - fun clickDeleteBrowsingOnQuitButtonSwitch() = onView(withResourceName("switch_widget")).click() - - fun verifyAllTheCheckBoxesText() { - openTabsCheckbox - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - browsingHistoryCheckbox - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - cookiesAndSiteDataCheckbox - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - onView(withText(R.string.preferences_delete_browsing_data_cookies_subtitle)) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - cachedFilesCheckbox - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - onView(withText(R.string.preferences_delete_browsing_data_cached_files_subtitle)) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - sitePermissionsCheckbox - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - } - - fun verifyAllTheCheckBoxesChecked(checked: Boolean) { - for (index in 2..7) { - onView(withId(R.id.recycler_view)) - .check( - matches( - atPosition( - index, - hasDescendant( - allOf( - withResourceName(containsString("checkbox")), - isChecked(checked), - ), - ), - ), - ), - ) - } - } - - class Transition { - fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { - goBackButton.click() - - SettingsRobot().interact() - return SettingsRobot.Transition() - } - } -} - -private val goBackButton = onView(withContentDescription("Navigate up")) - -private val deleteBrowsingOnQuitButton = - onView(withClassName(containsString("android.widget.Switch"))) - -private val openTabsCheckbox = - onView(withText(R.string.preferences_delete_browsing_data_tabs_title_2)) - -private val browsingHistoryCheckbox = - onView(withText(R.string.preferences_delete_browsing_data_browsing_history_title)) - -private val cookiesAndSiteDataCheckbox = onView(withText(R.string.preferences_delete_browsing_data_cookies_and_site_data)) - -private val cachedFilesCheckbox = - onView(withText(R.string.preferences_delete_browsing_data_cached_files)) - -private val sitePermissionsCheckbox = - onView(withText(R.string.preferences_delete_browsing_data_site_permissions)) +/* 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.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.withChild +import androidx.test.espresso.matcher.ViewMatchers.withClassName +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withResourceName +import androidx.test.espresso.matcher.ViewMatchers.withText +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.containsString +import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.assertIsChecked +import org.mozilla.fenix.helpers.atPosition +import org.mozilla.fenix.helpers.click +import org.mozilla.fenix.helpers.isChecked + +/** + * Implementation of Robot Pattern for the settings Delete Browsing Data On Quit sub menu. + */ +class SettingsSubMenuDeleteBrowsingDataOnQuitRobot { + + fun verifyNavigationToolBarHeader() = + onView( + allOf( + withId(R.id.navigationToolbar), + withChild(withText(R.string.preferences_delete_browsing_data_on_quit)), + ), + ) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + fun verifyDeleteBrowsingOnQuitEnabled(enabled: Boolean) = + deleteBrowsingOnQuitButton.assertIsChecked(enabled) + + fun verifyDeleteBrowsingOnQuitButtonSummary() = + onView( + withText(R.string.preference_summary_delete_browsing_data_on_quit_2), + ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + fun clickDeleteBrowsingOnQuitButtonSwitch() = onView(withResourceName("switch_widget")).click() + + fun verifyAllTheCheckBoxesText() { + openTabsCheckbox + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + browsingHistoryCheckbox + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + cookiesAndSiteDataCheckbox + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + onView(withText(R.string.preferences_delete_browsing_data_cookies_subtitle)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + cachedFilesCheckbox + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + onView(withText(R.string.preferences_delete_browsing_data_cached_files_subtitle)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + sitePermissionsCheckbox + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + } + + fun verifyAllTheCheckBoxesChecked(checked: Boolean) { + for (index in 2..7) { + onView(withId(R.id.recycler_view)) + .check( + matches( + atPosition( + index, + hasDescendant( + allOf( + withResourceName(containsString("checkbox")), + isChecked(checked), + ), + ), + ), + ), + ) + } + } + + class Transition { + fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { + goBackButton.click() + + SettingsRobot().interact() + return SettingsRobot.Transition() + } + } +} + +private val goBackButton = onView(withContentDescription("Navigate up")) + +private val deleteBrowsingOnQuitButton = + onView(withClassName(containsString("android.widget.Switch"))) + +private val openTabsCheckbox = + onView(withText(R.string.preferences_delete_browsing_data_tabs_title_2)) + +private val browsingHistoryCheckbox = + onView(withText(R.string.preferences_delete_browsing_data_browsing_history_title)) + +private val cookiesAndSiteDataCheckbox = onView(withText(R.string.preferences_delete_browsing_data_cookies_and_site_data)) + +private val cachedFilesCheckbox = + onView(withText(R.string.preferences_delete_browsing_data_cached_files)) + +private val sitePermissionsCheckbox = + onView(withText(R.string.preferences_delete_browsing_data_site_permissions)) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsExceptionsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsExceptionsRobot.kt index a95a24a208..35d52c2ed2 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsExceptionsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsExceptionsRobot.kt @@ -1,124 +1,124 @@ -/* 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.robots - -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.hasSibling -import androidx.test.espresso.matcher.ViewMatchers.isDisplayed -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.uiautomator.UiSelector -import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.CoreMatchers.containsString -import org.mozilla.fenix.R -import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource -import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone -import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText -import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime -import org.mozilla.fenix.helpers.TestHelper.mDevice -import org.mozilla.fenix.helpers.TestHelper.packageName -import org.mozilla.fenix.helpers.click - -/** - * Implementation of Robot Pattern for the settings Site Permissions Notification sub menu. - */ -class SettingsSubMenuSitePermissionsExceptionsRobot { - fun verifyExceptionsEmptyList() { - mDevice.findObject(UiSelector().text(getStringResource(R.string.no_site_exceptions))) - .waitForExists(waitingTime) - onView(withText(R.string.no_site_exceptions)).check(matches(isDisplayed())) - } - - fun verifyExceptionCreated(url: String, shouldBeDisplayed: Boolean) { - if (shouldBeDisplayed) { - exceptionsList.waitForExists(waitingTime) - onView(withText(containsString(url))).check(matches(isDisplayed())) - } else { - assertUIObjectIsGone(itemContainingText(url)) - } - } - - fun verifyClearPermissionsDialog() { - onView(withText(R.string.clear_permissions)).check(matches(isDisplayed())) - onView(withText(R.string.confirm_clear_permissions_on_all_sites)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) - } - - // Click button for resetting all of one site's permissions to default - fun clickClearPermissionsForOneSite() { - swipeToBottom() - onView(withText(R.string.clear_permissions)) - .check(matches(isDisplayed())) - .click() - } - fun verifyClearPermissionsForOneSiteDialog() { - onView(withText(R.string.clear_permissions)).check(matches(isDisplayed())) - onView(withText(R.string.confirm_clear_permissions_site)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) - } - - fun openSiteExceptionsDetails(url: String) { - exceptionsList.waitForExists(waitingTime) - onView(withText(containsString(url))).click() - } - - fun verifyPermissionSettingSummary(setting: String, summary: String) { - onView( - allOf( - withText(setting), - hasSibling(withText(summary)), - ), - ).check(matches(isDisplayed())) - } - - fun openChangePermissionSettingsMenu(permissionSetting: String) { - onView(withText(containsString(permissionSetting))).click() - } - - // Click button for resetting all permissions for all websites - fun clickClearPermissionsOnAllSites() { - exceptionsList.waitForExists(waitingTime) - onView(withId(R.id.delete_all_site_permissions_button)) - .check(matches(isDisplayed())) - .click() - } - - // Click button for resetting one site permission to default - fun clickClearOnePermissionForOneSite() { - onView(withText(R.string.clear_permission)) - .check(matches(isDisplayed())) - .click() - } - - fun verifyResetPermissionDefaultForThisSiteDialog() { - onView(withText(R.string.clear_permission)).check(matches(isDisplayed())) - onView(withText(R.string.confirm_clear_permission_site)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) - onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) - } - - fun clickOK() = onView(withText(R.string.clear_permissions_positive)).click() - - fun clickCancel() = onView(withText(R.string.clear_permissions_negative)).click() - - class Transition { - fun goBack(interact: SettingsSubMenuSitePermissionsRobot.() -> Unit): SettingsSubMenuSitePermissionsRobot.Transition { - goBackButton().click() - - SettingsSubMenuSitePermissionsRobot().interact() - return SettingsSubMenuSitePermissionsRobot.Transition() - } - } -} - -private fun goBackButton() = - onView(allOf(withContentDescription("Navigate up"))) - -private val exceptionsList = - mDevice.findObject(UiSelector().resourceId("$packageName:id/exceptions")) +/* 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.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.hasSibling +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.uiautomator.UiSelector +import org.hamcrest.CoreMatchers.allOf +import org.hamcrest.CoreMatchers.containsString +import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource +import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone +import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText +import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime +import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestHelper.packageName +import org.mozilla.fenix.helpers.click + +/** + * Implementation of Robot Pattern for the settings Site Permissions Notification sub menu. + */ +class SettingsSubMenuSitePermissionsExceptionsRobot { + fun verifyExceptionsEmptyList() { + mDevice.findObject(UiSelector().text(getStringResource(R.string.no_site_exceptions))) + .waitForExists(waitingTime) + onView(withText(R.string.no_site_exceptions)).check(matches(isDisplayed())) + } + + fun verifyExceptionCreated(url: String, shouldBeDisplayed: Boolean) { + if (shouldBeDisplayed) { + exceptionsList.waitForExists(waitingTime) + onView(withText(containsString(url))).check(matches(isDisplayed())) + } else { + assertUIObjectIsGone(itemContainingText(url)) + } + } + + fun verifyClearPermissionsDialog() { + onView(withText(R.string.clear_permissions)).check(matches(isDisplayed())) + onView(withText(R.string.confirm_clear_permissions_on_all_sites)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) + } + + // Click button for resetting all of one site's permissions to default + fun clickClearPermissionsForOneSite() { + swipeToBottom() + onView(withText(R.string.clear_permissions)) + .check(matches(isDisplayed())) + .click() + } + fun verifyClearPermissionsForOneSiteDialog() { + onView(withText(R.string.clear_permissions)).check(matches(isDisplayed())) + onView(withText(R.string.confirm_clear_permissions_site)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) + } + + fun openSiteExceptionsDetails(url: String) { + exceptionsList.waitForExists(waitingTime) + onView(withText(containsString(url))).click() + } + + fun verifyPermissionSettingSummary(setting: String, summary: String) { + onView( + allOf( + withText(setting), + hasSibling(withText(summary)), + ), + ).check(matches(isDisplayed())) + } + + fun openChangePermissionSettingsMenu(permissionSetting: String) { + onView(withText(containsString(permissionSetting))).click() + } + + // Click button for resetting all permissions for all websites + fun clickClearPermissionsOnAllSites() { + exceptionsList.waitForExists(waitingTime) + onView(withId(R.id.delete_all_site_permissions_button)) + .check(matches(isDisplayed())) + .click() + } + + // Click button for resetting one site permission to default + fun clickClearOnePermissionForOneSite() { + onView(withText(R.string.clear_permission)) + .check(matches(isDisplayed())) + .click() + } + + fun verifyResetPermissionDefaultForThisSiteDialog() { + onView(withText(R.string.clear_permission)).check(matches(isDisplayed())) + onView(withText(R.string.confirm_clear_permission_site)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_positive)).check(matches(isDisplayed())) + onView(withText(R.string.clear_permissions_negative)).check(matches(isDisplayed())) + } + + fun clickOK() = onView(withText(R.string.clear_permissions_positive)).click() + + fun clickCancel() = onView(withText(R.string.clear_permissions_negative)).click() + + class Transition { + fun goBack(interact: SettingsSubMenuSitePermissionsRobot.() -> Unit): SettingsSubMenuSitePermissionsRobot.Transition { + goBackButton().click() + + SettingsSubMenuSitePermissionsRobot().interact() + return SettingsSubMenuSitePermissionsRobot.Transition() + } + } +} + +private fun goBackButton() = + onView(allOf(withContentDescription("Navigate up"))) + +private val exceptionsList = + mDevice.findObject(UiSelector().resourceId("$packageName:id/exceptions")) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsRobot.kt index 955fa28aa8..5d39481063 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsRobot.kt @@ -1,199 +1,199 @@ -/* 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.robots - -import androidx.preference.R -import androidx.recyclerview.widget.RecyclerView -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.contrib.RecyclerViewActions -import androidx.test.espresso.matcher.ViewMatchers.Visibility -import androidx.test.espresso.matcher.ViewMatchers.hasDescendant -import androidx.test.espresso.matcher.ViewMatchers.hasSibling -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import org.hamcrest.CoreMatchers.allOf -import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText -import org.mozilla.fenix.helpers.click - -/** - * Implementation of Robot Pattern for the settings Site Permissions sub menu. - */ -class SettingsSubMenuSitePermissionsRobot { - - fun verifySitePermissionsToolbarTitle() = - onView(withText("Site permissions")).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - fun verifyToolbarGoBackButton() = - goBackButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - - fun verifySitePermissionOption(option: String, summary: String = "") { - scrollToElementByText(option) - onView( - allOf( - withText(option), - hasSibling(withText(summary)), - ), - ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - } - - class Transition { - fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { - goBackButton().click() - - SettingsRobot().interact() - return SettingsRobot.Transition() - } - - fun openAutoPlay( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Autoplay")), - ), - ) - - openAutoPlay().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openCamera( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Camera")), - ), - ) - - openCamera().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openLocation( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Location")), - ), - ) - - openLocation().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openMicrophone( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Microphone")), - ), - ) - - openMicrophone().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openNotification( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Notification")), - ), - ) - - openNotification().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openPersistentStorage( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Persistent Storage")), - ), - ) - - openPersistentStorage().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openDRMControlledContent( - interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsCommonRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("DRM-controlled content")), - ), - ) - - openDrmControlledContent().click() - - SettingsSubMenuSitePermissionsCommonRobot().interact() - return SettingsSubMenuSitePermissionsCommonRobot.Transition() - } - - fun openExceptions( - interact: SettingsSubMenuSitePermissionsExceptionsRobot.() -> Unit, - ): SettingsSubMenuSitePermissionsExceptionsRobot.Transition { - onView(withId(R.id.recycler_view)).perform( - RecyclerViewActions.scrollTo( - hasDescendant(withText("Exceptions")), - ), - ) - - openExceptions().click() - - SettingsSubMenuSitePermissionsExceptionsRobot().interact() - return SettingsSubMenuSitePermissionsExceptionsRobot.Transition() - } - } -} - -private fun goBackButton() = - onView(withContentDescription("Navigate up")) - -private fun openAutoPlay() = - onView(allOf(withText("Autoplay"))) - -private fun openCamera() = - onView(allOf(withText("Camera"))) - -private fun openLocation() = - onView(allOf(withText("Location"))) - -private fun openMicrophone() = - onView(allOf(withText("Microphone"))) - -private fun openNotification() = - onView(allOf(withText("Notification"))) - -private fun openPersistentStorage() = - onView(allOf(withText("Persistent Storage"))) - -private fun openDrmControlledContent() = - onView(allOf(withText("DRM-controlled content"))) - -private fun openExceptions() = - onView(allOf(withText("Exceptions"))) +/* 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.robots + +import androidx.preference.R +import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.hasSibling +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import org.hamcrest.CoreMatchers.allOf +import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText +import org.mozilla.fenix.helpers.click + +/** + * Implementation of Robot Pattern for the settings Site Permissions sub menu. + */ +class SettingsSubMenuSitePermissionsRobot { + + fun verifySitePermissionsToolbarTitle() = + onView(withText("Site permissions")).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + fun verifyToolbarGoBackButton() = + goBackButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + fun verifySitePermissionOption(option: String, summary: String = "") { + scrollToElementByText(option) + onView( + allOf( + withText(option), + hasSibling(withText(summary)), + ), + ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + } + + class Transition { + fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { + goBackButton().click() + + SettingsRobot().interact() + return SettingsRobot.Transition() + } + + fun openAutoPlay( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Autoplay")), + ), + ) + + openAutoPlay().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openCamera( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Camera")), + ), + ) + + openCamera().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openLocation( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Location")), + ), + ) + + openLocation().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openMicrophone( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Microphone")), + ), + ) + + openMicrophone().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openNotification( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Notification")), + ), + ) + + openNotification().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openPersistentStorage( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Persistent Storage")), + ), + ) + + openPersistentStorage().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openDRMControlledContent( + interact: SettingsSubMenuSitePermissionsCommonRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsCommonRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("DRM-controlled content")), + ), + ) + + openDrmControlledContent().click() + + SettingsSubMenuSitePermissionsCommonRobot().interact() + return SettingsSubMenuSitePermissionsCommonRobot.Transition() + } + + fun openExceptions( + interact: SettingsSubMenuSitePermissionsExceptionsRobot.() -> Unit, + ): SettingsSubMenuSitePermissionsExceptionsRobot.Transition { + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + hasDescendant(withText("Exceptions")), + ), + ) + + openExceptions().click() + + SettingsSubMenuSitePermissionsExceptionsRobot().interact() + return SettingsSubMenuSitePermissionsExceptionsRobot.Transition() + } + } +} + +private fun goBackButton() = + onView(withContentDescription("Navigate up")) + +private fun openAutoPlay() = + onView(allOf(withText("Autoplay"))) + +private fun openCamera() = + onView(allOf(withText("Camera"))) + +private fun openLocation() = + onView(allOf(withText("Location"))) + +private fun openMicrophone() = + onView(allOf(withText("Microphone"))) + +private fun openNotification() = + onView(allOf(withText("Notification"))) + +private fun openPersistentStorage() = + onView(allOf(withText("Persistent Storage"))) + +private fun openDrmControlledContent() = + onView(allOf(withText("DRM-controlled content"))) + +private fun openExceptions() = + onView(allOf(withText("Exceptions"))) diff --git a/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/ContextCompatDetectorTest.kt b/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/ContextCompatDetectorTest.kt index 658845be71..9a8a7fa99c 100644 --- a/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/ContextCompatDetectorTest.kt +++ b/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/ContextCompatDetectorTest.kt @@ -102,7 +102,7 @@ class ContextCompatDetectorTest : LintDetectorTest() { | fun trigger(context: Context, id: Int) { | getDrawable(context, id) | } - | + | | fun getDrawable(context: Context, id: Int) {} | |}""".trimMargin() @@ -126,7 +126,7 @@ class ContextCompatDetectorTest : LintDetectorTest() { | fun trigger(context: Context, id: Int) { | getColorStateList(context, id) | } - | + | | fun getColorStateList(context: Context, id: Int) {} | |}""".trimMargin() @@ -160,4 +160,4 @@ class ContextCompatDetectorTest : LintDetectorTest() { |""".trimMargin() ) } -} \ No newline at end of file +} diff --git a/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/LicenseDetectorTest.kt b/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/LicenseDetectorTest.kt index 2074450921..c64b8ce034 100644 --- a/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/LicenseDetectorTest.kt +++ b/mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/LicenseDetectorTest.kt @@ -151,4 +151,4 @@ class LicenseDetectorTest : LintDetectorTest() { .expect(expectedReport) .expectFixDiffs(expectedFixOutput) } -} \ No newline at end of file +}