Updated the method to verify system notifications and added new tests for media notifications (#9330)
parent
cee34893ed
commit
5f68d6cb29
@ -0,0 +1,26 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Audio_Test_Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<p id="testContent">Page content: audio player</p>
|
||||
<div class="audioPlayer">
|
||||
<audio id="audioSample" controls loop>
|
||||
<source src="../resources/audioSample.mp3">
|
||||
</audio>
|
||||
</div>
|
||||
<div class="playbackState">
|
||||
</div>
|
||||
<script>
|
||||
const audio = document.querySelector('audio');
|
||||
|
||||
audio.addEventListener('playing', (event) => {
|
||||
document.querySelector('.playbackState').innerText="Media file is playing"
|
||||
});
|
||||
|
||||
audio.addEventListener('pause', (event) => {
|
||||
document.querySelector('.playbackState').innerText="Media file is paused"
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,26 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Video_Test_Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<p id="testContent">Page content: video player</p>
|
||||
<div id="video-container">
|
||||
<video id="videoSample" width="320" height="240" controls loop>
|
||||
<source src="../resources/videoSample.webm">
|
||||
</video>
|
||||
</div>
|
||||
<div class="playbackState">
|
||||
</div>
|
||||
<script>
|
||||
const video = document.querySelector('video');
|
||||
|
||||
video.addEventListener('playing', (event) => {
|
||||
document.querySelector('.playbackState').innerText="Media file is playing";
|
||||
});
|
||||
|
||||
video.addEventListener('pause', (event) => {
|
||||
document.querySelector('.playbackState').innerHTML="Media file is paused";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,131 @@
|
||||
/* 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
|
||||
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
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.mDevice
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@get:Rule
|
||||
val activityTestRule = HomeActivityTestRule()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockWebServer = MockWebServer().apply {
|
||||
setDispatcher(AndroidAssetDispatcher())
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun videoPlaybackSystemNotificationTest() {
|
||||
val videoTestPage = TestAssetHelper.getVideoPageAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(videoTestPage.url) {
|
||||
clickMediaPlayerPlayButton()
|
||||
waitForPlaybackToStart()
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists(videoTestPage.title)
|
||||
clickMediaSystemNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
verifyMediaIsPaused()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun audioPlaybackSystemNotificationTest() {
|
||||
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(audioTestPage.url) {
|
||||
verifyPageContent(audioTestPage.content)
|
||||
clickMediaPlayerPlayButton()
|
||||
waitForPlaybackToStart()
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists(audioTestPage.title)
|
||||
clickMediaSystemNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
verifyMediaIsPaused()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tabMediaControlButtonTest() {
|
||||
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(audioTestPage.url) {
|
||||
verifyPageContent(audioTestPage.content)
|
||||
clickMediaPlayerPlayButton()
|
||||
waitForPlaybackToStart()
|
||||
}.openHomeScreen {
|
||||
verifyTabMediaControlButtonState("Pause")
|
||||
clickTabMediaControlButton()
|
||||
verifyTabMediaControlButtonState("Play")
|
||||
}.openTab(audioTestPage.title) {
|
||||
verifyMediaIsPaused()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mediaSystemNotificationInPrivateModeTest() {
|
||||
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)
|
||||
|
||||
homeScreen { }.togglePrivateBrowsingMode()
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(audioTestPage.url) {
|
||||
verifyPageContent(audioTestPage.content)
|
||||
clickMediaPlayerPlayButton()
|
||||
waitForPlaybackToStart()
|
||||
}.openNotificationShade {
|
||||
verifySystemNotificationExists("A site is playing media")
|
||||
clickMediaSystemNotificationControlButton("Pause")
|
||||
verifyMediaSystemNotificationButtonState("Play")
|
||||
}
|
||||
|
||||
mDevice.pressBack()
|
||||
|
||||
browserScreen {
|
||||
verifyMediaIsPaused()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package org.mozilla.fenix.ui.robots
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.test.uiautomator.By.text
|
||||
import androidx.test.uiautomator.UiScrollable
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||
|
||||
class NotificationRobot {
|
||||
|
||||
fun verifySystemNotificationExists(notificationMessage: String) {
|
||||
|
||||
fun notificationTray() = UiScrollable(
|
||||
UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller")
|
||||
)
|
||||
|
||||
mDevice.waitNotNull(
|
||||
Until.hasObject(text(notificationMessage)),
|
||||
waitingTime
|
||||
)
|
||||
|
||||
var notificationFound = false
|
||||
while (!notificationFound) {
|
||||
try {
|
||||
val notification = notificationTray().getChildByText(
|
||||
UiSelector().text(notificationMessage), notificationMessage,
|
||||
true
|
||||
)
|
||||
notification.exists()
|
||||
notificationFound = true
|
||||
} catch (e: Resources.NotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun verifyPrivateTabsNotification() {
|
||||
mDevice.waitNotNull(Until.hasObject(text("Close private tabs")), waitingTime)
|
||||
assertPrivateTabsNotification()
|
||||
}
|
||||
|
||||
fun clickMediaSystemNotificationControlButton(action: String) {
|
||||
mediaSystemNotificationButton(action).waitForExists(waitingTime)
|
||||
mediaSystemNotificationButton(action).click()
|
||||
}
|
||||
|
||||
fun verifyMediaSystemNotificationButtonState(action: String) {
|
||||
mediaSystemNotificationButton(action).waitForExists(waitingTime)
|
||||
}
|
||||
|
||||
class Transition {
|
||||
|
||||
fun clickClosePrivateTabsNotification(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
||||
NotificationRobot().verifySystemNotificationExists("Close private tabs")
|
||||
closePrivateTabsNotification().clickAndWaitForNewWindow()
|
||||
|
||||
HomeScreenRobot().interact()
|
||||
return HomeScreenRobot.Transition()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun notificationShade(interact: NotificationRobot.() -> Unit): NotificationRobot.Transition {
|
||||
NotificationRobot().interact()
|
||||
return NotificationRobot.Transition()
|
||||
}
|
||||
|
||||
private fun assertPrivateTabsNotification() {
|
||||
mDevice.findObject(UiSelector().text("Firefox Preview (Private)")).exists()
|
||||
mDevice.findObject(UiSelector().text("Close private tabs")).exists()
|
||||
}
|
||||
|
||||
private fun closePrivateTabsNotification() =
|
||||
mDevice.findObject(UiSelector().text("Close private tabs"))
|
||||
|
||||
private fun mediaSystemNotificationButton(action: String) =
|
||||
mDevice.findObject(
|
||||
UiSelector()
|
||||
.resourceId("android:id/action0")
|
||||
.descriptionContains(action)
|
||||
)
|
Loading…
Reference in New Issue