Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Updated the method to verify system notifications and added new tests…
Browse files Browse the repository at this point in the history
… for media notifications (#9330)
  • Loading branch information
Oana Horvath authored Mar 31, 2020
1 parent cee3489 commit 5f68d6c
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 56 deletions.
Empty file added -e
Empty file.
26 changes: 26 additions & 0 deletions app/src/androidTest/assets/pages/audioMediaPage.html
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions app/src/androidTest/assets/pages/videoMediaPage.html
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object TestAssetHelper {
val waitingTime: Long = TimeUnit.SECONDS.toMillis(15)
val waitingTimeShort: Long = TimeUnit.SECONDS.toMillis(1)

data class TestAsset(val url: Uri, val content: String)
data class TestAsset(val url: Uri, val content: String, val title: String)

/**
* Hosts 3 simple websites, found at androidTest/assets/pages/generic[1|2|3].html
Expand All @@ -33,60 +33,79 @@ object TestAssetHelper {
return (1..4).map {
TestAsset(
server.url("pages/generic$it.html").toString().toUri()!!,
"Page content: $it"
"Page content: $it",
""
)
}
}

fun getGenericAsset(server: MockWebServer, pageNum: Int): TestAsset {
val url = server.url("pages/generic$pageNum.html").toString().toUri()!!
val content = "Page content: $pageNum"
val title = "Test_Page_$pageNum"

return TestAsset(url, content)
return TestAsset(url, content, title)
}

fun getLoremIpsumAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/lorem-ipsum.html").toString().toUri()!!
val content = "Page content: lorem ipsum"
return TestAsset(url, content)

return TestAsset(url, content, "")
}

fun getRefreshAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/refresh.html").toString().toUri()!!
val content = "Page content: refresh"

return TestAsset(url, content)
return TestAsset(url, content, "")
}

fun getUUIDPage(server: MockWebServer): TestAsset {
val url = server.url("pages/basic_nav_uuid.html").toString().toUri()!!
val content = "Page content: basic_nav_uuid"

return TestAsset(url, content)
return TestAsset(url, content, "")
}

fun getDownloadAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/download.html").toString().toUri()!!
val content = "Page content: Globe.svg"

return TestAsset(url, content)
return TestAsset(url, content, "")
}

fun getEnhancedTrackingProtectionAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/etp.html").toString().toUri()!!

return TestAsset(url, "")
return TestAsset(url, "", "")
}

fun getImageAsset(server: MockWebServer): TestAsset {
val url = server.url("resources/rabbit.jpg").toString().toUri()!!

return TestAsset(url, "")
return TestAsset(url, "", "")
}

fun getSaveLoginAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/password.html").toString().toUri()!!

return TestAsset(url, "")
return TestAsset(url, "", "")
}

fun getAudioPageAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/audioMediaPage.html").toString().toUri()!!
val title = "Audio_Test_Page"
val content = "Page content: audio player"

return TestAsset(url, content, title)
}

fun getVideoPageAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/videoMediaPage.html").toString().toUri()!!
val title = "Video_Test_Page"
val content = "Page content: video player"

return TestAsset(url, content, title)
}
}
131 changes: 131 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.ext.waitNotNull
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 tabbed browsing
Expand Down Expand Up @@ -259,6 +260,9 @@ class TabbedBrowsingTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
mDevice.openNotification()
}

notificationShade {
verifyPrivateTabsNotification()
}.clickClosePrivateTabsNotification {
verifyPrivateSessionMessage()
Expand Down
Loading

0 comments on commit 5f68d6c

Please sign in to comment.