dom/tests/mochitest/bugs/test_bug411103.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE html>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=411103
     5 -->
     6 <head>
     7   <title>Test for Bug 411103</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411103">Mozilla Bug 411103</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none"></div>
    16 <!-- XML's createElement and createElementNS aren't HTML's, of course -->
    17 <iframe src="data:application/xml,%3Cfoo%3EXML%3C/foo%3E" name="xmlWindow"></iframe>
    19 <!-- for good measure... -->
    20 <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"
    21         name="xhtmlWindow"></iframe>
    23 <pre id="test">
    24 <script class="testbody" type="text/javascript">
    26 SimpleTest.waitForExplicitFinish();
    28 /** Test for Bug 411103 **/
    29 var allNSTests =
    30   [
    31    { args: [undefined, undefined] },
    32    { args: [null, undefined] },
    33    { args: [undefined, null] },
    34    { args: [null, null] },
    35    { args: [null, ""], code: 5 },
    36    { args: ["", null] },
    37    { args: ["", ""], code: 5 },
    38    { args: [null, "<div>"], code: 5 },
    39    { args: [null, "0div"], code: 5 },
    40    { args: [null, "di v"], code: 5 },
    41    { args: [null, "di<v"], code: 5 },
    42    { args: [null, "-div"], code: 5 },
    43    { args: [null, ".div"], code: 5 },
    44    { args: ["http://example.com/", "<div>"], code: 5 },
    45    { args: ["http://example.com/", "0div"], code: 5 },
    46    { args: ["http://example.com/", "di<v"], code: 5 },
    47    { args: ["http://example.com/", "-div"], code: 5 },
    48    { args: ["http://example.com/", ".div"], code: 5 },
    49    { args: [null, ":div"], code: 14 },
    50    { args: [null, "div:"], code: 14 },
    51    { args: ["http://example.com/", ":div"], code: 14 },
    52    { args: ["http://example.com/", "div:"], code: 14 },
    53    { args: [null, "d:iv"], code: 14 },
    54    { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
    55    { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
    56    { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" },
    57    { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name, invalid QName" },
    58    { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, not a valid QName" },
    59    { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
    60    { args: ["http://example.com/", "a:_"] },
    61    { args: ["http://example.com/", "a:\u0BC6"], code: 14,
    62      message: "non-ASCII character after colon is CombiningChar, which is " +
    63               "NCNameChar but not (Letter | \"_\") so invalid at start of " +
    64               "NCName (but still a valid XML name, hence not 5)" },
    65    { args: ["http://example.com/", "\u0BC6:a"], code: 14,
    66      message: "non-ASCII character after colon is CombiningChar, which is " +
    67               "NCNameChar but not (Letter | \"_\") so invalid at start of " +
    68               "NCName (Gecko chooses to throw 14 here, but either is valid " +
    69               "as this is both an invalid XML name and an invalid QName)" },
    70    { args: ["http://example.com/", "a:a\u0BC6"] },
    71    { args: ["http://example.com/", "a\u0BC6:a"] },
    72    { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" },
    73    { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xmlns prefix wrong" },
    74    { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "binding namespace namespace to wrong prefix" },
    75    { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
    76    { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
    77    { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
    78   ];
    80 var allNoNSTests =
    81   [
    82    { args: [undefined] },
    83    { args: [null] },
    84    { args: [""], code: 5 },
    85    { args: ["<div>"], code: 5 },
    86    { args: ["0div"], code: 5 },
    87    { args: ["di v"], code: 5 },
    88    { args: ["di<v"], code: 5 },
    89    { args: ["-div"], code: 5 },
    90    { args: [".div"], code: 5 },
    91    { args: [":"], message: "valid XML name, invalid QName" },
    92    { args: [":div"], message: "valid XML name, invalid QName" },
    93    { args: ["div:"], message: "valid XML name, invalid QName" },
    94    { args: ["d:iv"] },
    95    { args: ["a:b:c"], message: "valid XML name, invalid QName" },
    96    { args: ["a::c"], message: "valid XML name, invalid QName" },
    97    { args: ["a::c:"], message: "valid XML name, invalid QName" },
    98    { args: ["a:0"], message: "valid XML name, not a valid QName" },
    99    { args: ["0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
   100    { args: ["a:_"] },
   101    { args: ["a:\u0BC6"],
   102      message: "non-ASCII character after colon is CombiningChar, which is " +
   103               "valid in pre-namespace XML" },
   104    { args: ["\u0BC6:a"], code: 5, message: "not a valid start character" },
   105    { args: ["a:a\u0BC6"] },
   106    { args: ["a\u0BC6:a"] },
   107    { args: ["xml:test"] },
   108    { args: ["xmlns:test"] },
   109    { args: ["x:test"] },
   110    { args: ["xmlns:test"] },
   111   ];
   113 function sourceify(v)
   114 {
   115   switch (typeof v)
   116   {
   117     case "undefined":
   118       return v;
   120     case "string":
   121       return '"' + v.replace('"', '\\"') + '"';
   123     default:
   124       return String(v);
   125   }
   126 }
   128 function sourceifyArgs(args)
   129 {
   130   var copy = new Array(args.length);
   131   for (var i = 0, sz = args.length; i < sz; i++)
   132     copy[i] = sourceify(args[i]);
   134   return copy.join(", ");
   135 }
   137 function runTests(tests, methodName, document)
   138 {
   139   for (var i = 0, sz = tests.length; i < sz; i++)
   140   {
   141     var test = tests[i];
   143     var argStr = sourceifyArgs(test.args);
   144     try
   145     {
   146       document[methodName].apply(document, test.args);
   147       var msg = "expected no exception for " +
   148                 "document." + methodName + "(" + argStr + ")";
   149       if ("message" in test)
   150         msg += "; " + test.message;
   151       ok(!("code" in test), msg);
   152     }
   153     catch (e)
   154     {
   155       msg = "exception code for document." + methodName + "(" + argStr + ")";
   156       if ("message" in test)
   157         msg += "; " + test.message;
   158       is(e.code, test.code || "no exception", msg);
   159     }
   160   }
   161 }
   164 function run()
   165 {
   166   // HTML document
   167   runTests(allNSTests, "createElementNS", document);
   168   runTests(allNoNSTests, "createElement", document);
   170   // XML document
   171   var xmlDocument = window.frames.xmlWindow.document;
   172   runTests(allNSTests, "createElementNS", xmlDocument);
   173   runTests(allNoNSTests, "createElement", xmlDocument);
   175   // XHTML document, for good measure
   176   var xhtmlDocument = window.frames.xhtmlWindow.document;
   177   runTests(allNSTests, "createElementNS", xhtmlDocument);
   178   runTests(allNoNSTests, "createElement", xhtmlDocument);
   180   SimpleTest.finish();
   181 }
   183 window.addEventListener("load", run, false);
   185 </script>
   186 </pre>
   187 </body>
   188 </html>

mercurial