summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/dom/documents/resource-metadata-management/document-readyState.html
blob: 8c91e0a001938f8af7c98eafe26ba47248ccb9a1 (plain)
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
<!DOCTYPE html>
<meta charset=utf-8>
<title>document.readyState</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/#resource-metadata-management">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
  var t1 = async_test("readyState equals 'complete' when the document has loaded"),
      t2 = async_test("readyState equals 'interactive' when the document is finished parsing"),
      t3 = async_test("readystatechange event is fired each time document.readyState changes");

  window.onload = t1.step_func_done(function(){
    assert_equals(document.readyState, "complete");
  });

  document.addEventListener("DOMContentLoaded", function(event) {
    t2.step(function() {
      assert_equals(document.readyState, "interactive")
    });
    t2.done();
  });

  var states = [document.readyState];
  document.onreadystatechange = t3.step_func(function(){
    states.push(document.readyState);
    if (document.readyState === "complete") {
      assert_array_equals(states, ["loading", "interactive", "complete"]);
      t3.done();
    }
  })
</script>