1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.ui
7 import androidx.core.net.toUri
8 import androidx.test.espresso.Espresso.pressBack
9 import androidx.test.filters.SdkSuppress
10 import mozilla.components.concept.engine.mediasession.MediaSession
11 import org.junit.Ignore
14 import org.mozilla.fenix.customannotations.SmokeTest
15 import org.mozilla.fenix.helpers.AppAndSystemHelper.grantSystemPermission
16 import org.mozilla.fenix.helpers.HomeActivityTestRule
17 import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
18 import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
19 import org.mozilla.fenix.helpers.TestAssetHelper.getMutedVideoPageAsset
20 import org.mozilla.fenix.helpers.TestAssetHelper.getVideoPageAsset
21 import org.mozilla.fenix.helpers.TestHelper.exitMenu
22 import org.mozilla.fenix.helpers.TestSetup
23 import org.mozilla.fenix.ui.robots.browserScreen
24 import org.mozilla.fenix.ui.robots.clickPageObject
25 import org.mozilla.fenix.ui.robots.homeScreen
26 import org.mozilla.fenix.ui.robots.navigationToolbar
30 * - site permissions settings sub-menu
31 * - the settings effects on the app behavior
34 class SettingsSitePermissionsTest : TestSetup() {
35 /* Test page created and handled by the Mozilla mobile test-eng team */
36 private val permissionsTestPage = "https://mozilla-mobile.github.io/testapp/v2.0/permissions"
37 private val permissionsTestPageHost = "https://mozilla-mobile.github.io"
38 private val testPageSubstring = "https://mozilla-mobile.github.io:443"
41 val activityTestRule = HomeActivityTestRule(
42 isJumpBackInCFREnabled = false,
43 isPWAsPromptEnabled = false,
44 isTCPCFREnabled = false,
45 isDeleteSitePermissionsEnabled = true,
48 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/246974
50 fun sitePermissionsItemsTest() {
54 }.openSettingsSubMenuSitePermissions {
55 verifySitePermissionsToolbarTitle()
56 verifyToolbarGoBackButton()
57 verifySitePermissionOption("Autoplay", "Block audio only")
58 verifySitePermissionOption("Camera", "Blocked by Android")
59 verifySitePermissionOption("Location", "Blocked by Android")
60 verifySitePermissionOption("Microphone", "Blocked by Android")
61 verifySitePermissionOption("Notification", "Ask to allow")
62 verifySitePermissionOption("Persistent Storage", "Ask to allow")
63 verifySitePermissionOption("Cross-site cookies", "Ask to allow")
64 verifySitePermissionOption("DRM-controlled content", "Ask to allow")
65 verifySitePermissionOption("Exceptions")
69 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247680
70 // Verifies that you can go to System settings and change app's permissions from inside the app
73 @SdkSuppress(minSdkVersion = 29)
74 fun systemBlockedPermissionsRedirectToSystemAppSettingsTest() {
78 }.openSettingsSubMenuSitePermissions {
80 verifyBlockedByAndroidSection()
83 verifyBlockedByAndroidSection()
86 verifyBlockedByAndroidSection()
87 clickGoToSettingsButton()
88 openAppSystemPermissionsSettings()
89 switchAppPermissionSystemSetting("Camera", "Allow")
90 goBackToSystemAppPermissionSettings()
91 verifySystemGrantedPermission("Camera")
92 switchAppPermissionSystemSetting("Location", "Allow")
93 goBackToSystemAppPermissionSettings()
94 verifySystemGrantedPermission("Location")
95 switchAppPermissionSystemSetting("Microphone", "Allow")
96 goBackToSystemAppPermissionSettings()
97 verifySystemGrantedPermission("Microphone")
98 goBackToPermissionsSettingsSubMenu()
99 verifyUnblockedByAndroid()
102 verifyUnblockedByAndroid()
105 verifyUnblockedByAndroid()
109 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2095125
112 fun verifyAutoplayBlockAudioOnlySettingOnNotMutedVideoTest() {
113 val genericPage = getGenericAsset(mockWebServer, 1)
114 val videoTestPage = getVideoPageAsset(mockWebServer)
119 }.openSettingsSubMenuSitePermissions {
121 verifySitePermissionsAutoPlaySubMenuItems()
125 }.enterURLAndEnterToBrowser(genericPage.url) {
126 verifyPageContent(genericPage.content)
131 }.enterURLAndEnterToBrowser(videoTestPage.url) {
133 verifyPageContent(videoTestPage.content)
134 clickPageObject(itemWithText("Play"))
135 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
136 } catch (e: java.lang.AssertionError) {
140 verifyPageContent(videoTestPage.content)
141 clickPageObject(itemWithText("Play"))
142 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
148 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2286807
149 @Ignore("Failing, see https://bugzilla.mozilla.org/show_bug.cgi?id=1827599")
152 fun verifyAutoplayBlockAudioOnlySettingOnMutedVideoTest() {
153 val genericPage = getGenericAsset(mockWebServer, 1)
154 val mutedVideoTestPage = getMutedVideoPageAsset(mockWebServer)
157 }.enterURLAndEnterToBrowser(genericPage.url) {
158 verifyPageContent(genericPage.content)
163 }.enterURLAndEnterToBrowser(mutedVideoTestPage.url) {
165 verifyPageContent("Media file is playing")
166 } catch (e: java.lang.AssertionError) {
170 verifyPageContent("Media file is playing")
176 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2095124
178 fun verifyAutoplayAllowAudioVideoSettingOnNotMutedVideoTestTest() {
179 val genericPage = getGenericAsset(mockWebServer, 1)
180 val videoTestPage = getVideoPageAsset(mockWebServer)
185 }.openSettingsSubMenuSitePermissions {
187 selectAutoplayOption("Allow audio and video")
191 }.enterURLAndEnterToBrowser(genericPage.url) {
192 verifyPageContent(genericPage.content)
197 }.enterURLAndEnterToBrowser(videoTestPage.url) {
199 verifyPageContent(videoTestPage.content)
200 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
201 } catch (e: java.lang.AssertionError) {
205 verifyPageContent(videoTestPage.content)
206 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
212 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2286806
213 @Ignore("Failing, see https://bugzilla.mozilla.org/show_bug.cgi?id=1827599")
215 fun verifyAutoplayAllowAudioVideoSettingOnMutedVideoTest() {
216 val mutedVideoTestPage = getMutedVideoPageAsset(mockWebServer)
221 }.openSettingsSubMenuSitePermissions {
223 selectAutoplayOption("Allow audio and video")
227 }.enterURLAndEnterToBrowser(mutedVideoTestPage.url) {
229 verifyPageContent("Media file is playing")
230 } catch (e: java.lang.AssertionError) {
234 verifyPageContent("Media file is playing")
240 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2095126
242 fun verifyAutoplayBlockAudioAndVideoSettingOnNotMutedVideoTest() {
243 val videoTestPage = getVideoPageAsset(mockWebServer)
248 }.openSettingsSubMenuSitePermissions {
250 selectAutoplayOption("Block audio and video")
254 }.enterURLAndEnterToBrowser(videoTestPage.url) {
256 verifyPageContent(videoTestPage.content)
257 clickPageObject(itemWithText("Play"))
258 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
259 } catch (e: java.lang.AssertionError) {
263 verifyPageContent(videoTestPage.content)
264 clickPageObject(itemWithText("Play"))
265 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
271 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2286808
273 fun verifyAutoplayBlockAudioAndVideoSettingOnMutedVideoTest() {
274 val mutedVideoTestPage = getMutedVideoPageAsset(mockWebServer)
279 }.openSettingsSubMenuSitePermissions {
281 selectAutoplayOption("Block audio and video")
285 }.enterURLAndEnterToBrowser(mutedVideoTestPage.url) {
286 verifyPageContent("Media file not playing")
287 clickPageObject(itemWithText("Play"))
289 verifyPageContent("Media file is playing")
290 } catch (e: java.lang.AssertionError) {
294 clickPageObject(itemWithText("Play"))
295 verifyPageContent("Media file is playing")
301 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247362
303 fun verifyCameraPermissionSettingsTest() {
305 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
306 }.clickStartCameraButton {
307 grantSystemPermission()
308 verifyCameraPermissionPrompt(testPageSubstring)
315 }.openSettingsSubMenuSitePermissions {
317 verifySitePermissionsCommonSubMenuItems()
318 selectPermissionSettingOption("Blocked")
321 }.clickStartCameraButton {}
323 verifyPageContent("Camera not allowed")
327 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247364
329 fun verifyMicrophonePermissionSettingsTest() {
331 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
332 }.clickStartMicrophoneButton {
333 grantSystemPermission()
334 verifyMicrophonePermissionPrompt(testPageSubstring)
341 }.openSettingsSubMenuSitePermissions {
343 verifySitePermissionsCommonSubMenuItems()
344 selectPermissionSettingOption("Blocked")
347 }.clickStartMicrophoneButton {}
349 verifyPageContent("Microphone not allowed")
353 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247363
355 fun verifyLocationPermissionSettingsTest() {
357 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
358 }.clickGetLocationButton {
359 verifyLocationPermissionPrompt(testPageSubstring)
366 }.openSettingsSubMenuSitePermissions {
368 verifySitePermissionsCommonSubMenuItems()
369 selectPermissionSettingOption("Blocked")
372 }.clickGetLocationButton {}
374 verifyPageContent("User denied geolocation prompt")
378 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247365
380 fun verifyNotificationsPermissionSettingsTest() {
382 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
383 }.clickOpenNotificationButton {
384 verifyNotificationsPermissionPrompt(testPageSubstring)
391 }.openSettingsSubMenuSitePermissions {
393 verifyNotificationSubMenuItems()
394 selectPermissionSettingOption("Blocked")
397 }.clickOpenNotificationButton {}
399 verifyPageContent("Notifications not allowed")
403 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1923415
405 fun verifyPersistentStoragePermissionSettingsTest() {
407 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
408 }.clickRequestPersistentStorageAccessButton {
409 verifyPersistentStoragePermissionPrompt(testPageSubstring)
416 }.openSettingsSubMenuSitePermissions {
417 }.openPersistentStorage {
418 verifySitePermissionsPersistentStorageSubMenuItems()
419 selectPermissionSettingOption("Blocked")
422 }.clickRequestPersistentStorageAccessButton {}
424 verifyPageContent("Persistent storage permission denied")
428 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1923417
430 fun verifyDRMControlledContentPermissionSettingsTest() {
432 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
433 }.clickRequestDRMControlledContentAccessButton {
434 verifyDRMContentPermissionPrompt(testPageSubstring)
439 }.openSettingsSubMenuSitePermissions {
440 }.openDRMControlledContent {
441 verifyDRMControlledContentSubMenuItems()
442 selectDRMControlledContentPermissionSettingOption("Blocked")
446 }.clickRequestDRMControlledContentAccessButton {}
448 verifyPageContent("DRM-controlled content not allowed")
451 }.openSettingsSubMenuSitePermissions {
452 }.openDRMControlledContent {
453 selectDRMControlledContentPermissionSettingOption("Allowed")
459 }.clickRequestDRMControlledContentAccessButton {}
461 verifyPageContent("DRM-controlled content allowed")
466 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/246976
469 fun clearAllSitePermissionsExceptionsTest() {
471 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
472 }.clickOpenNotificationButton {
473 verifyNotificationsPermissionPrompt(testPageSubstring)
474 }.clickPagePermissionButton(true) {
477 }.openSettingsSubMenuSitePermissions {
479 verifyExceptionCreated(permissionsTestPageHost, true)
480 clickClearPermissionsOnAllSites()
481 verifyClearPermissionsDialog()
483 clickClearPermissionsOnAllSites()
485 verifyExceptionsEmptyList()
489 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/247007
491 fun addAndClearOneWebPagePermission() {
493 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
494 }.clickOpenNotificationButton {
495 verifyNotificationsPermissionPrompt(testPageSubstring)
496 }.clickPagePermissionButton(true) {
499 }.openSettingsSubMenuSitePermissions {
501 verifyExceptionCreated(permissionsTestPageHost, true)
502 openSiteExceptionsDetails(permissionsTestPageHost)
503 clickClearPermissionsForOneSite()
504 verifyClearPermissionsForOneSiteDialog()
506 clickClearPermissionsForOneSite()
508 verifyExceptionsEmptyList()
512 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/326477
514 fun clearIndividuallyAWebPagePermission() {
516 }.enterURLAndEnterToBrowser(permissionsTestPage.toUri()) {
517 }.clickOpenNotificationButton {
518 verifyNotificationsPermissionPrompt(testPageSubstring)
519 }.clickPagePermissionButton(true) {
522 }.openSettingsSubMenuSitePermissions {
524 verifyExceptionCreated(permissionsTestPageHost, true)
525 openSiteExceptionsDetails(permissionsTestPageHost)
526 verifyPermissionSettingSummary("Notification", "Allowed")
527 openChangePermissionSettingsMenu("Notification")
528 clickClearOnePermissionForOneSite()
529 verifyResetPermissionDefaultForThisSiteDialog()
532 verifyPermissionSettingSummary("Notification", "Ask to allow")
534 // This should be changed to false, when https://bugzilla.mozilla.org/show_bug.cgi?id=1826297 is fixed
535 verifyExceptionCreated(permissionsTestPageHost, true)