mirror of
https://github.com/servo/servo.git
synced 2025-10-08 12:39:30 +01:00
123 lines
5.7 KiB
HTML
123 lines
5.7 KiB
HTML
<!doctype html>
|
|
<meta charset=utf-8>
|
|
<title>DOMImplementation.createDocument(namespace, qualifiedName, doctype)</title>
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocument">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="Document-createElementNS.js"></script>
|
|
<div id="log"></div>
|
|
<script>
|
|
test(function() {
|
|
var tests = createElementNS_tests.map(function(t) {
|
|
return [t[0], t[1], null, t[2]]
|
|
}).concat([
|
|
/* Arrays with four elements:
|
|
* the namespace argument
|
|
* the qualifiedName argument
|
|
* the doctype argument
|
|
* the expected exception, or null if none
|
|
*/
|
|
[null, null, false, new TypeError()],
|
|
[null, null, null, null],
|
|
[null, "", null, null],
|
|
[undefined, null, undefined, null],
|
|
[undefined, undefined, undefined, null],
|
|
[undefined, "", undefined, null],
|
|
["http://example.com/", null, null, null],
|
|
["http://example.com/", "", null, null],
|
|
["/", null, null, null],
|
|
["/", "", null, null],
|
|
["http://www.w3.org/XML/1998/namespace", null, null, null],
|
|
["http://www.w3.org/XML/1998/namespace", "", null, null],
|
|
["http://www.w3.org/2000/xmlns/", null, null, null],
|
|
["http://www.w3.org/2000/xmlns/", "", null, null],
|
|
["foo:", null, null, null],
|
|
["foo:", "", null, null],
|
|
[null, null, document.implementation.createDocumentType("foo", "", ""), null],
|
|
[null, null, document.doctype, null], // This causes a horrible WebKit bug (now fixed in trunk).
|
|
[null, null, function() {
|
|
var foo = document.implementation.createDocumentType("foo", "", "");
|
|
document.implementation.createDocument(null, null, foo);
|
|
return foo;
|
|
}(), null], // DOCTYPE already associated with a document.
|
|
[null, null, function() {
|
|
var bar = document.implementation.createDocument(null, null, null);
|
|
return bar.implementation.createDocumentType("bar", "", "");
|
|
}(), null], // DOCTYPE created by a different implementation.
|
|
[null, null, function() {
|
|
var bar = document.implementation.createDocument(null, null, null);
|
|
var magic = bar.implementation.createDocumentType("bar", "", "");
|
|
bar.implementation.createDocument(null, null, magic);
|
|
return magic;
|
|
}(), null], // DOCTYPE created by a different implementation and already associated with a document.
|
|
[null, "foo", document.implementation.createDocumentType("foo", "", ""), null],
|
|
["foo", null, document.implementation.createDocumentType("foo", "", ""), null],
|
|
["foo", "bar", document.implementation.createDocumentType("foo", "", ""), null],
|
|
])
|
|
|
|
tests.forEach(function(t, i) {
|
|
var namespace = t[0], qualifiedName = t[1], doctype = t[2], expected = t[3]
|
|
test(function() {
|
|
if (expected != null) {
|
|
assert_throws(expected, function() { document.implementation.createDocument(namespace, qualifiedName, doctype) })
|
|
} else {
|
|
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
|
assert_equals(doc.nodeType, Node.DOCUMENT_NODE)
|
|
assert_equals(doc.nodeType, doc.DOCUMENT_NODE)
|
|
assert_equals(doc.nodeName, "#document")
|
|
assert_equals(doc.nodeValue, null)
|
|
var omitRootElement = qualifiedName === null || String(qualifiedName) === ""
|
|
if (omitRootElement) {
|
|
assert_equals(doc.documentElement, null)
|
|
} else {
|
|
var element = doc.documentElement
|
|
assert_not_equals(element, null)
|
|
assert_equals(element.nodeType, Node.ELEMENT_NODE)
|
|
assert_equals(element.ownerDocument, doc)
|
|
var qualified = String(qualifiedName), names = []
|
|
if (qualified.indexOf(":") >= 0) {
|
|
names = qualified.split(":", 2)
|
|
} else {
|
|
names = [null, qualified]
|
|
}
|
|
assert_equals(element.prefix, names[0])
|
|
assert_equals(element.localName, names[1])
|
|
assert_equals(element.namespaceURI, namespace === undefined ? null : namespace)
|
|
}
|
|
if (!doctype) {
|
|
assert_equals(doc.doctype, null)
|
|
} else {
|
|
assert_equals(doc.doctype, doctype)
|
|
assert_equals(doc.doctype.ownerDocument, doc)
|
|
}
|
|
assert_equals(doc.childNodes.length, !omitRootElement + !!doctype)
|
|
}
|
|
}, "createDocument test " + i + ": " + t.map(function(el) { return format_value(el) }))
|
|
|
|
if (expected === null) {
|
|
test(function() {
|
|
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
|
assert_equals(doc.compatMode, "CSS1Compat")
|
|
assert_equals(doc.characterSet, "UTF-8")
|
|
assert_equals(doc.contentType, "application/xml")
|
|
assert_equals(doc.URL, "about:blank")
|
|
assert_equals(doc.documentURI, "about:blank")
|
|
assert_equals(doc.createElement("DIV").localName, "DIV");
|
|
}, "createDocument test " + i + ": metadata for " +
|
|
[namespace, qualifiedName, doctype].map(function(el) { return format_value(el) }))
|
|
|
|
test(function() {
|
|
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
|
assert_equals(doc.characterSet, "UTF-8", "characterSet");
|
|
assert_equals(doc.charset, "UTF-8", "charset");
|
|
assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding");
|
|
}, "createDocument test " + i + ": characterSet aliases for " +
|
|
[namespace, qualifiedName, doctype].map(function(el) { return format_value(el) }))
|
|
}
|
|
})
|
|
})
|
|
</script>
|