Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Window / get-set-properties.html
blobc845913842cf75e980dc7284a6d2b388aaf5372e
1 <p>This page tests getting and setting window properties and functions.</p>
2 <pre id="console"></pre>
4 <script>
5 function log(s)
7 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
10 function shouldBe(a, b)
12 var evalA, evalB;
13 try {
14 evalA = eval(a);
15 evalB = eval(b);
16 } catch(e) {
17 evalA = e;
20 var message = (evalA === evalB)
21 ? "PASS: " + a + " should be '" + evalB + "' and is."
22 : "*** FAIL: " + a + " should be '" + evalB + "' but instead is " + evalA + ". ***";
23 log(message);
26 function shouldBeTrue(a)
28 shouldBe(a, "true");
31 function shouldBeFalse(b)
33 shouldBe(b, "false");
36 function canGet(keyPath)
38 try {
39 return eval("window." + keyPath) !== undefined;
40 } catch(e) {
41 return false;
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";
52 try {
53 eval("window." + keyPath + " = " + valuePath);
54 return eval("window." + keyPath) === eval("window." + valuePath);
55 } catch(e) {
56 return false;
60 function canSetWithTypeConversion(keyPath)
62 var valuePath = "window.marker";
64 try {
65 eval("window." + keyPath + " = " + valuePath);
66 return eval("window." + keyPath) == eval("window." + valuePath);
67 } catch(e) {
68 return false;
72 function canSetWithCallable(keyPath)
74 var valuePath = "window.callableMarker";
76 try {
77 eval("window." + keyPath + " = " + valuePath);
78 return eval("window." + keyPath) === eval("window." + valuePath);
79 } catch(e) {
80 return false;
84 var windowReadWriteProperties = [
85 "Attr",
86 "CDATASection",
87 "CSSRule",
88 "CSSStyleDeclaration",
89 "CharacterData",
90 "Comment",
91 "DOMException",
92 "DOMImplementation",
93 "DOMParser",
94 "Document",
95 "DocumentFragment",
96 "DocumentType",
97 "Element",
98 "EvalError",
99 "Event",
100 "HTMLAnchorElement",
101 "HTMLAreaElement",
102 "HTMLBRElement",
103 "HTMLBaseElement",
104 "HTMLBodyElement",
105 "HTMLButtonElement",
106 "HTMLCanvasElement",
107 "HTMLDListElement",
108 "HTMLDirectoryElement",
109 "HTMLDivElement",
110 "HTMLDocument",
111 "HTMLElement",
112 "HTMLFieldSetElement",
113 "HTMLFontElement",
114 "HTMLFormElement",
115 "HTMLFrameElement",
116 "HTMLFrameSetElement",
117 "HTMLHRElement",
118 "HTMLHeadElement",
119 "HTMLHeadingElement",
120 "HTMLHtmlElement",
121 "HTMLIFrameElement",
122 "HTMLImageElement",
123 "HTMLInputElement",
124 "HTMLIsIndexElement",
125 "HTMLLIElement",
126 "HTMLLabelElement",
127 "HTMLLegendElement",
128 "HTMLLinkElement",
129 "HTMLMapElement",
130 "HTMLMarqueeElement",
131 "HTMLMenuElement",
132 "HTMLMetaElement",
133 "HTMLModElement",
134 "HTMLOListElement",
135 "HTMLOptGroupElement",
136 "HTMLOptionElement",
137 "HTMLParagraphElement",
138 "HTMLParamElement",
139 "HTMLPreElement",
140 "HTMLQuoteElement",
141 "HTMLScriptElement",
142 "HTMLSelectElement",
143 "HTMLStyleElement",
144 "HTMLTableCaptionElement",
145 "HTMLTableCellElement",
146 "HTMLTableColElement",
147 "HTMLTableElement",
148 "HTMLTableRowElement",
149 "HTMLTableSectionElement",
150 "HTMLTextAreaElement",
151 "HTMLTitleElement",
152 "HTMLUListElement",
153 "Image",
154 "MutationEvent",
155 "Node",
156 "NodeFilter",
157 "Option",
158 "ProcessingInstruction",
159 "Range",
160 "RangeError",
161 "ReferenceError",
162 "SyntaxError",
163 "Text",
164 "TypeError",
165 "URIError",
166 "XMLDocument",
167 "XMLHttpRequest",
168 "XMLSerializer",
169 "XPathEvaluator",
170 "XPathResult",
171 "XSLTProcessor",
172 "addEventListener",
173 "alert",
174 "atob",
175 "btoa",
176 "captureEvents",
177 "clearInterval",
178 "clearTimeout",
179 "clientInformation",
180 "console",
181 "devicePixelRatio",
182 "event",
183 "frames",
184 "innerHeight",
185 "innerWidth",
186 "length",
187 "locationbar",
188 "menubar",
189 "offscreenBuffering",
190 "opener",
191 "outerHeight",
192 "outerWidth",
193 "pageXOffset",
194 "pageYOffset",
195 "parent",
196 "personalbar",
197 "screen",
198 "screenLeft",
199 "screenTop",
200 "screenX",
201 "screenY",
202 "scrollX",
203 "scrollY",
204 "scrollbars",
205 "self",
206 "statusbar",
207 "toolbar"
210 var windowReadOnlyProperties = [
211 "closed",
212 "document",
213 "history",
214 "navigator",
215 "window",
216 "top"
219 var windowReadWriteStringProperties = [
220 "defaultStatus",
221 "defaultstatus",
222 "name",
223 "status"
226 var windowFunctions = [
227 "blur",
228 "close",
229 "confirm",
230 "find",
231 "focus",
232 "getComputedStyle",
233 "getMatchedCSSRules",
234 "getSelection",
235 "moveBy",
236 "moveTo",
237 "open",
238 "print",
239 "prompt",
240 "releaseEvents",
241 "removeEventListener",
242 "resizeBy",
243 "resizeTo",
244 "scroll",
245 "scrollBy",
246 "scrollTo",
247 "setInterval",
248 "setTimeout",
249 "stop"
252 var windowEventHandlers = [
253 "onabort",
254 "onbeforeunload",
255 "onblur",
256 "onchange",
257 "onclick",
258 "ondblclick",
259 "onerror",
260 "onfocus",
261 "onkeydown",
262 "onkeypress",
263 "onkeyup",
264 "onload",
265 "onmousedown",
266 "onmousemove",
267 "onmouseout",
268 "onmouseover",
269 "onmouseup",
270 "onmousewheel",
271 "onreset",
272 "onresize",
273 "onscroll",
274 "onsearch",
275 "onselect",
276 "onsubmit",
277 "onunload"
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 + "')");
325 </script>