| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 3 <title>Document.createElementNS</title> | 3 <title>Document.createElementNS</title> |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns"> | 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns"> |
| 5 <script src="/resources/testharness.js"></script> | 5 <script src="/resources/testharness.js"></script> |
| 6 <script src="/resources/testharnessreport.js"></script> | 6 <script src="/resources/testharnessreport.js"></script> |
| 7 <script src="Document-createElementNS.js"></script> | 7 <script src="Document-createElementNS.js"></script> |
| 8 <div id="log"></div> | 8 <div id="log"></div> |
| 9 <iframe src="/common/dummy.xml"></iframe> | |
| 10 <iframe src="/common/dummy.xhtml"></iframe> | |
| 11 <script> | 9 <script> |
| 12 var tests = createElementNS_tests.concat([ | 10 test(function() { |
| 13 /* Arrays with three elements: | 11 var tests = createElementNS_tests.concat([ |
| 14 * the namespace argument | 12 /* Arrays with three elements: |
| 15 * the qualifiedName argument | 13 * the namespace argument |
| 16 * the expected exception, or null if none | 14 * the qualifiedName argument |
| 17 */ | 15 * the expected exception, or null if none |
| 18 ["", "", "INVALID_CHARACTER_ERR"], | 16 */ |
| 19 [null, null, null], | 17 ["", "", "INVALID_CHARACTER_ERR"], |
| 20 [null, "", "INVALID_CHARACTER_ERR"], | 18 [null, null, null], |
| 21 [undefined, null, null], | 19 [null, "", "INVALID_CHARACTER_ERR"], |
| 22 [undefined, "", "INVALID_CHARACTER_ERR"], | 20 [undefined, null, null], |
| 23 ["http://example.com/", null, null], | 21 [undefined, "", "INVALID_CHARACTER_ERR"], |
| 24 ["http://example.com/", "", "INVALID_CHARACTER_ERR"], | 22 ["http://example.com/", null, null], |
| 25 ["/", null, null], | 23 ["http://example.com/", "", "INVALID_CHARACTER_ERR"], |
| 26 ["/", "", "INVALID_CHARACTER_ERR"], | 24 ["/", null, null], |
| 27 ["http://www.w3.org/XML/1998/namespace", null, null], | 25 ["/", "", "INVALID_CHARACTER_ERR"], |
| 28 ["http://www.w3.org/XML/1998/namespace", "", "INVALID_CHARACTER_ERR"], | 26 ["http://www.w3.org/XML/1998/namespace", null, null], |
| 29 ["http://www.w3.org/2000/xmlns/", null, "NAMESPACE_ERR"], | 27 ["http://www.w3.org/XML/1998/namespace", "", "INVALID_CHARACTER_ERR"], |
| 30 ["http://www.w3.org/2000/xmlns/", "", "INVALID_CHARACTER_ERR"], | 28 ["http://www.w3.org/2000/xmlns/", null, "NAMESPACE_ERR"], |
| 31 ["foo:", null, null], | 29 ["http://www.w3.org/2000/xmlns/", "", "INVALID_CHARACTER_ERR"], |
| 32 ["foo:", "", "INVALID_CHARACTER_ERR"], | 30 ["foo:", null, null], |
| 33 ]) | 31 ["foo:", "", "INVALID_CHARACTER_ERR"], |
| 32 ]) |
| 34 | 33 |
| 35 var xmlIframe = document.querySelector('[src="/common/dummy.xml"]'); | 34 tests.forEach(function(t, i) { |
| 36 var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]'); | 35 test(function() { |
| 37 | 36 var namespace = t[0], qualifiedName = t[1], expected = t[2] |
| 38 function runTest(t, i, desc) { | 37 if (expected != null) { |
| 39 async_test(function(testObj) { | 38 assert_throws(expected, function() { document.createElementNS(namespace,
qualifiedName) }) |
| 40 window.addEventListener("load", function() { | 39 } else { |
| 41 testObj.step(function() { | 40 var element = document.createElementNS(namespace, qualifiedName) |
| 42 var doc; | 41 assert_not_equals(element, null) |
| 43 if (desc == "HTML document") { | 42 assert_equals(element.nodeType, Node.ELEMENT_NODE) |
| 44 doc = document; | 43 assert_equals(element.nodeType, element.ELEMENT_NODE) |
| 45 } else if (desc == "XML document") { | 44 assert_equals(element.nodeValue, null) |
| 46 doc = xmlIframe.contentDocument; | 45 assert_equals(element.ownerDocument, document) |
| 47 // Make sure we're testing the right document | 46 var qualified = String(qualifiedName), names = [] |
| 48 assert_equals(doc.documentElement.textContent, "Dummy XML document"); | 47 if (qualified.indexOf(":") >= 0) { |
| 49 } else if (desc == "XHTML document") { | 48 names = qualified.split(":", 2) |
| 50 doc = xhtmlIframe.contentDocument; | 49 } else { |
| 51 assert_equals(doc.documentElement.textContent, "Dummy XHTML document")
; | 50 names = [null, qualified] |
| 52 } | 51 } |
| 53 var namespace = t[0], qualifiedName = t[1], expected = t[2] | 52 assert_equals(element.prefix, names[0]) |
| 54 if (expected != null) { | 53 assert_equals(element.localName, names[1]) |
| 55 assert_throws(expected, function() { doc.createElementNS(namespace, qu
alifiedName) }) | 54 assert_equals(element.tagName, qualified) |
| 56 } else { | 55 assert_equals(element.nodeName, qualified) |
| 57 var element = doc.createElementNS(namespace, qualifiedName) | 56 assert_equals(element.namespaceURI, namespace === undefined ? null : nam
espace) |
| 58 assert_not_equals(element, null) | 57 } |
| 59 assert_equals(element.nodeType, Node.ELEMENT_NODE) | 58 }, "createElementNS test: " + t.map(format_value)) |
| 60 assert_equals(element.nodeType, element.ELEMENT_NODE) | 59 }) |
| 61 assert_equals(element.nodeValue, null) | |
| 62 assert_equals(element.ownerDocument, doc) | |
| 63 var qualified = String(qualifiedName), names = [] | |
| 64 if (qualified.indexOf(":") >= 0) { | |
| 65 names = qualified.split(":", 2) | |
| 66 } else { | |
| 67 names = [null, qualified] | |
| 68 } | |
| 69 assert_equals(element.prefix, names[0]) | |
| 70 assert_equals(element.localName, names[1]) | |
| 71 assert_equals(element.tagName, qualified) | |
| 72 assert_equals(element.nodeName, qualified) | |
| 73 assert_equals(element.namespaceURI, | |
| 74 namespace === undefined || namespace === "" ? null | |
| 75 : namespace) | |
| 76 } | |
| 77 }); | |
| 78 testObj.done(); | |
| 79 }); | |
| 80 }, "createElementNS test in " + desc + ": " + t.map(format_value)) | |
| 81 } | |
| 82 | |
| 83 tests.forEach(function(t, i) { | |
| 84 runTest(t, i, "HTML document") | |
| 85 runTest(t, i, "XML document") | |
| 86 runTest(t, i, "XHTML document") | |
| 87 }) | 60 }) |
| 88 | 61 |
| 89 | |
| 90 test(function() { | 62 test(function() { |
| 91 var HTMLNS = "http://www.w3.org/1999/xhtml"; | 63 var HTMLNS = "http://www.w3.org/1999/xhtml"; |
| 92 var element = document.createElementNS(HTMLNS, "span"); | 64 var element = document.createElementNS(HTMLNS, "span"); |
| 93 assert_equals(element.namespaceURI, HTMLNS); | 65 assert_equals(element.namespaceURI, HTMLNS); |
| 94 assert_equals(element.prefix, null); | 66 assert_equals(element.prefix, null); |
| 95 assert_equals(element.localName, "span"); | 67 assert_equals(element.localName, "span"); |
| 96 assert_equals(element.tagName, "SPAN"); | 68 assert_equals(element.tagName, "SPAN"); |
| 97 assert_true(element instanceof Node, "Should be a Node"); | 69 assert_true(element instanceof Node, "Should be a Node"); |
| 98 assert_true(element instanceof Element, "Should be an Element"); | 70 assert_true(element instanceof Element, "Should be an Element"); |
| 99 assert_true(element instanceof HTMLElement, "Should be an HTMLElement"); | 71 assert_true(element instanceof HTMLElement, "Should be an HTMLElement"); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 assert_equals(element.namespaceURI, null); | 189 assert_equals(element.namespaceURI, null); |
| 218 assert_equals(element.prefix, null); | 190 assert_equals(element.prefix, null); |
| 219 assert_equals(element.localName, "span"); | 191 assert_equals(element.localName, "span"); |
| 220 assert_equals(element.tagName, "span"); | 192 assert_equals(element.tagName, "span"); |
| 221 assert_true(element instanceof Node, "Should be a Node"); | 193 assert_true(element instanceof Node, "Should be a Node"); |
| 222 assert_true(element instanceof Element, "Should be an Element"); | 194 assert_true(element instanceof Element, "Should be an Element"); |
| 223 assert_false(element instanceof HTMLElement, "Should not be an HTMLElement"); | 195 assert_false(element instanceof HTMLElement, "Should not be an HTMLElement"); |
| 224 assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanEle
ment"); | 196 assert_false(element instanceof HTMLSpanElement, "Should not be an HTMLSpanEle
ment"); |
| 225 }, "empty string namespace"); | 197 }, "empty string namespace"); |
| 226 </script> | 198 </script> |
| OLD | NEW |