diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt index a2b96ee0e..49ccc160b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.ui import android.os.Build import android.view.autofill.AutofillManager import androidx.core.net.toUri +import androidx.test.filters.SdkSuppress import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import okhttp3.mockwebserver.MockWebServer @@ -445,6 +446,45 @@ class SettingsPrivacyTest { } } + @SmokeTest + @Test + @SdkSuppress(minSdkVersion = 29) + // Verifies that you can go to System settings and change app's permissions from inside the app + fun redirectToAppPermissionsSystemSettingsTest() { + homeScreen { + }.openThreeDotMenu { + }.openSettings { + }.openSettingsSubMenuSitePermissions { + }.openCamera { + verifyBlockedByAndroid() + }.goBack { + }.openLocation { + verifyBlockedByAndroid() + }.goBack { + }.openMicrophone { + verifyBlockedByAndroid() + clickGoToSettingsButton() + openAppSystemPermissionsSettings() + switchAppPermissionSystemSetting("Camera", "Allow") + goBackToSystemAppPermissionSettings() + verifySystemGrantedPermission("Camera") + switchAppPermissionSystemSetting("Location", "Allow") + goBackToSystemAppPermissionSettings() + verifySystemGrantedPermission("Location") + switchAppPermissionSystemSetting("Microphone", "Allow") + goBackToSystemAppPermissionSettings() + verifySystemGrantedPermission("Microphone") + goBackToPermissionsSettingsSubMenu() + verifyUnblockedByAndroid() + }.goBack { + }.openLocation { + verifyUnblockedByAndroid() + }.goBack { + }.openCamera { + verifyUnblockedByAndroid() + } + } + @Test fun deleteBrowsingDataOptionStatesTest() { homeScreen { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index cc78fcc85..024d1f4ba 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -10,7 +10,6 @@ import android.view.View import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.core.net.toUri import androidx.test.espresso.IdlingRegistry -import androidx.test.filters.SdkSuppress import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.UiDevice @@ -532,43 +531,6 @@ class SmokeTest { } } - @Ignore("Failing, see: https://github.com/mozilla-mobile/fenix/issues/25034") - @Test - @SdkSuppress(minSdkVersion = 29) - // Verifies that you can go to System settings and change app's permissions from inside the app - fun redirectToAppPermissionsSystemSettingsTest() { - homeScreen { - }.openThreeDotMenu { - }.openSettings { - }.openSettingsSubMenuSitePermissions { - }.openCamera { - verifyBlockedByAndroid() - }.goBack { - }.openLocation { - verifyBlockedByAndroid() - }.goBack { - }.openMicrophone { - verifyBlockedByAndroid() - clickGoToSettingsButton() - openAppSystemPermissionsSettings() - switchAppPermissionSystemSetting("Camera", "Allow") - mDevice.pressBack() - switchAppPermissionSystemSetting("Location", "Allow") - mDevice.pressBack() - switchAppPermissionSystemSetting("Microphone", "Allow") - mDevice.pressBack() - mDevice.pressBack() - mDevice.pressBack() - verifyUnblockedByAndroid() - }.goBack { - }.openLocation { - verifyUnblockedByAndroid() - }.goBack { - }.openCamera { - verifyUnblockedByAndroid() - } - } - @Test // Verifies that a recently closed item is properly opened fun openRecentlyClosedItemTest() { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsCommonRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsCommonRobot.kt index 5ead5b002..4d7db0a4b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsCommonRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSitePermissionsCommonRobot.kt @@ -7,17 +7,20 @@ 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.isDisplayed 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 androidx.test.uiautomator.UiSelector import org.hamcrest.CoreMatchers.allOf -import org.hamcrest.Matchers.not +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.mozilla.fenix.R import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort +import org.mozilla.fenix.helpers.TestHelper.getStringResource +import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.assertIsChecked import org.mozilla.fenix.helpers.click @@ -106,6 +109,40 @@ class SettingsSubMenuSitePermissionsCommonRobot { } } + fun goBackToSystemAppPermissionSettings() { + mDevice.pressBack() + mDevice.waitForIdle(waitingTime) + } + + fun goBackToPermissionsSettingsSubMenu() { + while (!permissionSettingMenu().waitForExists(waitingTimeShort)) { + mDevice.pressBack() + mDevice.waitForIdle(waitingTime) + } + } + + fun verifySystemGrantedPermission(permissionCategory: String) { + assertTrue( + mDevice.findObject( + UiSelector().className("android.widget.RelativeLayout") + ).getChild( + UiSelector() + .resourceId("android:id/title") + .textContains(permissionCategory) + ).waitForExists(waitingTime) + ) + + assertTrue( + mDevice.findObject( + UiSelector().className("android.widget.RelativeLayout") + ).getChild( + UiSelector() + .resourceId("android:id/summary") + .textContains("Only while app is in use") + ).waitForExists(waitingTime) + ) + } + class Transition { fun goBack(interact: SettingsSubMenuSitePermissionsRobot.() -> Unit): SettingsSubMenuSitePermissionsRobot.Transition { goBackButton().click() @@ -158,11 +195,27 @@ private fun assertCheckCommonRadioButtonDefault() { onView(withId(R.id.block_radio)).assertIsChecked(isChecked = false) } -private fun assertBlockedByAndroid() = onView(withText(R.string.phone_feature_blocked_by_android)) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertBlockedByAndroid() { + blockedByAndroidContainer().waitForExists(waitingTime) + assertTrue( + mDevice.findObject( + UiSelector().textContains(getStringResource(R.string.phone_feature_blocked_by_android)) + ).waitForExists(waitingTimeShort) + ) +} -private fun assertUnblockedByAndroid() = onView(withText(R.string.phone_feature_blocked_by_android)) - .check(matches(not(isDisplayed()))) +private fun assertUnblockedByAndroid() { + blockedByAndroidContainer().waitUntilGone(waitingTime) + assertFalse( + mDevice.findObject( + UiSelector().textContains(getStringResource(R.string.phone_feature_blocked_by_android)) + ).waitForExists(waitingTimeShort) + ) +} + +private fun blockedByAndroidContainer() = mDevice.findObject(UiSelector().resourceId("$packageName:id/permissions_blocked_container")) + +private fun permissionSettingMenu() = mDevice.findObject(UiSelector().resourceId("$packageName:id/container")) private fun assertToAllowIt() = onView(withText(R.string.phone_feature_blocked_intro)) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) 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 0ee06d454..5284566ae 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 @@ -9,8 +9,8 @@ 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.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId