tor-browser

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

test_allowMedia.html (2481B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=759964
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 759964</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 759964 */
     14 
     15 SimpleTest.waitForExplicitFinish();
     16 addLoadEvent(runNextTest);
     17 
     18 var SJS = `${location.origin}/tests/dom/html/test/allowMedia.sjs`;
     19 var TEST_PAGE = "data:text/html,<audio src='" + SJS + "?audio'></audio>";
     20 
     21 function runNextTest() {
     22  var test = tests.shift();
     23  if (!test) {
     24    SimpleTest.finish();
     25    return;
     26  }
     27  test();
     28 }
     29 
     30 var tests = [
     31 
     32  // Set allowMedia = false, load a page with <audio>, verify the <audio>
     33  // doesn't load its source.
     34  function basic() {
     35    var iframe = insertIframe();
     36    SpecialPowers.allowMedia(iframe.contentWindow, false);
     37    loadIframe(iframe, TEST_PAGE, function () {
     38      verifyPass();
     39      iframe.remove();
     40      runNextTest();
     41    });
     42  },
     43 
     44  // Set allowMedia = false on parent docshell, load a page with <audio> in a
     45  // child iframe, verify the <audio> doesn't load its source.
     46  function inherit() {
     47    SpecialPowers.allowMedia(window, false);
     48 
     49    var iframe = insertIframe();
     50    loadIframe(iframe, TEST_PAGE, function () {
     51      verifyPass();
     52      iframe.remove();
     53      SpecialPowers.allowMedia(window, true);
     54      runNextTest();
     55    });
     56  },
     57 
     58  // In a display:none iframe, set allowMedia = false, load a page with <audio>,
     59  // verify the <audio> doesn't load its source.
     60  function displayNone() {
     61    var iframe = insertIframe();
     62    iframe.style.display = "none";
     63    SpecialPowers.allowMedia(iframe.contentWindow, false);
     64    loadIframe(iframe, TEST_PAGE, function () {
     65      verifyPass();
     66      iframe.remove();
     67      runNextTest();
     68    });
     69  },
     70 ];
     71 
     72 function insertIframe() {
     73  var iframe = document.createElement("iframe");
     74  document.body.appendChild(iframe);
     75  return iframe;
     76 }
     77 
     78 function loadIframe(iframe, url, onDone) {
     79  iframe.setAttribute("src", url);
     80  iframe.addEventListener("load", onDone);
     81 }
     82 
     83 function verifyPass() {
     84  var xhr = new XMLHttpRequest();
     85  xhr.open("GET", SJS, false);
     86  xhr.send();
     87  is(xhr.responseText, "PASS", "<audio> source should not have been loaded.");
     88 }
     89 
     90  </script>
     91 </head>
     92 <body>
     93 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=759964">Mozilla Bug 759964</a>
     94 <p id="display">
     95 </p>
     96 </body>
     97 </html>