OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../../../resources/js-test.js"></script> | |
4 </head> | |
5 <body> | |
6 <p>Basic test for the <style scoped> attribute.</p> | |
7 <div id="scope"> | |
8 <style id="global1"></style> | |
9 <style scoped='scoped' id="scoped1"></style> | |
10 </div> | |
11 | |
12 <div id="console"></div> | |
13 | |
14 <script> | |
15 function testBooleanAttribute(elem, attr) | |
16 { | |
17 var val = elem.getAttribute(attr); | |
18 if (val === null) | |
19 return false | |
20 if (val === '' || val === attr) | |
21 return true; | |
22 throw "Illegal value for boolean attribute!"; | |
23 } | |
24 | |
25 var scope = document.getElementById('scope'); | |
26 | |
27 var global1 = document.getElementById('global1'); | |
28 var scoped1 = document.getElementById('scoped1'); | |
29 | |
30 var global2 = document.createElement('style'); | |
31 var scoped2 = document.createElement('style'); | |
32 scoped2.setAttribute('scoped', 'scoped'); | |
33 var scoped3 = document.createElement('style'); | |
34 scoped3.scoped = true; | |
35 | |
36 debug("--- Initial ---"); | |
37 shouldBeNull("global1.getAttribute('scoped')"); | |
38 shouldBeFalse("global1.scoped"); | |
39 shouldBeNull("global2.getAttribute('scoped')"); | |
40 shouldBeFalse("global2.scoped"); | |
41 shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')"); | |
42 shouldBeTrue("scoped1.scoped"); | |
43 shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')"); | |
44 shouldBeTrue("scoped2.scoped"); | |
45 shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')"); | |
46 shouldBeTrue("scoped3.scoped"); | |
47 | |
48 debug("--- After insertion into tree ---") | |
49 scope.appendChild(global2); | |
50 scope.appendChild(scoped2); | |
51 scope.appendChild(scoped3); | |
52 | |
53 shouldBeNull("global1.getAttribute('scoped')"); | |
54 shouldBeFalse("global1.scoped"); | |
55 shouldBeNull("global2.getAttribute('scoped')"); | |
56 shouldBeFalse("global2.scoped"); | |
57 shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')"); | |
58 shouldBeTrue("scoped1.scoped"); | |
59 shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')"); | |
60 shouldBeTrue("scoped2.scoped"); | |
61 shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')"); | |
62 shouldBeTrue("scoped3.scoped"); | |
63 | |
64 debug("--- Inverting 'scoped' attribute while in tree ---"); | |
65 scoped1.scoped = null; | |
66 scoped2.scoped = false; | |
67 scoped3.removeAttribute('scoped'); | |
68 global1.scoped = true; | |
69 global2.setAttribute('scoped', 'scoped'); | |
70 | |
71 shouldBeTrue("testBooleanAttribute(global1, 'scoped')"); | |
72 shouldBeTrue("global1.scoped"); | |
73 shouldBeTrue("testBooleanAttribute(global2, 'scoped')"); | |
74 shouldBeTrue("global2.scoped"); | |
75 shouldBeNull("scoped1.getAttribute('scoped')"); | |
76 shouldBeFalse("scoped1.scoped"); | |
77 shouldBeNull("scoped2.getAttribute('scoped')"); | |
78 shouldBeFalse("scoped2.scoped"); | |
79 shouldBeNull("scoped3.getAttribute('scoped')"); | |
80 shouldBeFalse("scoped3.scoped"); | |
81 | |
82 debug("--- After removal from tree (attribute is still inverted) ---"); | |
83 scope.removeChild(global1); | |
84 scope.removeChild(global2); | |
85 scope.removeChild(scoped1); | |
86 scope.removeChild(scoped2); | |
87 scope.removeChild(scoped3); | |
88 | |
89 shouldBeTrue("testBooleanAttribute(global1, 'scoped')"); | |
90 shouldBeTrue("global1.scoped"); | |
91 shouldBeTrue("testBooleanAttribute(global2, 'scoped')"); | |
92 shouldBeTrue("global2.scoped"); | |
93 shouldBeNull("scoped1.getAttribute('scoped')"); | |
94 shouldBeFalse("scoped1.scoped"); | |
95 shouldBeNull("scoped2.getAttribute('scoped')"); | |
96 shouldBeFalse("scoped2.scoped"); | |
97 shouldBeNull("scoped3.getAttribute('scoped')"); | |
98 shouldBeFalse("scoped3.scoped"); | |
99 | |
100 debug("--- Inverting 'scoped' attribute again, while outside tree ---"); | |
101 scoped1.scoped = true; | |
102 scoped2.scoped = true; | |
103 scoped3.setAttribute('scoped', 'scoped'); | |
104 global1.scoped = false; | |
105 global2.removeAttribute('scoped'); | |
106 | |
107 shouldBeNull("global1.getAttribute('scoped')"); | |
108 shouldBeFalse("global1.scoped"); | |
109 shouldBeNull("global2.getAttribute('scoped')"); | |
110 shouldBeFalse("global2.scoped"); | |
111 shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')"); | |
112 shouldBeTrue("scoped1.scoped"); | |
113 shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')"); | |
114 shouldBeTrue("scoped2.scoped"); | |
115 shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')"); | |
116 shouldBeTrue("scoped3.scoped"); | |
117 | |
118 debug("--- DONE ---"); | |
119 var successfullyParsed = true; | |
120 </script> | |
121 </body> | |
122 </html> | |
OLD | NEW |