mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 04:05:32 +00:00
e08b3c171c
I don't think we should allow media without audio tracks to autoplay because: * It means play() before loaded metadata behaves differently than play() called after loaded metadata. * With the current impl we dispatch the "play" event and then the "pause" event when we decide we should block, which may confuse some sites' controls. * Delaying running the play() algorithm until we've loaded metadata would add significant complexity, and may break sites. * Chrome doesn't have this provision, meaning the complexity required to support it will not result in much benefit to us. MozReview-Commit-ID: FSVlDJAOisw --HG-- extra : rebase_source : 93b1bcf8d8edbd6ca10ad918b40a87cd3cfbbf0b
76 lines
2.4 KiB
HTML
76 lines
2.4 KiB
HTML
<!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>
|
|
|
|
// Tests that origins with "autoplay-media" permission can autoplay.
|
|
|
|
gTestPrefs.push(["media.autoplay.enabled", false],
|
|
["media.autoplay.enabled.user-gestures-needed", true]);
|
|
|
|
SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
|
|
runTest();
|
|
});
|
|
|
|
async function testPlayInOrigin(testCase) {
|
|
// Run test in a new window, to ensure its user gesture
|
|
// activation state isn't tainted by preceeding tests.
|
|
let child = window.open("file_autoplay_policy_permission.html", "", "width=500,height=500");
|
|
await once(child, "load");
|
|
child.postMessage(testCase, "*");
|
|
await nextWindowMessage();
|
|
child.close();
|
|
}
|
|
|
|
async function runTest() {
|
|
// First verify that we can't play in a document unwhitelisted.
|
|
is(window.origin, "http://mochi.test:8888", "Origin should be as we assume, otherwise the rest of the test is bogus!");
|
|
|
|
await testPlayInOrigin({
|
|
origin: "http://mochi.test:8888",
|
|
shouldPlay: false,
|
|
message: "Should not be able to play unwhitelisted."
|
|
});
|
|
|
|
// Add our origin to the whitelist.
|
|
await pushAutoplayAllowedPermission();
|
|
|
|
// Now we should be able to play...
|
|
await testPlayInOrigin({
|
|
origin: "http://mochi.test:8888",
|
|
shouldPlay: true,
|
|
message: "Should be able to play since whitelisted."
|
|
});
|
|
|
|
// But sub-origins should not.
|
|
await testPlayInOrigin({
|
|
origin: "http://test1.mochi.test:8888",
|
|
shouldPlay: false,
|
|
message: "Sub origin should not count as whitelisted."
|
|
});
|
|
await testPlayInOrigin({
|
|
origin: "http://sub1.test1.mochi.test:8888",
|
|
shouldPlay: false,
|
|
message: "Sub-sub-origins should not count as whitelisted."
|
|
});
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
|
|
</html> |