Bumping manifests a=b2g-bump
[gecko.git] / dom / bindings / test / test_dom_xrays.html
blob96704d2a56e83b1ee24034150bcfd03dc753d6fc
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=787070
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 787070</title>
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=787070">Mozilla Bug 787070</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
16 <iframe id="t" src="http://example.org/tests/dom/bindings/test/file_dom_xrays.html"></iframe>
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
21 /** Test for Bug 1021066 **/
23 var Cu = Components.utils;
25 // values should contain the values that the property should have on each of
26 // the objects on the prototype chain of obj. A value of undefined signals
27 // that the value should not be present on that prototype.
28 function checkXrayProperty(obj, name, values)
30 var instance = obj;
31 do {
32 var value = values.shift();
33 if (typeof value == "undefined") {
34 ok(!obj.hasOwnProperty(name), "hasOwnProperty shouldn't see \"" + name + "\" through Xrays");
35 ise(Object.getOwnPropertyDescriptor(obj, name), undefined, "getOwnPropertyDescriptor shouldn't see \"" + name + "\" through Xrays");
36 ok(Object.keys(obj).indexOf(name) == -1, "Enumerating the Xray should not return \"" + name + "\"");
37 } else {
38 ok(obj.hasOwnProperty(name), "hasOwnProperty should see \"" + name + "\" through Xrays");
39 var pd = Object.getOwnPropertyDescriptor(obj, name);
40 ok(pd, "getOwnPropertyDescriptor should see \"" + name + "\" through Xrays");
41 if (pd && pd.get) {
42 is(pd.get.call(instance), value, "Should get the right value for \"" + name + "\" through Xrays");
43 } else {
44 is(obj[name], value, "Should get the right value for \"" + name + "\" through Xrays");
46 if (pd && pd.enumerable) {
47 ok(Object.keys(obj).indexOf("" + name) > -1, "Enumerating the Xray should return \"" + name + "\"");
50 } while ((obj = Object.getPrototypeOf(obj)));
53 function checkWindowXrayProperty(obj, name, windowValue, windowPrototypeValue, namedPropertiesValue, eventTargetValue)
55 checkXrayProperty(obj, name, [ windowValue, windowPrototypeValue, namedPropertiesValue, eventTargetValue ]);
58 function test()
60 // Window
61 var win = document.getElementById("t").contentWindow;
62 var doc = document.getElementById("t").contentDocument;
64 var winProto = Object.getPrototypeOf(win);
65 ise(winProto, win.Window.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
67 var namedPropertiesObject = Object.getPrototypeOf(winProto);
68 ise(Cu.getClassName(namedPropertiesObject, /* unwrap = */ true), "WindowProperties", "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
70 var eventTargetProto = Object.getPrototypeOf(namedPropertiesObject);
71 ise(eventTargetProto, win.EventTarget.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
73 // Xrays need to filter expandos.
74 checkWindowXrayProperty(win, "expando", undefined);
75 ok(!("expando" in win), "Xrays should filter expandos");
77 checkWindowXrayProperty(win, "shadowedIframe", undefined, undefined, doc.getElementById("shadowedIframe").contentWindow);
78 ok("shadowedIframe" in win, "Named properties should be exposed through Xrays");
80 // Named properties live on the named properties object for global objects.
81 checkWindowXrayProperty(win, "iframe", undefined, undefined, doc.getElementById("iframe").contentWindow);
82 ok("iframe" in win, "Named properties should be exposed through Xrays");
84 // Window properties live on the instance, shadowing the properties of the named property object.
85 checkWindowXrayProperty(win, "document", doc, undefined, doc.getElementById("document").contentWindow);
86 ok("document" in win, "WebIDL properties should be exposed through Xrays");
88 // Unforgeable properties live on the instance, shadowing the properties of the named property object.
89 checkWindowXrayProperty(win, "self", win, undefined, doc.getElementById("self").contentWindow);
90 ok("self" in win, "WebIDL properties should be exposed through Xrays");
92 // Object.prototype is at the end of the prototype chain.
93 var obj = win;
94 while ((proto = Object.getPrototypeOf(obj))) {
95 obj = proto;
97 ise(obj, win.Object.prototype, "Object.prototype should be at the end of the prototype chain");
99 // Named properties shouldn't shadow WebIDL- or ECMAScript-defined properties.
100 checkWindowXrayProperty(win, "addEventListener", undefined, undefined, undefined, eventTargetProto.addEventListener);
101 ise(win.addEventListener, eventTargetProto.addEventListener, "Named properties shouldn't shadow WebIDL-defined properties");
103 ise(win.toString, win.Object.prototype.toString, "Named properties shouldn't shadow ECMAScript-defined properties");
105 // HTMLDocument
106 // Unforgeable properties live on the instance.
107 checkXrayProperty(doc, "location", [ document.getElementById("t").src ]);
109 // HTMLHtmlElement
110 var elem = doc.documentElement;
112 var elemProto = Object.getPrototypeOf(elem);
113 ise(elemProto, win.HTMLHtmlElement.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
115 elemProto = Object.getPrototypeOf(elemProto);
116 ise(elemProto, win.HTMLElement.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
118 elemProto = Object.getPrototypeOf(elemProto);
119 ise(elemProto, win.Element.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
121 elemProto = Object.getPrototypeOf(elemProto);
122 ise(elemProto, win.Node.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
124 elemProto = Object.getPrototypeOf(elemProto);
125 ise(elemProto, win.EventTarget.prototype, "The proto chain of the Xray should mirror the prototype chain of the Xrayed object");
127 // Xrays need to filter expandos.
128 ok(!("expando" in elem), "Xrays should filter expandos");
130 // WebIDL-defined properties live on the prototype.
131 checkXrayProperty(elem, "version", [ undefined, "" ]);
132 ise(elem.version, "", "WebIDL properties should be exposed through Xrays");
134 // HTMLCollection
135 var coll = doc.getElementsByTagName("iframe");
137 // Named properties live on the instance for non-global objects.
138 checkXrayProperty(coll, "iframe", [ doc.getElementById("iframe") ]);
140 // Indexed properties live on the instance.
141 checkXrayProperty(coll, 0, [ doc.getElementById("shadowedIframe") ]);
143 // WebIDL-defined properties live on the prototype, overriding any named properties.
144 checkXrayProperty(coll, "item", [ undefined, win.HTMLCollection.prototype.item ]);
146 // ECMAScript-defined properties live on the prototype, overriding any named properties.
147 checkXrayProperty(coll, "toString", [ undefined, undefined, win.Object.prototype.toString ]);
149 SimpleTest.finish();
152 SimpleTest.waitForExplicitFinish();
153 addLoadEvent(test);
155 </script>
156 </pre>
157 </body>
158 </html>