| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../resources/js-test.js"></script> | |
| 4 </head> | |
| 5 <body> | |
| 6 <p>Test [un]registering a <style scoped> element from its parent</p> | |
| 7 <div id="scope1"> | |
| 8 <style id="global1"></style> | |
| 9 <style scoped='scoped1' id="scoped1"></style> | |
| 10 </div> | |
| 11 <div id="scope2"> | |
| 12 </div> | |
| 13 | |
| 14 <div id="console"></div> | |
| 15 | |
| 16 <script> | |
| 17 if (!window.internals || !window.internals.numberOfScopedHTMLStyleChildr
en) | |
| 18 debug("windows.internals.numberOfScopedHTMLStyleChildren not found!"
); | |
| 19 else { | |
| 20 var scope1 = document.getElementById('scope1'); | |
| 21 var scope2 = document.getElementById('scope2'); | |
| 22 var scope3 = document.createElement('div'); | |
| 23 | |
| 24 var global1 = document.getElementById('global1'); | |
| 25 var scoped1 = document.getElementById('scoped1'); | |
| 26 | |
| 27 var global2 = document.createElement('style'); | |
| 28 var scoped2 = document.createElement('style'); | |
| 29 scoped2.setAttribute('scoped', 'scoped'); | |
| 30 var scoped3 = document.createElement('style'); | |
| 31 scoped3.scoped = true; | |
| 32 | |
| 33 /* NOTE: <style scoped> outside the document is NOT registered! */ | |
| 34 debug("--- Initial ---"); | |
| 35 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "1");
/* in tree */ | |
| 36 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* out of tree */ | |
| 37 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* out of tree */ | |
| 38 | |
| 39 debug("--- Attaching ---"); | |
| 40 scope2.appendChild(scoped2); | |
| 41 scope2.appendChild(global2); | |
| 42 scope3.appendChild(scoped3); | |
| 43 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "1");
/* in tree */ | |
| 44 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "1");
/* in tree */ | |
| 45 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* out of tree */ | |
| 46 | |
| 47 debug("--- Unsetting @scoped ---"); | |
| 48 scoped1.scoped = false; | |
| 49 scoped2.scoped = false; | |
| 50 scoped3.removeAttribute('scoped'); | |
| 51 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "0");
/* in tree */ | |
| 52 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* in tree */ | |
| 53 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* out of tree */ | |
| 54 | |
| 55 debug("--- Re-setting @scoped ---"); | |
| 56 scoped1.scoped = true; | |
| 57 scoped2.setAttribute('scoped', 'scoped'); | |
| 58 scoped3.setAttribute('scoped', ''); | |
| 59 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "1");
/* in tree */ | |
| 60 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "1");
/* in tree */ | |
| 61 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* out of tree */ | |
| 62 | |
| 63 debug("--- Inserting/removing scope elements from document ---"); | |
| 64 document.body.insertBefore(scope3, scope2); | |
| 65 document.body.removeChild(scope2); | |
| 66 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "1");
/* in tree */ | |
| 67 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* out of tree */ | |
| 68 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "1");
/* in tree */ | |
| 69 | |
| 70 debug("--- Multiple scoped style elements within single scope ---"); | |
| 71 scope2.removeChild(scoped2); | |
| 72 scope2.removeChild(global2); | |
| 73 scope3.removeChild(scoped3); | |
| 74 scope1.appendChild(scoped3); | |
| 75 scope1.appendChild(scoped2); | |
| 76 scope1.appendChild(global2); | |
| 77 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "3");
/* in tree */ | |
| 78 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* out of tree */ | |
| 79 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* in tree */ | |
| 80 | |
| 81 debug("--- Removing scoping element from document ---"); | |
| 82 document.body.removeChild(scope1); | |
| 83 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "0");
/* out of tree */ | |
| 84 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* out of tree */ | |
| 85 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* in tree */ | |
| 86 | |
| 87 debug("--- Inserting scope within other scope ---"); | |
| 88 document.body.insertBefore(scope2, scope3); | |
| 89 scope1.removeChild(scoped2); | |
| 90 scope2.appendChild(scoped2); | |
| 91 scope2.appendChild(scope1); | |
| 92 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "2");
/* in tree, child of scope2 */ | |
| 93 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "1");
/* in tree */ | |
| 94 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* in tree */ | |
| 95 | |
| 96 debug("--- Cloning <style scoped> and parents ---"); | |
| 97 var clonescope1deep = scope1.cloneNode(true); | |
| 98 var clonescope1shallow = scope1.cloneNode(false); | |
| 99 var clonescope2deep = scope2.cloneNode(true); | |
| 100 var clonescope2shallow = scope2.cloneNode(false); | |
| 101 var clonescoped1deep = scoped1.cloneNode(true); | |
| 102 var clonescoped1shallow = scoped1.cloneNode(false); | |
| 103 var clonescoped2deep = scoped2.cloneNode(true); | |
| 104 var clonescoped2shallow = scoped2.cloneNode(false); | |
| 105 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "2");
/* in tree, child of scope2 */ | |
| 106 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "1");
/* in tree */ | |
| 107 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "0");
/* in tree */ | |
| 108 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope1deep)
", "0"); /* out of tree */ | |
| 109 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope1shall
ow)", "0"); /* out of tree */ | |
| 110 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope2deep)
", "0"); /* out of tree */ | |
| 111 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope2shall
ow)", "0"); /* out of tree */ | |
| 112 | |
| 113 debug("--- inserting clones into single parent ---"); | |
| 114 scope3.appendChild(clonescope1deep); | |
| 115 scope3.appendChild(clonescope1shallow); | |
| 116 scope3.appendChild(clonescope2deep); | |
| 117 scope3.appendChild(clonescope2shallow); | |
| 118 scope3.appendChild(clonescoped1deep); | |
| 119 scope3.appendChild(clonescoped1shallow); | |
| 120 scope3.appendChild(clonescoped2deep); | |
| 121 scope3.appendChild(clonescoped2shallow); | |
| 122 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "2");
/* in tree, child of scope2 */ | |
| 123 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "1");
/* in tree */ | |
| 124 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "4");
/* in tree */ | |
| 125 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope1deep)
", "2"); /* in tree */ | |
| 126 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope1shall
ow)", "0"); /* in tree */ | |
| 127 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope2deep)
", "1"); /* in tree */ | |
| 128 shouldBe("internals.numberOfScopedHTMLStyleChildren(clonescope2shall
ow)", "0"); /* in tree */ | |
| 129 | |
| 130 debug("--- Unsetting @scoped in nested scope ---"); | |
| 131 scoped1.scoped = false; | |
| 132 scoped2.removeAttribute('scoped'); | |
| 133 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope1)", "1");
/* in tree, child of scope2 */ | |
| 134 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope2)", "0");
/* in tree */ | |
| 135 shouldBe("internals.numberOfScopedHTMLStyleChildren(scope3)", "4");
/* in tree */ | |
| 136 | |
| 137 debug("--- DONE ---"); | |
| 138 } | |
| 139 var successfullyParsed = true; | |
| 140 </script> | |
| 141 </body> | |
| 142 </html> | |
| OLD | NEW |