tor-browser

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

test_crossorigin_iframe.html (1549B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for geolocation is disabled by default, and set
      5    allow="geolocation" in iframe could enable geolcation</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <script class="testbody" type="text/javascript">
     11 
     12 SimpleTest.waitForExplicitFinish();
     13 
     14 var tests = [
     15  // default cross-origin permission is denied
     16  [ null, "denied" ],
     17  [ "geolocation", "allowed"],
     18 ];
     19 
     20 function checkGeolocationResult(test) {
     21  return new Promise(resolve => {
     22    function onMessage(event) {
     23      is(event.data, test[1], "Expected " + test[1] + " for " + test[0]);
     24      window.removeEventListener("message", onMessage);
     25      resolve();
     26    }
     27 
     28    window.addEventListener("message", onMessage);
     29  });
     30 }
     31 
     32 async function nextTest() {
     33  if (!tests.length) {
     34    SimpleTest.finish();
     35    return;
     36  }
     37 
     38  let test = tests.shift();
     39 
     40  var iframe = document.createElement("iframe");
     41  if (test[0]) {
     42    iframe.allow = test[0];
     43  }
     44 
     45  let geolocationPromise = checkGeolocationResult(test);
     46  iframe.src =
     47    "https://example.net/tests/dom/geolocation/test/mochitest/crossorigin_iframe.html";
     48  document.body.appendChild(iframe);
     49  await geolocationPromise;
     50 
     51  document.body.removeChild(iframe);
     52  SimpleTest.executeSoon(nextTest);
     53 }
     54 
     55 SpecialPowers.pushPrefEnv({"set": [
     56  ["dom.security.featurePolicy.header.enabled", true],
     57  ["dom.security.featurePolicy.webidl.enabled", true],
     58 ]}).then(nextTest);
     59 </script>
     60 </body>
     61 </html>