OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <style> |
| 5 #first_child:first-child, |
| 6 #first_child:first-child #first_child_inner, |
| 7 #last_child:last-child, |
| 8 #last_child:last-child #last_child_inner, |
| 9 #only_child:only-child, |
| 10 #only_child:only-child #only_child_inner { |
| 11 background-color: green |
| 12 } |
| 13 |
| 14 span:first-child { |
| 15 color: green; |
| 16 } |
| 17 </style> |
| 18 <div> |
| 19 <div id="first_child"> |
| 20 <div></div> |
| 21 <div></div> |
| 22 <div id="first_child_inner"></div> |
| 23 <div></div> |
| 24 </div> |
| 25 </div> |
| 26 <div> |
| 27 <div id="last_child"> |
| 28 <div></div> |
| 29 <div></div> |
| 30 <div id="last_child_inner"></div> |
| 31 <div></div> |
| 32 </div> |
| 33 </div> |
| 34 <div> |
| 35 <div id="only_child"> |
| 36 <div></div> |
| 37 <div></div> |
| 38 <div id="only_child_inner"></div> |
| 39 <div></div> |
| 40 </div> |
| 41 </div> |
| 42 |
| 43 <div> |
| 44 <span></span> |
| 45 XXX |
| 46 <span id="after_text_node"></span> |
| 47 </div> |
| 48 |
| 49 <script> |
| 50 function backgroundIsGreen(element) { |
| 51 assert_equals(getComputedStyle(element).backgroundColor, "rgb(0, 128, 0)
"); |
| 52 } |
| 53 |
| 54 function backgroundIsTransparent(element) { |
| 55 assert_equals(getComputedStyle(element).backgroundColor, "rgba(0, 0, 0,
0)"); |
| 56 } |
| 57 |
| 58 test(() => { |
| 59 backgroundIsGreen(first_child); |
| 60 backgroundIsGreen(first_child_inner); |
| 61 backgroundIsGreen(last_child); |
| 62 backgroundIsGreen(last_child_inner); |
| 63 backgroundIsGreen(only_child); |
| 64 backgroundIsGreen(only_child_inner); |
| 65 }, "Check initial computed styles"); |
| 66 |
| 67 var div = document.createElement("div"); |
| 68 |
| 69 test(() => { |
| 70 first_child.offsetTop; |
| 71 first_child.parentNode.insertBefore(div, first_child); |
| 72 if (window.internals) |
| 73 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
3); |
| 74 backgroundIsTransparent(first_child); |
| 75 backgroundIsTransparent(first_child_inner); |
| 76 }, "Insert element before first child."); |
| 77 |
| 78 test(() => { |
| 79 first_child.offsetTop; |
| 80 div.remove(); |
| 81 if (window.internals) |
| 82 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
2); |
| 83 backgroundIsGreen(first_child); |
| 84 backgroundIsGreen(first_child_inner); |
| 85 }, "Remove first child."); |
| 86 |
| 87 test(() => { |
| 88 last_child.offsetTop; |
| 89 last_child.parentNode.insertBefore(div, null); |
| 90 if (window.internals) |
| 91 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
3); |
| 92 backgroundIsTransparent(last_child); |
| 93 backgroundIsTransparent(last_child_inner); |
| 94 }, "Insert element before after last child."); |
| 95 |
| 96 test(() => { |
| 97 last_child.offsetTop; |
| 98 div.remove(); |
| 99 if (window.internals) |
| 100 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
2); |
| 101 backgroundIsGreen(last_child); |
| 102 backgroundIsGreen(last_child_inner); |
| 103 }, "Remove last child."); |
| 104 |
| 105 test(() => { |
| 106 only_child.offsetTop; |
| 107 only_child.parentNode.insertBefore(div, only_child); |
| 108 if (window.internals) |
| 109 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
3); |
| 110 backgroundIsTransparent(only_child); |
| 111 backgroundIsTransparent(only_child_inner); |
| 112 }, "Insert element before only child."); |
| 113 |
| 114 test(() => { |
| 115 only_child.offsetTop; |
| 116 div.remove(); |
| 117 if (window.internals) |
| 118 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
2); |
| 119 backgroundIsGreen(only_child); |
| 120 backgroundIsGreen(only_child_inner); |
| 121 }, "Remove element before only child."); |
| 122 |
| 123 test(() => { |
| 124 only_child.offsetTop; |
| 125 only_child.parentNode.insertBefore(div, null); |
| 126 if (window.internals) |
| 127 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
3); |
| 128 backgroundIsTransparent(only_child); |
| 129 backgroundIsTransparent(only_child_inner); |
| 130 }, "Insert element after only child."); |
| 131 |
| 132 test(() => { |
| 133 only_child.offsetTop; |
| 134 div.remove(); |
| 135 if (window.internals) |
| 136 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
2); |
| 137 backgroundIsGreen(only_child); |
| 138 backgroundIsGreen(only_child_inner); |
| 139 }, "Remove element after only child."); |
| 140 |
| 141 test(() => { |
| 142 first_child.offsetTop; |
| 143 first_child.parentNode.insertBefore(div, null); |
| 144 if (window.internals) |
| 145 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
1); |
| 146 div.remove(); |
| 147 if (window.internals) |
| 148 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
0); |
| 149 }, "No first-child mutation."); |
| 150 |
| 151 test(() => { |
| 152 last_child.offsetTop; |
| 153 last_child.parentNode.insertBefore(div, last_child); |
| 154 if (window.internals) |
| 155 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
1); |
| 156 div.remove(); |
| 157 if (window.internals) |
| 158 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
0); |
| 159 }, "No last-child mutation."); |
| 160 |
| 161 test(() => { |
| 162 document.body.offsetTop; |
| 163 after_text_node.parentNode.insertBefore(div, after_text_node); |
| 164 if (window.internals) |
| 165 assert_equals(internals.updateStyleAndReturnAffectedElementCount(),
1); |
| 166 }, "Inserting sibling before text-node should not update for :first-child if
text-node has element predecessor."); |
| 167 |
| 168 </script> |
OLD | NEW |