content/base/test/test_bug424359-1.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug424359-1.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,205 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for HTML serializer</title>
    1.10 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body>
    1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=424359">Mozilla Bug </a>
    1.15 +<p id="display"></p>
    1.16 +<div id="content" style="display: none">
    1.17 +  <iframe id="testframe" src="file_htmlserializer_1.html">
    1.18 +  </iframe>
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +
    1.23 +
    1.24 +function loadFileContent(aFile, aCharset) {
    1.25 +    //if(aAsIso == undefined) aAsIso = false;
    1.26 +    if(aCharset == undefined)
    1.27 +        aCharset = 'UTF-8';
    1.28 +
    1.29 +    var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
    1.30 +                   .createInstance(SpecialPowers.Ci.nsIURI);
    1.31 +    baseUri.spec = window.location.href;
    1.32 +
    1.33 +    var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
    1.34 +            .getService(SpecialPowers.Ci.nsIIOService);
    1.35 +    var chann = ios.newChannel(aFile, aCharset, baseUri);
    1.36 +
    1.37 +    var cis = SpecialPowers.Ci.nsIConverterInputStream;
    1.38 +
    1.39 +    var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
    1.40 +                       .createInstance(cis);
    1.41 +    inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
    1.42 +    var str = {}, content = '';
    1.43 +    while (inputStream.readString(4096, str) != 0) {
    1.44 +        content += str.value;
    1.45 +    }
    1.46 +    return content;
    1.47 +}
    1.48 +
    1.49 +function isRoughly(actual, expected, message) {
    1.50 +  return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 
    1.51 +            expected, 
    1.52 +            message);
    1.53 +}
    1.54 +
    1.55 +function testHtmlSerializer_1 () {
    1.56 +  const de = SpecialPowers.Ci.nsIDocumentEncoder;
    1.57 +  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
    1.58 +                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
    1.59 +
    1.60 +  var doc = $("testframe").contentDocument;
    1.61 +  var out, expected;
    1.62 +
    1.63 +  // in the following tests, we must use the OutputLFLineBreak flag, to avoid
    1.64 +  // to have the default line break of the platform in the result, so the test
    1.65 +  // can pass on all platform
    1.66 +
    1.67 +  //------------ no flags
    1.68 +  encoder.init(doc, "text/html", de.OutputLFLineBreak);
    1.69 +  encoder.setCharset("UTF-8");
    1.70 +  out = encoder.encodeToString();
    1.71 +  expected = loadFileContent("file_htmlserializer_1_noflag.html");
    1.72 +  isRoughly(out, expected, "test no flags");
    1.73 +
    1.74 +  //------------- unsupported flags
    1.75 +  // since the following flags are not supported, we should
    1.76 +  // have a result like the one without flag
    1.77 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputPreformatted);
    1.78 +  out = encoder.encodeToString();
    1.79 +  isRoughly(out, expected, "test OutputPreformatted");
    1.80 +
    1.81 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatFlowed);
    1.82 +  out = encoder.encodeToString();
    1.83 +  isRoughly(out, expected, "test OutputFormatFlowed");
    1.84 +
    1.85 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoScriptContent);
    1.86 +  out = encoder.encodeToString();
    1.87 +  isRoughly(out, expected, "test OutputNoScriptContent");
    1.88 +
    1.89 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFramesContent);
    1.90 +  out = encoder.encodeToString();
    1.91 +  isRoughly(out, expected, "test OutputNoFramesContent");
    1.92 +
    1.93 +
    1.94 +  //------------ OutputWrap
    1.95 +  encoder.init(doc, "text/html", de.OutputLFLineBreak |de.OutputWrap);
    1.96 +  out = encoder.encodeToString();
    1.97 +  expected = loadFileContent("file_htmlserializer_1_wrap.html");
    1.98 +  isRoughly(out, expected, "test OutputWrap");
    1.99 +
   1.100 +  //------------ OutputFormatted
   1.101 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatted);
   1.102 +  out = encoder.encodeToString();
   1.103 +  expected = loadFileContent("file_htmlserializer_1_format.html");
   1.104 +  isRoughly(out, expected, "test OutputFormatted");
   1.105 +
   1.106 +  //------------ OutputRaw
   1.107 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputRaw);
   1.108 +  out = encoder.encodeToString();
   1.109 +  expected = loadFileContent("file_htmlserializer_1_raw.html");
   1.110 +  isRoughly(out, expected, "test OutputRaw");
   1.111 +
   1.112 +  //------------ OutputBodyOnly
   1.113 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly);
   1.114 +  out = encoder.encodeToString();
   1.115 +  expected = loadFileContent("file_htmlserializer_1_bodyonly.html");
   1.116 +  isRoughly(out, expected, "test OutputBodyOnly");
   1.117 +
   1.118 +
   1.119 +
   1.120 +  //------------ OutputAbsoluteLinks
   1.121 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
   1.122 +  out = encoder.encodeToString();
   1.123 +  expected = loadFileContent("file_htmlserializer_1_links.html").trim('\n');
   1.124 +  isRoughly(out, expected, "test OutputAbsoluteLinks");
   1.125 +
   1.126 +  //------------ OutputLFLineBreak
   1.127 +  encoder.init(doc, "text/html",de.OutputLFLineBreak);
   1.128 +  out = encoder.encodeToString();
   1.129 +  expected = loadFileContent("file_htmlserializer_1_linebreak.html");
   1.130 +  isRoughly(out, expected, "test OutputLFLineBreak");
   1.131 +
   1.132 +  //------------ OutputCRLineBreak
   1.133 +  encoder.init(doc, "text/html",de.OutputCRLineBreak);
   1.134 +  out = encoder.encodeToString();
   1.135 +  expected = expected.replace(/\n/mg, "\r");
   1.136 +  isRoughly(out, expected, "test OutputCRLineBreak");
   1.137 +
   1.138 +  //------------ OutputLFLineBreak + OutputCRLineBreak
   1.139 +  encoder.init(doc, "text/html",de.OutputLFLineBreak | de.OutputCRLineBreak);
   1.140 +  out = encoder.encodeToString();
   1.141 +  expected = expected.replace(/\r/mg, "\r\n");
   1.142 +  isRoughly(out, expected, "test OutputLFLineBreak + OutputCRLineBreak");
   1.143 +
   1.144 +  //------------ OutputNoFormattingInPre
   1.145 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFormattingInPre);
   1.146 +  out = encoder.encodeToString();
   1.147 +  expected = loadFileContent("file_htmlserializer_1_noformatpre.html");
   1.148 +  isRoughly(out, expected, "test OutputNoFormattingInPre");
   1.149 +
   1.150 +  // ------------- nested body elements
   1.151 +  var body2 = doc.createElement('body');
   1.152 +  var p = doc.createElement('p');
   1.153 +  p.appendChild(doc.createTextNode("this is an other body element"));
   1.154 +  body2.appendChild(p);
   1.155 +  var body = doc.getElementsByTagName('body')[0];
   1.156 +  body.appendChild(body2);
   1.157 +
   1.158 +  is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
   1.159 +
   1.160 +  encoder.init(doc, "text/html", de.OutputLFLineBreak);
   1.161 +  encoder.setCharset("UTF-8");
   1.162 +  out = encoder.encodeToString();
   1.163 +  expected = loadFileContent("file_htmlserializer_1_nested_body.html");
   1.164 +  isRoughly(out, expected, "test with two nested body elements");
   1.165 +
   1.166 +  // ------------- two body elements
   1.167 +  body.parentNode.insertBefore(body2, body);
   1.168 +
   1.169 +  is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
   1.170 +  encoder.init(doc, "text/html", de.OutputLFLineBreak);
   1.171 +  encoder.setCharset("UTF-8");
   1.172 +  out = encoder.encodeToString();
   1.173 +  expected = loadFileContent("file_htmlserializer_1_sibling_body.html");
   1.174 +  isRoughly(out, expected, "test with two body elements");
   1.175 +
   1.176 +  encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly);
   1.177 +  encoder.setCharset("UTF-8");
   1.178 +  out = encoder.encodeToString();
   1.179 +  expected = loadFileContent("file_htmlserializer_1_sibling_body_only_body.html");
   1.180 +  isRoughly(out, expected, "test with two body elements, and output body only");
   1.181 +
   1.182 +  // --------------- no body element
   1.183 +  doc.documentElement.removeChild(body);
   1.184 +  doc.documentElement.removeChild(body2);
   1.185 +
   1.186 +  encoder.init(doc, "text/html", de.OutputLFLineBreak);
   1.187 +  encoder.setCharset("UTF-8");
   1.188 +  out = encoder.encodeToString();
   1.189 +  expected = loadFileContent("file_htmlserializer_1_no_body.html");
   1.190 +  isRoughly(out, expected, "test with no body element");
   1.191 +
   1.192 +  SimpleTest.finish();
   1.193 +}
   1.194 +
   1.195 +
   1.196 +SimpleTest.waitForExplicitFinish();
   1.197 +
   1.198 +addLoadEvent(testHtmlSerializer_1);
   1.199 +
   1.200 +</script>
   1.201 +</pre>
   1.202 +<!--<h1>1</h1><h2>result</h2><textarea id="t1" cols="80" rows="20"></textarea>
   1.203 +          <h2>expected</h2><textarea id="t1e" cols="80" rows="20"></textarea>-->
   1.204 +
   1.205 +</body>
   1.206 +</html>
   1.207 +
   1.208 +

mercurial