tor-browser

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

document-base-url-window-initiator-is-not-opener.https.window.js (1380B)


      1 // Tests that a popup about:blank window inherits its base url from
      2 // the initiator, and not the opener.
      3 const runTest = (description) => {
      4  const opener_base_uri = document.baseURI;
      5 
      6  promise_test((test) => {
      7    return new Promise(async resolve => {
      8      window.popup = window.open();
      9      test.add_cleanup(() => popup.close());
     10      assert_equals(window.popup.location.href, 'about:blank');
     11 
     12      // Create iframe to be the initiator.
     13      const iframe = document.createElement('iframe');
     14      iframe.srcdoc = `
     15      <head>
     16      <base href='https://example.com'>
     17      <script>
     18        window.top.popup.location.href = 'about:blank';
     19      </scr` + `ipt>
     20      </head>
     21      <body></body>
     22      `;
     23 
     24      const popup_navigated = new Promise(r => window.popup.onpagehide = e => r());
     25      document.body.append(iframe);
     26      await popup_navigated;  // This makes sure the old child has unloaded, but
     27                             // with the timeout below it's really not needed.
     28 
     29      // This is necessary, or else the test times out. The about:blank load
     30      // does not fire an onload event we can access.
     31      test.step_timeout(resolve, 500);
     32    }).then(() => {
     33      assert_equals('https://example.com/', window.popup.document.baseURI);
     34    });
     35  }, description);
     36 };
     37 
     38 onload = () => {
     39  runTest("window.open() gets base url from initiator not opener.");
     40 };