From 8281e16c83b55514986b4b4334647c024e8a0d17 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Thu, 8 Oct 2020 14:02:13 -0400 Subject: [PATCH] [fenix] Fix lint warnings and test in site permissions --- .../mozilla/fenix/ui/SettingsPrivacyTest.kt | 6 +++ ...ttingsSubMenuSitePermissionsCommonRobot.kt | 6 +++ .../SettingsSubMenuSitePermissionsRobot.kt | 40 ++++++++++++++++++- .../quicksettings/WebsitePermissionsView.kt | 25 ++++++++---- ...itePermissionsDetailsExceptionsFragment.kt | 6 ++- .../QuickSettingsFragmentStoreTest.kt | 2 + .../org/mozilla/fenix/utils/SettingsTest.kt | 20 +++++++++- 7 files changed, 95 insertions(+), 10 deletions(-) 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 a618087737..78802cda9a 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt @@ -119,6 +119,12 @@ class SettingsPrivacyTest { verifySitePermissionsNotificationSubMenuItems() }.goBack { + // SITE PERMISSIONS PERSISTENT STORAGE + }.openPersistentStorage { + verifyNavigationToolBarHeader("Persistent Storage") + verifySitePermissionsPersistentStorageSubMenuItems() + }.goBack { + // SITE PERMISSIONS EXCEPTIONS }.openExceptions { verifyNavigationToolBarHeader() 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 c6f6d039fd..e88b38ba02 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 @@ -75,6 +75,12 @@ class SettingsSubMenuSitePermissionsCommonRobot { verifyCheckCommonRadioButtonDefault() } + fun verifySitePermissionsPersistentStorageSubMenuItems() { + verifyassertAskToAllowRecommended() + verifyassertBlocked() + verifyCheckCommonRadioButtonDefault() + } + class Transition { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!! 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 da14f4c991..4c5a966290 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 @@ -118,6 +118,22 @@ class SettingsSubMenuSitePermissionsRobot { 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 openExceptions( interact: SettingsSubMenuSitePermissionsExceptionsRobot.() -> Unit ): SettingsSubMenuSitePermissionsExceptionsRobot.Transition { @@ -176,8 +192,27 @@ class SettingsSubMenuSitePermissionsRobot { val notificationText = "Ask to allow" - onView(withText(notificationText)) + + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + allOf(hasDescendant(withText("Notification")), hasDescendant(withText(notificationText))) + ) + ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + onView(withText("Persistent Storage")) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + val persistentStorageText = + "Ask to allow" + + onView(withId(R.id.recycler_view)).perform( + RecyclerViewActions.scrollTo( + allOf( + hasDescendant(withText("Persistent Storage")), + hasDescendant(withText(persistentStorageText)) + ) + ) + ).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) } } @@ -199,5 +234,8 @@ private fun openMicrophone() = private fun openNotification() = onView(allOf(withText("Notification"))) +private fun openPersistentStorage() = + onView(allOf(withText("Persistent Storage"))) + private fun openExceptions() = onView(allOf(withText("Exceptions"))) diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt index 912ccb2735..44d0f85768 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt @@ -52,13 +52,24 @@ class WebsitePermissionsView( val view: View = LayoutInflater.from(context) .inflate(R.layout.quicksettings_permissions, containerView, true) - private val permissionViews: Map = EnumMap(mapOf( - PhoneFeature.CAMERA to PermissionViewHolder(view.cameraLabel, view.cameraStatus), - PhoneFeature.LOCATION to PermissionViewHolder(view.locationLabel, view.locationStatus), - PhoneFeature.MICROPHONE to PermissionViewHolder(view.microphoneLabel, view.microphoneStatus), - PhoneFeature.NOTIFICATION to PermissionViewHolder(view.notificationLabel, view.notificationStatus), - PhoneFeature.PERSISTENT_STORAGE to PermissionViewHolder(view.persistentStorageLabel, view.persistentStorageStatus) - )) + private val permissionViews: Map = EnumMap( + mapOf( + PhoneFeature.CAMERA to PermissionViewHolder(view.cameraLabel, view.cameraStatus), + PhoneFeature.LOCATION to PermissionViewHolder(view.locationLabel, view.locationStatus), + PhoneFeature.MICROPHONE to PermissionViewHolder( + view.microphoneLabel, + view.microphoneStatus + ), + PhoneFeature.NOTIFICATION to PermissionViewHolder( + view.notificationLabel, + view.notificationStatus + ), + PhoneFeature.PERSISTENT_STORAGE to PermissionViewHolder( + view.persistentStorageLabel, + view.persistentStorageStatus + ) + ) + ) /** * Allows changing what this View displays. diff --git a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt index 013224ec46..cda13889c6 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt @@ -21,7 +21,11 @@ import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.settings.PhoneFeature -import org.mozilla.fenix.settings.PhoneFeature.* +import org.mozilla.fenix.settings.PhoneFeature.CAMERA +import org.mozilla.fenix.settings.PhoneFeature.LOCATION +import org.mozilla.fenix.settings.PhoneFeature.MICROPHONE +import org.mozilla.fenix.settings.PhoneFeature.NOTIFICATION +import org.mozilla.fenix.settings.PhoneFeature.PERSISTENT_STORAGE import org.mozilla.fenix.settings.requirePreference class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() { diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt index c7a7755316..8b69a28c4b 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt @@ -94,6 +94,7 @@ class QuickSettingsFragmentStoreTest { every { permissions.microphone } returns SitePermissions.Status.NO_DECISION every { permissions.notification } returns SitePermissions.Status.BLOCKED every { permissions.location } returns SitePermissions.Status.ALLOWED + every { permissions.localStorage } returns SitePermissions.Status.ALLOWED every { permissions.autoplayAudible } returns SitePermissions.Status.BLOCKED every { permissions.autoplayInaudible } returns SitePermissions.Status.BLOCKED every { appSettings.getAutoplayUserSetting(any()) } returns AUTOPLAY_BLOCK_ALL @@ -111,6 +112,7 @@ class QuickSettingsFragmentStoreTest { assertNotNull(state[PhoneFeature.LOCATION]) assertNotNull(state[PhoneFeature.AUTOPLAY_AUDIBLE]) assertNotNull(state[PhoneFeature.AUTOPLAY_INAUDIBLE]) + assertNotNull(state[PhoneFeature.PERSISTENT_STORAGE]) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt b/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt index 4ff101244b..4d68cda8da 100644 --- a/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt +++ b/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt @@ -31,7 +31,8 @@ class SettingsTest { microphone = ASK_TO_ALLOW, notification = ASK_TO_ALLOW, autoplayAudible = AutoplayAction.BLOCKED, - autoplayInaudible = AutoplayAction.BLOCKED + autoplayInaudible = AutoplayAction.BLOCKED, + persistentStorage = ASK_TO_ALLOW ) @Before @@ -577,6 +578,23 @@ class SettingsTest { ) } + @Test + fun getSitePermissionsCustomSettingsRules_persistentStorage() { + settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.PERSISTENT_STORAGE, ALLOWED) + + assertEquals( + defaultPermissions.copy(persistentStorage = ALLOWED), + settings.getSitePermissionsCustomSettingsRules() + ) + + settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.PERSISTENT_STORAGE, BLOCKED) + + assertEquals( + defaultPermissions.copy(persistentStorage = BLOCKED), + settings.getSitePermissionsCustomSettingsRules() + ) + } + @Test fun overrideAmoCollection() { // When just created