tor-browser

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

document-close-with-pending-script.html (2350B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>document.close called while a script is pending</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <body>
      7  <script>
      8    window.t = async_test();
      9    // We want start a document load, create an non-blocking script load inside
     10    // it, have the parser complete, then call document.open()/document.close()
     11    // after the parser is done but before the non-blocking script load
     12    // completes.  After we do that, the document should reach the 'complete'
     13    // ready state and the iframe's load event should fire.
     14    var loadFired = false;
     15    var i;
     16 
     17    var finish = t.step_func_done(() => {
     18      assert_equals(loadFired, true, "Should have fired a load event");
     19      assert_equals(i.contentDocument.readyState, "complete",
     20                    "Should be fully loaded");
     21    });
     22 
     23    var checkForLoad = t.step_func(() => {
     24      if (loadFired) {
     25        finish();
     26      } else {
     27        i.addEventListener("load", finish);
     28      }
     29    });
     30 
     31    window.parserDone = t.step_func(() => {
     32      var doc = i.contentDocument;
     33      i.onload = () => { loadFired = true; }
     34      doc.open();
     35      doc.close();
     36      // It's not very clearly specced whether the document is
     37      // supposed to be fully loaded at this point or not, so allow
     38      // that to be the case, or to happen soonish.
     39      assert_true(doc.readyState == "interactive" ||
     40                  doc.readyState == "complete", "Should be almost loaded");
     41      if (doc.readyState == "complete") {
     42        checkForLoad();
     43      } else {
     44        doc.addEventListener("readystatechange", checkForLoad);
     45      }
     46    });
     47 
     48    t.step(() => {
     49        i = document.createElement("iframe");
     50        i.srcdoc = `
     51          <script>
     52            parent.t.step(() => {
     53              var s = document.createElement("script");
     54              s.src = "/common/slow.py";
     55              document.documentElement.appendChild(s);
     56              // Call into the parent async, so we finish our "end of parse"
     57              // work before it runs.
     58              document.addEventListener(
     59                "DOMContentLoaded",
     60                () => parent.t.step_timeout(parent.parserDone, 0));
     61            });
     62          <\/script>
     63        `;
     64        document.body.appendChild(i);
     65    });
     66  </script>
     67 </body>