gecko/content/base/test/test_bug450160.html
Olli Pettay 2f2d683768 Bug 675166 - Make DocumentTypeNode to use NodeInfoManager of the document, r=sicking
--HG--
extra : rebase_source : c05867591dc394695c35de92a0c62ca5df9db1d6
2011-09-17 06:32:32 -07:00

150 lines
6.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=450160
-->
<head>
<title>Test for Bug 450160</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450160">Mozilla Bug 450160</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 450160 **/
function testHTMLDocuments(ids, isXHTML) {
for (var i = 0; i < ids.length; ++i) {
var docType1 =
document.implementation.createDocumentType(isXHTML ? "html" : "HTML",
ids[i],
null);
ok(docType1, "No doctype?");
ok(docType1.ownerDocument, "docType should have ownerDocument!");
var doc1 = document.implementation.createDocument(null, null, docType1);
is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
ok(!doc1.documentElement, "Document shouldn't have document element!");
is(doc1.body, null, "Shouldn't have .body!");
ok(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument,
"Document should be an HTML document!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
"Document shouldn't be an SVG document!");
var docType2 =
document.implementation.createDocumentType(isXHTML ? "html" : "HTML",
ids[i],
null);
var doc2 = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml", "html", docType2);
is(docType2.ownerDocument, doc2, "docType should have ownerDocument!");
ok(doc2.documentElement, "Document should have document element!");
is(doc2.documentElement.localName, "html", "Wrong document element!");
is(doc2.body, null, "Shouldn't have .body!");
doc2.documentElement.appendChild(doc2.createElement("body"));
is(doc2.body, doc2.documentElement.firstChild, "Should have .body!");
if (isXHTML) {
doc2.body.appendChild(doc2.createElementNS("http://www.w3.org/1999/xhtml", "form"));
} else {
doc2.body.appendChild(doc2.createElement("form"));
}
is(doc2.forms.length, 1, "Form wasn't added .forms");
}
}
function testSVGDocument() {
var docType1 =
document.implementation.createDocumentType("svg",
"-//W3C//DTD SVG 1.1//EN",
null);
ok(docType1, "No doctype?");
ok(docType1.ownerDocument, "docType should have ownerDocument!");
var doc1 = document.implementation.createDocument(null, null, docType1);
is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
ok(!doc1.documentElement, "Document shouldn't have document element!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
"Document shouldn't be an HTML document!");
ok(doc1 instanceof Components.interfaces.nsIDOMSVGDocument,
"Document should be an SVG document!");
// SVG documents have .rootElement.
ok("rootElement" in doc1, "No .rootElement in document");
var docType2 =
document.implementation.createDocumentType("svg",
"-//W3C//DTD SVG 1.1//EN",
null);
var doc2 = document.implementation.createDocument("http://www.w3.org/2000/svg",
"svg", docType2);
ok(doc2.documentElement, "Document should have document element!");
ok(doc2.rootElement, "Should have .rootElement in document");
is(doc2.rootElement.localName, "svg", "Wrong .rootElement!");
}
function testFooBarDocument() {
var docType1 =
document.implementation.createDocumentType("FooBar", "FooBar", null);
ok(docType1, "No doctype?");
ok(docType1.ownerDocument, "docType should have ownerDocument!");
var doc1 = document.implementation.createDocument(null, null, docType1);
is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
ok(!doc1.documentElement, "Document shouldn't have document element!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
"Document shouldn't be an HTML document!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
"Document shouldn't be an SVG document!");
var docType2 =
document.implementation.createDocumentType("FooBar", "FooBar", null);
var doc2 = document.implementation.createDocument("FooBarNS",
"FooBar", docType2);
ok(doc2.documentElement, "Document should have document element!");
is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!");
is(doc2.documentElement.localName, "FooBar", "Wrong localName!");
}
function testNullDocTypeDocument() {
var doc1 = document.implementation.createDocument(null, null, null);
ok(!doc1.documentElement, "Document shouldn't have document element!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMHTMLDocument),
"Document shouldn't be an HTML document!");
ok(!(doc1 instanceof Components.interfaces.nsIDOMSVGDocument),
"Document shouldn't be an SVG document!");
var doc2 = document.implementation.createDocument("FooBarNS",
"FooBar", null);
ok(doc2.documentElement, "Document should have document element!");
is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!");
is(doc2.documentElement.localName, "FooBar", "Wrong localName!");
}
var htmlPublicIDs =
[ "-//W3C//DTD HTML 4.01//EN",
"-//W3C//DTD HTML 4.01 Transitional//EN",
"-//W3C//DTD HTML 4.01 Frameset//EN",
"-//W3C//DTD HTML 4.0//EN",
"-//W3C//DTD HTML 4.0 Transitional//EN",
"-//W3C//DTD HTML 4.0 Frameset//EN" ];
var xhtmlPublicIDs =
[ "-//W3C//DTD XHTML 1.0 Strict//EN",
"-//W3C//DTD XHTML 1.0 Transitional//EN",
"-//W3C//DTD XHTML 1.0 Frameset//EN" ];
testHTMLDocuments(htmlPublicIDs, false);
testHTMLDocuments(xhtmlPublicIDs, true);
testSVGDocument();
testFooBarDocument();
testNullDocTypeDocument();
</script>
</pre>
</body>
</html>