mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 04:35:33 +00:00
21f07622bf
Prior to the changes in this bug, a document would request autoplay permission for its own origin, and not use the top level document's origin for the permission check. Since now we use the top level document's origin for requesting autoplay permission, some mochitests need to change, namely: * test_autoplay_policy_permission.html can use file_autoplay_policy_activation_frame.html directly. The test was failing because its helper page was loaded same origin and the helper page was testing if cross origin iframes could play; since we use the top level document's permission request, this no longer effectively tests whether the cross origin child can autoplay, as the cross origin child just uses the top level window's origin for requests. So we can instead load the helper window cross orgin instead, and remove one helper layer. Also an issue here is the way I was waiting for a new window to load was racy, so now we wait for loading windows to send us a "ready" message. * test_autoplay_policy_activation.html; this test's helper needs to wait for loading windows to send it a "ready" message, as its helper is shared with the above test. MozReview-Commit-ID: LvRa4G7tqFw --HG-- extra : rebase_source : 8ecd0e58200d79f0065a6d7b146d1d110d35953d
67 lines
2.5 KiB
HTML
67 lines
2.5 KiB
HTML
<!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>
|
|
|
|
function testAutoplayInWindow(test_case, parent_window) {
|
|
log("testAutoplayInWindow: " + test_case.name);
|
|
playAndPostResult(test_case.muted, parent_window);
|
|
}
|
|
|
|
async function testAutoplayInChildFrame(test_case, parent_window) {
|
|
log("testAutoplayInChildFrame: " + test_case.name);
|
|
// Create a child iframe...
|
|
var frame = document.createElement("iframe");
|
|
var origin = test_case.same_origin_child
|
|
? "http://mochi.test:8888" : "http://example.org";
|
|
frame.src = origin + "/tests/dom/media/test/file_autoplay_policy_activation_frame.html";
|
|
// Wait for it to load...
|
|
document.body.appendChild(frame);
|
|
is((await nextWindowMessage()).data, "ready", "Expected a 'ready' message");
|
|
// Click the iframe to activate if appropriate.
|
|
if (test_case.activated_child) {
|
|
frame.contentWindow.postMessage("click", "*");
|
|
}
|
|
// Ask the child iframe to try to play video.
|
|
let play_message = test_case.muted ? "play-muted" : "play-audible";
|
|
frame.contentWindow.postMessage(play_message, "*");
|
|
// Wait for the iframe to tell us whether it could play video.
|
|
let result = await nextWindowMessage();
|
|
// Report whether the iframe could play to the parent.
|
|
parent_window.postMessage(result.data, "*");
|
|
}
|
|
|
|
nextWindowMessage().then(
|
|
(event) => {
|
|
let test_case = event.data;
|
|
// Click the window to activate if appropriate.
|
|
if (test_case.activated_parent) {
|
|
synthesizeMouseAtCenter(document.body, {});
|
|
}
|
|
let parent_window = event.source;
|
|
if (test_case.same_origin_child === undefined) {
|
|
testAutoplayInWindow(test_case, parent_window);
|
|
} else {
|
|
testAutoplayInChildFrame(test_case, parent_window);
|
|
}
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|