dom/xbl/test/test_bug398135.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/test/test_bug398135.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=398135
     1.9 +-->
    1.10 +<window title="Mozilla Bug 398135"
    1.11 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +  <script type="application/javascript">window.log = ""</script>
    1.14 +  <bindings xmlns="http://www.mozilla.org/xbl">
    1.15 +    <binding id="ancestor">
    1.16 +      <implementation>
    1.17 +        <constructor>
    1.18 +          window.log += "ancestorConstructor:";
    1.19 +        </constructor>
    1.20 +        <destructor>
    1.21 +          window.log += "ancestorDestructor:";
    1.22 +        </destructor>
    1.23 +        <field name="ancestorField">"ancestorField"</field>
    1.24 +        <property name="ancestorProp" onget="return 'ancestorProp'"/>
    1.25 +        <method name="ancestorMethod">
    1.26 +          <body>
    1.27 +            return "ancestorMethod";
    1.28 +          </body>
    1.29 +        </method>
    1.30 +      </implementation>
    1.31 +    </binding>
    1.32 +    <binding id="test" extends="#ancestor">
    1.33 +      <implementation>
    1.34 +        <constructor>
    1.35 +          window.log += "descendantConstructor:";
    1.36 +        </constructor>
    1.37 +        <destructor>
    1.38 +          window.log += "descendantDestructor:";
    1.39 +        </destructor>
    1.40 +        <field name="descendantField">"descendantField"</field>
    1.41 +        <field name="contentField">
    1.42 +          document.getAnonymousNodes(this)[0];
    1.43 +        </field>
    1.44 +        <property name="descendantProp" onget="return 'descendantProp'"/>
    1.45 +        <method name="descendantMethod">
    1.46 +          <body>
    1.47 +            return "descendantMethod";
    1.48 +          </body>
    1.49 +        </method>
    1.50 +      </implementation>
    1.51 +      <content>
    1.52 +        <span/>
    1.53 +        <children/>
    1.54 +      </content>
    1.55 +    </binding>
    1.56 +  </bindings>
    1.57 +
    1.58 +  <!-- test results are displayed in the html:body -->
    1.59 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.60 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=398135"
    1.61 +     target="_blank">Mozilla Bug 398135</a>
    1.62 +  </body>
    1.63 +
    1.64 +  <hbox id="display" style="-moz-binding: url(#test)"></hbox>
    1.65 +
    1.66 +<script type="application/javascript">
    1.67 +<![CDATA[
    1.68 +/** Test for Bug 398135 **/
    1.69 +SimpleTest.waitForExplicitFinish();
    1.70 +addLoadEvent(function() {
    1.71 +  var d;
    1.72 +  d = $("display");
    1.73 +
    1.74 +  function testInTree(type) {
    1.75 +    is(d.ancestorField, "ancestorField", "Wrong ancestor field " + type);
    1.76 +    is(d.descendantField, "descendantField", "Wrong descendant field " + type);
    1.77 +    is(d.ancestorProp, "ancestorProp", "Wrong ancestor prop " + type);
    1.78 +    is(d.descendantProp, "descendantProp", "Wrong descendant prop " + type);
    1.79 +    is(d.ancestorMethod(), "ancestorMethod", "Wrong ancestor method " + type);
    1.80 +    is(d.descendantMethod(), "descendantMethod",
    1.81 +       "Wrong descendant method " + type);
    1.82 +    is(d.contentField, document.getAnonymousNodes(d)[0],
    1.83 +       "Unexpected content field " + type);
    1.84 +  }
    1.85 +
    1.86 +  function testNotInTree(type) {
    1.87 +    is(typeof(d.ancestorField), "undefined", "Wrong ancestor field " + type);
    1.88 +    is(typeof(d.descendantField), "undefined",
    1.89 +       "Wrong descendant field " + type);
    1.90 +    is(typeof(d.ancestorProp), "undefined", "Wrong ancestor prop " + type);
    1.91 +    is(typeof(d.descendantProp), "undefined", "Wrong descendant prop " + type);
    1.92 +    is(typeof(d.ancestorMethod), "undefined", "Wrong ancestor method " + type);
    1.93 +    is(typeof(d.descendantMethod), "undefined",
    1.94 +       "Wrong descendant method " + type);
    1.95 +    is(typeof(d.contentField), "undefined",
    1.96 +       "Unexpected content field " + type);
    1.97 +  }
    1.98 +
    1.99 +  is(window.log, "ancestorConstructor:descendantConstructor:",
   1.100 +     "Constructors did not fire?");
   1.101 +  window.log = "";
   1.102 +  testInTree("before removal");
   1.103 +
   1.104 +  var parent = d.parentNode;
   1.105 +  var nextSibling = d.nextSibling;
   1.106 +  parent.removeChild(d);
   1.107 +  testNotInTree("after first removal");
   1.108 +
   1.109 +  todo(window.log == "descendantDestructor:ancestorDestructor:",
   1.110 +     "Destructors did not fire");
   1.111 +  window.log = "";
   1.112 +  
   1.113 +  parent.insertBefore(d, nextSibling);
   1.114 +  is(window.log, "ancestorConstructor:descendantConstructor:",
   1.115 +     "Constructors did not fire a second time?");
   1.116 +  window.log = "";
   1.117 +  testInTree("after reinsertion");
   1.118 +
   1.119 +  // Now munge the proto chain to test the robustness of the proto-unhooking
   1.120 +  // code
   1.121 +  var origProto = d.__proto__;
   1.122 +  var origProtoProto = origProto.__proto__;
   1.123 +  var newProto = new Object();
   1.124 +  origProto.__proto__ = newProto;
   1.125 +  newProto.__proto__ = origProtoProto;
   1.126 +
   1.127 +  parent.removeChild(d);
   1.128 +  todo(window.log == "descendantDestructor:ancestorDestructor:",
   1.129 +     "Destructors did not fire a second time?");
   1.130 +
   1.131 +  testNotInTree("after second removal");
   1.132 +});
   1.133 +addLoadEvent(SimpleTest.finish);
   1.134 +
   1.135 +]]>
   1.136 +</script>
   1.137 +</window>
   1.138 +

mercurial