Bug 1322505 - part3 : add test. r=baku,jaws

MozReview-Commit-ID: 2YnWEO98M2e

--HG--
extra : rebase_source : 757ce29a8049d5b800530f331f09f57bf32e14c9
This commit is contained in:
Alastor Wu 2017-01-23 14:46:28 +08:00
parent 07ed0954e6
commit 3fe21cfdba
6 changed files with 141 additions and 0 deletions

View File

@ -7003,6 +7003,12 @@
</getter>
</property>
<property name="soundBlocked" readonly="true">
<getter>
return this.getAttribute("blocked") == "true";
</getter>
</property>
<property name="lastAccessed">
<getter>
return this._lastAccessed == Infinity ? Date.now() : this._lastAccessed;

View File

@ -13,6 +13,11 @@ support-files =
tags = audiochannel
support-files =
file_multipleAudio.html
[browser_block_autoplay_media_pausedAfterPlay.js]
tags = audiochannel
support-files =
file_blockMedia_shouldPlay.html
file_blockMedia_shouldNotPlay.html
[browser_bug295977_autoscroll_overflow.js]
[browser_bug451286.js]
skip-if = !e10s

View File

@ -0,0 +1,82 @@
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";
var SuspendedType = {
NONE_SUSPENDED : 0,
SUSPENDED_PAUSE : 1,
SUSPENDED_BLOCK : 2,
SUSPENDED_PAUSE_DISPOSABLE : 3
};
function check_audio_suspended(suspendedType) {
var audio = content.document.getElementById("testAudio");
if (!audio) {
ok(false, "Can't get the audio element!");
}
is(audio.computedSuspended, suspendedType,
"The suspeded state of audio is correct.");
}
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.")
}
add_task(function* setup_test_preference() {
yield SpecialPowers.pushPrefEnv({"set": [
["media.useAudioChannelService.testing", true],
["media.block-autoplay-until-in-foreground", true]
]});
});
add_task(function* block_autoplay_media() {
info("- open new background tab1, and check tab1's media suspend type -");
let tab1 = window.gBrowser.addTab("about:blank");
tab1.linkedBrowser.loadURI(PAGE_SHOULD_NOT_PLAY);
yield BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
check_audio_suspended);
info("- the tab1 should not be blocked -");
yield waitForTabBlockEvent(tab1, false);
info("- open new background tab2, and check tab2's media suspend type -");
let tab2 = window.gBrowser.addTab("about:blank");
tab2.linkedBrowser.loadURI(PAGE_SHOULD_PLAY);
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
check_audio_suspended);
info("- the tab2 should be blocked -");
yield waitForTabBlockEvent(tab2, true);
info("- select tab1 as foreground tab, and tab1's media should be paused -");
yield BrowserTestUtils.switchTab(window.gBrowser, tab1);
yield ContentTask.spawn(tab1.linkedBrowser, true,
check_audio_pause_state);
info("- the tab1 should not be blocked -");
yield waitForTabBlockEvent(tab1, false);
info("- select tab2 as foreground tab, and tab2's media should be playing -");
yield BrowserTestUtils.switchTab(window.gBrowser, tab2);
yield ContentTask.spawn(tab2.linkedBrowser, false,
check_audio_pause_state);
info("- the tab2 should not be blocked -");
yield waitForTabBlockEvent(tab2, false);
info("- check tab2's media suspend type -");
yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.NONE_SUSPENDED,
check_audio_suspended);
info("- remove tabs -");
yield BrowserTestUtils.removeTab(tab1);
yield BrowserTestUtils.removeTab(tab2);
});

View File

@ -0,0 +1,15 @@
<!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>

View File

@ -0,0 +1,16 @@
<!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"></audio>
<script type="text/javascript">
var audio = document.getElementById("testAudio");
audio.play();
audio.pause();
audio.play();
</script>
</body>

View File

@ -31,3 +31,20 @@ function pushPrefs(...aPrefs) {
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
return deferred.promise;
}
/**
* Used to check whether the audio unblocking icon is in the tab.
*/
function* waitForTabBlockEvent(tab, expectBlocked) {
if (tab.soundBlocked == expectBlocked) {
ok(true, "The tab should " + (expectBlocked ? "" : "not ") + "be blocked");
} else {
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.indexOf("blocked") >= 0) {
is(tab.soundBlocked, expectBlocked, "The tab should " + (expectBlocked ? "" : "not ") + "be blocked");
return true;
}
return false;
});
}
}