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 (409f3966645a)

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 149 150 151 152 153 154 155 156 157 158
<!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 videos can only play audibly in windows/frames
        // which have been activated by same-origin user gesture.

        gTestPrefs.push(["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
                        ["media.autoplay.enabled.user-gestures-needed", true]);

        SpecialPowers.pushPrefEnv({'set': gTestPrefs}, () => {
          runTest();
        });

        let test_cases = [
          {
            name: "inaudible playback in unactivated same-origin iframe in activated parent allowed",
            muted: true,
            same_origin_child: true,
            activated_child: false,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated same-origin iframe in unactivated parent allowed",
            muted: true,
            same_origin_child: true,
            activated_child: false,
            activated_parent: false,
            should_play: true,
          },

          {
            name: "audible playback in unactivated same-origin iframe in activated parent allowed",
            muted: false,
            same_origin_child: true,
            activated_child: false,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "audible playback in unactivated same-origin iframe in unactivated parent blocked",
            muted: false,
            same_origin_child: true,
            activated_child: false,
            activated_parent: false,
            should_play: false,
          },

          {
            name: "inaudible playback in unactivated cross-origin iframe in activated parent allowed",
            muted: true,
            same_origin_child: false,
            activated_child: false,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated cross-origin iframe in unactivated parent allowed",
            muted: true,
            same_origin_child: false,
            activated_child: false,
            activated_parent: false,
            should_play: true,
          },

          {
            name: "audible playback in unactivated cross-origin iframe in activated parent allowed",
            muted: false,
            same_origin_child: false,
            activated_child: false,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "audible playback in unactivated cross-origin iframe in unactivated parent blocked",
            muted: false,
            same_origin_child: false,
            activated_child: false,
            activated_parent: false,
            should_play: false,
          },

          {
            name: "audible playback in activated cross-origin iframe allowed",
            muted: false,
            same_origin_child: false,
            activated_child: true,
            activated_parent: false,
            should_play: true,
          },

          {
            name: "audible playback in activated document allowed",
            muted: false,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "audible playback in unactivated document blocked",
            muted: false,
            activated_parent: false,
            should_play: false,
          },

          {
            name: "inaudible playback in activated document allowed",
            muted: true,
            activated_parent: true,
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated document allowed",
            muted: true,
            activated_parent: false,
            should_play: true,
          },

        ];

        let child_url = "file_autoplay_policy_activation_window.html";

        async function runTest() {
          for (test_case of test_cases) {
            // 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(test_case, window.origin);
            let result = await nextWindowMessage();
            SimpleTest.is(result.data.allowedToPlay, test_case.should_play, "allowed - " + test_case.name);
            SimpleTest.is(result.data.played, test_case.should_play, "played - " + test_case.name);
            child.close();
          }
          SimpleTest.finish();
        }

        SimpleTest.waitForExplicitFinish();

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