3 <script src="../../resources/js-test.js"></script>
6 <div id="element" name="element_name"></div>
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.');
10 var element = document.getElementById("element");
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 = [
25 'ProcessingInstruction',
35 'HTMLDirectoryElement',
39 'HTMLFieldSetElement',
43 'HTMLFrameSetElement',
62 'HTMLOptGroupElement',
64 'HTMLParagraphElement',
71 'HTMLTableCaptionElement',
72 'HTMLTableColElement',
74 'HTMLTableSectionElement',
75 'HTMLTableCellElement',
76 'HTMLTableRowElement',
77 'HTMLTextAreaElement',
81 'CanvasRenderingContext2D',
89 'CSSStyleDeclaration',
115 'HTMLOptionsCollection',
125 // These objects should have a working constructor.
126 var objects_constructor = [
138 // These objects should have no constructor.
139 var objects_no_constructor = [
141 'UndetectableHTMLCollection',
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'
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'; }
163 function check(name, expected) {
164 actual = TryAllocate(node);
165 if (actual == expected) {
166 document.write("PASS: " + name + " '" + expected + "'<br>");
168 document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
173 for (var i = 0; i < objects_exception.length; i++) {
174 var obj = objects_exception[i];
175 shouldBe("TryAllocate('" + obj + "')", "'exception'");
178 for (var i = 0; i < objects_no_constructor.length; i++) {
179 var obj = objects_no_constructor[i];
180 shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
183 for (var i = 0; i < objects_constructor.length; i++) {
184 var obj = objects_constructor[i];
185 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
187 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
188 element.id = "element";
190 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
191 element.name = "element_name";
194 for (var obj in objects_different_constructor) {
195 shouldBe("TryAllocate('" + obj + "')",
196 "'[object " + objects_different_constructor[obj] + "]'");
198 shouldBe("TryAllocate('" + obj + "')",
199 "'[object " + objects_different_constructor[obj] + "]'");
200 element.id = "element";
202 shouldBe("TryAllocate('" + obj + "')",
203 "'[object " + objects_different_constructor[obj] + "]'");
204 element.name = "element_name";