tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_autoplay_policy_permission.html (2922B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 
      4 <head>
      5  <title>Autoplay policy test</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <script type="text/javascript" src="manifest.js"></script>
      9  <script type="text/javascript" src="AutoplayTestUtils.js"></script>
     10 </head>
     11 
     12 <body>
     13  <pre id="test">
     14      <script>
     15 
     16        // Tests that origins with "autoplay-media" permission can autoplay.
     17 
     18        gTestPrefs.push(["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
     19          ["media.autoplay.blocking_policy", 0]);
     20 
     21        SpecialPowers.pushPrefEnv({ 'set': gTestPrefs }, () => {
     22          runTest();
     23        });
     24 
     25        async function testPlayInOrigin(testCase) {
     26          // Run test in a new window, to ensure its user gesture
     27          // activation state isn't tainted by preceeding tests.
     28          let url = testCase.origin + "/tests/dom/media/autoplay/test/mochitest/file_autoplay_policy_activation_frame.html";
     29          let child = window.open(url, "", "width=500,height=500");
     30          is((await nextWindowMessage()).data, "ready", "Expected a 'ready' message");
     31          child.postMessage("play-audible", testCase.origin);
     32          // Wait for the window to tell us whether it could play video.
     33          let result = await nextWindowMessage();
     34          is(result.data.allowedToPlay, testCase.shouldPlay, "allowedToPlay - " + testCase.message);
     35          is(result.data.played, testCase.shouldPlay, "played - " + testCase.message);
     36          child.close();
     37        }
     38 
     39        async function runTest() {
     40          // First verify that we can't play in a document unwhitelisted.
     41          is(window.origin, "http://mochi.test:8888", "Origin should be as we assume, otherwise the rest of the test is bogus!");
     42 
     43          await testPlayInOrigin({
     44            origin: "http://mochi.test:8888",
     45            shouldPlay: false,
     46            message: "Should not be able to play unwhitelisted."
     47          });
     48 
     49          // Add our origin to the whitelist.
     50          await pushAutoplayAllowedPermission();
     51 
     52          // Now we should be able to play...
     53          await testPlayInOrigin({
     54            origin: "http://mochi.test:8888",
     55            shouldPlay: true,
     56            message: "Should be able to play since whitelisted."
     57          });
     58 
     59          // But sub-origins should not.
     60          await testPlayInOrigin({
     61            origin: "http://test1.mochi.test:8888",
     62            shouldPlay: false,
     63            message: "Sub origin should not count as whitelisted."
     64          });
     65          await testPlayInOrigin({
     66            origin: "http://sub1.test1.mochi.test:8888",
     67            shouldPlay: false,
     68            message: "Sub-sub-origins should not count as whitelisted."
     69          });
     70 
     71          SimpleTest.finish();
     72        }
     73 
     74        SimpleTest.waitForExplicitFinish();
     75 
     76      </script>
     77    </pre>
     78 </body>
     79 
     80 </html>