tor-browser

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

window-top-null.html (2298B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>window.top: `null`</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <div id="log"></div>
      7 <script>
      8 async_test(function (t) {
      9  var iframe = document.createElement('iframe');
     10  iframe.onload  = t.step_func_done(() => {
     11    var iWindow = iframe.contentWindow;
     12    /**
     13     * `top` should return the top-level browsing context but will return
     14     * `null` if none exists, such as when any of the BC's ancestor browsing
     15     *  context container's document elements are disconnected/removed.
     16     */
     17    assert_equals(iWindow.top, window);
     18    document.body.removeChild(iframe);
     19    assert_equals(iWindow.top, null);
     20  });
     21 
     22  document.body.appendChild(iframe);
     23 }, '`window.top` is null when browsing context container element removed');
     24 
     25 async_test(t => {
     26  var iframe = document.createElement('iframe');
     27  var iframe2, removedEl;
     28 
     29  var testFunc = t.step_func(() => {
     30    var frameWindow = iframe.contentWindow;
     31    var frame2Window = iframe2.contentWindow;
     32 
     33    assert_equals(frameWindow.top, window);
     34    assert_equals(frame2Window.top, window);
     35 
     36    iframe.removeEventListener('load', nestFrame);
     37    iframe2.removeEventListener('load', testFunc);
     38 
     39    removedEl = document.body.removeChild(iframe);
     40 
     41    assert_equals(frameWindow.top, null);
     42    assert_equals(frame2Window.top, null);
     43 
     44    removedEl.addEventListener('load', t.step_func_done(() => {
     45      // reattached iframe's browsing context will report window.top
     46      assert_equals(removedEl.contentWindow.top, window);
     47      // removed/re-added iframes will have new browsing context / window
     48      assert_equals(frameWindow.top, null);
     49      assert_equals(frame2Window.top, null);
     50    }));
     51 
     52    document.body.appendChild(removedEl);
     53  });
     54 
     55  var nestFrame = function () {
     56    iframe2 = iframe.contentDocument.createElement('iframe');
     57    // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1229707
     58    iframe2.src = '/common/blank.html';
     59    iframe2.addEventListener('load', testFunc);
     60    iframe.contentDocument.body.appendChild(iframe2);
     61  };
     62 
     63  iframe.addEventListener('load', nestFrame);
     64  document.body.appendChild(iframe);
     65 }, '`window.top`null when any ancestor browsing context container removed');
     66 </script>