Update To 11.40.268.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     "CharacterData", 
91     "Comment", 
92     "DOMException", 
93     "DOMImplementation", 
94     "DOMParser", 
95     "Document", 
96     "DocumentFragment", 
97     "DocumentType", 
98     "Element", 
99     "EvalError", 
100     "Event", 
101     "HTMLAnchorElement", 
102     "HTMLAppletElement", 
103     "HTMLAreaElement", 
104     "HTMLBRElement", 
105     "HTMLBaseElement", 
106     "HTMLBodyElement", 
107     "HTMLButtonElement", 
108     "HTMLCanvasElement", 
109     "HTMLDListElement", 
110     "HTMLDirectoryElement", 
111     "HTMLDivElement", 
112     "HTMLDocument", 
113     "HTMLElement", 
114     "HTMLFieldSetElement", 
115     "HTMLFontElement", 
116     "HTMLFormElement", 
117     "HTMLFrameElement", 
118     "HTMLFrameSetElement", 
119     "HTMLHRElement", 
120     "HTMLHeadElement", 
121     "HTMLHeadingElement", 
122     "HTMLHtmlElement", 
123     "HTMLIFrameElement", 
124     "HTMLImageElement", 
125     "HTMLInputElement", 
126     "HTMLIsIndexElement", 
127     "HTMLLIElement", 
128     "HTMLLabelElement", 
129     "HTMLLegendElement", 
130     "HTMLLinkElement", 
131     "HTMLMapElement", 
132     "HTMLMarqueeElement", 
133     "HTMLMenuElement", 
134     "HTMLMetaElement", 
135     "HTMLModElement", 
136     "HTMLOListElement", 
137     "HTMLOptGroupElement", 
138     "HTMLOptionElement", 
139     "HTMLParagraphElement", 
140     "HTMLParamElement", 
141     "HTMLPreElement", 
142     "HTMLQuoteElement", 
143     "HTMLScriptElement", 
144     "HTMLSelectElement", 
145     "HTMLStyleElement", 
146     "HTMLTableCaptionElement", 
147     "HTMLTableCellElement", 
148     "HTMLTableColElement", 
149     "HTMLTableElement", 
150     "HTMLTableRowElement", 
151     "HTMLTableSectionElement", 
152     "HTMLTextAreaElement", 
153     "HTMLTitleElement", 
154     "HTMLUListElement", 
155     "Image", 
156     "MutationEvent", 
157     "Node", 
158     "NodeFilter", 
159     "Option", 
160     "ProcessingInstruction", 
161     "Range", 
162     "RangeError", 
163     "ReferenceError", 
164     "SyntaxError", 
165     "Text", 
166     "TypeError", 
167     "URIError", 
168     "XMLDocument", 
169     "XMLHttpRequest", 
170     "XMLSerializer", 
171     "XPathEvaluator", 
172     "XPathResult", 
173     "XSLTProcessor",
174     "addEventListener", 
175     "alert", 
176     "atob", 
177     "btoa", 
178     "captureEvents",
179     "clearInterval", 
180     "clearTimeout",
181     "clientInformation", 
182     "console", 
183     "devicePixelRatio", 
184     "event", 
185     "frames",
186     "innerHeight", 
187     "innerWidth", 
188     "length",
189     "locationbar", 
190     "menubar", 
191     "offscreenBuffering", 
192     "opener",
193     "outerHeight", 
194     "outerWidth", 
195     "parent",
196     "personalbar",
197     "screenLeft", 
198     "screenTop", 
199     "screenX", 
200     "screenY", 
201     "scrollX", 
202     "scrollY", 
203     "scrollbars",
204     "self",
205     "statusbar",
206     "toolbar"
207 ];
208
209 var windowReadOnlyProperties = [
210     "closed",
211     "document",
212     "history",
213     "navigator",
214     "pageXOffset",
215     "pageYOffset",
216     "screen",
217     "window",
218     "top"
219 ];
220
221 var windowReadWriteStringProperties = [
222     "defaultStatus",
223     "defaultstatus",
224     "name",
225     "status"
226 ];
227
228 var windowFunctions = [
229     "blur",
230     "close",
231     "confirm",
232     "find", 
233     "focus",
234     "getComputedStyle",
235     "getMatchedCSSRules", 
236     "getSelection",
237     "moveBy", 
238     "moveTo", 
239     "open", 
240     "print", 
241     "prompt", 
242     "releaseEvents",
243     "removeEventListener", 
244     "resizeBy", 
245     "resizeTo", 
246     "scroll", 
247     "scrollBy", 
248     "scrollTo", 
249     "setInterval", 
250     "setTimeout", 
251     "stop"
252 ];
253
254 var windowEventHandlers = [
255     "onabort", 
256     "onbeforeunload", 
257     "onblur", 
258     "onchange", 
259     "onclick", 
260     "ondblclick", 
261     "onerror", 
262     "onfocus", 
263     "onkeydown", 
264     "onkeypress", 
265     "onkeyup", 
266     "onload", 
267     "onmousedown", 
268     "onmousemove", 
269     "onmouseout", 
270     "onmouseover", 
271     "onmouseup", 
272     "onmousewheel", 
273     "onreset", 
274     "onresize", 
275     "onscroll", 
276     "onsearch", 
277     "onselect", 
278     "onsubmit", 
279     "onunload"
280 ];
281
282 window.onload = function()
283 {
284     if (window.testRunner)
285         testRunner.dumpAsText();
286
287     log("\n----- tests for getting/setting read-write properties -----\n");
288
289     for (var i = 0; i < windowReadWriteProperties.length; i++) {
290         var property = windowReadWriteProperties[i];
291         shouldBeTrue("canGet('" + property + "')");
292         shouldBeTrue("canSet('" + property + "')");
293     }
294
295     log("\n----- tests for getting/setting readonly properties -----\n");
296
297     for (var i = 0; i < windowReadOnlyProperties.length; i++) {
298         var property = windowReadOnlyProperties[i];
299         shouldBeTrue("canGet('" + property + "')");
300         shouldBeFalse("canSet('" + property + "')");
301     }
302
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 + "')");
308         
309     }
310
311     log("\n----- tests for getting/setting functions -----\n");
312
313     for (var i = 0; i < windowFunctions.length; i++) {
314         var property = windowFunctions[i];
315         shouldBeTrue("canGet('" + property + "')");
316         shouldBeTrue("canSet('" + property + "')");
317     }
318
319     log("\n----- tests for getting/setting event handlers -----\n");
320
321     for (var i = 0; i < windowEventHandlers.length; i++) {
322         var property = windowEventHandlers[i];
323         shouldBeTrue("canGet('" + property + "')");
324         shouldBeTrue("canSetWithCallable('" + property + "')");
325     }
326 }
327 </script>