tor-browser

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

test_open_javascript_noopener.html (1199B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      7  </head>
      8  <body>
      9  <script>
     10 
     11 add_task(async function test_open_javascript_noopener() {
     12  const topic = "test-javascript-was-run";
     13  function jsuri(version) {
     14    return `javascript:SpecialPowers.notifyObservers(null, "${topic}", "${version}");window.close()`;
     15  }
     16 
     17  let seen = [];
     18  function observer(_subject, _topic, data) {
     19    info(`got notification ${data}`);
     20    seen.push(data);
     21  }
     22  SpecialPowers.addObserver(observer, topic);
     23 
     24  isDeeply(seen, [], "seen no test notifications");
     25  window.open(jsuri("1"));
     26 
     27  // Bounce off the parent process to make sure the JS will have run.
     28  await SpecialPowers.spawnChrome([], () => {});
     29 
     30  isDeeply(seen, ["1"], "seen the opener notification");
     31 
     32  window.open(jsuri("2"), "", "noopener");
     33 
     34  // Bounce off the parent process to make sure the JS will have run.
     35  await SpecialPowers.spawnChrome([], () => {});
     36 
     37  isDeeply(seen, ["1"], "didn't get a notification from the noopener popup");
     38 
     39  SpecialPowers.removeObserver(observer, topic);
     40 });
     41 
     42  </script>
     43  </body>
     44 </html>