Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / mobile / android / fenix / app / src / androidTest / java / org / mozilla / fenix / ui / ComposeMediaNotificationTest.kt
blobc673cbe3deeb0aa77df5319f942d447b2b85ab40
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
9 import org.junit.Rule
10 import org.junit.Test
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
25 /**
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
30  */
31 class ComposeMediaNotificationTest : TestSetup() {
32     @get:Rule(order = 0)
33     val composeTestRule =
34         AndroidComposeTestRule(
35             HomeActivityTestRule.withDefaultSettingsOverrides(
36                 tabsTrayRewriteEnabled = true,
37             ),
38         ) { it.activity }
40     @Rule(order = 1)
41     @JvmField
42     val retryTestRule = RetryTestRule(3)
44     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1347033
45     @SmokeTest
46     @Test
47     fun verifyVideoPlaybackSystemNotificationTest() {
48         val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
50         navigationToolbar {
51         }.enterURLAndEnterToBrowser(videoTestPage.url) {
52             mDevice.waitForIdle()
53             clickPageObject(MatcherHelper.itemWithText("Play"))
54             assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
55         }.openNotificationShade {
56             verifySystemNotificationExists(videoTestPage.title)
57             clickMediaNotificationControlButton("Pause")
58             verifyMediaSystemNotificationButtonState("Play")
59         }
61         mDevice.pressBack()
63         browserScreen {
64             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
65         }.openComposeTabDrawer(composeTestRule) {
66             closeTab()
67         }
69         mDevice.openNotification()
71         notificationShade {
72             verifySystemNotificationDoesNotExist(videoTestPage.title)
73         }
75         // close notification shade before the next test
76         mDevice.pressBack()
77     }
79     // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2316010
80     @SmokeTest
81     @Test
82     fun verifyAudioPlaybackSystemNotificationTest() {
83         val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
85         navigationToolbar {
86         }.enterURLAndEnterToBrowser(audioTestPage.url) {
87             mDevice.waitForIdle()
88             clickPageObject(MatcherHelper.itemWithText("Play"))
89             assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
90         }.openNotificationShade {
91             verifySystemNotificationExists(audioTestPage.title)
92             clickMediaNotificationControlButton("Pause")
93             verifyMediaSystemNotificationButtonState("Play")
94         }
96         mDevice.pressBack()
98         browserScreen {
99             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
100         }.openComposeTabDrawer(composeTestRule) {
101             closeTab()
102         }
104         mDevice.openNotification()
106         notificationShade {
107             verifySystemNotificationDoesNotExist(audioTestPage.title)
108         }
110         // close notification shade before the next test
111         mDevice.pressBack()
112     }
114     // TestRail: https://testrail.stage.mozaws.net/index.php?/cases/view/903595
115     @Test
116     fun mediaSystemNotificationInPrivateModeTest() {
117         val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
119         homeScreen {
120         }.openComposeTabDrawer(composeTestRule) {
121         }.toggleToPrivateTabs {
122         }.openNewTab {
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")
131         }
133         mDevice.pressBack()
135         browserScreen {
136             assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
137         }.openComposeTabDrawer(composeTestRule) {
138             closeTab()
139             verifySnackBarText("Private tab closed")
140         }
142         mDevice.openNotification()
144         notificationShade {
145             verifySystemNotificationDoesNotExist("A site is playing media")
146         }
148         // close notification shade before and go back to regular mode before the next test
149         mDevice.pressBack()
150         homeScreen { }.togglePrivateBrowsingMode()
151     }