https://github.com/web-platform-tests/wpt
Raw File
Tip revision: fde5297e01bba6c17ed7a80b606fa0e26e6c2c29 authored by Hallvord R. M. Steen on 01 April 2014, 12:49:35 UTC
minor bugfixes
Tip revision: fde5297
Document-createElement.html
<!DOCTYPE html>
<meta charset=utf-8>
<title>Document.createElement</title>
<link rel=help href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement">
<link rel=help href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-element-localname">
<link rel=help href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-element-tagname">
<link rel=help href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-element-prefix">
<link rel=help href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#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>
back to top