Bug 1434804 - Test that setting a muted-autoplay media to audible pauses media. r=kamidphish

MozReview-Commit-ID: 7cPgJMvUoja

--HG--
extra : rebase_source : 1d94df4e2fe75e1854207c52259c88813c24be50
This commit is contained in:
Chris Pearce 2018-03-12 14:15:54 +13:00
parent f589142a62
commit 7101cc436e
3 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Autoplay policy window</title>
<style>
video {
width: 50%;
height: 50%;
}
</style>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="manifest.js"></script>
<script type="text/javascript" src="AutoplayTestUtils.js"></script>
</head>
<body>
<pre id="test">
<script>
window.is = window.opener.is;
window.info = window.opener.info;
function testAutoplayUnmutePauses(testCase, parent_window) {
return new Promise(function (resolve, reject) {
info("testAutoplayUnmutePauses: " + testCase.property);
let element = document.createElement("video");
element.preload = "auto";
// Make inaudible.
element[testCase.property] = testCase.inaudible;
// Once we've loaded, play, then make audible.
// Assert that the media is paused when we make it audible.
element.addEventListener("loadeddata", () => {
info("loadeddata");
element.play();
is(element.paused, false, testCase.property + "=" + testCase.inaudible + " - should be playing");
element[testCase.property] = testCase.audible;
is(element.paused, true, testCase.property + "=" + testCase.audible + " - should be paused.");
resolve();
});
element.src = "short.mp4";
element.id = "video";
document.body.appendChild(element);
});
}
nextWindowMessage().then(
(event) => {
testAutoplayUnmutePauses(event.data, event.source)
.then(() => {
event.source.postMessage("done", "*");
});
});
</script>
</pre>
</body>
</html>

View File

@ -438,6 +438,7 @@ support-files =
dynamic_resource.sjs
eme.js
file_access_controls.html
file_autoplay_policy_unmute_pauses.html
file_autoplay_policy_activation_window.html
file_autoplay_policy_activation_frame.html
flac-s24.flac
@ -689,6 +690,8 @@ skip-if = android_version == '15' || android_version == '17' || android_version
skip-if = android_version == '23' # bug 1424903
[test_autoplay_policy_activation.html]
skip-if = android_version == '23' # bug 1424903
[test_autoplay_policy_unmute_pauses.html]
skip-if = android_version == '23' # bug 1424903
[test_buffered.html]
skip-if = android_version == '15' || android_version == '22' # bug 1308388, android(bug 1232305)
[test_bug448534.html]

View File

@ -0,0 +1,64 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Autoplay policy test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
<script type="text/javascript" src="AutoplayTestUtils.js"></script>
</head>
<body>
<pre id="test">
<script>
window.is = SimpleTest.is;
window.info = SimpleTest.info;
// Tests that videos can only play audibly in windows/frames
// which have been activated by same-origin user gesture.
gTestPrefs.push(["media.autoplay.enabled", false],
["media.autoplay.enabled.user-gestures-needed", true]);
SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
runTest();
});
let testCases = [
{
property: "muted",
inaudible: true,
audible: false,
},
{
property: "volume",
inaudible: 0.0,
audible: 1.0,
},
];
let child_url = "file_autoplay_policy_unmute_pauses.html";
async function runTest() {
for (testCase of testCases) {
// Run each test in a new window, to ensure its user gesture
// activation state isn't tainted by preceeding tests.
let child = window.open(child_url, "", "width=500,height=500");
await once(child, "load");
child.postMessage(testCase, window.origin);
let result = await nextWindowMessage();
child.close();
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>