Bug 1456037 - Test that documents gesture activate on key/mouse down instead of up. r=masayuki
☠☠ backed out by b22046e5f4d5 ☠ ☠
authorChris Pearce <cpearce@mozilla.com>
Mon, 23 Apr 2018 15:53:25 +1200
changeset 471322 10ac210e88db65412b3a62ae99a15dbb883ba0d1
parent 471321 e3b70cecf47160d7184cd88caf2f541728b29ba5
child 471323 b22046e5f4d540dfe506a43e9810c03516c3746b
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)
reviewersmasayuki
bugs1456037
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 1456037 - Test that documents gesture activate on key/mouse down instead of up. r=masayuki MozReview-Commit-ID: AGZM0JdSUDv
dom/media/test/file_autoplay_policy_eventdown_activation.html
dom/media/test/mochitest.ini
dom/media/test/test_autoplay_policy_eventdown_activation.html
new file mode 100644
--- /dev/null
+++ b/dom/media/test/file_autoplay_policy_eventdown_activation.html
@@ -0,0 +1,85 @@
+<!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.ok = window.opener.ok;
+        window.is = window.opener.is;
+        window.info = window.opener.info;
+
+        async function testEventDownActivates(eventNames, activator) {
+          let element = document.createElement("video");
+          element.preload = "auto";
+          element.src = "short.mp4";
+          document.body.appendChild(element);
+
+          await once(element, "loadedmetadata");
+
+          let played = await element.play().then(() => true, () => false);
+          ok(!played, "Document should start out not activated, with playback blocked.");
+
+          let x = eventNames.map(
+            (eventName) => {
+              return new Promise(async function (resolve, reject) {
+                window.addEventListener(eventName, async function (event) {
+                  let played = await element.play().then(() => true, () => false);
+                  ok(played, "Expect to be activated already in " + eventName);
+                  resolve();
+                }, false);
+              });
+            });
+
+          activator();
+
+          await Promise.all(x);
+
+          removeNodeAndSource(element);
+        }
+
+        nextWindowMessage().then(
+          async (event) => {
+            try {
+              if (event.data == "run keydown test") {
+                await testEventDownActivates(["keydown", "keypress", "keyup"], () => {
+                  document.body.focus();
+                  synthesizeKey(" ");
+                });
+              } else if (event.data == "run mousedown test") {
+                let events = ["mousedown", "mouseup", "click"];
+                if (getAndroidVersion() < 0) {
+                  // Non-Android, also listen on pointer events.
+                  events.push("pointerdown", "pointerup");
+                }
+                await testEventDownActivates(events, () => {
+                  synthesizeMouseAtCenter(document.body, {});
+                });
+              } else {
+                ok(false, "unexpected message");
+              }
+            } 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
@@ -432,16 +432,17 @@ support-files =
   detodos-recorder-test.opus^headers^
   detodos-short.opus
   detodos-short.opus^headers^
   dirac.ogg
   dirac.ogg^headers^
   dynamic_resource.sjs
   eme.js
   file_access_controls.html
+  file_autoplay_policy_eventdown_activation.html
   file_autoplay_policy_unmute_pauses.html
   file_autoplay_policy_activation_window.html
   file_autoplay_policy_activation_frame.html
   file_autoplay_policy_play_before_loadedmetadata.html
   flac-s24.flac
   flac-s24.flac^headers^
   flac-noheader-s16.flac
   flac-noheader-s16.flac^headers^
@@ -689,16 +690,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_eventdown_activation.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_buffered.html]
 skip-if = android_version == '15' || android_version == '22' # bug 1308388, android(bug 1232305)
 [test_bug448534.html]
 [test_bug463162.xhtml]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_autoplay_policy_eventdown_activation.html
@@ -0,0 +1,55 @@
+<!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 we gesture activate on mousedown and keydown.
+
+        gTestPrefs.push(["media.autoplay.enabled", false],
+          ["media.autoplay.enabled.user-gestures-needed", true]);
+
+        SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
+          runTest();
+        });
+
+        let child_url = "file_autoplay_policy_eventdown_activation.html";
+
+        async function runTest() {
+          // Run 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("run keydown test", window.origin);
+            let result = await nextWindowMessage();
+            child.close();
+          }
+
+          {
+            let child = window.open(child_url, "", "width=500,height=500");
+            await once(child, "load");
+            child.postMessage("run mousedown test", window.origin);
+            let result = await nextWindowMessage();
+            child.close();
+          }
+
+          SimpleTest.finish();
+        }
+
+        SimpleTest.waitForExplicitFinish();
+
+      </script>
+    </pre>
+</body>
+
+</html>
\ No newline at end of file