summaryrefslogtreecommitdiff
path: root/dom/xbl/test/test_bug398135.xul
blob: 6b0b68c626ac6ed78e1d753c1a9f6f7ae588898a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=398135
-->
<window title="Mozilla Bug 398135"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript">window.log = ""</script>
  <bindings xmlns="http://www.mozilla.org/xbl">
    <binding id="ancestor">
      <implementation>
        <constructor>
          window.log += "ancestorConstructor:";
        </constructor>
        <destructor>
          window.log += "ancestorDestructor:";
        </destructor>
        <field name="ancestorField">"ancestorField"</field>
        <property name="ancestorProp" onget="return 'ancestorProp'"/>
        <method name="ancestorMethod">
          <body>
            return "ancestorMethod";
          </body>
        </method>
      </implementation>
    </binding>
    <binding id="test" extends="#ancestor">
      <implementation>
        <constructor>
          window.log += "descendantConstructor:";
        </constructor>
        <destructor>
          window.log += "descendantDestructor:";
        </destructor>
        <field name="descendantField">"descendantField"</field>
        <field name="contentField">
          document.getAnonymousNodes(this)[0];
        </field>
        <property name="descendantProp" onget="return 'descendantProp'"/>
        <method name="descendantMethod">
          <body>
            return "descendantMethod";
          </body>
        </method>
      </implementation>
      <content>
        <span/>
        <children/>
      </content>
    </binding>
  </bindings>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=398135"
     target="_blank">Mozilla Bug 398135</a>
  </body>

  <hbox id="display" style="-moz-binding: url(#test)"></hbox>

<script type="application/javascript">
<![CDATA[
/** Test for Bug 398135 **/
SimpleTest.waitForExplicitFinish();
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;
  parent.removeChild(d);
  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;

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

  testNotInTree("after second removal");
});
addLoadEvent(SimpleTest.finish);

]]>
</script>
</window>