Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / htmlcollection-non-html.html
blobb79a4348bcc3daeab902199947c49919ee4baee4
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 <script>
5 'use strict';
6 var elem, select;
7 var ns = "http://not-html.test";
9 function testDocumentProperty(attributeName, elementName, base) {
10 var elem;
11 if (typeof base == 'undefined')
12 base = 0;
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) {
26 var elem;
27 if (typeof base == 'undefined')
28 base = 0;
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) {
46 var subelem;
47 if (typeof base == 'undefined')
48 base = 0;
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);
62 function runTest() {
63 if (window.testRunner)
64 window.testRunner.dumpAsText();
66 description('Tests that HTMLCollection only properly contains HTML elements');
68 var elem;
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");
99 </script>
100 </head>
101 <body>
102 <script>runTest();</script>
103 </body>
104 </html>