tor-browser

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

opener.html (1850B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Auxiliary Browsing Contexts: window.opener</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7    <script src="/common/PrefixedLocalStorage.js"></script>
      8  </head>
      9  <body>
     10    <div id="log"></div>
     11    <script>
     12    var prefixedLocalStorage;
     13    setup (() => {
     14      window.name = 'topWindow';
     15      prefixedLocalStorage = new PrefixedLocalStorageTest();
     16    });
     17 
     18    function cleanup () {
     19      prefixedLocalStorage.setItem('closeAll', 'true');
     20      prefixedLocalStorage.clear();
     21    }
     22 
     23    function testOpener (t, target) {
     24      t.add_cleanup(cleanup);
     25      window.addEventListener('message', t.step_func(e => {
     26        if (e.data.name === target) {
     27          // The opener IDL attribute...must return the WindowProxy object of the
     28          // browsing context from which the current browsing context was created
     29          assert_equals(e.data.openerName, 'topWindow');
     30          // Auxiliary browsing contexts are always top-level browsing contexts
     31          assert_equals(e.data.isTop, true);
     32          t.done();
     33        }
     34      }));
     35    }
     36 
     37    async_test(t => {
     38      var target = 'windowOpenerA';
     39      var a      = document.createElement('a');
     40      a.href     = prefixedLocalStorage.url('resources/message-window-opener.html');
     41      a.target   = target;
     42      document.body.appendChild(a);
     43      testOpener(t, target);
     44      a.click();
     45    }, 'Newly-created auxiliary browsing context should report `window.opener`');
     46 
     47    async_test(t => {
     48      var target = 'windowOpenerB';
     49      testOpener(t, target);
     50      window.open(prefixedLocalStorage.url('resources/message-window-opener.html'),
     51        target);
     52    }, 'Browsing context created with `window.open` should report `window.opener`');
     53    </script>
     54  </body>
     55 </html>