dom/xbl/test/test_bug398135.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial