Upstream version 5.34.104.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     'Notation',
26     'ProcessingInstruction',
27     'HTMLAllCollection',
28     'HTMLAnchorElement',
29     'HTMLAppletElement',
30     'HTMLAreaElement',
31     'HTMLBaseElement',
32     'HTMLBodyElement',
33     'HTMLBRElement',
34     'HTMLButtonElement',
35     'HTMLCanvasElement',
36     'HTMLDirectoryElement',
37     'HTMLDivElement',
38     'HTMLDListElement',
39     'HTMLEmbedElement',
40     'HTMLFieldSetElement',
41     'HTMLFontElement',
42     'HTMLFormElement',
43     'HTMLFrameElement',
44     'HTMLFrameSetElement',
45     'HTMLHeadingElement',
46     'HTMLHeadElement',
47     'HTMLHRElement',
48     'HTMLHtmlElement',
49     'HTMLIFrameElement',
50     'HTMLImageElement',
51     'HTMLInputElement',
52     'HTMLLabelElement',
53     'HTMLLegendElement',
54     'HTMLLIElement',
55     'HTMLLinkElement',
56     'HTMLMapElement',
57     'HTMLMarqueeElement',
58     'HTMLMenuElement',
59     'HTMLMetaElement',
60     'HTMLModElement',
61     'HTMLObjectElement',
62     'HTMLOListElement',
63     'HTMLOptGroupElement',
64     'HTMLOptionElement',
65     'HTMLParagraphElement',
66     'HTMLParamElement',
67     'HTMLPreElement',
68     'HTMLQuoteElement',
69     'HTMLScriptElement',
70     'HTMLSelectElement',
71     'HTMLStyleElement',
72     'HTMLTableCaptionElement',
73     'HTMLTableColElement',
74     'HTMLTableElement',
75     'HTMLTableSectionElement',
76     'HTMLTableCellElement',
77     'HTMLTableRowElement',
78     'HTMLTextAreaElement',
79     'HTMLTitleElement',
80     'HTMLUListElement',
81     'HTMLElement',
82     'CanvasRenderingContext2D',
83     'Clipboard',
84     'Counter',
85     'CSSCharsetRule',
86     'CSSFontFaceRule',
87     'CSSImportRule',
88     'CSSMediaRule',
89     'CSSPageRule',
90     'CSSPrimitiveValue',
91     'CSSRule',
92     'CSSRuleList',
93     'CSSStyleDeclaration',
94     'CSSStyleRule',
95     'CSSStyleSheet',
96     'CSSValue',
97     'CSSValueList',
98     'DOMImplementation',
99     'HTMLCollection',
100     'MediaList',
101     'MimeType',
102     'MimeTypeArray',
103     'MutationEvent',
104     'NamedNodeMap',
105     'NodeFilter',
106     'NodeList',
107     'Plugin',
108     'PluginArray',
109     'Rect',
110     'StyleSheet',
111     'StyleSheetList',
112     'TextEvent',
113     'XPathResult',
114     'BarInfo',
115     'CanvasGradient',
116     'CanvasPattern',
117     'Console',
118     'Selection',
119     'Window',
120     'History',
121     'HTMLOptionsCollection',
122     'Location',
123     'Navigator',
124     'NodeIterator',
125     'RGBColor',
126     'Screen',
127     'TreeWalker',
128     'XPathExpression',
129     'Worker'
130 ];
131
132 // These objects should have a working constructor.
133 var objects_constructor = [
134     'Comment',
135     'DOMParser',
136     'DocumentFragment',
137     'Range',
138     'Text',
139     'XMLHttpRequest',
140     'XMLSerializer',
141     'XPathEvaluator',
142     'XSLTProcessor'
143 ];
144
145 // These objects should have no constructor.
146 var objects_no_constructor = [
147     'EventTargetNode',
148     'UndetectableHTMLCollection',
149     'XPathNSResolver',
150     'EventListener',
151     'NPObject'
152 ];
153
154 // These objects should have a working constructor, but their constructed
155 // object names differ. This is therefore a map from constructor name to
156 // constructed object.
157 var objects_different_constructor = {
158     'Audio': 'HTMLAudioElement',
159     'Option': 'HTMLOptionElement',
160     'Image': 'HTMLImageElement'
161 }
162
163 function TryAllocate(node) {
164     var Cons = this[node];
165     if (!Cons) return 'no constructor';
166     try { return Object.prototype.toString.call(new Cons()); }
167     catch (e) { return 'exception'; }
168 }
169
170 function check(name, expected) {
171     actual = TryAllocate(node);
172     if (actual == expected) {
173       document.write("PASS: " + name + " '" + expected + "'<br>");
174     } else {
175       document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
176           actual + "'<br>");
177     }
178 }
179
180 for (var i = 0; i < objects_exception.length; i++) {
181     var obj = objects_exception[i];
182     shouldBe("TryAllocate('" + obj + "')", "'exception'");
183 }
184
185 for (var i = 0; i < objects_no_constructor.length; i++) {
186     var obj = objects_no_constructor[i];
187     shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
188 }
189
190 for (var i = 0; i < objects_constructor.length; i++) {
191     var obj = objects_constructor[i];
192     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
193     element.id = obj;
194     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
195     element.id = "element";
196     element.name = obj;
197     shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
198     element.name = "element_name";
199 }
200
201 for (var obj in objects_different_constructor) {
202     shouldBe("TryAllocate('" + obj + "')",
203              "'[object " + objects_different_constructor[obj] + "]'");
204     element.id = obj;
205     shouldBe("TryAllocate('" + obj + "')",
206              "'[object " + objects_different_constructor[obj] + "]'");
207     element.id = "element";
208     element.name = obj;
209     shouldBe("TryAllocate('" + obj + "')",
210              "'[object " + objects_different_constructor[obj] + "]'");
211     element.name = "element_name";
212 }
213 </script>
214 </body>
215 </html>