1 <p>This page tests getting and setting window properties and functions.
</p>
2 <pre id=
"console"></pre>
7 document
.getElementById("console").appendChild(document
.createTextNode(s
+ "\n"));
10 function shouldBe(a
, b
)
20 var message
= (evalA
=== evalB
)
21 ? "PASS: " + a
+ " should be '" + evalB
+ "' and is."
22 : "*** FAIL: " + a
+ " should be '" + evalB
+ "' but instead is " + evalA
+ ". ***";
26 function shouldBeTrue(a
)
31 function shouldBeFalse(b
)
36 function canGet(keyPath
)
39 return eval("window." + keyPath
) !== undefined;
45 window
.marker
= { "foo": "bar", toString: function(){ return "window.marker.toString()"; } };
46 window
.callableMarker = function() { return "window.callableMarker.toString()"; };
48 function canSet(keyPath
)
50 var valuePath
= "window.marker";
53 eval("window." + keyPath
+ " = " + valuePath
);
54 return eval("window." + keyPath
) === eval("window." + valuePath
);
60 function canSetWithTypeConversion(keyPath
)
62 var valuePath
= "window.marker";
65 eval("window." + keyPath
+ " = " + valuePath
);
66 return eval("window." + keyPath
) == eval("window." + valuePath
);
72 function canSetWithCallable(keyPath
)
74 var valuePath
= "window.callableMarker";
77 eval("window." + keyPath
+ " = " + valuePath
);
78 return eval("window." + keyPath
) === eval("window." + valuePath
);
84 var windowReadWriteProperties
= [
88 "CSSStyleDeclaration",
108 "HTMLDirectoryElement",
112 "HTMLFieldSetElement",
116 "HTMLFrameSetElement",
119 "HTMLHeadingElement",
124 "HTMLIsIndexElement",
130 "HTMLMarqueeElement",
135 "HTMLOptGroupElement",
137 "HTMLParagraphElement",
144 "HTMLTableCaptionElement",
145 "HTMLTableCellElement",
146 "HTMLTableColElement",
148 "HTMLTableRowElement",
149 "HTMLTableSectionElement",
150 "HTMLTextAreaElement",
158 "ProcessingInstruction",
189 "offscreenBuffering",
210 var windowReadOnlyProperties
= [
219 var windowReadWriteStringProperties
= [
226 var windowFunctions
= [
233 "getMatchedCSSRules",
241 "removeEventListener",
252 var windowEventHandlers
= [
280 window
.onload = function()
282 if (window
.testRunner
)
283 testRunner
.dumpAsText();
285 log("\n----- tests for getting/setting read-write properties -----\n");
287 for (var i
= 0; i
< windowReadWriteProperties
.length
; i
++) {
288 var property
= windowReadWriteProperties
[i
];
289 shouldBeTrue("canGet('" + property
+ "')");
290 shouldBeTrue("canSet('" + property
+ "')");
293 log("\n----- tests for getting/setting readonly properties -----\n");
295 for (var i
= 0; i
< windowReadOnlyProperties
.length
; i
++) {
296 var property
= windowReadOnlyProperties
[i
];
297 shouldBeTrue("canGet('" + property
+ "')");
298 shouldBeFalse("canSet('" + property
+ "')");
301 log("\n----- tests for getting/setting string properties -----\n");
302 for (var i
= 0; i
< windowReadWriteStringProperties
.length
; i
++) {
303 var property
= windowReadWriteStringProperties
[i
];
304 shouldBeTrue("canGet('" + property
+ "')");
305 shouldBeTrue("canSetWithTypeConversion('" + property
+ "')");
309 log("\n----- tests for getting/setting functions -----\n");
311 for (var i
= 0; i
< windowFunctions
.length
; i
++) {
312 var property
= windowFunctions
[i
];
313 shouldBeTrue("canGet('" + property
+ "')");
314 shouldBeTrue("canSet('" + property
+ "')");
317 log("\n----- tests for getting/setting event handlers -----\n");
319 for (var i
= 0; i
< windowEventHandlers
.length
; i
++) {
320 var property
= windowEventHandlers
[i
];
321 shouldBeTrue("canGet('" + property
+ "')");
322 shouldBeTrue("canSetWithCallable('" + property
+ "')");