From 97c3ac49e4d6cc9a820768772e4ce2c89b061cea Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Thu, 8 Jun 2023 17:00:35 +0300 Subject: [PATCH] Bug 1837378 - New system notification settings UI tests --- .../mozilla/fenix/ui/MediaNotificationTest.kt | 6 +-- .../mozilla/fenix/ui/SettingsPrivacyTest.kt | 39 +++++++++++++++++++ .../fenix/ui/robots/NotificationRobot.kt | 9 ++++- .../fenix/ui/robots/SystemSettingsRobot.kt | 34 ++++++++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt index 9880fab8bc..1a54953777 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt @@ -91,7 +91,7 @@ class MediaNotificationTest { mDevice.openNotification() notificationShade { - verifySystemNotificationGone(videoTestPage.title) + verifySystemNotificationDoesNotExist(videoTestPage.title) } // close notification shade before the next test @@ -125,7 +125,7 @@ class MediaNotificationTest { mDevice.openNotification() notificationShade { - verifySystemNotificationGone(audioTestPage.title) + verifySystemNotificationDoesNotExist(audioTestPage.title) } // close notification shade before the next test @@ -162,7 +162,7 @@ class MediaNotificationTest { mDevice.openNotification() notificationShade { - verifySystemNotificationGone("A site is playing media") + verifySystemNotificationDoesNotExist("A site is playing media") } // close notification shade before and go back to regular mode before the next test 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 a5f334bd77..dd591ed73f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsPrivacyTest.kt @@ -13,7 +13,10 @@ import org.junit.Rule import org.junit.Test import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.ui.robots.homeScreen +import org.mozilla.fenix.ui.robots.navigationToolbar +import org.mozilla.fenix.ui.robots.notificationShade /** * Tests for verifying the the privacy and security section of the Settings menu @@ -144,4 +147,40 @@ class SettingsPrivacyTest { verifySitePermissionOption("Exceptions") } } + + @Test + fun verifyNotificationsSettingsTest() { + val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + // Clear all existing notifications + notificationShade { + mDevice.openNotification() + clearNotifications() + } + + homeScreen { + }.togglePrivateBrowsingMode() + + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + }.openNotificationShade { + verifySystemNotificationExists("Close private tabs") + }.closeNotificationTray { + }.openThreeDotMenu { + }.openSettings { + verifySettingsOptionSummary("Notifications", "Allowed") + }.openSettingsSubMenuNotifications { + verifyAllSystemNotificationsToggleState(true) + verifyPrivateBrowsingSystemNotificationsToggleState(true) + clickPrivateBrowsingSystemNotificationsToggle() + verifyPrivateBrowsingSystemNotificationsToggleState(false) + clickAllSystemNotificationsToggle() + verifyAllSystemNotificationsToggleState(false) + }.goBack { + verifySettingsOptionSummary("Notifications", "Not allowed") + }.goBackToBrowser { + }.openNotificationShade { + verifySystemNotificationDoesNotExist("Close private tabs") + } + } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt index 5466ec1bbe..92f323b3d7 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt @@ -51,7 +51,7 @@ class NotificationRobot { cancelAll() } - fun verifySystemNotificationGone(notificationMessage: String) { + fun verifySystemNotificationDoesNotExist(notificationMessage: String) { mDevice.waitNotNull( Until.gone(text(notificationMessage)), waitingTime, @@ -128,6 +128,13 @@ class NotificationRobot { HomeScreenRobot().interact() return HomeScreenRobot.Transition() } + + fun closeNotificationTray(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { + mDevice.pressBack() + + BrowserRobot().interact() + return BrowserRobot.Transition() + } } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SystemSettingsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SystemSettingsRobot.kt index 22520a3cd3..7df5a8994c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SystemSettingsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SystemSettingsRobot.kt @@ -7,7 +7,9 @@ package org.mozilla.fenix.ui.robots import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction import androidx.test.uiautomator.UiSelector +import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue +import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndDescription import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper import org.mozilla.fenix.helpers.TestHelper.mDevice @@ -22,6 +24,26 @@ class SystemSettingsRobot { Intents.intended(hasAction(SettingsRobot.DEFAULT_APPS_SETTINGS_ACTION)) } + fun verifyAllSystemNotificationsToggleState(enabled: Boolean) { + if (enabled) { + assertTrue(allSystemSettingsNotificationsToggle.isChecked) + } else { + assertFalse(allSystemSettingsNotificationsToggle.isChecked) + } + } + + fun verifyPrivateBrowsingSystemNotificationsToggleState(enabled: Boolean) { + if (enabled) { + assertTrue(privateBrowsingSystemSettingsNotificationsToggle.isChecked) + } else { + assertFalse(privateBrowsingSystemSettingsNotificationsToggle.isChecked) + } + } + + fun clickPrivateBrowsingSystemNotificationsToggle() = privateBrowsingSystemSettingsNotificationsToggle.click() + + fun clickAllSystemNotificationsToggle() = allSystemSettingsNotificationsToggle.click() + class Transition { // Difficult to know where this will go fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition { @@ -46,3 +68,15 @@ private fun assertSystemNotificationsView() { .waitForExists(waitingTime), ) } + +private val allSystemSettingsNotificationsToggle = + mDevice.findObject( + UiSelector().resourceId("com.android.settings:id/switch_bar") + .childSelector( + UiSelector() + .resourceId("com.android.settings:id/switch_widget") + .index(1), + ), + ) +private val privateBrowsingSystemSettingsNotificationsToggle = + itemWithResIdAndDescription("com.android.settings:id/switchWidget", "Private browsing session")