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 = [
26 'ProcessingInstruction',
36 'HTMLDirectoryElement',
40 'HTMLFieldSetElement',
44 'HTMLFrameSetElement',
63 'HTMLOptGroupElement',
65 'HTMLParagraphElement',
72 'HTMLTableCaptionElement',
73 'HTMLTableColElement',
75 'HTMLTableSectionElement',
76 'HTMLTableCellElement',
77 'HTMLTableRowElement',
78 'HTMLTextAreaElement',
82 'CanvasRenderingContext2D',
93 'CSSStyleDeclaration',
121 'HTMLOptionsCollection',
132 // These objects should have a working constructor.
133 var objects_constructor = [
145 // These objects should have no constructor.
146 var objects_no_constructor = [
148 'UndetectableHTMLCollection',
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'
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'; }
170 function check(name, expected) {
171 actual = TryAllocate(node);
172 if (actual == expected) {
173 document.write("PASS: " + name + " '" + expected + "'<br>");
175 document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
180 for (var i = 0; i < objects_exception.length; i++) {
181 var obj = objects_exception[i];
182 shouldBe("TryAllocate('" + obj + "')", "'exception'");
185 for (var i = 0; i < objects_no_constructor.length; i++) {
186 var obj = objects_no_constructor[i];
187 shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
190 for (var i = 0; i < objects_constructor.length; i++) {
191 var obj = objects_constructor[i];
192 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
194 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
195 element.id = "element";
197 shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
198 element.name = "element_name";
201 for (var obj in objects_different_constructor) {
202 shouldBe("TryAllocate('" + obj + "')",
203 "'[object " + objects_different_constructor[obj] + "]'");
205 shouldBe("TryAllocate('" + obj + "')",
206 "'[object " + objects_different_constructor[obj] + "]'");
207 element.id = "element";
209 shouldBe("TryAllocate('" + obj + "')",
210 "'[object " + objects_different_constructor[obj] + "]'");
211 element.name = "element_name";