| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 3 <title>DOMImplementation.createDocument(namespace, qualifiedName, doctype)</titl
e> | 3 <title>DOMImplementation.createDocument(namespace, qualifiedName, doctype)</titl
e> |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdo
cument"> | 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdo
cument"> |
| 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns"> | 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns"> |
| 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype"> | 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype"> |
| 7 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement"> | 7 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement"> |
| 8 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype"> | 8 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype"> |
| 9 <script src="../../../../resources/testharness.js"></script> | 9 <script src="../../../../resources/testharness.js"></script> |
| 10 <script src="../../../../resources/testharnessreport.js"></script> | 10 <script src="../../../../resources/testharnessreport.js"></script> |
| 11 <script src="Document-createElementNS.js"></script> | 11 <script src="Document-createElementNS.js"></script> |
| 12 <div id="log"></div> | 12 <div id="log"></div> |
| 13 <script> | 13 <script> |
| 14 var htmlNamespace = "http://www.w3.org/1999/xhtml" |
| 15 var svgNamespace = "http://www.w3.org/2000/svg" |
| 16 var mathMLNamespace = "http://www.w3.org/1998/Math/MathML" |
| 17 |
| 14 test(function() { | 18 test(function() { |
| 15 var tests = createElementNS_tests.map(function(t) { | 19 var tests = createElementNS_tests.map(function(t) { |
| 16 return [t[0], t[1], null, t[2]] | 20 return [t[0], t[1], null, t[2]] |
| 17 }).concat([ | 21 }).concat([ |
| 18 /* Arrays with four elements: | 22 /* Arrays with four elements: |
| 19 * the namespace argument | 23 * the namespace argument |
| 20 * the qualifiedName argument | 24 * the qualifiedName argument |
| 21 * the doctype argument | 25 * the doctype argument |
| 22 * the expected exception, or null if none | 26 * the expected exception, or null if none |
| 23 */ | 27 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 }(), null], // DOCTYPE created by a different implementation. | 54 }(), null], // DOCTYPE created by a different implementation. |
| 51 [null, null, function() { | 55 [null, null, function() { |
| 52 var bar = document.implementation.createDocument(null, null, null); | 56 var bar = document.implementation.createDocument(null, null, null); |
| 53 var magic = bar.implementation.createDocumentType("bar", "", ""); | 57 var magic = bar.implementation.createDocumentType("bar", "", ""); |
| 54 bar.implementation.createDocument(null, null, magic); | 58 bar.implementation.createDocument(null, null, magic); |
| 55 return magic; | 59 return magic; |
| 56 }(), null], // DOCTYPE created by a different implementation and already as
sociated with a document. | 60 }(), null], // DOCTYPE created by a different implementation and already as
sociated with a document. |
| 57 [null, "foo", document.implementation.createDocumentType("foo", "", ""), nul
l], | 61 [null, "foo", document.implementation.createDocumentType("foo", "", ""), nul
l], |
| 58 ["foo", null, document.implementation.createDocumentType("foo", "", ""), nul
l], | 62 ["foo", null, document.implementation.createDocumentType("foo", "", ""), nul
l], |
| 59 ["foo", "bar", document.implementation.createDocumentType("foo", "", ""), nu
ll], | 63 ["foo", "bar", document.implementation.createDocumentType("foo", "", ""), nu
ll], |
| 64 [htmlNamespace, "", null, null], |
| 65 [svgNamespace, "", null, null], |
| 66 [mathMLNamespace, "", null, null], |
| 67 [null, "html", null, null], |
| 68 [null, "svg", null, null], |
| 69 [null, "math", null, null], |
| 70 [null, "", document.implementation.createDocumentType("html", |
| 71 "-//W3C//DTD XHTML 1.0 Transitional//EN", |
| 72 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")], |
| 73 [null, "", document.implementation.createDocumentType("svg", |
| 74 "-//W3C//DTD SVG 1.1//EN", |
| 75 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")], |
| 76 [null, "", document.implementation.createDocumentType("math", |
| 77 "-//W3C//DTD MathML 2.0//EN", |
| 78 "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd")], |
| 60 ]) | 79 ]) |
| 61 | 80 |
| 62 tests.forEach(function(t, i) { | 81 tests.forEach(function(t, i) { |
| 63 var namespace = t[0], qualifiedName = t[1], doctype = t[2], expected = t[3] | 82 var namespace = t[0], qualifiedName = t[1], doctype = t[2], expected = t[3] |
| 64 test(function() { | 83 test(function() { |
| 65 if (expected != null) { | 84 if (expected != null) { |
| 66 assert_throws(expected, function() { document.implementation.createDocum
ent(namespace, qualifiedName, doctype) }) | 85 assert_throws(expected, function() { document.implementation.createDocum
ent(namespace, qualifiedName, doctype) }) |
| 67 } else { | 86 } else { |
| 68 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) | 87 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) |
| 69 assert_equals(doc.nodeType, Node.DOCUMENT_NODE) | 88 assert_equals(doc.nodeType, Node.DOCUMENT_NODE) |
| 70 assert_equals(doc.nodeType, doc.DOCUMENT_NODE) | 89 assert_equals(doc.nodeType, doc.DOCUMENT_NODE) |
| 71 assert_equals(doc.nodeName, "#document") | 90 assert_equals(doc.nodeName, "#document") |
| 72 assert_equals(doc.nodeValue, null) | 91 assert_equals(doc.nodeValue, null) |
| 92 assert_equals(Object.getPrototypeOf(doc), XMLDocument.prototype) |
| 73 var omitRootElement = qualifiedName === null || String(qualifiedName) ==
= "" | 93 var omitRootElement = qualifiedName === null || String(qualifiedName) ==
= "" |
| 74 if (omitRootElement) { | 94 if (omitRootElement) { |
| 75 assert_equals(doc.documentElement, null) | 95 assert_equals(doc.documentElement, null) |
| 76 } else { | 96 } else { |
| 77 var element = doc.documentElement | 97 var element = doc.documentElement |
| 78 assert_not_equals(element, null) | 98 assert_not_equals(element, null) |
| 79 assert_equals(element.nodeType, Node.ELEMENT_NODE) | 99 assert_equals(element.nodeType, Node.ELEMENT_NODE) |
| 80 assert_equals(element.ownerDocument, doc) | 100 assert_equals(element.ownerDocument, doc) |
| 81 var qualified = String(qualifiedName), names = [] | 101 var qualified = String(qualifiedName), names = [] |
| 82 if (qualified.indexOf(":") >= 0) { | 102 if (qualified.indexOf(":") >= 0) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 96 } | 116 } |
| 97 assert_equals(doc.childNodes.length, !omitRootElement + !!doctype) | 117 assert_equals(doc.childNodes.length, !omitRootElement + !!doctype) |
| 98 } | 118 } |
| 99 }, "createDocument test " + i + ": " + t.map(function(el) { return format_va
lue(el) })) | 119 }, "createDocument test " + i + ": " + t.map(function(el) { return format_va
lue(el) })) |
| 100 | 120 |
| 101 if (expected === null) { | 121 if (expected === null) { |
| 102 test(function() { | 122 test(function() { |
| 103 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) | 123 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) |
| 104 assert_equals(doc.compatMode, "CSS1Compat") | 124 assert_equals(doc.compatMode, "CSS1Compat") |
| 105 assert_equals(doc.characterSet, "UTF-8") | 125 assert_equals(doc.characterSet, "UTF-8") |
| 106 assert_equals(doc.contentType, "application/xml") | 126 assert_equals(doc.contentType, namespace == htmlNamespace ? "text/html" |
| 127 : namespace == svgNamespace ? "image/svg+xml" |
| 128 : "application/xml") |
| 107 assert_equals(doc.URL, "about:blank") | 129 assert_equals(doc.URL, "about:blank") |
| 108 assert_equals(doc.documentURI, "about:blank") | 130 assert_equals(doc.documentURI, "about:blank") |
| 109 assert_equals(doc.createElement("DIV").localName, "DIV"); | 131 assert_equals(doc.createElement("DIV").localName, "DIV"); |
| 110 }, "createDocument test " + i + ": metadata for " + | 132 }, "createDocument test " + i + ": metadata for " + |
| 111 [namespace, qualifiedName, doctype].map(function(el) { return format_value
(el) })) | 133 [namespace, qualifiedName, doctype].map(function(el) { return format_value
(el) })) |
| 112 | 134 |
| 113 test(function() { | 135 test(function() { |
| 114 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) | 136 var doc = document.implementation.createDocument(namespace, qualifiedNam
e, doctype) |
| 115 assert_equals(doc.characterSet, "UTF-8", "characterSet"); | 137 assert_equals(doc.characterSet, "UTF-8", "characterSet"); |
| 116 assert_equals(doc.charset, "UTF-8", "charset"); | 138 assert_equals(doc.charset, "UTF-8", "charset"); |
| 117 assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding"); | 139 assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding"); |
| 118 }, "createDocument test " + i + ": characterSet aliases for " + | 140 }, "createDocument test " + i + ": characterSet aliases for " + |
| 119 [namespace, qualifiedName, doctype].map(function(el) { return format_value
(el) })) | 141 [namespace, qualifiedName, doctype].map(function(el) { return format_value
(el) })) |
| 120 } | 142 } |
| 121 }) | 143 }) |
| 122 }) | 144 }) |
| 123 | 145 |
| 124 test(function() { | 146 test(function() { |
| 125 assert_throws(new TypeError(), function() { | 147 assert_throws(new TypeError(), function() { |
| 126 document.implementation.createDocument() | 148 document.implementation.createDocument() |
| 127 }, "createDocument() should throw") | 149 }, "createDocument() should throw") |
| 128 | 150 |
| 129 assert_throws(new TypeError(), function() { | 151 assert_throws(new TypeError(), function() { |
| 130 document.implementation.createDocument('') | 152 document.implementation.createDocument('') |
| 131 }, "createDocument('') should throw") | 153 }, "createDocument('') should throw") |
| 132 }, "createDocument with missing arguments"); | 154 }, "createDocument with missing arguments"); |
| 133 </script> | 155 </script> |
| OLD | NEW |