author Igor Bukanov <>
Fri, 20 Jun 2008 11:46:36 +0200
changeset 15452 056158a4c1e84b8621d066d1d4f1fc92db37ae06
parent 7064 f0645e127d75ca3638cab55bf4b23c3d2dbfe6a6
permissions -rw-r--r--
Backed out changeset 97977f224aff due to build breakage

<html xmlns="">
  <title>Test for Bug 398135</title>
  <script type="text/javascript" src="/MochiKit/packed.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript">window.log = ""</script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <bindings xmlns="">
    <binding id="ancestor">
          window.log += "ancestorConstructor:";
          window.log += "ancestorDestructor:";
        <field name="ancestorField">"ancestorField"</field>
        <property name="ancestorProp" onget="return 'ancestorProp'"/>
        <method name="ancestorMethod">
            return "ancestorMethod";
    <binding id="test" extends="#ancestor">
          window.log += "descendantConstructor:";
          window.log += "descendantDestructor:";
        <field name="descendantField">"descendantField"</field>
        <field name="contentField">
        <property name="descendantProp" onget="return 'descendantProp'"/>
        <method name="descendantMethod">
            return "descendantMethod";
<a target="_blank" href="">Mozilla Bug 398135</a>
<p id="display" style="-moz-binding: url(#test)"></p>
<div id="content" style="display: none">
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 398135 **/
addLoadEvent(function() {
  var d;
  d = $("display");

  function testInTree(type) {
    is(d.ancestorField, "ancestorField", "Wrong ancestor field " + type);
    is(d.descendantField, "descendantField", "Wrong descendant field " + type);
    is(d.ancestorProp, "ancestorProp", "Wrong ancestor prop " + type);
    is(d.descendantProp, "descendantProp", "Wrong descendant prop " + type);
    is(d.ancestorMethod(), "ancestorMethod", "Wrong ancestor method " + type);
    is(d.descendantMethod(), "descendantMethod",
       "Wrong descendant method " + type);
    is(d.contentField, document.getAnonymousNodes(d)[0],
       "Unexpected content field " + type);

  function testNotInTree(type) {
    is(typeof(d.ancestorField), "undefined", "Wrong ancestor field " + type);
    is(typeof(d.descendantField), "undefined",
       "Wrong descendant field " + type);
    is(typeof(d.ancestorProp), "undefined", "Wrong ancestor prop " + type);
    is(typeof(d.descendantProp), "undefined", "Wrong descendant prop " + type);
    is(typeof(d.ancestorMethod), "undefined", "Wrong ancestor method " + type);
    is(typeof(d.descendantMethod), "undefined",
       "Wrong descendant method " + type);
    is(typeof(d.contentField), "undefined",
       "Unexpected content field " + type);

  is(window.log, "ancestorConstructor:descendantConstructor:",
     "Constructors did not fire?");
  window.log = "";
  testInTree("before removal");

  var parent = d.parentNode;
  var nextSibling = d.nextSibling;
  testNotInTree("after first removal");

  todo(window.log == "descendantDestructor:ancestorDestructor:",
     "Destructors did not fire");
  window.log = "";
  parent.insertBefore(d, nextSibling);
  is(window.log, "ancestorConstructor:descendantConstructor:",
     "Constructors did not fire a second time?");
  window.log = "";
  testInTree("after reinsertion");

  // Now munge the proto chain to test the robustness of the proto-unhooking
  // code
  var origProto = d.__proto__;
  var origProtoProto = origProto.__proto__;
  var newProto = new Object();
  origProto.__proto__ = newProto;
  newProto.__proto__ = origProtoProto;

  todo(window.log == "descendantDestructor:ancestorDestructor:",
     "Destructors did not fire a second time?");

  testNotInTree("after second removal");