OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../../resources/testharness.js"></script> | 2 <script src="../../../resources/testharness.js"></script> |
3 <script src="../../../resources/testharnessreport.js"></script> | 3 <script src="../../../resources/testharnessreport.js"></script> |
4 <style></style> | 4 <style></style> |
5 <div> | 5 <div> |
6 <div></div> | 6 <div></div> |
7 <div></div> | 7 <div></div> |
8 <div></div> | 8 <div></div> |
9 <div></div> | 9 <div></div> |
10 <div></div> | 10 <div></div> |
| 11 <div id="found"> |
| 12 <div></div> |
| 13 </div> |
11 <span></span> | 14 <span></span> |
12 </div> | 15 </div> |
13 <script> | 16 <script> |
14 test(() => { | 17 test(() => { |
15 assert_true(!!window.internals, "Test requires window.internals."); | 18 assert_true(!!window.internals, "Tests require window.internals."); |
| 19 }, "Test for prerequisites."); |
| 20 |
| 21 function applyRuleAndReturnAffectedElementCount(ruleString) { |
16 document.body.offsetTop; | 22 document.body.offsetTop; |
17 document.styleSheets[0].insertRule("span{background:green}", 0); | 23 document.styleSheets[0].insertRule(ruleString, 0); |
18 assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 1, "
Check that only the span is affected."); | 24 var recalcCount = internals.updateStyleAndReturnAffectedElementCount(); |
19 }, "Inserting a style rule with a type selector should only invalidate eleme
nts with that type."); | 25 document.styleSheets[0].removeRule(); |
| 26 return recalcCount; |
| 27 } |
| 28 |
| 29 test(() => { |
| 30 assert_equals(applyRuleAndReturnAffectedElementCount( |
| 31 "span { background: green }"), 1, |
| 32 "Check that only the span is affected."); |
| 33 }, "A style rule with a type selector should only invalidate elements with t
hat type."); |
| 34 |
| 35 test(() => { |
| 36 assert_equals(applyRuleAndReturnAffectedElementCount( |
| 37 "#notfound div { background: red }"), 0, |
| 38 "Check that none of divs are recalculated."); |
| 39 }, "A type selector scoped in an unknown id should not invalidate any elemen
ts."); |
| 40 |
| 41 test(() => { |
| 42 assert_equals(applyRuleAndReturnAffectedElementCount( |
| 43 "#found div { background: red }"), 1, |
| 44 "Check that only one of the divs is recalculated."); |
| 45 }, "A type selector scoped by a known id should only invalidate descendants
of the element with that id."); |
20 </script> | 46 </script> |
OLD | NEW |