Bug 1457048 - Test that whitelisted origins are able to autoplay. r=bryce
☠☠ backed out by 5bf13799a1fc ☠ ☠
authorChris Pearce <cpearce@mozilla.com>
Mon, 30 Apr 2018 17:40:22 +1200
changeset 472854 cd70fc188bc877c9ccee93ece83135555a45cc93
parent 472853 34a5f8bd932c7a907c25ba01fd292416a6a186ff
child 472855 a5d71f8bf413dad54fdb107bf037bcecc7ad92c4
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1457048
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1457048 - Test that whitelisted origins are able to autoplay. r=bryce MozReview-Commit-ID: 9kLIx8MzCY8
dom/media/test/AutoplayTestUtils.js
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/AutoplayTestUtils.js
+++ b/dom/media/test/AutoplayTestUtils.js
@@ -20,8 +20,20 @@ function nextWindowMessage() {
   return nextEvent(window, "message");
 }
 
 function log(msg) {
   var log_pane = document.body;
   log_pane.appendChild(document.createTextNode(msg));
   log_pane.appendChild(document.createElement("br"));
 }
+
+const autoplayPermission = "autoplay-media";
+
+async function pushAutoplayAllowedPermission() {
+  return new Promise((resolve, reject) => {
+    SpecialPowers.pushPermissions([{
+      'type': autoplayPermission,
+      'allow': true,
+      'context': document
+    }], resolve);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/dom/media/test/file_autoplay_policy_permission.html
@@ -0,0 +1,54 @@
+<!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,16 +437,17 @@ 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
@@ -699,16 +700,18 @@ skip-if = android_version == '23' # bug 
 [test_autoplay_policy_eventdown_activation.html]
 skip-if = android_version == '23' # bug 1424903
 [test_autoplay_policy_key_blacklist.html]
 skip-if = android_version == '23' # bug 1424903
 [test_autoplay_policy_unmute_pauses.html]
 skip-if = android_version == '23' # bug 1424903
 [test_autoplay_policy_play_before_loadedmetadata.html]
 skip-if = android_version == '23' # bug 1424903
+[test_autoplay_policy_permission.html]
+skip-if = android_version == '23' # bug 1424903
 [test_buffered.html]
 skip-if = android_version == '15' || android_version == '22' # bug 1308388, android(bug 1232305)
 [test_bug448534.html]
 [test_bug463162.xhtml]
 [test_bug465498.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_bug495145.html]
 skip-if = (os == 'mac' && os_version == '10.6') || (toolkit == 'android')  # bug 1311229, android(bug 1232305)
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_autoplay_policy_permission.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+
+<head>
+  <title>Autoplay policy test</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <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.
+
+        gTestPrefs.push(["media.autoplay.enabled", false],
+          ["media.autoplay.enabled.user-gestures-needed", true]);
+
+        SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
+          runTest();
+        });
+
+        async function canPlayIn(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, "*");
+          let result = await nextWindowMessage();
+          child.close();
+          return result.played == true;
+        }
+
+        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 canPlayIn({
+            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...
+          await canPlayIn({
+            origin: "http://mochi.test:8888",
+            shouldPlay: true,
+            message: "Should be able to play since whitelisted."
+          });
+
+          // But sub-origins should not.
+          await canPlayIn({
+            origin: "http://test1.mochi.test:8888",
+            shouldPlay: false,
+            message: "Sub origin should not count as whitelisted."
+          });
+          await canPlayIn({
+            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>
+
+</html>
\ No newline at end of file