content/base/test/test_bug498433.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 <!--
     4 -->
     5 <head>
     6   <title>Test for HTML serializer</title>
     7   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     9 </head>
    10 <body>
    11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498433">Mozilla Bug </a>
    12 <p id="display"></p>
    13 <div id="content" style="display: none">
    14   <iframe id="testframe" src="file_htmlserializer_ipv6.html">
    15   </iframe>
    16 </div>
    17 <pre id="test">
    18 <script class="testbody" type="text/javascript">
    21 function loadFileContent(aFile, aCharset) {
    22     if (aCharset == undefined)
    23         aCharset = 'UTF-8';
    25     var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
    26                    .createInstance(SpecialPowers.Ci.nsIURI);
    27     baseUri.spec = window.location.href;
    29     var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
    30             .getService(SpecialPowers.Ci.nsIIOService);
    31     var chann = ios.newChannel(aFile, aCharset, baseUri);
    33     var cis = SpecialPowers.Ci.nsIConverterInputStream;
    35     var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
    36                        .createInstance(cis);
    37     inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
    38     var str = {}, content = '';
    39     while (inputStream.readString(4096, str) != 0) {
    40         content += str.value;
    41     }
    42     return content;
    43 }
    45 function isRoughly(actual, expected, message) {
    46   return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 
    47             expected, 
    48             message);
    49 }
    51 function testHtmlSerializer_1 () {
    52   const de = SpecialPowers.Ci.nsIDocumentEncoder;
    53   var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
    54                    .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
    56   var doc = $("testframe").contentDocument;
    57   var out, expected;
    59   // in the following tests, we must use the OutputLFLineBreak flag, to avoid
    60   // to have the default line break of the platform in the result, so the test
    61   // can pass on all platform
    63   //------------ no flags
    64   encoder.init(doc, "text/html", de.OutputLFLineBreak);
    65   encoder.setCharset("UTF-8");
    66   out = encoder.encodeToString();
    67   expected = loadFileContent("file_htmlserializer_ipv6_out.html");
    68   isRoughly(out, expected, "test no flags");
    69   //------------ OutputAbsoluteLinks
    70   encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
    71   encoder.setCharset("UTF-8");
    72   out = encoder.encodeToString();
    73   expected = loadFileContent("file_htmlserializer_ipv6_out.html");
    74   isRoughly(out, expected, "test OutputAbsoluteLinks");
    75   //------------ serializing a selection
    76   encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
    77   encoder.setNode(doc.links[0]);
    78   out = encoder.encodeToString();
    79   expected = "<a href=\"http://[2001:4860:a003::68]/\">Test</a>";
    80   isRoughly(out, expected, "test selection");
    83   SimpleTest.finish();
    84 }
    87 SimpleTest.waitForExplicitFinish();
    89 addLoadEvent(testHtmlSerializer_1);
    91 </script>
    92 </pre>
    94 </body>
    95 </html>

mercurial