Bug 1841168 - Convert `MediaNotificationTest` to support Tabs Tray rewrite
parent
d65da96bd0
commit
bbfd236a51
@ -0,0 +1,173 @@
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.concept.engine.mediasession.MediaSession
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.MatcherHelper
|
||||
import org.mozilla.fenix.helpers.RetryTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
|
||||
import org.mozilla.fenix.ui.robots.browserScreen
|
||||
import org.mozilla.fenix.ui.robots.clickPageObject
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
import org.mozilla.fenix.ui.robots.notificationShade
|
||||
|
||||
/**
|
||||
* Tests for verifying basic functionality of media notifications:
|
||||
* - video and audio playback system notifications appear and can pause/play the media content
|
||||
* - a media notification icon is displayed on the homescreen for the tab playing media content
|
||||
* Note: this test only verifies media notifications, not media itself
|
||||
*/
|
||||
class ComposeMediaNotificationTest {
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
private lateinit var mDevice: UiDevice
|
||||
private lateinit var browserStore: BrowserStore
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val composeTestRule =
|
||||
AndroidComposeTestRule(
|
||||
HomeActivityTestRule.withDefaultSettingsOverrides(
|
||||
tabsTrayRewriteEnabled = true,
|
||||
),
|
||||
) { it.activity }
|
||||
|
||||
@Rule(order = 1)
|
||||
@JvmField
|
||||
val retryTestRule = RetryTestRule(3)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
// Initializing this as part of class construction, below the rule would throw a NPE
|
||||
// So we are initializing this here instead of in all tests.
|
||||
browserStore = composeTestRule.activity.components.core.store
|
||||
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mockWebServer = MockWebServer().apply {
|
||||
dispatcher = AndroidAssetDispatcher()
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun videoPlaybackSystemNotificationTest() {
|
||||
val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(videoTestPage.url) {
|
||||
mDevice.waitForIdle()
|
||||
clickPageObject(MatcherHelper.itemWithText("Play"))
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists(videoTestPage.title)
|
||||
clickMediaNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
|
||||
}.openComposeTabDrawer(composeTestRule) {
|
||||
closeTab()
|
||||
}
|
||||
|
||||
mDevice.openNotification()
|
||||
|
||||
notificationShade {
|
||||
verifySystemNotificationDoesNotExist(videoTestPage.title)
|
||||
}
|
||||
|
||||
// close notification shade before the next test
|
||||
mDevice.pressBack()
|
||||
}
|
||||
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun audioPlaybackSystemNotificationTest() {
|
||||
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(audioTestPage.url) {
|
||||
mDevice.waitForIdle()
|
||||
clickPageObject(MatcherHelper.itemWithText("Play"))
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists(audioTestPage.title)
|
||||
clickMediaNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
|
||||
}.openComposeTabDrawer(composeTestRule) {
|
||||
closeTab()
|
||||
}
|
||||
|
||||
mDevice.openNotification()
|
||||
|
||||
notificationShade {
|
||||
verifySystemNotificationDoesNotExist(audioTestPage.title)
|
||||
}
|
||||
|
||||
// close notification shade before the next test
|
||||
mDevice.pressBack()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mediaSystemNotificationInPrivateModeTest() {
|
||||
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
||||
|
||||
homeScreen {
|
||||
}.openComposeTabDrawer(composeTestRule) {
|
||||
}.toggleToPrivateTabs {
|
||||
}.openNewTab {
|
||||
}.submitQuery(audioTestPage.url.toString()) {
|
||||
mDevice.waitForIdle()
|
||||
clickPageObject(MatcherHelper.itemWithText("Play"))
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists("A site is playing media")
|
||||
clickMediaNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
|
||||
}.openComposeTabDrawer(composeTestRule) {
|
||||
closeTab()
|
||||
verifySnackBarText("Private tab closed")
|
||||
}
|
||||
|
||||
mDevice.openNotification()
|
||||
|
||||
notificationShade {
|
||||
verifySystemNotificationDoesNotExist("A site is playing media")
|
||||
}
|
||||
|
||||
// close notification shade before and go back to regular mode before the next test
|
||||
mDevice.pressBack()
|
||||
homeScreen { }.togglePrivateBrowsingMode()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue