content/base/test/test_bug422403-1.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug422403-1.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for XHTML 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=422043">Mozilla Bug </a>
    1.15 +<p id="display"></p>
    1.16 +<div id="content" style="display: none">
    1.17 +  <iframe id="testframe" src="file_xhtmlserializer_1.xhtml">
    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 +
    1.50 +function testHtmlSerializer_1 () {
    1.51 +  const de = SpecialPowers.Ci.nsIDocumentEncoder
    1.52 +  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
    1.53 +                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
    1.54 +
    1.55 +  var doc = SpecialPowers.wrap($("testframe")).contentDocument;
    1.56 +  var out, expected;
    1.57 +
    1.58 +  // in the following tests, we must use the OutputLFLineBreak flag, to avoid
    1.59 +  // to have the default line break of the platform in the result, so the test
    1.60 +  // can pass on all platform
    1.61 +
    1.62 +  //------------ no flags
    1.63 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
    1.64 +  encoder.setCharset("UTF-8");
    1.65 +  out = encoder.encodeToString();
    1.66 +  expected = loadFileContent("file_xhtmlserializer_1_noflag.xhtml");
    1.67 +  is(out, expected, "test no flags");
    1.68 +
    1.69 +  //------------- unsupported flags
    1.70 +  // since the following flags are not supported, we should
    1.71 +  // have a result like the one without flag
    1.72 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputPreformatted);
    1.73 +  out = encoder.encodeToString();
    1.74 +  is(out, expected, "test OutputPreformatted");
    1.75 +
    1.76 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatFlowed);
    1.77 +  out = encoder.encodeToString();
    1.78 +  is(out, expected, "test OutputFormatFlowed");
    1.79 +
    1.80 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoScriptContent);
    1.81 +  out = encoder.encodeToString();
    1.82 +  is(out, expected, "test OutputNoScriptContent");
    1.83 +
    1.84 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFramesContent);
    1.85 +  out = encoder.encodeToString();
    1.86 +  is(out, expected, "test OutputNoFramesContent");
    1.87 +
    1.88 +
    1.89 +  //------------ OutputWrap
    1.90 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputWrap);
    1.91 +  out = encoder.encodeToString();
    1.92 +  expected = loadFileContent("file_xhtmlserializer_1_wrap.xhtml");
    1.93 +  is(out, expected, "test OutputWrap");
    1.94 +
    1.95 +  //------------ OutputFormatted
    1.96 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatted);
    1.97 +  out = encoder.encodeToString();
    1.98 +  expected = loadFileContent("file_xhtmlserializer_1_format.xhtml");
    1.99 +  is(out, expected, "test OutputFormatted");
   1.100 +
   1.101 +  //------------ OutputRaw
   1.102 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputRaw);
   1.103 +  out = encoder.encodeToString();
   1.104 +  expected = loadFileContent("file_xhtmlserializer_1_raw.xhtml");
   1.105 +  is(out, expected, "test OutputRaw");
   1.106 +
   1.107 +  //------------ OutputBodyOnly
   1.108 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
   1.109 +  out = encoder.encodeToString();
   1.110 +  expected = loadFileContent("file_xhtmlserializer_1_bodyonly.xhtml");
   1.111 +  is(out, expected, "test OutputBodyOnly");
   1.112 +
   1.113 +
   1.114 +  //------------ OutputAbsoluteLinks
   1.115 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
   1.116 +  out = encoder.encodeToString();
   1.117 +  expected = loadFileContent("file_xhtmlserializer_1_links.xhtml").trim('\n');
   1.118 +  is(out, expected, "test OutputAbsoluteLinks");
   1.119 +
   1.120 +  //------------ OutputLFLineBreak
   1.121 +  encoder.init(doc, "application/xhtml+xml",de.OutputLFLineBreak);
   1.122 +  out = encoder.encodeToString();
   1.123 +  expected = loadFileContent("file_xhtmlserializer_1_linebreak.xhtml");
   1.124 +  is(out, expected, "test OutputLFLineBreak");
   1.125 +
   1.126 +  //------------ OutputCRLineBreak
   1.127 +  encoder.init(doc, "application/xhtml+xml",de.OutputCRLineBreak);
   1.128 +  out = encoder.encodeToString();
   1.129 +  expected = expected.replace(/\n/mg, "\r");
   1.130 +  is(out, expected, "test OutputCRLineBreak");
   1.131 +
   1.132 +  //------------ OutputLFLineBreak + OutputCRLineBreak
   1.133 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputCRLineBreak);
   1.134 +  out = encoder.encodeToString();
   1.135 +  expected = expected.replace(/\r/mg, "\r\n");
   1.136 +  is(out, expected, "test OutputLFLineBreak + OutputCRLineBreak");
   1.137 +
   1.138 +  //------------ OutputNoFormattingInPre
   1.139 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFormattingInPre);
   1.140 +  out = encoder.encodeToString();
   1.141 +  expected = loadFileContent("file_xhtmlserializer_1_noformatpre.xhtml");
   1.142 +  is(out, expected, "test OutputNoFormattingInPre");
   1.143 +
   1.144 +  // ------------- nested body elements
   1.145 +  var body2 = doc.createElement('body');
   1.146 +  var p = doc.createElement('p');
   1.147 +  p.appendChild(doc.createTextNode("this is an other body element"));
   1.148 +  body2.appendChild(p);
   1.149 +  var body = doc.getElementsByTagName('body')[0];
   1.150 +  body.appendChild(body2);
   1.151 +
   1.152 +  is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
   1.153 +
   1.154 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
   1.155 +  encoder.setCharset("UTF-8");
   1.156 +  out = encoder.encodeToString();
   1.157 +  expected = loadFileContent("file_xhtmlserializer_1_nested_body.xhtml");
   1.158 +  is(out, expected, "test with two nested body elements");
   1.159 +
   1.160 +  // ------------- two body elements
   1.161 +  body.parentNode.insertBefore(body2, body);
   1.162 +
   1.163 +  is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
   1.164 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
   1.165 +  encoder.setCharset("UTF-8");
   1.166 +  out = encoder.encodeToString();
   1.167 +  expected = loadFileContent("file_xhtmlserializer_1_sibling_body.xhtml");
   1.168 +  is(out, expected, "test with two body elements");
   1.169 +
   1.170 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
   1.171 +  encoder.setCharset("UTF-8");
   1.172 +  out = encoder.encodeToString();
   1.173 +  expected = loadFileContent("file_xhtmlserializer_1_sibling_body_only_body.xhtml");
   1.174 +  is(out, expected, "test with two body elements, and output body only");
   1.175 +
   1.176 +  // --------------- no body element
   1.177 +  doc.documentElement.removeChild(body);
   1.178 +  doc.documentElement.removeChild(body2);
   1.179 +
   1.180 +  encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
   1.181 +  encoder.setCharset("UTF-8");
   1.182 +  out = encoder.encodeToString();
   1.183 +  expected = loadFileContent("file_xhtmlserializer_1_no_body.xhtml");
   1.184 +  is(out, expected, "test with no body element");
   1.185 +
   1.186 +  SimpleTest.finish();
   1.187 +}
   1.188 +
   1.189 +
   1.190 +SimpleTest.waitForExplicitFinish();
   1.191 +
   1.192 +addLoadEvent(testHtmlSerializer_1);
   1.193 +
   1.194 +</script>
   1.195 +</pre>
   1.196 +</body>
   1.197 +</html>
   1.198 +
   1.199 +

mercurial