2018-04-30 08:40:22 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<title>Autoplay policy test</title>
|
2019-04-16 06:53:28 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2018-04-30 08:40:22 +03:00
|
|
|
<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.
|
|
|
|
|
2018-06-29 16:14:33 +03:00
|
|
|
gTestPrefs.push(["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
|
2019-01-07 21:41:58 +03:00
|
|
|
["media.autoplay.enabled.user-gestures-needed", true]);
|
2018-04-30 08:40:22 +03:00
|
|
|
|
|
|
|
SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
|
|
|
|
runTest();
|
|
|
|
});
|
|
|
|
|
2018-05-28 13:09:14 +03:00
|
|
|
async function testPlayInOrigin(testCase) {
|
2018-04-30 08:40:22 +03:00
|
|
|
// Run test in a new window, to ensure its user gesture
|
|
|
|
// activation state isn't tainted by preceeding tests.
|
2018-06-27 07:15:58 +03:00
|
|
|
let url = testCase.origin + "/tests/dom/media/test/file_autoplay_policy_activation_frame.html";
|
|
|
|
let child = window.open(url, "", "width=500,height=500");
|
|
|
|
is((await nextWindowMessage()).data, "ready", "Expected a 'ready' message");
|
|
|
|
child.postMessage("play-audible", testCase.origin);
|
|
|
|
// Wait for the window to tell us whether it could play video.
|
|
|
|
let result = await nextWindowMessage();
|
2018-07-25 05:25:17 +03:00
|
|
|
is(result.data.allowedToPlay, testCase.shouldPlay, "allowedToPlay - " + testCase.message);
|
|
|
|
is(result.data.played, testCase.shouldPlay, "played - " + testCase.message);
|
2018-04-30 08:40:22 +03:00
|
|
|
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!");
|
|
|
|
|
2018-05-28 13:09:14 +03:00
|
|
|
await testPlayInOrigin({
|
2018-04-30 08:40:22 +03:00
|
|
|
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...
|
2018-05-28 13:09:14 +03:00
|
|
|
await testPlayInOrigin({
|
2018-04-30 08:40:22 +03:00
|
|
|
origin: "http://mochi.test:8888",
|
|
|
|
shouldPlay: true,
|
|
|
|
message: "Should be able to play since whitelisted."
|
|
|
|
});
|
|
|
|
|
|
|
|
// But sub-origins should not.
|
2018-05-28 13:09:14 +03:00
|
|
|
await testPlayInOrigin({
|
2018-04-30 08:40:22 +03:00
|
|
|
origin: "http://test1.mochi.test:8888",
|
|
|
|
shouldPlay: false,
|
|
|
|
message: "Sub origin should not count as whitelisted."
|
|
|
|
});
|
2018-05-28 13:09:14 +03:00
|
|
|
await testPlayInOrigin({
|
2018-04-30 08:40:22 +03:00
|
|
|
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>
|
|
|
|
|
2018-06-27 07:15:58 +03:00
|
|
|
</html>
|