dom/media/test/file_autoplay_policy_eventdown_activation.html
author Dorel Luca <dluca@mozilla.com>
Sat, 12 Jan 2019 01:28:30 +0200
changeset 453595 c45da646fc6140bd59a36bda18f6cecde6163feb
parent 415356 10ac210e88db65412b3a62ae99a15dbb883ba0d1
child 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Backed out changeset 24243f13c895 (bug 1519308) for build bustage in mozbuild/mozbuild/test/configure/test_checks_configure.py. CLOSED TREE

<!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>