DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<!DOCTYPE HTML>
<html>

<head>
  <title>Autoplay policy window</title>
  <style>
    video {
      width: 50%;
      height: 50%;
    }
    :focus {
      background-color: blue;
    }
  </style>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="manifest.js"></script>
  <script type="text/javascript" src="AutoplayTestUtils.js"></script>
</head>

<body>
  <div id="x">This is a div with id=x.</div>
  <pre id="test">
      <input type="text" id="text-input"/>
      <script>

        window.ok = window.opener.ok;
        window.is = window.opener.is;
        window.info = window.opener.info;

        // Keys that are expected to be not considered interaction with the page, and
        // so not gesture activate the document.
        let blacklistKeyPresses = [
          "Tab",
          "CapsLock",
          "NumLock",
          "ScrollLock",
          "FnLock",
          "Meta",
          "OS",
          "Hyper",
          "Super",
          "ContextMenu",
          "ArrowUp",
          "ArrowDown",
          "ArrowLeft",
          "ArrowRight",
          "PageUp",
          "PageDown",
          "Home",
          "End",
          "Backspace",
          "Fn",
          "Alt",
          "AltGraph",
          "Control",
          "Shift",
          "Escape",
        ];

        let modifiedKeys = [
          { key: "V", modifiers: { altKey: true, shiftKey: true } },
          { key: "a", modifiers: { altKey: true } },
          { key: "a", modifiers: { ctrlKey: true } },
          { key: "KEY_ArrowRight", modifiers: { metaKey: true } },
          { key: "KEY_ArrowRight", modifiers: { altKey: true } },
        ];

        async function sendInput(element, name, input) {
          synthesizeMouseAtCenter(input, {});
          let played = await element.play().then(() => true, () => false);
          ok(!played, "Clicking " + name + " should not activate document and should not unblock play");

          synthesizeCompositionChange({
            composition: {
              string: "\u30E9\u30FC\u30E1\u30F3",
              clauses: [
                { length: 4, attr: COMPOSITION_ATTR_RAW_CLAUSE }
              ]
            },
            caret: { start: 4, length: 0 }
          });
          synthesizeComposition({ type: "compositioncommitasis" });
          played = await element.play().then(() => true, () => false);
          ok(!played, "Entering text to " + name + " via IME should not activate document and should not unblock play");

          input.focus();
          sendString("ascii text");
          played = await element.play().then(() => true, () => false);
          ok(!played, "Entering ASCII text into " + name + " should not activate document and should not unblock play");

          input.blur();
        }

        async function testAutoplayKeyBlacklist(testCase, parent_window) {
          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);
          is(played, false, "Document should start out not activated, with playback blocked.");

          // Try pressing all the keys in the blacklist, then playing.
          // Document should not be activated, so play should fail.

          for (let key of blacklistKeyPresses) {
            document.body.focus();
            synthesizeKey("KEY_" + key);
            played = await element.play().then(() => true, () => false);
            is(played, false, "Key " + key + " should not activate document and should not unblock play");
          }

          // Try pressing some keys with modifiers.
          let keyNames = (m) => Object.keys(m).join("+");
          for (let x of modifiedKeys) {
            document.body.focus();
            synthesizeKey(x.key, x.modifiers);
            played = await element.play().then(() => true, () => false);
            is(played, false, "Key (" + x.key + "+" + keyNames(x.modifiers) + ") should not activate document and should not unblock play");
          }

          // Try pressing a key not in the blacklist, then playing.
          // Document should be activated, and media should play.
          synthesizeKey(" ");
          played = await element.play().then(() => true, () => false);
          is(played, true, "Space key should activate document and should unblock play");

          removeNodeAndSource(element);
        }

        nextWindowMessage().then(
          async (event) => {
            try {
              await testAutoplayKeyBlacklist(event.data, event.source);
            } catch (e) {
              ok(false, "Caught exception " + e + " " + e.message + " " + e.stackTrace);
            }
            event.source.postMessage("done", "*");
          });

      </script>
    </pre>
</body>

</html>