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 mozilla.components.concept.engine.mediasession.MediaSession
10 import org.mozilla.fenix.customannotations.SmokeTest
11 import org.mozilla.fenix.helpers.HomeActivityTestRule
12 import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
13 import org.mozilla.fenix.helpers.RetryTestRule
14 import org.mozilla.fenix.helpers.TestAssetHelper
15 import org.mozilla.fenix.helpers.TestHelper.mDevice
16 import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
17 import org.mozilla.fenix.helpers.TestSetup
18 import org.mozilla.fenix.ui.robots.browserScreen
19 import org.mozilla.fenix.ui.robots.clickPageObject
20 import org.mozilla.fenix.ui.robots.homeScreen
21 import org.mozilla.fenix.ui.robots.navigationToolbar
22 import org.mozilla.fenix.ui.robots.notificationShade
25 * Tests for verifying basic functionality of media notifications:
26 * - video and audio playback system notifications appear and can pause/play the media content
27 * - a media notification icon is displayed on the homescreen for the tab playing media content
28 * Note: this test only verifies media notifications, not media itself
30 class MediaNotificationTest : TestSetup() {
32 val activityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
36 val retryTestRule = RetryTestRule(3)
38 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1347033
41 fun verifyVideoPlaybackSystemNotificationTest() {
42 val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
45 }.enterURLAndEnterToBrowser(videoTestPage.url) {
47 clickPageObject(itemWithText("Play"))
48 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
49 }.openNotificationShade {
50 verifySystemNotificationExists(videoTestPage.title)
51 clickMediaNotificationControlButton("Pause")
52 verifyMediaSystemNotificationButtonState("Play")
58 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
63 mDevice.openNotification()
66 verifySystemNotificationDoesNotExist(videoTestPage.title)
69 // close notification shade before the next test
73 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2316010
76 fun verifyAudioPlaybackSystemNotificationTest() {
77 val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
80 }.enterURLAndEnterToBrowser(audioTestPage.url) {
82 clickPageObject(itemWithText("Play"))
83 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
84 }.openNotificationShade {
85 verifySystemNotificationExists(audioTestPage.title)
86 clickMediaNotificationControlButton("Pause")
87 verifyMediaSystemNotificationButtonState("Play")
93 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
98 mDevice.openNotification()
101 verifySystemNotificationDoesNotExist(audioTestPage.title)
104 // close notification shade before the next test
108 // TestRail: https://testrail.stage.mozaws.net/index.php?/cases/view/903595
110 fun mediaSystemNotificationInPrivateModeTest() {
111 val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
115 }.toggleToPrivateTabs {
117 }.submitQuery(audioTestPage.url.toString()) {
118 mDevice.waitForIdle()
119 clickPageObject(itemWithText("Play"))
120 assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
121 }.openNotificationShade {
122 verifySystemNotificationExists("A site is playing media")
123 clickMediaNotificationControlButton("Pause")
124 verifyMediaSystemNotificationButtonState("Play")
130 assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
133 verifySnackBarText("Private tab closed")
136 mDevice.openNotification()
139 verifySystemNotificationDoesNotExist("A site is playing media")
142 // close notification shade before and go back to regular mode before the next test
144 homeScreen { }.togglePrivateBrowsingMode()