mirror of
https://github.com/servo/servo.git
synced 2025-07-12 01:43:43 +01:00
85 lines
2.5 KiB
HTML
85 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset=utf-8>
|
|
<title>Document.createElement</title>
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelement">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-localname">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-tagname">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-prefix">
|
|
<link rel=help href="https://dom.spec.whatwg.org/#dom-element-namespaceuri">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<div id="log"></div>
|
|
<script>
|
|
function toASCIIUppercase(str) {
|
|
var diff = "a".charCodeAt(0) - "A".charCodeAt(0);
|
|
var res = "";
|
|
for (var i = 0; i < str.length; ++i) {
|
|
if ("a" <= str[i] && str[i] <= "z") {
|
|
res += String.fromCharCode(str.charCodeAt(i) - diff);
|
|
} else {
|
|
res += str[i];
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
test(function() {
|
|
var HTMLNS = "http://www.w3.org/1999/xhtml",
|
|
valid = [
|
|
//[input, localName],
|
|
[undefined, "undefined"],
|
|
[null, "null"],
|
|
["foo", "foo"],
|
|
["f1oo", "f1oo"],
|
|
["foo1", "foo1"],
|
|
["f\u0300oo", "f\u0300oo"],
|
|
["foo\u0300", "foo\u0300"],
|
|
[":foo", ":foo"],
|
|
["f:oo", "f:oo"],
|
|
["foo:", "foo:"],
|
|
["xml", "xml"],
|
|
["xmlns", "xmlns"],
|
|
["xmlfoo", "xmlfoo"],
|
|
["xml:foo", "xml:foo"],
|
|
["xmlns:foo", "xmlns:foo"],
|
|
["xmlfoo:bar", "xmlfoo:bar"],
|
|
["svg", "svg"],
|
|
["math", "math"],
|
|
["FOO", "foo"],
|
|
["mar\u212a", "mar\u212a"],
|
|
["\u0130nput", "\u0130nput"],
|
|
["\u0131nput", "\u0131nput"]
|
|
],
|
|
invalid = [
|
|
"",
|
|
"1foo",
|
|
"\u0300foo",
|
|
"}foo",
|
|
"f}oo",
|
|
"foo}",
|
|
"\ufffffoo",
|
|
"f\uffffoo",
|
|
"foo\uffff",
|
|
"<foo",
|
|
"foo>",
|
|
"<foo>",
|
|
"f<oo"
|
|
]
|
|
|
|
valid.forEach(function(t) {
|
|
test(function() {
|
|
var elt = document.createElement(t[0])
|
|
assert_true(elt instanceof Element)
|
|
assert_true(elt instanceof Node)
|
|
assert_equals(elt.localName, t[1])
|
|
assert_equals(elt.tagName, toASCIIUppercase(t[1]))
|
|
assert_equals(elt.prefix, null)
|
|
assert_equals(elt.namespaceURI, HTMLNS)
|
|
}, "createElement(" + format_value(t[0]) + ")");
|
|
});
|
|
invalid.forEach(function(arg) {
|
|
test(function() {
|
|
assert_throws("INVALID_CHARACTER_ERR", function() { document.createElement(arg) })
|
|
}, "createElement(" + format_value(arg) + ")");
|
|
});
|
|
})
|
|
</script>
|