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 = [
89 "CSSStyleDeclaration",
111 "HTMLDirectoryElement",
115 "HTMLFieldSetElement",
119 "HTMLFrameSetElement",
122 "HTMLHeadingElement",
127 "HTMLIsIndexElement",
133 "HTMLMarqueeElement",
138 "HTMLOptGroupElement",
140 "HTMLParagraphElement",
147 "HTMLTableCaptionElement",
148 "HTMLTableCellElement",
149 "HTMLTableColElement",
151 "HTMLTableRowElement",
152 "HTMLTableSectionElement",
153 "HTMLTextAreaElement",
162 "ProcessingInstruction",
195 "offscreenBuffering",
213 var windowReadOnlyProperties = [
222 var windowReadWriteStringProperties = [
229 var windowFunctions = [
236 "getMatchedCSSRules",
244 "removeEventListener",
255 var windowEventHandlers = [
283 window.onload = function()
285 if (window.testRunner)
286 testRunner.dumpAsText();
288 log("\n----- tests for getting/setting read-write properties -----\n");
290 for (var i = 0; i < windowReadWriteProperties.length; i++) {
291 var property = windowReadWriteProperties[i];
292 shouldBeTrue("canGet('" + property + "')");
293 shouldBeTrue("canSet('" + property + "')");
296 log("\n----- tests for getting/setting readonly properties -----\n");
298 for (var i = 0; i < windowReadOnlyProperties.length; i++) {
299 var property = windowReadOnlyProperties[i];
300 shouldBeTrue("canGet('" + property + "')");
301 shouldBeFalse("canSet('" + property + "')");
304 log("\n----- tests for getting/setting string properties -----\n");
305 for (var i = 0; i < windowReadWriteStringProperties.length; i++) {
306 var property = windowReadWriteStringProperties[i];
307 shouldBeTrue("canGet('" + property + "')");
308 shouldBeTrue("canSetWithTypeConversion('" + property + "')");
312 log("\n----- tests for getting/setting functions -----\n");
314 for (var i = 0; i < windowFunctions.length; i++) {
315 var property = windowFunctions[i];
316 shouldBeTrue("canGet('" + property + "')");
317 shouldBeTrue("canSet('" + property + "')");
320 log("\n----- tests for getting/setting event handlers -----\n");
322 for (var i = 0; i < windowEventHandlers.length; i++) {
323 var property = windowEventHandlers[i];
324 shouldBeTrue("canGet('" + property + "')");
325 shouldBeTrue("canSetWithCallable('" + property + "')");