tor-browser

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

test_autoplay_policy_activation.html (5832B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <head>
      4    <title>Autoplay policy test</title>
      5    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7    <script type="text/javascript" src="manifest.js"></script>
      8    <script type="text/javascript" src="AutoplayTestUtils.js"></script>
      9  </head>
     10  <body>
     11    <pre id="test">
     12      <script>
     13 
     14        // Tests that videos can only play audibly in windows/frames
     15        // which have been activated by same-origin user gesture.
     16 
     17        gTestPrefs.push(["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
     18                        ["media.autoplay.blocking_policy", 0]);
     19 
     20        SpecialPowers.pushPrefEnv({'set': gTestPrefs}, () => {
     21          runTest();
     22        });
     23 
     24        let test_cases = [
     25          {
     26            name: "inaudible playback in unactivated same-origin iframe in activated parent -> allowed",
     27            muted: true,
     28            same_origin_child: true,
     29            activated_from: "parent",
     30            play_from: "child",
     31            should_play: true,
     32          },
     33 
     34          {
     35            name: "inaudible playback in unactivated same-origin iframe in unactivated parent -> allowed",
     36            muted: true,
     37            same_origin_child: true,
     38            activated_from: "none",
     39            play_from: "child",
     40            should_play: true,
     41          },
     42 
     43          {
     44            name: "audible playback in unactivated same-origin iframe in activated parent -> allowed",
     45            muted: false,
     46            same_origin_child: true,
     47            activated_from: "parent",
     48            play_from: "child",
     49            should_play: true,
     50          },
     51 
     52          {
     53            name: "audible playback in unactivated same-origin iframe in unactivated parent -> blocked",
     54            muted: false,
     55            same_origin_child: true,
     56            activated_from: "none",
     57            play_from: "child",
     58            should_play: false,
     59          },
     60 
     61          {
     62            name: "inaudible playback in unactivated cross-origin iframe in activated parent -> allowed",
     63            muted: true,
     64            same_origin_child: false,
     65            activated_from: "parent",
     66            play_from: "child",
     67            should_play: true,
     68          },
     69 
     70          {
     71            name: "inaudible playback in unactivated cross-origin iframe in unactivated parent -> allowed",
     72            muted: true,
     73            same_origin_child: false,
     74            activated_from: "none",
     75            play_from: "child",
     76            should_play: true,
     77          },
     78 
     79          {
     80            name: "audible playback in unactivated cross-origin iframe in activated parent -> allowed",
     81            muted: false,
     82            same_origin_child: false,
     83            activated_from: "parent",
     84            play_from: "child",
     85            should_play: true,
     86          },
     87 
     88          {
     89            name: "audible playback in unactivated cross-origin iframe in unactivated parent -> blocked",
     90            muted: false,
     91            same_origin_child: false,
     92            activated_from: "none",
     93            play_from: "child",
     94            should_play: false,
     95          },
     96 
     97          {
     98            name: "audible playback in activated cross-origin iframe -> allowed",
     99            muted: false,
    100            same_origin_child: false,
    101            activated_from: "child",
    102            play_from: "child",
    103            should_play: true,
    104          },
    105 
    106          {
    107            name: "audible playback in activated document -> allowed",
    108            muted: false,
    109            activated_from: "parent",
    110            play_from: "parent",
    111            should_play: true,
    112          },
    113 
    114          {
    115            name: "audible playback in unactivated document -> blocked",
    116            muted: false,
    117            activated_from: "none",
    118            play_from: "parent",
    119            should_play: false,
    120          },
    121 
    122          {
    123            name: "audible playback in activated document (via cross-origin child) -> allowed",
    124            muted: false,
    125            same_origin_child: false,
    126            activated_from: "child",
    127            play_from: "parent",
    128            should_play: true,
    129          },
    130 
    131          {
    132            name: "audible playback in activated document (via same-origin child) -> allowed",
    133            muted: false,
    134            same_origin_child: true,
    135            activated_from: "child",
    136            play_from: "parent",
    137            should_play: true,
    138          },
    139 
    140          {
    141            name: "inaudible playback in activated document -> allowed",
    142            muted: true,
    143            activated_from: "parent",
    144            play_from: "parent",
    145            should_play: true,
    146          },
    147 
    148          {
    149            name: "inaudible playback in unactivated document -> allowed",
    150            muted: true,
    151            activated_from: "none",
    152            play_from: "parent",
    153            should_play: true,
    154          },
    155 
    156        ];
    157 
    158        let child_url = "file_autoplay_policy_activation_window.html";
    159 
    160        async function runTest() {
    161          for (const test_case of test_cases) {
    162            // Run each test in a new window, to ensure its user gesture
    163            // activation state isn't tainted by preceeding tests.
    164            let child = window.open(child_url, "", "width=500,height=500");
    165            await once(child, "load");
    166            child.postMessage(test_case, window.origin);
    167            let result = await nextWindowMessage();
    168            SimpleTest.is(result.data.allowedToPlay, test_case.should_play, "allowed - " + test_case.name);
    169            SimpleTest.is(result.data.played, test_case.should_play, "played - " + test_case.name);
    170            child.close();
    171          }
    172          SimpleTest.finish();
    173        }
    174 
    175        SimpleTest.waitForExplicitFinish();
    176 
    177      </script>
    178    </pre>
    179  </body>
    180 </html>