4 https://bugzilla.mozilla.org/show_bug.cgi?id=450160
7 <title>Test for Bug
450160</title>
8 <script type=
"application/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=450160">Mozilla Bug
450160</a>
15 <div id=
"content" style=
"display: none">
19 <script type=
"application/javascript">
21 /** Test for Bug
450160 **/
24 function testHTMLDocuments(ids, isXHTML) {
25 for (var i =
0; i < ids.length; ++i) {
27 document.implementation.createDocumentType(isXHTML ?
"html" :
"HTML",
30 ok(docType1,
"No doctype?");
31 ok(!docType1.ownerDocument,
"docType shouldn't have ownerDocument!\n");
32 var doc1 = document.implementation.createDocument(null, null, docType1);
33 is(docType1.ownerDocument, doc1,
"docType should have ownerDocument!\n");
34 ok(!doc1.documentElement,
"Document shouldn't have document element!");
35 is(doc1.body, null,
"Shouldn't have .body!");
36 ok(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument,
37 "Document should be an HTML document!");
38 ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
39 "Document shouldn't be an SVG document!");
42 document.implementation.createDocumentType(isXHTML ?
"html" :
"HTML",
45 var doc2 = document.implementation.createDocument(
46 "http://www.w3.org/1999/xhtml",
"html", docType2);
47 is(docType2.ownerDocument, doc2,
"docType should have ownerDocument!\n");
48 ok(doc2.documentElement,
"Document should have document element!");
49 is(doc2.documentElement.localName,
"html",
"Wrong document element!");
50 is(doc2.body, null,
"Shouldn't have .body!");
51 doc2.documentElement.appendChild(doc2.createElement(
"body"));
52 is(doc2.body, doc2.documentElement.firstChild,
"Should have .body!");
54 doc2.body.appendChild(doc2.createElementNS(
"http://www.w3.org/1999/xhtml",
"form"));
56 doc2.body.appendChild(doc2.createElement(
"form"));
58 is(doc2.forms.length,
1,
"Form wasn't added .forms");
62 function testSVGDocument() {
64 document.implementation.createDocumentType(
"svg",
65 "-//W3C//DTD SVG 1.1//EN",
67 ok(docType1,
"No doctype?");
68 ok(!docType1.ownerDocument,
"docType shouldn't have ownerDocument!\n");
69 var doc1 = document.implementation.createDocument(null, null, docType1);
70 is(docType1.ownerDocument, doc1,
"docType should have ownerDocument!\n");
71 ok(!doc1.documentElement,
"Document shouldn't have document element!");
72 ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
73 "Document shouldn't be an HTML document!");
74 ok(doc1 instanceof Components.interfaces.nsIDOMSVGDocument,
75 "Document should be an SVG document!");
77 // SVG documents have .rootElement.
78 ok(
"rootElement" in doc1,
"No .rootElement in document");
81 document.implementation.createDocumentType(
"svg",
82 "-//W3C//DTD SVG 1.1//EN",
84 var doc2 = document.implementation.createDocument(
"http://www.w3.org/2000/svg",
86 ok(doc2.documentElement,
"Document should have document element!");
87 ok(doc2.rootElement,
"Should have .rootElement in document");
88 is(doc2.rootElement.localName,
"svg",
"Wrong .rootElement!");
91 function testFooBarDocument() {
93 document.implementation.createDocumentType(
"FooBar",
"FooBar", null);
94 ok(docType1,
"No doctype?");
95 ok(!docType1.ownerDocument,
"docType shouldn't have ownerDocument!\n");
96 var doc1 = document.implementation.createDocument(null, null, docType1);
97 is(docType1.ownerDocument, doc1,
"docType should have ownerDocument!\n");
98 ok(!doc1.documentElement,
"Document shouldn't have document element!");
99 ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
100 "Document shouldn't be an HTML document!");
101 ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
102 "Document shouldn't be an SVG document!");
105 document.implementation.createDocumentType(
"FooBar",
"FooBar", null);
106 var doc2 = document.implementation.createDocument(
"FooBarNS",
108 ok(doc2.documentElement,
"Document should have document element!");
109 is(doc2.documentElement.namespaceURI,
"FooBarNS",
"Wrong namespaceURI!");
110 is(doc2.documentElement.localName,
"FooBar",
"Wrong localName!");
113 function testNullDocTypeDocument() {
114 var doc1 = document.implementation.createDocument(null, null, null);
115 ok(!doc1.documentElement,
"Document shouldn't have document element!");
116 ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
117 "Document shouldn't be an HTML document!");
118 ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
119 "Document shouldn't be an SVG document!");
121 var doc2 = document.implementation.createDocument(
"FooBarNS",
123 ok(doc2.documentElement,
"Document should have document element!");
124 is(doc2.documentElement.namespaceURI,
"FooBarNS",
"Wrong namespaceURI!");
125 is(doc2.documentElement.localName,
"FooBar",
"Wrong localName!");
129 [
"-//W3C//DTD HTML 4.01//EN",
130 "-//W3C//DTD HTML 4.01 Transitional//EN",
131 "-//W3C//DTD HTML 4.01 Frameset//EN",
132 "-//W3C//DTD HTML 4.0//EN",
133 "-//W3C//DTD HTML 4.0 Transitional//EN",
134 "-//W3C//DTD HTML 4.0 Frameset//EN" ];
137 [
"-//W3C//DTD XHTML 1.0 Strict//EN",
138 "-//W3C//DTD XHTML 1.0 Transitional//EN",
139 "-//W3C//DTD XHTML 1.0 Frameset//EN" ];
141 testHTMLDocuments(htmlPublicIDs, false);
142 testHTMLDocuments(xhtmlPublicIDs, true);
144 testFooBarDocument();
145 testNullDocTypeDocument();