File: document-close-with-pending-script.html

package info (click to toggle)
firefox-esr 91.12.0esr-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,375,668 kB
  • sloc: cpp: 5,762,032; javascript: 5,481,714; ansic: 3,121,206; python: 851,492; asm: 331,174; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (67 lines) | stat: -rw-r--r-- 2,350 bytes parent folder | download | duplicates (26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!doctype html>
<meta charset=utf-8>
<title>document.close called while a script is pending</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
  <script>
    window.t = async_test();
    // We want start a document load, create an non-blocking script load inside
    // it, have the parser complete, then call document.open()/document.close()
    // after the parser is done but before the non-blocking script load
    // completes.  After we do that, the document should reach the 'complete'
    // ready state and the iframe's load event should fire.
    var loadFired = false;
    var i;

    var finish = t.step_func_done(() => {
      assert_equals(loadFired, true, "Should have fired a load event");
      assert_equals(i.contentDocument.readyState, "complete",
                    "Should be fully loaded");
    });

    var checkForLoad = t.step_func(() => {
      if (loadFired) {
        finish();
      } else {
        i.addEventListener("load", finish);
      }
    });

    window.parserDone = t.step_func(() => {
      var doc = i.contentDocument;
      i.onload = () => { loadFired = true; }
      doc.open();
      doc.close();
      // It's not very clearly specced whether the document is
      // supposed to be fully loaded at this point or not, so allow
      // that to be the case, or to happen soonish.
      assert_true(doc.readyState == "interactive" ||
                  doc.readyState == "complete", "Should be almost loaded");
      if (doc.readyState == "complete") {
        checkForLoad();
      } else {
        doc.addEventListener("readystatechange", checkForLoad);
      }
    });

    t.step(() => {
        i = document.createElement("iframe");
        i.srcdoc = `
          <script>
            parent.t.step(() => {
              var s = document.createElement("script");
              s.src = "/common/slow.py";
              document.documentElement.appendChild(s);
              // Call into the parent async, so we finish our "end of parse"
              // work before it runs.
              document.addEventListener(
                "DOMContentLoaded",
                () => parent.t.step_timeout(parent.parserDone, 0));
            });
          <\/script>
        `;
        document.body.appendChild(i);
    });
  </script>
</body>