This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the method to verify system notifications and added new tests…
… for media notifications (#9330)
- Loading branch information
Oana Horvath
authored
Mar 31, 2020
1 parent
cee3489
commit 5f68d6c
Showing
11 changed files
with
413 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
app/src/androidTest/java/org/mozilla/fenix/ui/MediaNotificationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.