| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 3 <title>Document.createElement</title> | 3 <title>Document.createElement</title> |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelement"> | 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelement"> |
| 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-localname"> | 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-localname"> |
| 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-tagname"> | 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-tagname"> |
| 7 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-prefix"> | 7 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-prefix"> |
| 8 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-namespaceuri"> | 8 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-namespaceuri"> |
| 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 <div id="log"></div> | 11 <div id="log"></div> |
| 12 <iframe src="/common/dummy.xml"></iframe> | |
| 13 <iframe src="/common/dummy.xhtml"></iframe> | |
| 14 <script> | 12 <script> |
| 15 function toASCIIUppercase(str) { | 13 function toASCIIUppercase(str) { |
| 16 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); | 14 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); |
| 17 var res = ""; | 15 var res = ""; |
| 18 for (var i = 0; i < str.length; ++i) { | 16 for (var i = 0; i < str.length; ++i) { |
| 19 if ("a" <= str[i] && str[i] <= "z") { | 17 if ("a" <= str[i] && str[i] <= "z") { |
| 20 res += String.fromCharCode(str.charCodeAt(i) - diff); | 18 res += String.fromCharCode(str.charCodeAt(i) - diff); |
| 21 } else { | 19 } else { |
| 22 res += str[i]; | 20 res += str[i]; |
| 23 } | 21 } |
| 24 } | 22 } |
| 25 return res; | 23 return res; |
| 26 } | 24 } |
| 27 function toASCIILowercase(str) { | 25 test(function() { |
| 28 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); | 26 var HTMLNS = "http://www.w3.org/1999/xhtml", |
| 29 var res = ""; | 27 valid = [ |
| 30 for (var i = 0; i < str.length; ++i) { | 28 //[input, localName], |
| 31 if ("A" <= str[i] && str[i] <= "Z") { | 29 [undefined, "undefined"], |
| 32 res += String.fromCharCode(str.charCodeAt(i) + diff); | 30 [null, "null"], |
| 33 } else { | 31 ["foo", "foo"], |
| 34 res += str[i]; | 32 ["f1oo", "f1oo"], |
| 35 } | 33 ["foo1", "foo1"], |
| 36 } | 34 ["f\u0300oo", "f\u0300oo"], |
| 37 return res; | 35 ["foo\u0300", "foo\u0300"], |
| 38 } | 36 [":foo", ":foo"], |
| 39 var HTMLNS = "http://www.w3.org/1999/xhtml", | 37 ["f:oo", "f:oo"], |
| 40 valid = [ | 38 ["foo:", "foo:"], |
| 41 undefined, | 39 ["xml", "xml"], |
| 42 null, | 40 ["xmlns", "xmlns"], |
| 43 "foo", | 41 ["xmlfoo", "xmlfoo"], |
| 44 "f1oo", | 42 ["xml:foo", "xml:foo"], |
| 45 "foo1", | 43 ["xmlns:foo", "xmlns:foo"], |
| 46 "f\u0BC6", | 44 ["xmlfoo:bar", "xmlfoo:bar"], |
| 47 "foo\u0BC6", | 45 ["svg", "svg"], |
| 48 ":", | 46 ["math", "math"], |
| 49 ":foo", | 47 ["FOO", "foo"], |
| 50 "f:oo", | 48 ["mar\u212a", "mar\u212a"], |
| 51 "foo:", | 49 ["\u0130nput", "\u0130nput"], |
| 52 "f:o:o", | 50 ["\u0131nput", "\u0131nput"] |
| 53 "f::oo", | 51 ], |
| 54 "f::oo:", | 52 invalid = [ |
| 55 "foo:0", | 53 "", |
| 56 "foo:_", | 54 "1foo", |
| 57 // combining char after :, invalid QName but valid Name | 55 "\u0300foo", |
| 58 "foo:\u0BC6", | 56 "}foo", |
| 59 "foo:foo\u0BC6", | 57 "f}oo", |
| 60 "foo\u0BC6:foo", | 58 "foo}", |
| 61 "xml", | 59 "\ufffffoo", |
| 62 "xmlns", | 60 "f\uffffoo", |
| 63 "xmlfoo", | 61 "foo\uffff", |
| 64 "xml:foo", | 62 "<foo", |
| 65 "xmlns:foo", | 63 "foo>", |
| 66 "xmlfoo:bar", | 64 "<foo>", |
| 67 "svg", | 65 "f<oo" |
| 68 "math", | 66 ] |
| 69 "FOO", | |
| 70 // Test that non-ASCII chars don't get uppercased/lowercased | |
| 71 "mar\u212a", | |
| 72 "\u0130nput", | |
| 73 "\u0131nput", | |
| 74 ], | |
| 75 invalid = [ | |
| 76 "", | |
| 77 "1foo", | |
| 78 "1:foo", | |
| 79 "fo o", | |
| 80 "\u0BC6foo", | |
| 81 "}foo", | |
| 82 "f}oo", | |
| 83 "foo}", | |
| 84 "\ufffffoo", | |
| 85 "f\uffffoo", | |
| 86 "foo\uffff", | |
| 87 "<foo", | |
| 88 "foo>", | |
| 89 "<foo>", | |
| 90 "f<oo", | |
| 91 "-foo", | |
| 92 ".foo", | |
| 93 "\u0BC6", | |
| 94 ] | |
| 95 | 67 |
| 96 var xmlIframe = document.querySelector('[src="/common/dummy.xml"]'); | 68 valid.forEach(function(t) { |
| 97 var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]'); | 69 test(function() { |
| 98 | 70 var elt = document.createElement(t[0]) |
| 99 function getWin(desc) { | 71 assert_true(elt instanceof Element) |
| 100 if (desc == "HTML document") { | 72 assert_true(elt instanceof Node) |
| 101 return window; | 73 assert_equals(elt.localName, t[1]) |
| 102 } | 74 assert_equals(elt.tagName, toASCIIUppercase(t[1])) |
| 103 if (desc == "XML document") { | 75 assert_equals(elt.prefix, null) |
| 104 assert_equals(xmlIframe.contentDocument.documentElement.textContent, | 76 assert_equals(elt.namespaceURI, HTMLNS) |
| 105 "Dummy XML document", "XML document didn't load"); | 77 }, "createElement(" + format_value(t[0]) + ")"); |
| 106 return xmlIframe.contentWindow; | |
| 107 } | |
| 108 if (desc == "XHTML document") { | |
| 109 assert_equals(xhtmlIframe.contentDocument.documentElement.textContent, | |
| 110 "Dummy XHTML document", "XHTML document didn't load"); | |
| 111 return xhtmlIframe.contentWindow; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 | |
| 116 valid.forEach(function(t) { | |
| 117 ["HTML document", "XML document", "XHTML document"].forEach(function(desc) { | |
| 118 async_test(function(testObj) { | |
| 119 window.addEventListener("load", function() { | |
| 120 testObj.step(function() { | |
| 121 var win = getWin(desc); | |
| 122 var doc = win.document; | |
| 123 var elt = doc.createElement(t) | |
| 124 assert_true(elt instanceof win.Element, "instanceof Element") | |
| 125 assert_true(elt instanceof win.Node, "instanceof Node") | |
| 126 assert_equals(elt.localName, | |
| 127 desc == "HTML document" ? toASCIILowercase(String(t)) | |
| 128 : String(t), | |
| 129 "localName") | |
| 130 assert_equals(elt.tagName, | |
| 131 desc == "HTML document" ? toASCIIUppercase(String(t)) | |
| 132 : String(t), | |
| 133 "tagName") | |
| 134 assert_equals(elt.prefix, null, "prefix") | |
| 135 assert_equals(elt.namespaceURI, | |
| 136 desc == "XML document" ? null : HTMLNS, "namespaceURI") | |
| 137 }); | |
| 138 testObj.done(); | |
| 139 }); | |
| 140 }, "createElement(" + format_value(t) + ") in " + desc); | |
| 141 }); | 78 }); |
| 142 }); | 79 invalid.forEach(function(arg) { |
| 143 invalid.forEach(function(arg) { | 80 test(function() { |
| 144 ["HTML document", "XML document", "XHTML document"].forEach(function(desc) { | 81 assert_throws("INVALID_CHARACTER_ERR", function() { document.createElement
(arg) }) |
| 145 async_test(function(testObj) { | 82 }, "createElement(" + format_value(arg) + ")"); |
| 146 window.addEventListener("load", function() { | |
| 147 testObj.step(function() { | |
| 148 var doc = getWin(desc).document; | |
| 149 assert_throws("InvalidCharacterError", | |
| 150 function() { doc.createElement(arg) }) | |
| 151 }); | |
| 152 testObj.done(); | |
| 153 }); | |
| 154 }, "createElement(" + format_value(arg) + ") in " + desc); | |
| 155 }); | 83 }); |
| 156 }); | 84 }) |
| 157 </script> | 85 </script> |
| OLD | NEW |