Bug 1434804 - Test that setting a muted-autoplay media to audible pauses media. r?kamidphish draft
authorChris Pearce <cpearce@mozilla.com>
Mon, 12 Mar 2018 14:15:54 +1300
changeset 766379 c9739aa902db3556d185022abf7ee24874aae7d2
parent 766378 6873d13f40f4c6b5fe81fb006d8b1bb3f1f8e77e
push id102308
push userbmo:cpearce@mozilla.com
push dateMon, 12 Mar 2018 20:11:44 +0000
reviewerskamidphish
bugs1434804
milestone60.0a1
Bug 1434804 - Test that setting a muted-autoplay media to audible pauses media. r?kamidphish MozReview-Commit-ID: 7cPgJMvUoja
dom/media/test/file_autoplay_policy_unmute_pauses.html
dom/media/test/mochitest.ini
dom/media/test/test_autoplay_policy_unmute_pauses.html
new file mode 100644
--- /dev/null
+++ b/dom/media/test/file_autoplay_policy_unmute_pauses.html
@@ -0,0 +1,65 @@
+<!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>
+
+        window.is = window.opener.is;
+        window.info = window.opener.info;
+
+        function testAutoplayUnmutePauses(testCase, parent_window) {
+          return new Promise(function (resolve, reject) {
+
+            info("testAutoplayUnmutePauses: " + testCase.property);
+
+            let element = document.createElement("video");
+            element.preload = "auto";
+
+            // Make inaudible.
+            element[testCase.property] = testCase.inaudible;
+
+            // Once we've loaded, play, then make audible.
+            // Assert that the media is paused when we make it audible.
+            element.addEventListener("loadeddata", () => {
+              info("loadeddata");
+              element.play();
+              is(element.paused, false, testCase.property + "=" + testCase.inaudible + " - should be playing");
+              element[testCase.property] = testCase.audible;
+              is(element.paused, true, testCase.property + "=" + testCase.audible + " - should be paused.");
+              resolve();
+            });
+
+            element.src = "short.mp4";
+            element.id = "video";
+            document.body.appendChild(element);
+          });
+        }
+
+        nextWindowMessage().then(
+          (event) => {
+            testAutoplayUnmutePauses(event.data, event.source)
+              .then(() => {
+                event.source.postMessage("done", "*");
+              });
+          });
+
+      </script>
+    </pre>
+</body>
+
+</html>
\ No newline at end of file
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -433,16 +433,17 @@ support-files =
   detodos-short.opus
   detodos-short.opus^headers^
   dirac.ogg
   dirac.ogg^headers^
   dynamic_redirect.sjs
   dynamic_resource.sjs
   eme.js
   file_access_controls.html
+  file_autoplay_policy_unmute_pauses.html
   file_autoplay_policy_activation_window.html
   file_autoplay_policy_activation_frame.html
   flac-s24.flac
   flac-s24.flac^headers^
   flac-noheader-s16.flac
   flac-noheader-s16.flac^headers^
   fragment_noplay.js
   fragment_play.js
@@ -684,16 +685,18 @@ skip-if = android_version == '15' # andr
 skip-if = true # bug 475110 - disabled since we don't play Wave files standalone
 [test_autoplay.html]
 [test_autoplay_contentEditable.html]
 skip-if = android_version == '15' || android_version == '17' || android_version == '22' # android(bug 1232305, bug 1232318, bug 1372457)
 [test_autoplay_policy.html]
 skip-if = android_version == '23' # bug 1424903
 [test_autoplay_policy_activation.html]
 skip-if = android_version == '23' # bug 1424903
+[test_autoplay_policy_unmute_pauses.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_unmute_pauses.html
@@ -0,0 +1,64 @@
+<!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>
+
+        window.is = SimpleTest.is;
+        window.info = SimpleTest.info;
+
+        // Tests that videos can only play audibly in windows/frames
+        // which have been activated by same-origin user gesture.
+
+        gTestPrefs.push(["media.autoplay.enabled", false],
+          ["media.autoplay.enabled.user-gestures-needed", true]);
+
+        SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
+          runTest();
+        });
+
+        let testCases = [
+          {
+            property: "muted",
+            inaudible: true,
+            audible: false,
+          },
+
+          {
+            property: "volume",
+            inaudible: 0.0,
+            audible: 1.0,
+          },
+        ];
+
+        let child_url = "file_autoplay_policy_unmute_pauses.html";
+
+        async function runTest() {
+          for (testCase of testCases) {
+            // Run each test in a new window, to ensure its user gesture
+            // activation state isn't tainted by preceeding tests.
+            let child = window.open(child_url, "", "width=500,height=500");
+            await once(child, "load");
+            child.postMessage(testCase, window.origin);
+            let result = await nextWindowMessage();
+            child.close();
+          }
+          SimpleTest.finish();
+        }
+
+        SimpleTest.waitForExplicitFinish();
+
+      </script>
+    </pre>
+</body>
+
+</html>
\ No newline at end of file