|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <!-- |
|
3 https://bugzilla.mozilla.org/show_bug.cgi?id=372769 |
|
4 --> |
|
5 <head> |
|
6 <title>Test for Bug 372769</title> |
|
7 <bindings xmlns="http://www.mozilla.org/xbl"> |
|
8 <binding id="test1"> |
|
9 <implementation> |
|
10 <field name="one">1</field> |
|
11 <field name="two">9</field> |
|
12 <field name="three">3</field> |
|
13 <field name="four">10</field> |
|
14 <field name="five">11</field> |
|
15 <field name="six">this.four = 4; 6;</field> |
|
16 <field name="seven">this.five = 5; 7;</field> |
|
17 </implementation> |
|
18 </binding> |
|
19 |
|
20 <binding id="test2"> |
|
21 <implementation> |
|
22 <!-- Tests for recursive resolves --> |
|
23 <field name="eight">this.eight</field> |
|
24 <field name="nine">this.ten</field> |
|
25 <field name="ten">this.nine</field> |
|
26 <!-- Tests for non-DOM overrides --> |
|
27 <field name="eleven">11</field> |
|
28 <field name="twelve">12</field> |
|
29 <!-- Tests for DOM overrides --> |
|
30 <field name="parentNode">this.parentNode</field> |
|
31 <field name="ownerDocument">"ownerDocument override"</field> |
|
32 </implementation> |
|
33 </binding> |
|
34 |
|
35 <binding id="test3-ancestor"> |
|
36 <implementation> |
|
37 <field name="thirteen">"13 ancestor"</field> |
|
38 <field name="fourteen">"14 ancestor"</field> |
|
39 <property name="fifteen" readonly="true" onget="return '15 ancestor'"/> |
|
40 </implementation> |
|
41 </binding> |
|
42 |
|
43 <binding id="test3" extends="#test3-ancestor"> |
|
44 <implementation> |
|
45 <field name="thirteen">13</field> |
|
46 <field name="fifteen">15</field> |
|
47 <field name="sixteen">16</field> |
|
48 <field name="sixteen">"16 later"</field> |
|
49 <field name="seventeen">17</field> |
|
50 <field name="eighteen">"18 field"</field> |
|
51 <property name="eighteen" readonly="true" onget="return 18"/> |
|
52 <property name="nineteen" readonly="true" onget="return 19"/> |
|
53 <field name="nineteen">"19 field"</field> |
|
54 </implementation> |
|
55 </binding> |
|
56 |
|
57 <binding id="test4"> |
|
58 <implementation> |
|
59 <field name="twenty">for (var i in this) ; 20;</field> |
|
60 </implementation> |
|
61 </binding> |
|
62 |
|
63 <binding id="test5"> |
|
64 <implementation> |
|
65 <field name="twenty-one">for (var i in this) ; 21;</field> |
|
66 </implementation> |
|
67 </binding> |
|
68 </bindings> |
|
69 </head> |
|
70 <body> |
|
71 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=372769">Mozilla Bug 372769</a> |
|
72 <p id="display1" style="-moz-binding: url(#test1)"></p> |
|
73 <p id="display2" style="-moz-binding: url(#test2)"></p> |
|
74 <p id="display3" style="-moz-binding: url(#test3)"></p> |
|
75 <p id="display4" style="-moz-binding: url(#test4)"></p> |
|
76 <p id="display5" style="-moz-binding: url(#test5)"></p> |
|
77 <div id="content" style="display: none"> |
|
78 |
|
79 </div> |
|
80 <pre id="test"> |
|
81 <script class="testbody" type="text/javascript"> |
|
82 <![CDATA[ |
|
83 |
|
84 /** Test for Bug 372769 **/ |
|
85 |
|
86 SimpleTest = parent.SimpleTest; |
|
87 ok = parent.ok; |
|
88 is = parent.is; |
|
89 $ = function(x) { return document.getElementById(x); } |
|
90 |
|
91 window.onload = function() { |
|
92 var d = $("display1"); |
|
93 is(d.one, 1, "Should be able to read field"); |
|
94 |
|
95 d.two = 2; |
|
96 is(d.two, 2, "Should be able to write field"); |
|
97 |
|
98 is("three" in d, true, 'Should have a property named "three"'); |
|
99 is(d.three, 3, "Should be 3"); |
|
100 |
|
101 is(d.four, 10, "Unexpected value so far"); |
|
102 |
|
103 // Save "five" for now |
|
104 |
|
105 is(d.six, 6, "Should be 6"); |
|
106 |
|
107 is(d.four, 4, "Now should be 4"); |
|
108 |
|
109 d.four = 9; |
|
110 is(d.four, 9, "Just set it to 9"); |
|
111 |
|
112 var found = false; |
|
113 for (var prop in d) { |
|
114 if (prop == "seven") { |
|
115 found = true; |
|
116 break; |
|
117 } |
|
118 } |
|
119 is(found, true, "Enumeration is broken"); |
|
120 |
|
121 is(d.four, 9, "Shouldn't have rerun field six"); |
|
122 is(d.five, 11, "Shouldn't have run field 7"); |
|
123 is(d.seven, 7, "Should be 7") |
|
124 is(d.five, 5, "Should have run field 7"); |
|
125 |
|
126 d = $("display2"); |
|
127 is(typeof(d.eight), "undefined", "Recursive resolve should bail out"); |
|
128 is(typeof(d.nine), "undefined", "Recursive double resolve should bail out"); |
|
129 is(typeof(d.ten), "undefined", |
|
130 "This recursive double resolve should bail out too"); |
|
131 |
|
132 // Get .eleven so it's resolved now |
|
133 is(d.eleven, 11, "Unexpected value for .eleven"); |
|
134 var newProto = {}; |
|
135 newProto.eleven = "Proto 11"; |
|
136 newProto.twelve = "Proto 12"; |
|
137 newProto.__proto__ = d.__proto__; |
|
138 d.__proto__ = newProto; |
|
139 is(d.eleven, 11, "Proto should not have affected this"); |
|
140 is(d.twelve, "Proto 12", "Proto should have overridden 'twelve'"); |
|
141 |
|
142 is(d.parentNode, undefined, "We overrode this, yes we did"); |
|
143 is(typeof(d.parentNode), "undefined", "This is a recursive resolve too"); |
|
144 is(d.ownerDocument, "ownerDocument override", |
|
145 "Should have overridden ownerDocument"); |
|
146 |
|
147 d = $("display3"); |
|
148 is(d.thirteen, 13, "descendant should win here"); |
|
149 is(d.fourteen, "14 ancestor", |
|
150 "ancestor should win if descendant does nothing") |
|
151 is(d.fifteen, 15, |
|
152 "Field beats ancestor's property, since the latter lives on higher proto") |
|
153 is(d.sixteen, 16, "First field wins"); |
|
154 is(d.__proto__.seventeen, undefined, "Shouldn't have this on proto"); |
|
155 is(typeof(d.__proto__.seventeen), "undefined", |
|
156 "Really, should be undefined"); |
|
157 is(d.seventeen, 17, "Should have this prop on the node itself, though"); |
|
158 is(d.eighteen, 18, "Property beats field"); |
|
159 is(d.nineteen, 19, "Property still beats field"); |
|
160 |
|
161 d = $("display4"); |
|
162 is(d.twenty, 20, "Should be 20"); |
|
163 |
|
164 d = $("display5"); |
|
165 found = false; |
|
166 for (var prop2 in d) { |
|
167 if (prop2 == "twenty-one") { |
|
168 found = true; |
|
169 break; |
|
170 } |
|
171 } |
|
172 is(found, true, "Enumeration is broken"); |
|
173 is(d["twenty-one"], 21, "Should be 21"); |
|
174 SimpleTest.finish(); |
|
175 } |
|
176 ]]> |
|
177 </script> |
|
178 </pre> |
|
179 </body> |
|
180 </html> |
|
181 |