Bug 1463919 - Adjust mochitests to pass after changes. r=jya draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 27 Jun 2018 16:15:58 +1200
changeset 813234 8ecd0e58200d79f0065a6d7b146d1d110d35953d
parent 813233 5cf26822c9e5f23a83d69f5f52c39be6ab6f9eb0
child 813235 0e475316f2e8de538204e663078af430eacbf1eb
push id114832
push userbmo:cpearce@mozilla.com
push dateMon, 02 Jul 2018 19:32:21 +0000
reviewersjya
bugs1463919
milestone63.0a1
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
dom/media/test/file_autoplay_policy_activation_frame.html
dom/media/test/file_autoplay_policy_activation_window.html
dom/media/test/file_autoplay_policy_permission.html
dom/media/test/mochitest.ini
dom/media/test/test_autoplay_policy_permission.html
--- a/dom/media/test/file_autoplay_policy_activation_frame.html
+++ b/dom/media/test/file_autoplay_policy_activation_frame.html
@@ -19,11 +19,13 @@
           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);
+      let w = window.opener || window.parent;
+      w.postMessage("ready", "*");
     </script>
   </body>
 </html>
--- a/dom/media/test/file_autoplay_policy_activation_window.html
+++ b/dom/media/test/file_autoplay_policy_activation_window.html
@@ -26,17 +26,17 @@
           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");
+          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.
deleted file mode 100644
--- a/dom/media/test/file_autoplay_policy_permission.html
+++ /dev/null
@@ -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>
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -437,17 +437,16 @@ support-files =
   dynamic_resource.sjs
   eme.js
   file_access_controls.html
   file_autoplay_policy_eventdown_activation.html
   file_autoplay_policy_key_blacklist.html
   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^
   flac-noheader-s16.flac
   flac-noheader-s16.flac^headers^
   fragment_noplay.js
   fragment_play.js
   gizmo.mp4
--- a/dom/media/test/test_autoplay_policy_permission.html
+++ b/dom/media/test/test_autoplay_policy_permission.html
@@ -11,29 +11,35 @@
 
 <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]);
+          ["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();
         });
 
         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();
         }
 
         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({
@@ -68,9 +74,9 @@
         }
 
         SimpleTest.waitForExplicitFinish();
 
       </script>
     </pre>
 </body>
 
-</html>
\ No newline at end of file
+</html>