dom/tests/mochitest/bugs/test_bug411103.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug411103.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,188 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=411103
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 411103</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411103">Mozilla Bug 411103</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none"></div>
    1.18 +
    1.19 +<!-- XML's createElement and createElementNS aren't HTML's, of course -->
    1.20 +<iframe src="data:application/xml,%3Cfoo%3EXML%3C/foo%3E" name="xmlWindow"></iframe>
    1.21 +
    1.22 +<!-- for good measure... -->
    1.23 +<iframe src="data:application/xhtml+xml,%3Chtml%20xmlns=%22http://www.w3.org/1999/xhtml%22%3E%3Cbody%3E%3Cp%3EXHTML%3C/p%3E%3C/body%3E%3C/html%3E"
    1.24 +        name="xhtmlWindow"></iframe>
    1.25 +
    1.26 +<pre id="test">
    1.27 +<script class="testbody" type="text/javascript">
    1.28 +
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +/** Test for Bug 411103 **/
    1.32 +var allNSTests =
    1.33 +  [
    1.34 +   { args: [undefined, undefined] },
    1.35 +   { args: [null, undefined] },
    1.36 +   { args: [undefined, null] },
    1.37 +   { args: [null, null] },
    1.38 +   { args: [null, ""], code: 5 },
    1.39 +   { args: ["", null] },
    1.40 +   { args: ["", ""], code: 5 },
    1.41 +   { args: [null, "<div>"], code: 5 },
    1.42 +   { args: [null, "0div"], code: 5 },
    1.43 +   { args: [null, "di v"], code: 5 },
    1.44 +   { args: [null, "di<v"], code: 5 },
    1.45 +   { args: [null, "-div"], code: 5 },
    1.46 +   { args: [null, ".div"], code: 5 },
    1.47 +   { args: ["http://example.com/", "<div>"], code: 5 },
    1.48 +   { args: ["http://example.com/", "0div"], code: 5 },
    1.49 +   { args: ["http://example.com/", "di<v"], code: 5 },
    1.50 +   { args: ["http://example.com/", "-div"], code: 5 },
    1.51 +   { args: ["http://example.com/", ".div"], code: 5 },
    1.52 +   { args: [null, ":div"], code: 14 },
    1.53 +   { args: [null, "div:"], code: 14 },
    1.54 +   { args: ["http://example.com/", ":div"], code: 14 },
    1.55 +   { args: ["http://example.com/", "div:"], code: 14 },
    1.56 +   { args: [null, "d:iv"], code: 14 },
    1.57 +   { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
    1.58 +   { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
    1.59 +   { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" },
    1.60 +   { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name, invalid QName" },
    1.61 +   { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, not a valid QName" },
    1.62 +   { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
    1.63 +   { args: ["http://example.com/", "a:_"] },
    1.64 +   { args: ["http://example.com/", "a:\u0BC6"], code: 14,
    1.65 +     message: "non-ASCII character after colon is CombiningChar, which is " +
    1.66 +              "NCNameChar but not (Letter | \"_\") so invalid at start of " +
    1.67 +              "NCName (but still a valid XML name, hence not 5)" },
    1.68 +   { args: ["http://example.com/", "\u0BC6:a"], code: 14,
    1.69 +     message: "non-ASCII character after colon is CombiningChar, which is " +
    1.70 +              "NCNameChar but not (Letter | \"_\") so invalid at start of " +
    1.71 +              "NCName (Gecko chooses to throw 14 here, but either is valid " +
    1.72 +              "as this is both an invalid XML name and an invalid QName)" },
    1.73 +   { args: ["http://example.com/", "a:a\u0BC6"] },
    1.74 +   { args: ["http://example.com/", "a\u0BC6:a"] },
    1.75 +   { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" },
    1.76 +   { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xmlns prefix wrong" },
    1.77 +   { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "binding namespace namespace to wrong prefix" },
    1.78 +   { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
    1.79 +   { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
    1.80 +   { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
    1.81 +  ];
    1.82 +
    1.83 +var allNoNSTests =
    1.84 +  [
    1.85 +   { args: [undefined] },
    1.86 +   { args: [null] },
    1.87 +   { args: [""], code: 5 },
    1.88 +   { args: ["<div>"], code: 5 },
    1.89 +   { args: ["0div"], code: 5 },
    1.90 +   { args: ["di v"], code: 5 },
    1.91 +   { args: ["di<v"], code: 5 },
    1.92 +   { args: ["-div"], code: 5 },
    1.93 +   { args: [".div"], code: 5 },
    1.94 +   { args: [":"], message: "valid XML name, invalid QName" },
    1.95 +   { args: [":div"], message: "valid XML name, invalid QName" },
    1.96 +   { args: ["div:"], message: "valid XML name, invalid QName" },
    1.97 +   { args: ["d:iv"] },
    1.98 +   { args: ["a:b:c"], message: "valid XML name, invalid QName" },
    1.99 +   { args: ["a::c"], message: "valid XML name, invalid QName" },
   1.100 +   { args: ["a::c:"], message: "valid XML name, invalid QName" },
   1.101 +   { args: ["a:0"], message: "valid XML name, not a valid QName" },
   1.102 +   { args: ["0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
   1.103 +   { args: ["a:_"] },
   1.104 +   { args: ["a:\u0BC6"],
   1.105 +     message: "non-ASCII character after colon is CombiningChar, which is " +
   1.106 +              "valid in pre-namespace XML" },
   1.107 +   { args: ["\u0BC6:a"], code: 5, message: "not a valid start character" },
   1.108 +   { args: ["a:a\u0BC6"] },
   1.109 +   { args: ["a\u0BC6:a"] },
   1.110 +   { args: ["xml:test"] },
   1.111 +   { args: ["xmlns:test"] },
   1.112 +   { args: ["x:test"] },
   1.113 +   { args: ["xmlns:test"] },
   1.114 +  ];
   1.115 +
   1.116 +function sourceify(v)
   1.117 +{
   1.118 +  switch (typeof v)
   1.119 +  {
   1.120 +    case "undefined":
   1.121 +      return v;
   1.122 +
   1.123 +    case "string":
   1.124 +      return '"' + v.replace('"', '\\"') + '"';
   1.125 +
   1.126 +    default:
   1.127 +      return String(v);
   1.128 +  }
   1.129 +}
   1.130 +
   1.131 +function sourceifyArgs(args)
   1.132 +{
   1.133 +  var copy = new Array(args.length);
   1.134 +  for (var i = 0, sz = args.length; i < sz; i++)
   1.135 +    copy[i] = sourceify(args[i]);
   1.136 +
   1.137 +  return copy.join(", ");
   1.138 +}
   1.139 +
   1.140 +function runTests(tests, methodName, document)
   1.141 +{
   1.142 +  for (var i = 0, sz = tests.length; i < sz; i++)
   1.143 +  {
   1.144 +    var test = tests[i];
   1.145 +  
   1.146 +    var argStr = sourceifyArgs(test.args);
   1.147 +    try
   1.148 +    {
   1.149 +      document[methodName].apply(document, test.args);
   1.150 +      var msg = "expected no exception for " +
   1.151 +                "document." + methodName + "(" + argStr + ")";
   1.152 +      if ("message" in test)
   1.153 +        msg += "; " + test.message;
   1.154 +      ok(!("code" in test), msg);
   1.155 +    }
   1.156 +    catch (e)
   1.157 +    {
   1.158 +      msg = "exception code for document." + methodName + "(" + argStr + ")";
   1.159 +      if ("message" in test)
   1.160 +        msg += "; " + test.message;
   1.161 +      is(e.code, test.code || "no exception", msg);
   1.162 +    }
   1.163 +  }
   1.164 +}
   1.165 +
   1.166 +
   1.167 +function run()
   1.168 +{
   1.169 +  // HTML document
   1.170 +  runTests(allNSTests, "createElementNS", document);
   1.171 +  runTests(allNoNSTests, "createElement", document);
   1.172 +
   1.173 +  // XML document
   1.174 +  var xmlDocument = window.frames.xmlWindow.document;
   1.175 +  runTests(allNSTests, "createElementNS", xmlDocument);
   1.176 +  runTests(allNoNSTests, "createElement", xmlDocument);
   1.177 +
   1.178 +  // XHTML document, for good measure
   1.179 +  var xhtmlDocument = window.frames.xhtmlWindow.document;
   1.180 +  runTests(allNSTests, "createElementNS", xhtmlDocument);
   1.181 +  runTests(allNoNSTests, "createElement", xhtmlDocument);
   1.182 +
   1.183 +  SimpleTest.finish();
   1.184 +}
   1.185 +
   1.186 +window.addEventListener("load", run, false);
   1.187 +
   1.188 +</script>
   1.189 +</pre>
   1.190 +</body>
   1.191 +</html>

mercurial