summaryrefslogtreecommitdiffstats
path: root/dom/xbl/test/file_bug372769.xhtml
blob: 79a36be854a77ce0f0fecfd23a90aba8d2411b72 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=372769
-->
<head>
  <title>Test for Bug 372769</title>
  <bindings xmlns="http://www.mozilla.org/xbl">
    <binding id="test1">
      <implementation>
        <field name="one">1</field>
        <field name="two">9</field>
        <field name="three">3</field>
        <field name="four">10</field>
        <field name="five">11</field>
        <field name="six">this.four = 4; 6;</field>
        <field name="seven">this.five = 5; 7;</field>
      </implementation>
    </binding>

    <binding id="test2">
      <implementation>
        <!-- Tests for recursive resolves -->
        <field name="eight">this.eight</field>
        <field name="nine">this.ten</field>
        <field name="ten">this.nine</field>
        <!-- Tests for non-DOM overrides -->
        <field name="eleven">11</field>
        <field name="twelve">12</field>
        <!-- Tests for DOM overrides -->
        <field name="parentNode">this.parentNode</field>
        <field name="ownerDocument">"ownerDocument override"</field>
      </implementation>
    </binding>

    <binding id="test3-ancestor">
      <implementation>
        <field name="thirteen">"13 ancestor"</field>
        <field name="fourteen">"14 ancestor"</field>
        <property name="fifteen" readonly="true" onget="return '15 ancestor'"/>
      </implementation>
    </binding>

    <binding id="test3" extends="#test3-ancestor">
      <implementation>
        <field name="thirteen">13</field>
        <field name="fifteen">15</field>
        <field name="sixteen">16</field>
        <field name="sixteen">"16 later"</field>
        <field name="seventeen">17</field>
        <field name="eighteen">"18 field"</field>
        <property name="eighteen" readonly="true" onget="return 18"/>
        <property name="nineteen" readonly="true" onget="return 19"/>
        <field name="nineteen">"19 field"</field>
      </implementation>
    </binding>

    <binding id="test4">
      <implementation>
        <field name="twenty">for (var i in this) ; 20;</field>
      </implementation>
    </binding>

      <binding id="test5">
      <implementation>
        <field name="twenty-one">for (var i in this) ; 21;</field>
      </implementation>
    </binding>
</bindings>  
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=372769">Mozilla Bug 372769</a>
<p id="display1" style="-moz-binding: url(#test1)"></p>
<p id="display2" style="-moz-binding: url(#test2)"></p>
<p id="display3" style="-moz-binding: url(#test3)"></p>
<p id="display4" style="-moz-binding: url(#test4)"></p>
<p id="display5" style="-moz-binding: url(#test5)"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

/** Test for Bug 372769 **/

SimpleTest = parent.SimpleTest;
ok = parent.ok;
is = parent.is;
$ = function(x) { return document.getElementById(x); }

window.onload = function() {
  var d = $("display1");
  is(d.one, 1, "Should be able to read field");

  d.two = 2;
  is(d.two, 2, "Should be able to write field");

  is("three" in d, true, 'Should have a property named "three"');
  is(d.three, 3, "Should be 3");

  is(d.four, 10, "Unexpected value so far");

  // Save "five" for now

  is(d.six, 6, "Should be 6");

  is(d.four, 4, "Now should be 4");

  d.four = 9;
  is(d.four, 9, "Just set it to 9");
  
  var found = false;
  for (var prop in d) {
    if (prop == "seven") {
      found = true;
      break;
    }
  }
  is(found, true, "Enumeration is broken");

  is(d.four, 9, "Shouldn't have rerun field six");
  is(d.five, 11, "Shouldn't have run field 7");
  is(d.seven, 7, "Should be 7")
  is(d.five, 5, "Should have run field 7");

  d = $("display2");
  is(typeof(d.eight), "undefined", "Recursive resolve should bail out");
  is(typeof(d.nine), "undefined", "Recursive double resolve should bail out");
  is(typeof(d.ten), "undefined",
     "This recursive double resolve should bail out too");

  // Get .eleven so it's resolved now
  is(d.eleven, 11, "Unexpected value for .eleven");
  var newProto = {};
  newProto.eleven = "Proto 11";
  newProto.twelve = "Proto 12";  
  newProto.__proto__ = d.__proto__;
  d.__proto__ = newProto;
  is(d.eleven, 11, "Proto should not have affected this");
  is(d.twelve, "Proto 12", "Proto should have overridden 'twelve'");
  
  is(d.parentNode, undefined, "We overrode this, yes we did");
  is(typeof(d.parentNode), "undefined", "This is a recursive resolve too");
  is(d.ownerDocument, "ownerDocument override",
     "Should have overridden ownerDocument");

  d = $("display3");
  is(d.thirteen, 13, "descendant should win here");
  is(d.fourteen, "14 ancestor",
     "ancestor should win if descendant does nothing")
  is(d.fifteen, 15,
     "Field beats ancestor's property, since the latter lives on higher proto")
  is(d.sixteen, 16, "First field wins");
  is(d.__proto__.seventeen, undefined, "Shouldn't have this on proto");
  is(typeof(d.__proto__.seventeen), "undefined",
     "Really, should be undefined");
  is(d.seventeen, 17, "Should have this prop on the node itself, though");
  is(d.eighteen, 18, "Property beats field");
  is(d.nineteen, 19, "Property still beats field");

  d = $("display4");
  is(d.twenty, 20, "Should be 20");

  d = $("display5");
  found = false;
  for (var prop2 in d) {
    if (prop2 == "twenty-one") {
      found = true;
      break;
    }
  }
  is(found, true, "Enumeration is broken");
  is(d["twenty-one"], 21, "Should be 21");
  SimpleTest.finish();
}
]]>
</script>
</pre>
</body>
</html>