mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 1463919 - Adjust mochitests to pass after changes. r=jya
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
This commit is contained in:
parent
f88fe2a683
commit
21f07622bf
@ -24,6 +24,8 @@
|
||||
playAndPostResult(true, event.source);
|
||||
}
|
||||
}, false);
|
||||
let w = window.opener || window.parent;
|
||||
w.postMessage("ready", "*");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -31,7 +31,7 @@
|
||||
frame.src = origin + "/tests/dom/media/test/file_autoplay_policy_activation_frame.html";
|
||||
// Wait for it to load...
|
||||
document.body.appendChild(frame);
|
||||
await once(frame, "load");
|
||||
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", "*");
|
||||
|
@ -1,54 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Autoplay policy window</title>
|
||||
<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.ok = window.opener.ok;
|
||||
window.is = window.opener.is;
|
||||
window.info = window.opener.info;
|
||||
|
||||
async function testAutoplayPermission(testCase, parentWindow) {
|
||||
info("trying to play origin=" + testCase.origin + " shouldPlay=" + testCase.shouldPlay);
|
||||
const url = testCase.origin + "/tests/dom/media/test/file_autoplay_policy_activation_frame.html"
|
||||
info("canPlayIn " + url);
|
||||
|
||||
// Create a child iframe...
|
||||
var frame = document.createElement("iframe");
|
||||
frame.src = url;
|
||||
// Wait for it to load...
|
||||
document.body.appendChild(frame);
|
||||
info("awaiting loaded");
|
||||
await once(frame, "load");
|
||||
// Ask the child iframe to try to play video.
|
||||
info("loaded, trying to play");
|
||||
frame.contentWindow.postMessage("play-audible", "*");
|
||||
// Wait for the iframe to tell us whether it could play video.
|
||||
let result = await nextWindowMessage();
|
||||
is(result.data.played, testCase.shouldPlay, testCase.message);
|
||||
}
|
||||
|
||||
nextWindowMessage().then(
|
||||
async (event) => {
|
||||
try {
|
||||
await testAutoplayPermission(event.data, event.source);
|
||||
} catch (e) {
|
||||
ok(false, "Caught exception " + e + " " + e.message + " " + e.stackTrace);
|
||||
}
|
||||
event.source.postMessage("done", "*");
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -442,7 +442,6 @@ support-files =
|
||||
file_autoplay_policy_unmute_pauses.html
|
||||
file_autoplay_policy_activation_window.html
|
||||
file_autoplay_policy_activation_frame.html
|
||||
file_autoplay_policy_permission.html
|
||||
file_autoplay_policy_play_before_loadedmetadata.html
|
||||
flac-s24.flac
|
||||
flac-s24.flac^headers^
|
||||
|
@ -16,7 +16,10 @@
|
||||
// Tests that origins with "autoplay-media" permission can autoplay.
|
||||
|
||||
gTestPrefs.push(["media.autoplay.enabled", false],
|
||||
["media.autoplay.enabled.user-gestures-needed", true]);
|
||||
["media.autoplay.enabled.user-gestures-needed", true],
|
||||
// Note: permission prompt disabled, as we want immediate
|
||||
// notification in this test that an origin is blocked.
|
||||
["media.autoplay.ask-permission", false]);
|
||||
|
||||
SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
|
||||
runTest();
|
||||
@ -25,10 +28,13 @@
|
||||
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();
|
||||
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();
|
||||
is(result.data.played, testCase.shouldPlay, testCase.message);
|
||||
child.close();
|
||||
}
|
||||
|
||||
@ -73,4 +79,4 @@
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user