Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / dom-constructors.html
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 </head>
5 <body>
6 <div id="element" name="element_name"></div>
7 <script>
8 description('This test checks that all but a handful of dom constructors throw exceptions, and the rest return reasonable objects. It also tests that those constructors have higher precedence than a document element with the same ID or name.');
9
10 var element = document.getElementById("element");
11
12 // These objects should throw an exception when their constructor is called
13 // with no arguments. (Some of them may have working constructors that require
14 // arguments to be valid.)
15 var objects_exception = [
16     'Attr',
17     'CharacterData',
18     'CDATASection',
19     'Document',
20     'DocumentType',
21     'Element',
22     'EventTarget',
23     'HTMLDocument',
24     'Node',
25     'ProcessingInstruction',
26     'HTMLAllCollection',
27     'HTMLAnchorElement',
28     'HTMLAppletElement',
29     'HTMLAreaElement',
30     'HTMLBaseElement',
31     'HTMLBodyElement',
32     'HTMLBRElement',
33     'HTMLButtonElement',
34     'HTMLCanvasElement',
35     'HTMLDirectoryElement',
36     'HTMLDivElement',
37     'HTMLDListElement',
38     'HTMLEmbedElement',
39     'HTMLFieldSetElement',
40     'HTMLFontElement',
41     'HTMLFormElement',
42     'HTMLFrameElement',
43     'HTMLFrameSetElement',
44     'HTMLHeadingElement',
45     'HTMLHeadElement',
46     'HTMLHRElement',
47     'HTMLHtmlElement',
48     'HTMLIFrameElement',
49     'HTMLImageElement',
50     'HTMLInputElement',
51     'HTMLLabelElement',
52     'HTMLLegendElement',
53     'HTMLLIElement',
54     'HTMLLinkElement',
55     'HTMLMapElement',
56     'HTMLMarqueeElement',
57     'HTMLMenuElement',
58     'HTMLMetaElement',
59     'HTMLModElement',
60     'HTMLObjectElement',
61     'HTMLOListElement',
62     'HTMLOptGroupElement',
63     'HTMLOptionElement',
64     'HTMLParagraphElement',
65     'HTMLParamElement',
66     'HTMLPreElement',
67     'HTMLQuoteElement',
68     'HTMLScriptElement',
69     'HTMLSelectElement',
70     'HTMLStyleElement',
71     'HTMLTableCaptionElement',
72     'HTMLTableColElement',
73     'HTMLTableElement',
74     'HTMLTableSectionElement',
75     'HTMLTableCellElement',
76     'HTMLTableRowElement',
77     'HTMLTextAreaElement',
78     'HTMLTitleElement',
79     'HTMLUListElement',
80     'HTMLElement',
81     'CanvasRenderingContext2D',
82     'CSSCharsetRule',
83     'CSSFontFaceRule',
84     'CSSImportRule',
85     'CSSMediaRule',
86     'CSSPageRule',
87     'CSSRule',
88     'CSSRuleList',
89     'CSSStyleDeclaration',
90     'CSSStyleRule',
91     'CSSStyleSheet',
92     'DOMImplementation',
93     'DataTransfer',
94     'HTMLCollection',
95     'MediaList',
96     'MimeType',
97     'MimeTypeArray',
98     'MutationEvent',
99     'NamedNodeMap',
100     'NodeFilter',
101     'NodeList',
102     'Plugin',
103     'PluginArray',
104     'StyleSheet',
105     'StyleSheetList',
106     'TextEvent',
107     'XPathResult',
108     'BarInfo',
109     'CanvasGradient',
110     'CanvasPattern',
111     'Console',
112     'Selection',
113     'Window',
114     'History',
115     'HTMLOptionsCollection',
116     'Location',
117     'Navigator',
118     'NodeIterator',
119     'Screen',
120     'TreeWalker',
121     'XPathExpression',
122     'Worker'
123 ];
124
125 // These objects should have a working constructor.
126 var objects_constructor = [
127     'Comment',
128     'DOMParser',
129     'DocumentFragment',
130     'Range',
131     'Text',
132     'XMLHttpRequest',
133     'XMLSerializer',
134     'XPathEvaluator',
135     'XSLTProcessor'
136 ];
137
138 // These objects should have no constructor.
139 var objects_no_constructor = [
140     'EventTargetNode',
141     'UndetectableHTMLCollection',
142     'XPathNSResolver',
143     'EventListener',
144     'NPObject'
145 ];
146
147 // These objects should have a working constructor, but their constructed
148 // object names differ. This is therefore a map from constructor name to
149 // constructed object.
150 var objects_different_constructor = {
151     'Audio': 'HTMLAudioElement',
152     'Option': 'HTMLOptionElement',
153     'Image': 'HTMLImageElement'
154 }
155
156 function TryAllocate(node) {
157     var Cons = this[node];
158     if (!Cons) return 'no constructor';
159     try { return Object.prototype.toString.call(new Cons()); }
160     catch (e) { return 'exception'; }
161 }
162
163 function check(name, expected) {
164     actual = TryAllocate(node);
165     if (actual == expected) {
166       document.write("PASS: " + name + " '" + expected + "'<br>");
167     } else {
168       document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
169           actual + "'<br>");
170     }
171 }
172
173 for (var i = 0; i < objects_exception.length; i++) {
174     var obj = objects_exception[i];
175     shouldBe("TryAllocate('" + obj + "')", "'exception'");
176 }
177
178 for (var i = 0; i < objects_no_constructor.length; i++) {
179     var obj = objects_no_constructor[i];
180     shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
181 }
182
183 for (var i = 0; i < objects_constructor.length; i++) {
184     var obj = objects_constructor[i];
185     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
186     element.id = obj;
187     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
188     element.id = "element";
189     element.name = obj;
190     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
191     element.name = "element_name";
192 }
193
194 for (var obj in objects_different_constructor) {
195     shouldBe("TryAllocate('" + obj + "')",
196              "'[object " + objects_different_constructor[obj] + "]'");
197     element.id = obj;
198     shouldBe("TryAllocate('" + obj + "')",
199              "'[object " + objects_different_constructor[obj] + "]'");
200     element.id = "element";
201     element.name = obj;
202     shouldBe("TryAllocate('" + obj + "')",
203              "'[object " + objects_different_constructor[obj] + "]'");
204     element.name = "element_name";
205 }
206 </script>
207 </body>
208 </html>