3 <script src=
"../../resources/js-test.js"></script>
7 var ns
= "http://not-html.test";
9 function testDocumentProperty(attributeName
, elementName
, base
) {
11 if (typeof base
== 'undefined')
14 elem
= document
.createElementNS(ns
, elementName
);
15 document
.body
.appendChild(elem
);
16 shouldBe("document." + attributeName
+ ".length", base
+ "");
17 document
.body
.removeChild(elem
);
19 elem
= document
.createElement(elementName
);
20 document
.body
.appendChild(elem
);
21 shouldBe("document." + attributeName
+ ".length", base
+ 1 + "");
22 document
.body
.removeChild(elem
);
25 function testDocumentPropertyWithAttributes(attributeName
, elementName
, attributes
, base
) {
27 if (typeof base
== 'undefined')
30 elem
= document
.createElementNS(ns
, elementName
);
31 for (let k
in attributes
)
32 elem
.setAttribute(k
, attributes
[k
]);
33 document
.body
.appendChild(elem
);
34 shouldBe("document." + attributeName
+ ".length", base
+ "");
35 document
.body
.removeChild(elem
);
37 elem
= document
.createElement(elementName
);
38 for (let k
in attributes
)
39 elem
.setAttribute(k
, attributes
[k
]);
40 document
.body
.appendChild(elem
);
41 shouldBe("document." + attributeName
+ ".length", base
+ 1 + "");
42 document
.body
.removeChild(elem
);
45 function testElementProperty(elementName
, attributeName
, subelementName
, base
) {
47 if (typeof base
== 'undefined')
50 elem
= document
.createElement(elementName
);
51 subelem
= document
.createElementNS(ns
, subelementName
);
52 elem
.appendChild(subelem
);
53 shouldBe("elem." + attributeName
+ ".length", base
+ "");
54 elem
.removeChild(subelem
);
56 subelem
= document
.createElement(subelementName
);
57 elem
.appendChild(subelem
);
58 shouldBe("elem." + attributeName
+ ".length", base
+ 1 + "");
59 elem
.removeChild(subelem
);
63 if (window
.testRunner
)
64 window
.testRunner
.dumpAsText();
66 description('Tests that HTMLCollection only properly contains HTML elements');
69 select
= document
.createElement("select");
70 elem
= document
.createElementNS(ns
, "option");
71 select
.appendChild(elem
);
72 shouldBe("select.options.length", "0");
73 shouldBe("select.selectedOptions.length", "0");
75 elem
= document
.createElement("option");
76 select
.appendChild(elem
);
77 shouldBe("select.options.length", "1");
79 testDocumentProperty("images", "img");
80 testDocumentProperty("forms", "form");
81 testDocumentPropertyWithAttributes("applets", "object", {type
: "application/x-java-applet"});
82 testDocumentProperty("embeds", "embed");
84 // Note that this is run before the final script element on this page is inserted
85 testDocumentProperty("scripts", "script", 3);
87 testDocumentPropertyWithAttributes("links", "a", {href
: "foo"});
88 testDocumentPropertyWithAttributes("links", "area", {href
: "foo"});
89 testDocumentPropertyWithAttributes("anchors", "a", {name
: "foo"});
91 testElementProperty("map", "areas", "area");
92 testElementProperty("table", "rows", "tr");
93 testElementProperty("table", "tBodies", "tbody");
94 testElementProperty("tr", "cells", "td");
95 testElementProperty("thead", "rows", "tr");
96 testElementProperty("tbody", "rows", "tr");
97 testElementProperty("tfoot", "rows", "tr");
102 <script>runTest();</script>