Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / mobile / android / fenix / app / src / androidTest / java / org / mozilla / fenix / ui / MediaNotificationTest.kt
blob33304899c98697f07f0caf5fe2b4b55437933419
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
8 import org.junit.Rule
9 import org.junit.Test
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
24 /**
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
29  */
30 class MediaNotificationTest : TestSetup() {
31     @get:Rule
32     val activityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
34     @Rule
35     @JvmField
36     val retryTestRule = RetryTestRule(3)
38     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1347033
39     @SmokeTest
40     @Test
41     fun verifyVideoPlaybackSystemNotificationTest() {
42         val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
44         navigationToolbar {
45         }.enterURLAndEnterToBrowser(videoTestPage.url) {
46             mDevice.waitForIdle()
47             clickPageObject(itemWithText("Play"))
48             assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
49         }.openNotificationShade {
50             verifySystemNotificationExists(videoTestPage.title)
51             clickMediaNotificationControlButton("Pause")
52             verifyMediaSystemNotificationButtonState("Play")
53         }
55         mDevice.pressBack()
57         browserScreen {
58             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
59         }.openTabDrawer {
60             closeTab()
61         }
63         mDevice.openNotification()
65         notificationShade {
66             verifySystemNotificationDoesNotExist(videoTestPage.title)
67         }
69         // close notification shade before the next test
70         mDevice.pressBack()
71     }
73     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2316010
74     @SmokeTest
75     @Test
76     fun verifyAudioPlaybackSystemNotificationTest() {
77         val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
79         navigationToolbar {
80         }.enterURLAndEnterToBrowser(audioTestPage.url) {
81             mDevice.waitForIdle()
82             clickPageObject(itemWithText("Play"))
83             assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
84         }.openNotificationShade {
85             verifySystemNotificationExists(audioTestPage.title)
86             clickMediaNotificationControlButton("Pause")
87             verifyMediaSystemNotificationButtonState("Play")
88         }
90         mDevice.pressBack()
92         browserScreen {
93             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
94         }.openTabDrawer {
95             closeTab()
96         }
98         mDevice.openNotification()
100         notificationShade {
101             verifySystemNotificationDoesNotExist(audioTestPage.title)
102         }
104         // close notification shade before the next test
105         mDevice.pressBack()
106     }
108     // TestRail: https://testrail.stage.mozaws.net/index.php?/cases/view/903595
109     @Test
110     fun mediaSystemNotificationInPrivateModeTest() {
111         val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
113         navigationToolbar {
114         }.openTabTray {
115         }.toggleToPrivateTabs {
116         }.openNewTab {
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")
125         }
127         mDevice.pressBack()
129         browserScreen {
130             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
131         }.openTabDrawer {
132             closeTab()
133             verifySnackBarText("Private tab closed")
134         }
136         mDevice.openNotification()
138         notificationShade {
139             verifySystemNotificationDoesNotExist("A site is playing media")
140         }
142         // close notification shade before and go back to regular mode before the next test
143         mDevice.pressBack()
144         homeScreen { }.togglePrivateBrowsingMode()
145     }