content/base/test/test_domparsing.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset=utf-8>
     5   <title>Test for the DOM Parsing and Serialization Standard</title>
     6   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=816410">Mozilla Bug 816410</a>
    11 <p id="display"></p>
    12 <div id="content" style="display: none">
    14 </div>
    15 <pre id="test">
    16 <script type="application/javascript;version=1.7">
    17 "use strict";
    18 /** Test for Bug 816410 **/
    20 function throws(fn, type, message) {
    21   try {
    22     fn();
    23     ok(false, message);
    24   } catch (e) {
    25     if (type) {
    26       is(e.name, type, message);
    27     } else {
    28       ok(true, message);
    29     }
    30   }
    31 }
    33 let parser = new DOMParser();
    34 is(typeof parser.parseFromString, "function", "parseFromString should exist");
    35 is(typeof parser.parseFromBuffer, "undefined", "parseFromBuffer should NOT be visible from unprivileged callers");
    36 is(typeof parser.parseFromStream, "undefined", "parseFromStream should NOT be visible from unprivileged callers");
    37 is(typeof parser.init, "undefined", "init should NOT be visible from unprivileged callers");
    39 // The three-arguments constructor should not be visible from
    40 // unprivileged callers for interoperability with other browsers.
    41 // But we have no way to do that right now.
    42 try {
    43   new DOMParser(undefined);
    44   new DOMParser(null);
    45   new DOMParser(false);
    46   new DOMParser(0);
    47   new DOMParser("");
    48   new DOMParser({});
    49 } catch (e) {
    50   todo(false, "DOMParser constructor should not throw for extra arguments");
    51 }
    53 let serializer = new XMLSerializer();
    54 is(typeof serializer.serializeToString, "function", "serializeToString should exist");
    55 is(typeof serializer.serializeToStream, "undefined", "serializeToStream should NOT be visible from unprivileged callers");
    57 // XMLSerializer constructor should not throw for extra arguments
    58 new XMLSerializer(undefined);
    59 new XMLSerializer(null);
    60 new XMLSerializer(false);
    61 new XMLSerializer(0);
    62 new XMLSerializer("");
    63 new XMLSerializer({});
    65 let tests = [
    66   {input: "<html></html>", type: "text/html",
    67    expected: '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>'},
    68   {input: "<xml></xml>", type: "text/xml", expected: "<xml/>"},
    69   {input: "<xml></xml>", type: "application/xml", expected: "<xml/>"},
    70   {input: "<html></html>", type: "application/xhtml+xml", expected: "<html/>"},
    71   {input: "<svg></svg>", type: "image/svg+xml", expected: "<svg/>"},
    72 ];
    73 for (let t of tests) {
    74   is(serializer.serializeToString(parser.parseFromString(t.input, t.type)), t.expected,
    75      "parseFromString test for " + t.type);
    76 }
    78 throws(function() {
    79   parser.parseFromString("<xml></xml>", "foo/bar");
    80 }, "TypeError", "parseFromString should throw for the unknown type");
    81 </script>
    82 </pre>
    83 </body>
    84 </html>

mercurial