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",
110 "HTMLDirectoryElement",
114 "HTMLFieldSetElement",
118 "HTMLFrameSetElement",
121 "HTMLHeadingElement",
126 "HTMLIsIndexElement",
132 "HTMLMarqueeElement",
137 "HTMLOptGroupElement",
139 "HTMLParagraphElement",
146 "HTMLTableCaptionElement",
147 "HTMLTableCellElement",
148 "HTMLTableColElement",
150 "HTMLTableRowElement",
151 "HTMLTableSectionElement",
152 "HTMLTextAreaElement",
160 "ProcessingInstruction",
191 "offscreenBuffering",
209 var windowReadOnlyProperties = [
221 var windowReadWriteStringProperties = [
228 var windowFunctions = [
235 "getMatchedCSSRules",
243 "removeEventListener",
254 var windowEventHandlers = [
282 window.onload = function()
284 if (window.testRunner)
285 testRunner.dumpAsText();
287 log("\n----- tests for getting/setting read-write properties -----\n");
289 for (var i = 0; i < windowReadWriteProperties.length; i++) {
290 var property = windowReadWriteProperties[i];
291 shouldBeTrue("canGet('" + property + "')");
292 shouldBeTrue("canSet('" + property + "')");
295 log("\n----- tests for getting/setting readonly properties -----\n");
297 for (var i = 0; i < windowReadOnlyProperties.length; i++) {
298 var property = windowReadOnlyProperties[i];
299 shouldBeTrue("canGet('" + property + "')");
300 shouldBeFalse("canSet('" + property + "')");
303 log("\n----- tests for getting/setting string properties -----\n");
304 for (var i = 0; i < windowReadWriteStringProperties.length; i++) {
305 var property = windowReadWriteStringProperties[i];
306 shouldBeTrue("canGet('" + property + "')");
307 shouldBeTrue("canSetWithTypeConversion('" + property + "')");
311 log("\n----- tests for getting/setting functions -----\n");
313 for (var i = 0; i < windowFunctions.length; i++) {
314 var property = windowFunctions[i];
315 shouldBeTrue("canGet('" + property + "')");
316 shouldBeTrue("canSet('" + property + "')");
319 log("\n----- tests for getting/setting event handlers -----\n");
321 for (var i = 0; i < windowEventHandlers.length; i++) {
322 var property = windowEventHandlers[i];
323 shouldBeTrue("canGet('" + property + "')");
324 shouldBeTrue("canSetWithCallable('" + property + "')");