Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / Window / get-set-properties.html
1 <p>This page tests getting and setting window properties and functions.</p>
2 <pre id="console"></pre>
3
4 <script>
5 function log(s)
6 {
7     document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
8 }
9
10 function shouldBe(a, b)
11 {
12     var evalA, evalB;
13     try {
14         evalA = eval(a);
15         evalB = eval(b);
16     } catch(e) {
17         evalA = e;
18     }
19
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);
24 }
25
26 function shouldBeTrue(a) 
27
28     shouldBe(a, "true"); 
29 }
30
31 function shouldBeFalse(b) 
32
33     shouldBe(b, "false"); 
34 }
35
36 function canGet(keyPath)
37 {
38     try {
39         return eval("window." + keyPath) !== undefined;
40     } catch(e) {
41         return false;
42     }
43 }
44
45 window.marker = { "foo": "bar", toString: function(){ return "window.marker.toString()"; } };
46 window.callableMarker = function() { return "window.callableMarker.toString()"; };
47
48 function canSet(keyPath)
49 {
50     var valuePath = "window.marker";
51
52     try {
53         eval("window." + keyPath + " = " + valuePath);
54         return eval("window." + keyPath) === eval("window." + valuePath);
55     } catch(e) {
56         return false;
57     }
58 }
59
60 function canSetWithTypeConversion(keyPath)
61 {
62     var valuePath = "window.marker";
63
64     try {
65         eval("window." + keyPath + " = " + valuePath);
66         return eval("window." + keyPath) == eval("window." + valuePath);
67     } catch(e) {
68         return false;
69     }
70 }
71
72 function canSetWithCallable(keyPath)
73 {
74     var valuePath = "window.callableMarker";
75
76     try {
77         eval("window." + keyPath + " = " + valuePath);
78         return eval("window." + keyPath) === eval("window." + valuePath);
79     } catch(e) {
80         return false;
81     }
82 }
83
84 var windowReadWriteProperties = [
85     "Attr", 
86     "CDATASection", 
87     "CSSPrimitiveValue", 
88     "CSSRule", 
89     "CSSStyleDeclaration", 
90     "CSSValue", 
91     "CharacterData", 
92     "Comment", 
93     "DOMException", 
94     "DOMImplementation", 
95     "DOMParser", 
96     "Document", 
97     "DocumentFragment", 
98     "DocumentType", 
99     "Element", 
100     "EvalError", 
101     "Event", 
102     "HTMLAnchorElement", 
103     "HTMLAppletElement", 
104     "HTMLAreaElement", 
105     "HTMLBRElement", 
106     "HTMLBaseElement", 
107     "HTMLBodyElement", 
108     "HTMLButtonElement", 
109     "HTMLCanvasElement", 
110     "HTMLDListElement", 
111     "HTMLDirectoryElement", 
112     "HTMLDivElement", 
113     "HTMLDocument", 
114     "HTMLElement", 
115     "HTMLFieldSetElement", 
116     "HTMLFontElement", 
117     "HTMLFormElement", 
118     "HTMLFrameElement", 
119     "HTMLFrameSetElement", 
120     "HTMLHRElement", 
121     "HTMLHeadElement", 
122     "HTMLHeadingElement", 
123     "HTMLHtmlElement", 
124     "HTMLIFrameElement", 
125     "HTMLImageElement", 
126     "HTMLInputElement", 
127     "HTMLIsIndexElement", 
128     "HTMLLIElement", 
129     "HTMLLabelElement", 
130     "HTMLLegendElement", 
131     "HTMLLinkElement", 
132     "HTMLMapElement", 
133     "HTMLMarqueeElement", 
134     "HTMLMenuElement", 
135     "HTMLMetaElement", 
136     "HTMLModElement", 
137     "HTMLOListElement", 
138     "HTMLOptGroupElement", 
139     "HTMLOptionElement", 
140     "HTMLParagraphElement", 
141     "HTMLParamElement", 
142     "HTMLPreElement", 
143     "HTMLQuoteElement", 
144     "HTMLScriptElement", 
145     "HTMLSelectElement", 
146     "HTMLStyleElement", 
147     "HTMLTableCaptionElement", 
148     "HTMLTableCellElement", 
149     "HTMLTableColElement", 
150     "HTMLTableElement", 
151     "HTMLTableRowElement", 
152     "HTMLTableSectionElement", 
153     "HTMLTextAreaElement", 
154     "HTMLTitleElement", 
155     "HTMLUListElement", 
156     "Image", 
157     "MutationEvent", 
158     "Node", 
159     "NodeFilter", 
160     "Option", 
161     "ProcessingInstruction", 
162     "Range", 
163     "RangeError", 
164     "ReferenceError", 
165     "SyntaxError", 
166     "Text", 
167     "TypeError", 
168     "URIError", 
169     "XMLDocument", 
170     "XMLHttpRequest", 
171     "XMLSerializer", 
172     "XPathEvaluator", 
173     "XPathResult", 
174     "XSLTProcessor",
175     "addEventListener", 
176     "alert", 
177     "atob", 
178     "btoa", 
179     "captureEvents",
180     "clearInterval", 
181     "clearTimeout",
182     "clientInformation", 
183     "console", 
184     "devicePixelRatio", 
185     "event", 
186     "frames",
187     "innerHeight", 
188     "innerWidth", 
189     "length",
190     "locationbar", 
191     "menubar", 
192     "offscreenBuffering", 
193     "opener",
194     "outerHeight", 
195     "outerWidth", 
196     "parent",
197     "personalbar",
198     "screenLeft", 
199     "screenTop", 
200     "screenX", 
201     "screenY", 
202     "scrollX", 
203     "scrollY", 
204     "scrollbars",
205     "self",
206     "statusbar",
207     "toolbar"
208 ];
209
210 var windowReadOnlyProperties = [
211     "closed",
212     "document",
213     "history",
214     "navigator",
215     "pageXOffset",
216     "pageYOffset",
217     "screen",
218     "window",
219     "top"
220 ];
221
222 var windowReadWriteStringProperties = [
223     "defaultStatus",
224     "defaultstatus",
225     "name",
226     "status"
227 ];
228
229 var windowFunctions = [
230     "blur",
231     "close",
232     "confirm",
233     "find", 
234     "focus",
235     "getComputedStyle",
236     "getMatchedCSSRules", 
237     "getSelection",
238     "moveBy", 
239     "moveTo", 
240     "open", 
241     "print", 
242     "prompt", 
243     "releaseEvents",
244     "removeEventListener", 
245     "resizeBy", 
246     "resizeTo", 
247     "scroll", 
248     "scrollBy", 
249     "scrollTo", 
250     "setInterval", 
251     "setTimeout", 
252     "stop"
253 ];
254
255 var windowEventHandlers = [
256     "onabort", 
257     "onbeforeunload", 
258     "onblur", 
259     "onchange", 
260     "onclick", 
261     "ondblclick", 
262     "onerror", 
263     "onfocus", 
264     "onkeydown", 
265     "onkeypress", 
266     "onkeyup", 
267     "onload", 
268     "onmousedown", 
269     "onmousemove", 
270     "onmouseout", 
271     "onmouseover", 
272     "onmouseup", 
273     "onmousewheel", 
274     "onreset", 
275     "onresize", 
276     "onscroll", 
277     "onsearch", 
278     "onselect", 
279     "onsubmit", 
280     "onunload"
281 ];
282
283 window.onload = function()
284 {
285     if (window.testRunner)
286         testRunner.dumpAsText();
287
288     log("\n----- tests for getting/setting read-write properties -----\n");
289
290     for (var i = 0; i < windowReadWriteProperties.length; i++) {
291         var property = windowReadWriteProperties[i];
292         shouldBeTrue("canGet('" + property + "')");
293         shouldBeTrue("canSet('" + property + "')");
294     }
295
296     log("\n----- tests for getting/setting readonly properties -----\n");
297
298     for (var i = 0; i < windowReadOnlyProperties.length; i++) {
299         var property = windowReadOnlyProperties[i];
300         shouldBeTrue("canGet('" + property + "')");
301         shouldBeFalse("canSet('" + property + "')");
302     }
303
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 + "')");
309         
310     }
311
312     log("\n----- tests for getting/setting functions -----\n");
313
314     for (var i = 0; i < windowFunctions.length; i++) {
315         var property = windowFunctions[i];
316         shouldBeTrue("canGet('" + property + "')");
317         shouldBeTrue("canSet('" + property + "')");
318     }
319
320     log("\n----- tests for getting/setting event handlers -----\n");
321
322     for (var i = 0; i < windowEventHandlers.length; i++) {
323         var property = windowEventHandlers[i];
324         shouldBeTrue("canGet('" + property + "')");
325         shouldBeTrue("canSetWithCallable('" + property + "')");
326     }
327 }
328 </script>