зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1585231 - refactor test. r=bryce
We remove `file_blockMedia_shouldPlay.html` and `file_blockMedia_shouldNotPlay.html` and move those operation on test directly, and do those operations after media fully loading. And seperate two different test cases to two testing tasks. Differential Revision: https://phabricator.services.mozilla.com/D58275 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c18ed341f9
Коммит
2f1d5440af
|
@ -6,8 +6,6 @@ support-files =
|
|||
audio.ogg
|
||||
empty.png
|
||||
file_almostSilentAudioTrack.html
|
||||
file_blockMedia_shouldNotPlay.html
|
||||
file_blockMedia_shouldPlay.html
|
||||
file_contentTitle.html
|
||||
file_mediaPlayback.html
|
||||
file_mediaPlayback2.html
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
const PAGE_SHOULD_PLAY =
|
||||
"https://example.com/browser/toolkit/content/tests/browser/file_blockMedia_shouldPlay.html";
|
||||
const PAGE_SHOULD_NOT_PLAY =
|
||||
"https://example.com/browser/toolkit/content/tests/browser/file_blockMedia_shouldNotPlay.html";
|
||||
|
||||
function check_audio_pause_state(expectPause) {
|
||||
var audio = content.document.getElementById("testAudio");
|
||||
if (!audio) {
|
||||
ok(false, "Can't get the audio element!");
|
||||
}
|
||||
|
||||
is(audio.paused, expectPause, "The pause state of audio is corret.");
|
||||
}
|
||||
const PAGE =
|
||||
"https://example.com/browser/toolkit/content/tests/browser/file_nonAutoplayAudio.html";
|
||||
|
||||
add_task(async function setup_test_preference() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
|
@ -21,43 +10,112 @@ add_task(async function setup_test_preference() {
|
|||
});
|
||||
});
|
||||
|
||||
add_task(async function block_autoplay_media() {
|
||||
info("- open new background tab1, and tab1 should not be blocked -");
|
||||
let tab1 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
|
||||
BrowserTestUtils.loadURI(tab1.linkedBrowser, PAGE_SHOULD_NOT_PLAY);
|
||||
await BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
|
||||
await waitForTabBlockEvent(tab1, false);
|
||||
/**
|
||||
* When media starts in an unvisited tab, we would delay its playback and resume
|
||||
* media playback when the tab goes to foreground first time. There are two test
|
||||
* cases are used to check different situations.
|
||||
*
|
||||
* The first one is used to check if the delayed media has been paused before
|
||||
* the tab goes to foreground. Then, when the tab goes to foreground, media
|
||||
* should still be paused.
|
||||
*
|
||||
* The second one is used to check if the delayed media has been paused, but
|
||||
* it eventually was started again before the tab goes to foreground. Then, when
|
||||
* the tab goes to foreground, media should be resumed.
|
||||
*/
|
||||
add_task(async function testShouldNotResumePausedMedia() {
|
||||
info("- open new background tab and wait until it finishes loading -");
|
||||
const tab = BrowserTestUtils.addTab(window.gBrowser, PAGE);
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
info("- open new background tab2, and tab2 should be blocked -");
|
||||
let tab2 = BrowserTestUtils.addTab(window.gBrowser, "about:blank");
|
||||
BrowserTestUtils.loadURI(tab2.linkedBrowser, PAGE_SHOULD_PLAY);
|
||||
await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
|
||||
await waitForTabBlockEvent(tab2, true);
|
||||
info("- play media and then immediately pause it -");
|
||||
await doPlayThenPauseOnMedia(tab);
|
||||
|
||||
info("- select tab1 as foreground tab -");
|
||||
await BrowserTestUtils.switchTab(window.gBrowser, tab1);
|
||||
info("- show delay media playback icon on tab -");
|
||||
await waitForTabBlockEvent(tab, true);
|
||||
|
||||
info("- tab1 should not be blocked, and media should not started -");
|
||||
await waitForTabBlockEvent(tab1, false);
|
||||
await SpecialPowers.spawn(
|
||||
tab1.linkedBrowser,
|
||||
[true],
|
||||
check_audio_pause_state
|
||||
);
|
||||
info("- selecting tab as foreground tab would resume the tab -");
|
||||
await BrowserTestUtils.switchTab(window.gBrowser, tab);
|
||||
|
||||
info("- select tab2 as foreground tab -");
|
||||
await BrowserTestUtils.switchTab(window.gBrowser, tab2);
|
||||
info("- resuming tab should dismiss delay autoplay icon -");
|
||||
await waitForTabBlockEvent(tab, false);
|
||||
|
||||
info("- tab2 should not be blocked and media should be playing -");
|
||||
await waitForTabBlockEvent(tab2, false);
|
||||
await waitForTabPlayingEvent(tab2, true);
|
||||
await SpecialPowers.spawn(
|
||||
tab2.linkedBrowser,
|
||||
[false],
|
||||
check_audio_pause_state
|
||||
);
|
||||
info("- paused media should still be paused -");
|
||||
await checkAudioPauseState(tab, true /* should be paused */);
|
||||
|
||||
info("- remove tabs -");
|
||||
BrowserTestUtils.removeTab(tab1);
|
||||
BrowserTestUtils.removeTab(tab2);
|
||||
info("- paused media won't generate tab playing icon -");
|
||||
await waitForTabPlayingEvent(tab, false);
|
||||
|
||||
info("- remove tab -");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function testShouldResumePlayedMedia() {
|
||||
info("- open new background tab and wait until it finishes loading -");
|
||||
const tab = BrowserTestUtils.addTab(window.gBrowser, PAGE);
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
info("- play media, pause it, then play it again -");
|
||||
await doPlayPauseThenPlayOnMedia(tab);
|
||||
|
||||
info("- show delay media playback icon on tab -");
|
||||
await waitForTabBlockEvent(tab, true);
|
||||
|
||||
info("- select tab as foreground tab -");
|
||||
await BrowserTestUtils.switchTab(window.gBrowser, tab);
|
||||
|
||||
info("- resuming tab should dismiss delay autoplay icon -");
|
||||
await waitForTabBlockEvent(tab, false);
|
||||
|
||||
info("- played media should still be played -");
|
||||
await checkAudioPauseState(tab, false /* should be played */);
|
||||
|
||||
info("- played media would generate tab playing icon -");
|
||||
await waitForTabPlayingEvent(tab, true);
|
||||
|
||||
info("- remove tab -");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Helper functions.
|
||||
*/
|
||||
async function checkAudioPauseState(tab, expectedPaused) {
|
||||
await SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[expectedPaused],
|
||||
expectedPaused => {
|
||||
const audio = content.document.getElementById("testAudio");
|
||||
if (!audio) {
|
||||
ok(false, "Can't get the audio element!");
|
||||
}
|
||||
|
||||
is(audio.paused, expectedPaused, "The pause state of audio is corret.");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function doPlayThenPauseOnMedia(tab) {
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
|
||||
const audio = content.document.getElementById("testAudio");
|
||||
if (!audio) {
|
||||
ok(false, "Can't get the audio element!");
|
||||
}
|
||||
|
||||
audio.play();
|
||||
audio.pause();
|
||||
});
|
||||
}
|
||||
|
||||
async function doPlayPauseThenPlayOnMedia(tab) {
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
|
||||
const audio = content.document.getElementById("testAudio");
|
||||
if (!audio) {
|
||||
ok(false, "Can't get the audio element!");
|
||||
}
|
||||
|
||||
audio.play();
|
||||
audio.pause();
|
||||
audio.play();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
||||
<meta content="utf-8" http-equiv="encoding">
|
||||
</head>
|
||||
<body>
|
||||
<audio id="testAudio" src="audio.ogg" preload="none"></audio>
|
||||
<script type="text/javascript">
|
||||
|
||||
var audio = document.getElementById("testAudio");
|
||||
audio.play();
|
||||
audio.pause();
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -1,16 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
||||
<meta content="utf-8" http-equiv="encoding">
|
||||
</head>
|
||||
<body>
|
||||
<audio id="testAudio" src="audio.ogg" loop></audio>
|
||||
<script type="text/javascript">
|
||||
|
||||
var audio = document.getElementById("testAudio");
|
||||
audio.play();
|
||||
audio.pause();
|
||||
audio.play();
|
||||
|
||||
</script>
|
||||
</body>
|
Загрузка…
Ссылка в новой задаче