2020-03-31 18:11:41 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.ui
|
|
|
|
|
2022-07-05 16:56:21 +00:00
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
2021-05-21 14:20:21 +00:00
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
import mozilla.components.concept.engine.mediasession.MediaSession
|
2020-03-31 18:11:41 +00:00
|
|
|
import okhttp3.mockwebserver.MockWebServer
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Before
|
2022-11-16 16:24:41 +00:00
|
|
|
import org.junit.Ignore
|
2020-03-31 18:11:41 +00:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
2021-05-21 14:20:21 +00:00
|
|
|
import org.mozilla.fenix.ext.components
|
2020-03-31 18:11:41 +00:00
|
|
|
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
|
|
|
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
2022-04-18 13:44:04 +00:00
|
|
|
import org.mozilla.fenix.helpers.RetryTestRule
|
2020-03-31 18:11:41 +00:00
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper
|
|
|
|
import org.mozilla.fenix.ui.robots.browserScreen
|
|
|
|
import org.mozilla.fenix.ui.robots.homeScreen
|
|
|
|
import org.mozilla.fenix.ui.robots.navigationToolbar
|
2020-04-13 10:17:35 +00:00
|
|
|
import org.mozilla.fenix.ui.robots.notificationShade
|
2020-03-31 18:11:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 MediaNotificationTest {
|
|
|
|
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
|
|
|
|
|
|
|
|
private lateinit var mockWebServer: MockWebServer
|
2022-07-05 16:56:21 +00:00
|
|
|
private lateinit var mDevice: UiDevice
|
2020-03-31 18:11:41 +00:00
|
|
|
|
|
|
|
@get:Rule
|
2022-09-29 13:18:54 +00:00
|
|
|
val activityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
|
2021-05-21 14:20:21 +00:00
|
|
|
private lateinit var browserStore: BrowserStore
|
2020-03-31 18:11:41 +00:00
|
|
|
|
2022-04-18 13:44:04 +00:00
|
|
|
@Rule
|
|
|
|
@JvmField
|
|
|
|
val retryTestRule = RetryTestRule(3)
|
|
|
|
|
2020-03-31 18:11:41 +00:00
|
|
|
@Before
|
|
|
|
fun setUp() {
|
2021-05-21 14:20:21 +00:00
|
|
|
// 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 = activityTestRule.activity.components.core.store
|
|
|
|
|
2022-07-05 16:56:21 +00:00
|
|
|
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
2020-03-31 18:11:41 +00:00
|
|
|
mockWebServer = MockWebServer().apply {
|
2020-10-27 14:19:24 +00:00
|
|
|
dispatcher = AndroidAssetDispatcher()
|
2020-03-31 18:11:41 +00:00
|
|
|
start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
fun tearDown() {
|
|
|
|
mockWebServer.shutdown()
|
|
|
|
}
|
|
|
|
|
2022-11-16 16:24:41 +00:00
|
|
|
@Ignore("Failing after SDK 33 migration. See: https://github.com/mozilla-mobile/fenix/pull/25876")
|
2020-03-31 18:11:41 +00:00
|
|
|
@Test
|
|
|
|
fun videoPlaybackSystemNotificationTest() {
|
|
|
|
val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
|
|
|
|
|
|
|
|
navigationToolbar {
|
|
|
|
}.enterURLAndEnterToBrowser(videoTestPage.url) {
|
2020-07-08 09:59:53 +00:00
|
|
|
mDevice.waitForIdle()
|
2020-03-31 18:11:41 +00:00
|
|
|
clickMediaPlayerPlayButton()
|
2021-05-21 14:20:21 +00:00
|
|
|
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
|
2020-03-31 18:11:41 +00:00
|
|
|
}.openNotificationShade {
|
|
|
|
verifySystemNotificationExists(videoTestPage.title)
|
2022-04-27 14:53:45 +00:00
|
|
|
clickMediaNotificationControlButton("Pause")
|
2020-03-31 18:11:41 +00:00
|
|
|
verifyMediaSystemNotificationButtonState("Play")
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice.pressBack()
|
|
|
|
|
|
|
|
browserScreen {
|
2021-05-21 14:20:21 +00:00
|
|
|
assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
|
2020-06-05 17:59:08 +00:00
|
|
|
}.openTabDrawer {
|
2020-04-13 10:17:35 +00:00
|
|
|
closeTab()
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice.openNotification()
|
|
|
|
|
|
|
|
notificationShade {
|
|
|
|
verifySystemNotificationGone(videoTestPage.title)
|
2020-03-31 18:11:41 +00:00
|
|
|
}
|
2020-05-14 14:01:09 +00:00
|
|
|
|
|
|
|
// close notification shade before the next test
|
|
|
|
mDevice.pressBack()
|
2020-03-31 18:11:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 16:24:41 +00:00
|
|
|
@Ignore("Failing after SDK 33 migration. See: https://github.com/mozilla-mobile/fenix/pull/25876")
|
2020-03-31 18:11:41 +00:00
|
|
|
@Test
|
|
|
|
fun mediaSystemNotificationInPrivateModeTest() {
|
|
|
|
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
|
|
|
|
|
|
|
navigationToolbar {
|
2022-04-18 13:44:04 +00:00
|
|
|
}.openTabTray {
|
|
|
|
}.toggleToPrivateTabs {
|
|
|
|
}.openNewTab {
|
|
|
|
}.submitQuery(audioTestPage.url.toString()) {
|
2020-07-08 09:59:53 +00:00
|
|
|
mDevice.waitForIdle()
|
2020-03-31 18:11:41 +00:00
|
|
|
clickMediaPlayerPlayButton()
|
2021-05-21 14:20:21 +00:00
|
|
|
assertPlaybackState(browserStore, MediaSession.PlaybackState.PLAYING)
|
2020-03-31 18:11:41 +00:00
|
|
|
}.openNotificationShade {
|
|
|
|
verifySystemNotificationExists("A site is playing media")
|
2022-04-27 14:53:45 +00:00
|
|
|
clickMediaNotificationControlButton("Pause")
|
2020-03-31 18:11:41 +00:00
|
|
|
verifyMediaSystemNotificationButtonState("Play")
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevice.pressBack()
|
|
|
|
|
|
|
|
browserScreen {
|
2021-05-21 14:20:21 +00:00
|
|
|
assertPlaybackState(browserStore, MediaSession.PlaybackState.PAUSED)
|
2020-06-05 17:59:08 +00:00
|
|
|
}.openTabDrawer {
|
2020-04-13 10:17:35 +00:00
|
|
|
closeTab()
|
2020-09-07 14:29:28 +00:00
|
|
|
verifySnackBarText("Private tab closed")
|
2020-07-21 12:49:24 +00:00
|
|
|
}
|
2020-04-13 10:17:35 +00:00
|
|
|
|
|
|
|
mDevice.openNotification()
|
|
|
|
|
|
|
|
notificationShade {
|
2020-04-24 14:55:46 +00:00
|
|
|
verifySystemNotificationGone("A site is playing media")
|
2020-03-31 18:11:41 +00:00
|
|
|
}
|
2020-05-14 14:01:09 +00:00
|
|
|
|
2020-05-20 14:41:31 +00:00
|
|
|
// close notification shade before and go back to regular mode before the next test
|
2020-05-14 14:01:09 +00:00
|
|
|
mDevice.pressBack()
|
2020-05-20 14:41:31 +00:00
|
|
|
homeScreen { }.togglePrivateBrowsingMode()
|
2020-03-31 18:11:41 +00:00
|
|
|
}
|
|
|
|
}
|