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.compose.ui.test.junit4.AndroidComposeTestRule
8 import mozilla.components.concept.engine.mediasession.MediaSession
11 import org.mozilla.fenix.customannotations.SmokeTest
12 import org.mozilla.fenix.helpers.HomeActivityTestRule
13 import org.mozilla.fenix.helpers.MatcherHelper
14 import org.mozilla.fenix.helpers.RetryTestRule
15 import org.mozilla.fenix.helpers.TestAssetHelper
16 import org.mozilla.fenix.helpers.TestHelper.mDevice
17 import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
18 import org.mozilla.fenix.helpers.TestSetup
19 import org.mozilla.fenix.ui.robots.browserScreen
20 import org.mozilla.fenix.ui.robots.clickPageObject
21 import org.mozilla.fenix.ui.robots.homeScreen
22 import org.mozilla.fenix.ui.robots.navigationToolbar
23 import org.mozilla.fenix.ui.robots.notificationShade
26 * Tests for verifying basic functionality of media notifications:
27 * - video and audio playback system notifications appear and can pause/play the media content
28 * - a media notification icon is displayed on the homescreen for the tab playing media content
29 * Note: this test only verifies media notifications, not media itself
31 class ComposeMediaNotificationTest : TestSetup() {
34 AndroidComposeTestRule(
35 HomeActivityTestRule.withDefaultSettingsOverrides(
36 tabsTrayRewriteEnabled = true,
42 val retryTestRule = RetryTestRule(3)
44 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1347033
47 fun verifyVideoPlaybackSystemNotificationTest() {
48 val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
51 }.enterURLAndEnterToBrowser(videoTestPage.url) {
53 clickPageObject(MatcherHelper.itemWithText("Play"))
54 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
55 }.openNotificationShade {
56 verifySystemNotificationExists(videoTestPage.title)
57 clickMediaNotificationControlButton("Pause")
58 verifyMediaSystemNotificationButtonState("Play")
64 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
65 }.openComposeTabDrawer(composeTestRule) {
69 mDevice.openNotification()
72 verifySystemNotificationDoesNotExist(videoTestPage.title)
75 // close notification shade before the next test
79 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2316010
82 fun verifyAudioPlaybackSystemNotificationTest() {
83 val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
86 }.enterURLAndEnterToBrowser(audioTestPage.url) {
88 clickPageObject(MatcherHelper.itemWithText("Play"))
89 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
90 }.openNotificationShade {
91 verifySystemNotificationExists(audioTestPage.title)
92 clickMediaNotificationControlButton("Pause")
93 verifyMediaSystemNotificationButtonState("Play")
99 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
100 }.openComposeTabDrawer(composeTestRule) {
104 mDevice.openNotification()
107 verifySystemNotificationDoesNotExist(audioTestPage.title)
110 // close notification shade before the next test
114 // TestRail: https://testrail.stage.mozaws.net/index.php?/cases/view/903595
116 fun mediaSystemNotificationInPrivateModeTest() {
117 val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
120 }.openComposeTabDrawer(composeTestRule) {
121 }.toggleToPrivateTabs {
123 }.submitQuery(audioTestPage.url.toString()) {
124 mDevice.waitForIdle()
125 clickPageObject(MatcherHelper.itemWithText("Play"))
126 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
127 }.openNotificationShade {
128 verifySystemNotificationExists("A site is playing media")
129 clickMediaNotificationControlButton("Pause")
130 verifyMediaSystemNotificationButtonState("Play")
136 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
137 }.openComposeTabDrawer(composeTestRule) {
139 verifySnackBarText("Private tab closed")
142 mDevice.openNotification()
145 verifySystemNotificationDoesNotExist("A site is playing media")
148 // close notification shade before and go back to regular mode before the next test
150 homeScreen { }.togglePrivateBrowsingMode()