|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=450160 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 450160</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450160">Mozilla Bug 450160</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript"> |
|
19 |
|
20 /** Test for Bug 450160 **/ |
|
21 |
|
22 |
|
23 function testHTMLDocuments(ids, isXHTML) { |
|
24 for (var i = 0; i < ids.length; ++i) { |
|
25 var docType1 = |
|
26 document.implementation.createDocumentType(isXHTML ? "html" : "HTML", |
|
27 ids[i], |
|
28 null); |
|
29 ok(docType1, "No doctype?"); |
|
30 ok(docType1.ownerDocument, "docType should have ownerDocument!"); |
|
31 var doc1 = document.implementation.createDocument(null, null, docType1); |
|
32 is(docType1.ownerDocument, doc1, "docType should have ownerDocument!"); |
|
33 ok(!doc1.documentElement, "Document shouldn't have document element!"); |
|
34 is(doc1.body, null, "Shouldn't have .body!"); |
|
35 ok(doc1 instanceof HTMLDocument, |
|
36 "Document should be an HTML document!"); |
|
37 ok(!(doc1 instanceof SVGDocument), |
|
38 "Document shouldn't be an SVG document!"); |
|
39 |
|
40 var docType2 = |
|
41 document.implementation.createDocumentType(isXHTML ? "html" : "HTML", |
|
42 ids[i], |
|
43 null); |
|
44 var doc2 = document.implementation.createDocument( |
|
45 "http://www.w3.org/1999/xhtml", "html", docType2); |
|
46 is(docType2.ownerDocument, doc2, "docType should have ownerDocument!"); |
|
47 ok(doc2.documentElement, "Document should have document element!"); |
|
48 is(doc2.documentElement.localName, "html", "Wrong document element!"); |
|
49 is(doc2.body, null, "Shouldn't have .body!"); |
|
50 doc2.documentElement.appendChild(doc2.createElement("body")); |
|
51 is(doc2.body, doc2.documentElement.firstChild, "Should have .body!"); |
|
52 if (isXHTML) { |
|
53 doc2.body.appendChild(doc2.createElementNS("http://www.w3.org/1999/xhtml", "form")); |
|
54 } else { |
|
55 doc2.body.appendChild(doc2.createElement("form")); |
|
56 } |
|
57 is(doc2.forms.length, 1, "Form wasn't added .forms"); |
|
58 } |
|
59 } |
|
60 |
|
61 function testSVGDocument() { |
|
62 var docType1 = |
|
63 document.implementation.createDocumentType("svg", |
|
64 "-//W3C//DTD SVG 1.1//EN", |
|
65 null); |
|
66 ok(docType1, "No doctype?"); |
|
67 ok(docType1.ownerDocument, "docType should have ownerDocument!"); |
|
68 var doc1 = document.implementation.createDocument(null, null, docType1); |
|
69 is(docType1.ownerDocument, doc1, "docType should have ownerDocument!"); |
|
70 ok(!doc1.documentElement, "Document shouldn't have document element!"); |
|
71 ok(!(doc1 instanceof HTMLDocument), |
|
72 "Document shouldn't be an HTML document!"); |
|
73 ok(doc1 instanceof SVGDocument, |
|
74 "Document should be an SVG document!"); |
|
75 |
|
76 // SVG documents have .rootElement. |
|
77 ok("rootElement" in doc1, "No .rootElement in document"); |
|
78 |
|
79 var docType2 = |
|
80 document.implementation.createDocumentType("svg", |
|
81 "-//W3C//DTD SVG 1.1//EN", |
|
82 null); |
|
83 var doc2 = document.implementation.createDocument("http://www.w3.org/2000/svg", |
|
84 "svg", docType2); |
|
85 ok(doc2.documentElement, "Document should have document element!"); |
|
86 ok(doc2.rootElement, "Should have .rootElement in document"); |
|
87 is(doc2.rootElement.localName, "svg", "Wrong .rootElement!"); |
|
88 } |
|
89 |
|
90 function testFooBarDocument() { |
|
91 var docType1 = |
|
92 document.implementation.createDocumentType("FooBar", "FooBar", null); |
|
93 ok(docType1, "No doctype?"); |
|
94 ok(docType1.ownerDocument, "docType should have ownerDocument!"); |
|
95 var doc1 = document.implementation.createDocument(null, null, docType1); |
|
96 is(docType1.ownerDocument, doc1, "docType should have ownerDocument!"); |
|
97 ok(!doc1.documentElement, "Document shouldn't have document element!"); |
|
98 ok(!(doc1 instanceof HTMLDocument), |
|
99 "Document shouldn't be an HTML document!"); |
|
100 ok(!(doc1 instanceof SVGDocument), |
|
101 "Document shouldn't be an SVG document!"); |
|
102 |
|
103 var docType2 = |
|
104 document.implementation.createDocumentType("FooBar", "FooBar", null); |
|
105 var doc2 = document.implementation.createDocument("FooBarNS", |
|
106 "FooBar", docType2); |
|
107 ok(doc2.documentElement, "Document should have document element!"); |
|
108 is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!"); |
|
109 is(doc2.documentElement.localName, "FooBar", "Wrong localName!"); |
|
110 } |
|
111 |
|
112 function testNullDocTypeDocument() { |
|
113 var doc1 = document.implementation.createDocument(null, null, null); |
|
114 ok(!doc1.documentElement, "Document shouldn't have document element!"); |
|
115 ok(!(doc1 instanceof HTMLDocument), |
|
116 "Document shouldn't be an HTML document!"); |
|
117 ok(!(doc1 instanceof SVGDocument), |
|
118 "Document shouldn't be an SVG document!"); |
|
119 |
|
120 var doc2 = document.implementation.createDocument("FooBarNS", |
|
121 "FooBar", null); |
|
122 ok(doc2.documentElement, "Document should have document element!"); |
|
123 is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!"); |
|
124 is(doc2.documentElement.localName, "FooBar", "Wrong localName!"); |
|
125 } |
|
126 |
|
127 var htmlPublicIDs = |
|
128 [ "-//W3C//DTD HTML 4.01//EN", |
|
129 "-//W3C//DTD HTML 4.01 Transitional//EN", |
|
130 "-//W3C//DTD HTML 4.01 Frameset//EN", |
|
131 "-//W3C//DTD HTML 4.0//EN", |
|
132 "-//W3C//DTD HTML 4.0 Transitional//EN", |
|
133 "-//W3C//DTD HTML 4.0 Frameset//EN" ]; |
|
134 |
|
135 var xhtmlPublicIDs = |
|
136 [ "-//W3C//DTD XHTML 1.0 Strict//EN", |
|
137 "-//W3C//DTD XHTML 1.0 Transitional//EN", |
|
138 "-//W3C//DTD XHTML 1.0 Frameset//EN" ]; |
|
139 |
|
140 testHTMLDocuments(htmlPublicIDs, false); |
|
141 testHTMLDocuments(xhtmlPublicIDs, true); |
|
142 testSVGDocument(); |
|
143 testFooBarDocument(); |
|
144 testNullDocTypeDocument(); |
|
145 |
|
146 </script> |
|
147 </pre> |
|
148 </body> |
|
149 </html> |