File: scrollingElement.html

package info (click to toggle)
firefox-esr 140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,276 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,918; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (138 lines) | stat: -rw-r--r-- 5,901 bytes parent folder | download | duplicates (7)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<meta charset=utf-8>
<title>cssom-view - scrollingElement</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
function makeDescription(rootDisplay, bodyDisplay) {
  let a = [];
  if (rootDisplay) {
    a.push(`root ${rootDisplay}`);
  }
  if (bodyDisplay) {
    a.push(`body ${bodyDisplay}`);
  }
  let s = a.join(", ");
  if (s) {
    s = ` (${s})`;
  }
  return s;
}

function quirksTest(rootDisplay, bodyDisplay) {
  async_test(function() {
    let quirksFrame = document.createElement("iframe");
    quirksFrame.onload = this.step_func_done(function() {
      var quirksDoc = quirksFrame.contentDocument;
      assert_equals(quirksDoc.compatMode, "BackCompat", "Should be in quirks mode.");
      assert_not_equals(quirksDoc.body, null, "Should have a body element");

      quirksDoc.documentElement.style.display = rootDisplay;
      quirksDoc.body.style.display = bodyDisplay;

      // Tests for quirks mode document.
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body,
        "scrollingElement in quirks mode should default to body element.");

      quirksDoc.documentElement.style.overflow = "clip";
      quirksDoc.body.style.overflow = "auto";
      assert_equals(quirksDoc.scrollingElement, null);
      quirksDoc.body.style.overflow = "hidden";
      assert_equals(quirksDoc.scrollingElement, null);
      quirksDoc.body.style.overflow = "scroll";
      assert_equals(quirksDoc.scrollingElement, null);
      quirksDoc.body.style.overflow = "visible";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
      quirksDoc.body.style.overflow = "clip";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);

      quirksDoc.documentElement.style.overflow = "scroll";
      quirksDoc.body.style.overflow = "scroll";
      assert_equals(quirksDoc.scrollingElement, null,
        "scrollingElement in quirks mode should be null if overflow of body and root element isn't visible.");
      quirksDoc.documentElement.style.overflow = "visible";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
      quirksDoc.documentElement.style.overflow = "scroll";
      quirksDoc.body.style.overflow = "visible";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
      quirksDoc.documentElement.style.overflow = "visible";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);

      quirksDoc.body.style.display = "none";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body)
      quirksDoc.body.style.display = "block";
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);

      quirksDoc.documentElement.appendChild(quirksDoc.createElement("body"));
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
      assert_equals(quirksDoc.scrollingElement, quirksDoc.getElementsByTagName("body")[0]);
      quirksDoc.documentElement.removeChild(quirksDoc.documentElement.lastChild);
      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);

      quirksDoc.documentElement.removeChild(quirksDoc.body);
      assert_equals(quirksDoc.scrollingElement, null);
      quirksDoc.documentElement.appendChild(quirksDoc.createElementNS("foobarNS", "body"));
      assert_equals(quirksDoc.scrollingElement, null);

      quirksDoc.removeChild(quirksDoc.documentElement);
      assert_equals(quirksDoc.scrollingElement, null);

      quirksDoc.appendChild(quirksDoc.createElementNS("foobarNS", "html"));
      quirksDoc.documentElement.appendChild(quirksDoc.createElement("body"));
      assert_equals(quirksDoc.scrollingElement, null);

      quirksDoc.removeChild(quirksDoc.documentElement);
      quirksDoc.appendChild(quirksDoc.createElement("body"));
      assert_equals(quirksDoc.scrollingElement, null);

      quirksFrame.remove();
    });
    quirksFrame.src =
      URL.createObjectURL(new Blob([], { type: "text/html" }));
    document.body.append(quirksFrame);
  }, `scrollingElement in quirks mode${makeDescription(rootDisplay, bodyDisplay)}`);
}

function nonQuirksTest(rootDisplay, bodyDisplay) {
  async_test(function() {
    let nonQuirksFrame = document.createElement("iframe");
    nonQuirksFrame.onload = this.step_func_done(function() {
      var nonQuirksDoc = nonQuirksFrame.contentDocument;
      assert_equals(nonQuirksDoc.compatMode, "CSS1Compat", "Should be in standards mode.");
      assert_not_equals(nonQuirksDoc.body, null, "Should have a body element");

      nonQuirksDoc.documentElement.style.display = rootDisplay;
      nonQuirksDoc.body.style.display = bodyDisplay;

      assert_equals(nonQuirksDoc.scrollingElement, nonQuirksDoc.documentElement,
        "scrollingElement in standards mode should be the document element.");

      for (let rootOverflow of ["", "clip", "scroll", "hidden", "visible"]) {
        for (let bodyOverflow of ["", "clip", "scroll", "hidden", "visible"]) {
          nonQuirksDoc.documentElement.style.overflow = rootOverflow;
          nonQuirksDoc.body.style.overflow = bodyOverflow;
          assert_equals(nonQuirksDoc.scrollingElement, nonQuirksDoc.documentElement);
        }
      }

      nonQuirksDoc.removeChild(nonQuirksDoc.documentElement);
      assert_equals(nonQuirksDoc.scrollingElement, null);
      nonQuirksDoc.appendChild(nonQuirksDoc.createElement("foobar"));
      assert_equals(nonQuirksDoc.scrollingElement.localName, "foobar");

      nonQuirksFrame.remove();
    });
    nonQuirksFrame.src =
      URL.createObjectURL(new Blob([`<!doctype html>`], { type: "text/html" }));
    document.body.append(nonQuirksFrame);
  }, `scrollingElement in no-quirks mode ${makeDescription(rootDisplay, bodyDisplay)}`);
}

for (let rootDisplay of ["", "table"]) {
  for (let bodyDisplay of ["", "table"]) {
    quirksTest(rootDisplay, bodyDisplay);
    nonQuirksTest(rootDisplay, bodyDisplay);
  }
}
</script>