| 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> |
| 12 <script> | 14 <script> |
| 13 function toASCIIUppercase(str) { | 15 function toASCIIUppercase(str) { |
| 14 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); | 16 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); |
| 15 var res = ""; | 17 var res = ""; |
| 16 for (var i = 0; i < str.length; ++i) { | 18 for (var i = 0; i < str.length; ++i) { |
| 17 if ("a" <= str[i] && str[i] <= "z") { | 19 if ("a" <= str[i] && str[i] <= "z") { |
| 18 res += String.fromCharCode(str.charCodeAt(i) - diff); | 20 res += String.fromCharCode(str.charCodeAt(i) - diff); |
| 19 } else { | 21 } else { |
| 20 res += str[i]; | 22 res += str[i]; |
| 21 } | 23 } |
| 22 } | 24 } |
| 23 return res; | 25 return res; |
| 24 } | 26 } |
| 25 test(function() { | 27 function toASCIILowercase(str) { |
| 26 var HTMLNS = "http://www.w3.org/1999/xhtml", | 28 var diff = "a".charCodeAt(0) - "A".charCodeAt(0); |
| 27 valid = [ | 29 var res = ""; |
| 28 //[input, localName], | 30 for (var i = 0; i < str.length; ++i) { |
| 29 [undefined, "undefined"], | 31 if ("A" <= str[i] && str[i] <= "Z") { |
| 30 [null, "null"], | 32 res += String.fromCharCode(str.charCodeAt(i) + diff); |
| 31 ["foo", "foo"], | 33 } else { |
| 32 ["f1oo", "f1oo"], | 34 res += str[i]; |
| 33 ["foo1", "foo1"], | 35 } |
| 34 ["f\u0300oo", "f\u0300oo"], | 36 } |
| 35 ["foo\u0300", "foo\u0300"], | 37 return res; |
| 36 [":foo", ":foo"], | 38 } |
| 37 ["f:oo", "f:oo"], | 39 var HTMLNS = "http://www.w3.org/1999/xhtml", |
| 38 ["foo:", "foo:"], | 40 valid = [ |
| 39 ["xml", "xml"], | 41 undefined, |
| 40 ["xmlns", "xmlns"], | 42 null, |
| 41 ["xmlfoo", "xmlfoo"], | 43 "foo", |
| 42 ["xml:foo", "xml:foo"], | 44 "f1oo", |
| 43 ["xmlns:foo", "xmlns:foo"], | 45 "foo1", |
| 44 ["xmlfoo:bar", "xmlfoo:bar"], | 46 "f\u0BC6", |
| 45 ["svg", "svg"], | 47 "foo\u0BC6", |
| 46 ["math", "math"], | 48 ":", |
| 47 ["FOO", "foo"], | 49 ":foo", |
| 48 ["mar\u212a", "mar\u212a"], | 50 "f:oo", |
| 49 ["\u0130nput", "\u0130nput"], | 51 "foo:", |
| 50 ["\u0131nput", "\u0131nput"] | 52 "f:o:o", |
| 51 ], | 53 "f::oo", |
| 52 invalid = [ | 54 "f::oo:", |
| 53 "", | 55 "foo:0", |
| 54 "1foo", | 56 "foo:_", |
| 55 "\u0300foo", | 57 // combining char after :, invalid QName but valid Name |
| 56 "}foo", | 58 "foo:\u0BC6", |
| 57 "f}oo", | 59 "foo:foo\u0BC6", |
| 58 "foo}", | 60 "foo\u0BC6:foo", |
| 59 "\ufffffoo", | 61 "xml", |
| 60 "f\uffffoo", | 62 "xmlns", |
| 61 "foo\uffff", | 63 "xmlfoo", |
| 62 "<foo", | 64 "xml:foo", |
| 63 "foo>", | 65 "xmlns:foo", |
| 64 "<foo>", | 66 "xmlfoo:bar", |
| 65 "f<oo" | 67 "svg", |
| 66 ] | 68 "math", |
| 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 ] |
| 67 | 95 |
| 68 valid.forEach(function(t) { | 96 var xmlIframe = document.querySelector('[src="/common/dummy.xml"]'); |
| 69 test(function() { | 97 var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]'); |
| 70 var elt = document.createElement(t[0]) | 98 |
| 71 assert_true(elt instanceof Element) | 99 function getWin(desc) { |
| 72 assert_true(elt instanceof Node) | 100 if (desc == "HTML document") { |
| 73 assert_equals(elt.localName, t[1]) | 101 return window; |
| 74 assert_equals(elt.tagName, toASCIIUppercase(t[1])) | 102 } |
| 75 assert_equals(elt.prefix, null) | 103 if (desc == "XML document") { |
| 76 assert_equals(elt.namespaceURI, HTMLNS) | 104 assert_equals(xmlIframe.contentDocument.documentElement.textContent, |
| 77 }, "createElement(" + format_value(t[0]) + ")"); | 105 "Dummy XML document", "XML document didn't load"); |
| 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); |
| 78 }); | 141 }); |
| 79 invalid.forEach(function(arg) { | 142 }); |
| 80 test(function() { | 143 invalid.forEach(function(arg) { |
| 81 assert_throws("INVALID_CHARACTER_ERR", function() { document.createElement
(arg) }) | 144 ["HTML document", "XML document", "XHTML document"].forEach(function(desc) { |
| 82 }, "createElement(" + format_value(arg) + ")"); | 145 async_test(function(testObj) { |
| 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); |
| 83 }); | 155 }); |
| 84 }) | 156 }); |
| 85 </script> | 157 </script> |
| OLD | NEW |