3 <script src=
"../../resources/js-test.js"></script>
5 <div><!-- Extra divs so it's clear when we're doing a full document recalc -->
17 <div class=
"foo">foo
</div>
18 <div class=
"foo">foo
</div>
19 <div class=
"foo">foo
</div>
20 <div class=
"bar">bar
</div>
21 <div class=
"bar">bar
</div>
22 <div class=
"bar">bar
</div>
23 <div class=
"baz">baz
</div>
24 <div class=
"baz">baz
</div>
25 <div class=
"baz">baz
</div>
27 function createSheet(selector
)
29 var sheet
= document
.createElement('style');
30 sheet
.textContent
= selector
+ ' { color: red }';
34 function addSheet(selector
)
36 var sheet
= createSheet(selector
);
37 document
.head
.appendChild(sheet
);
41 if (window
.internals
) {
42 // Add sheet with non-existant classname.
43 document
.documentElement
.offsetTop
;
44 var nonexistantSheet
= addSheet('.nonexistant');
45 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "0");
47 // Remove sheet with non-existant classname.
48 document
.documentElement
.offsetTop
;
49 nonexistantSheet
.remove();
50 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "0");
52 // Add sheet that matches one node.
53 document
.documentElement
.offsetTop
;
54 var barSheet
= addSheet('.bar');
55 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "3");
57 // Remove sheet that matches one node.
58 document
.documentElement
.offsetTop
;
60 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "3");
62 // Add two sheets that each match one node.
63 document
.documentElement
.offsetTop
;
64 var barSheet
= addSheet('.bar');
65 var bazSheet
= addSheet('.baz');
66 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
68 // Remove two sheets that each match one node.
69 document
.documentElement
.offsetTop
;
72 // Recalc 6 elements + documentElement.
73 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
75 // Add two sheets that each match one node. Add one to the beginning of the stylesheet list.
76 document
.documentElement
.offsetTop
;
77 var barSheet
= addSheet('.bar');
78 var bazSheet
= createSheet('.baz');
79 document
.head
.insertBefore(bazSheet
, document
.head
.firstChild
);
80 // Recalc 6 elements + documentElement.
81 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
83 // Remove two sheets that each match one node. One is from the beginning of the stylesheet list.
84 document
.documentElement
.offsetTop
;
87 // Recalc 6 elements + documentElement.
88 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
90 // Add and remove sheets in the same run.
91 document
.documentElement
.offsetTop
;
92 var fooSheet
= addSheet('.foo');
93 var barSheet
= addSheet('.bar');
94 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");
95 document
.documentElement
.offsetTop
;
96 var bazSheet
= addSheet('.baz');
98 // Recalc 6 elements + documentElement.
99 shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "6");