dom/xbl/test/test_bug398135.xul

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:07b43683ff43
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=398135
6 -->
7 <window title="Mozilla Bug 398135"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript">window.log = ""</script>
11 <bindings xmlns="http://www.mozilla.org/xbl">
12 <binding id="ancestor">
13 <implementation>
14 <constructor>
15 window.log += "ancestorConstructor:";
16 </constructor>
17 <destructor>
18 window.log += "ancestorDestructor:";
19 </destructor>
20 <field name="ancestorField">"ancestorField"</field>
21 <property name="ancestorProp" onget="return 'ancestorProp'"/>
22 <method name="ancestorMethod">
23 <body>
24 return "ancestorMethod";
25 </body>
26 </method>
27 </implementation>
28 </binding>
29 <binding id="test" extends="#ancestor">
30 <implementation>
31 <constructor>
32 window.log += "descendantConstructor:";
33 </constructor>
34 <destructor>
35 window.log += "descendantDestructor:";
36 </destructor>
37 <field name="descendantField">"descendantField"</field>
38 <field name="contentField">
39 document.getAnonymousNodes(this)[0];
40 </field>
41 <property name="descendantProp" onget="return 'descendantProp'"/>
42 <method name="descendantMethod">
43 <body>
44 return "descendantMethod";
45 </body>
46 </method>
47 </implementation>
48 <content>
49 <span/>
50 <children/>
51 </content>
52 </binding>
53 </bindings>
54
55 <!-- test results are displayed in the html:body -->
56 <body xmlns="http://www.w3.org/1999/xhtml">
57 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=398135"
58 target="_blank">Mozilla Bug 398135</a>
59 </body>
60
61 <hbox id="display" style="-moz-binding: url(#test)"></hbox>
62
63 <script type="application/javascript">
64 <![CDATA[
65 /** Test for Bug 398135 **/
66 SimpleTest.waitForExplicitFinish();
67 addLoadEvent(function() {
68 var d;
69 d = $("display");
70
71 function testInTree(type) {
72 is(d.ancestorField, "ancestorField", "Wrong ancestor field " + type);
73 is(d.descendantField, "descendantField", "Wrong descendant field " + type);
74 is(d.ancestorProp, "ancestorProp", "Wrong ancestor prop " + type);
75 is(d.descendantProp, "descendantProp", "Wrong descendant prop " + type);
76 is(d.ancestorMethod(), "ancestorMethod", "Wrong ancestor method " + type);
77 is(d.descendantMethod(), "descendantMethod",
78 "Wrong descendant method " + type);
79 is(d.contentField, document.getAnonymousNodes(d)[0],
80 "Unexpected content field " + type);
81 }
82
83 function testNotInTree(type) {
84 is(typeof(d.ancestorField), "undefined", "Wrong ancestor field " + type);
85 is(typeof(d.descendantField), "undefined",
86 "Wrong descendant field " + type);
87 is(typeof(d.ancestorProp), "undefined", "Wrong ancestor prop " + type);
88 is(typeof(d.descendantProp), "undefined", "Wrong descendant prop " + type);
89 is(typeof(d.ancestorMethod), "undefined", "Wrong ancestor method " + type);
90 is(typeof(d.descendantMethod), "undefined",
91 "Wrong descendant method " + type);
92 is(typeof(d.contentField), "undefined",
93 "Unexpected content field " + type);
94 }
95
96 is(window.log, "ancestorConstructor:descendantConstructor:",
97 "Constructors did not fire?");
98 window.log = "";
99 testInTree("before removal");
100
101 var parent = d.parentNode;
102 var nextSibling = d.nextSibling;
103 parent.removeChild(d);
104 testNotInTree("after first removal");
105
106 todo(window.log == "descendantDestructor:ancestorDestructor:",
107 "Destructors did not fire");
108 window.log = "";
109
110 parent.insertBefore(d, nextSibling);
111 is(window.log, "ancestorConstructor:descendantConstructor:",
112 "Constructors did not fire a second time?");
113 window.log = "";
114 testInTree("after reinsertion");
115
116 // Now munge the proto chain to test the robustness of the proto-unhooking
117 // code
118 var origProto = d.__proto__;
119 var origProtoProto = origProto.__proto__;
120 var newProto = new Object();
121 origProto.__proto__ = newProto;
122 newProto.__proto__ = origProtoProto;
123
124 parent.removeChild(d);
125 todo(window.log == "descendantDestructor:ancestorDestructor:",
126 "Destructors did not fire a second time?");
127
128 testNotInTree("after second removal");
129 });
130 addLoadEvent(SimpleTest.finish);
131
132 ]]>
133 </script>
134 </window>
135

mercurial