Bug 1441424 - Fix autoplay activation test. r?kamidphish
Post landing of
bug 1193394 test_autoplay_policy_activation was failing.
This is because we weren't clicking the child frame properly in the test.
MozReview-Commit-ID: Ius4GWIX8Ng
--- a/dom/media/test/AutoplayTestUtils.js
+++ b/dom/media/test/AutoplayTestUtils.js
@@ -1,14 +1,12 @@
-function playAndPostResult(test_case, parent_window) {
- log("runTest " + test_case.name);
-
+function playAndPostResult(muted, parent_window) {
let element = document.createElement("video");
element.preload = "auto";
- element.muted = test_case.muted;
+ element.muted = muted;
element.src = "short.mp4";
element.id = "video";
document.body.appendChild(element);
element.play().then(
() => {
parent_window.postMessage({played: true}, "*");
},
--- a/dom/media/test/file_autoplay_policy_activation_frame.html
+++ b/dom/media/test/file_autoplay_policy_activation_frame.html
@@ -1,21 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Autoplay policy frame</title>
<script type="text/javascript" src="AutoplayTestUtils.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<style>
video {
width: 50%;
height: 50%;
}
</style>
</head>
<body>
<script>
- nextWindowMessage().then(
+ window.addEventListener("message",
(event) => {
- playAndPostResult(event.data, event.source);
- });
+ if (event.data == "click") {
+ synthesizeMouseAtCenter(document.body, {});
+ } else if (event.data == "play-audible") {
+ playAndPostResult(false, event.source);
+ } else if (event.data == "play-muted") {
+ playAndPostResult(true, event.source);
+ }
+ }, false);
</script>
</body>
</html>
--- a/dom/media/test/file_autoplay_policy_activation_window.html
+++ b/dom/media/test/file_autoplay_policy_activation_window.html
@@ -14,35 +14,36 @@
<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, parent_window);
+ 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);
await once(frame, "load");
// Click the iframe to activate if appropriate.
if (test_case.activated_child) {
- synthesizeMouseAtCenter(frame, {});
+ frame.contentWindow.postMessage("click", "*");
}
// Ask the child iframe to try to play video.
- frame.contentWindow.postMessage(test_case, "*");
+ 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) => {
--- a/dom/media/test/test_autoplay_policy_activation.html
+++ b/dom/media/test/test_autoplay_policy_activation.html
@@ -71,25 +71,24 @@
name: "inaudible playback in unactivated cross-origin iframe in unactivated parent allowed",
muted: true,
same_origin_child: false,
activated_child: false,
activated_parent: false,
should_play: true,
},
- // TODO: This case fails, Firefox's behaviour needs to be fixed.
- // {
- // name: "audible playback in unactivated cross-origin iframe in activated parent blocked",
- // muted: false,
- // same_origin_child: false,
- // activated_child: false,
- // activated_parent: true,
- // should_play: false,
- // },
+ {
+ name: "audible playback in unactivated cross-origin iframe in activated parent blocked",
+ muted: false,
+ same_origin_child: false,
+ activated_child: false,
+ activated_parent: true,
+ should_play: false,
+ },
{
name: "audible playback in unactivated cross-origin iframe in unactivated parent blocked",
muted: false,
same_origin_child: false,
activated_child: false,
activated_parent: false,
should_play: false,