1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug498433.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 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=498433">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_ipv6.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 (aCharset == undefined) 1.26 + aCharset = 'UTF-8'; 1.27 + 1.28 + var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1'] 1.29 + .createInstance(SpecialPowers.Ci.nsIURI); 1.30 + baseUri.spec = window.location.href; 1.31 + 1.32 + var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1'] 1.33 + .getService(SpecialPowers.Ci.nsIIOService); 1.34 + var chann = ios.newChannel(aFile, aCharset, baseUri); 1.35 + 1.36 + var cis = SpecialPowers.Ci.nsIConverterInputStream; 1.37 + 1.38 + var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"] 1.39 + .createInstance(cis); 1.40 + inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER); 1.41 + var str = {}, content = ''; 1.42 + while (inputStream.readString(4096, str) != 0) { 1.43 + content += str.value; 1.44 + } 1.45 + return content; 1.46 +} 1.47 + 1.48 +function isRoughly(actual, expected, message) { 1.49 + return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 1.50 + expected, 1.51 + message); 1.52 +} 1.53 + 1.54 +function testHtmlSerializer_1 () { 1.55 + const de = SpecialPowers.Ci.nsIDocumentEncoder; 1.56 + var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"] 1.57 + .createInstance(SpecialPowers.Ci.nsIDocumentEncoder); 1.58 + 1.59 + var doc = $("testframe").contentDocument; 1.60 + var out, expected; 1.61 + 1.62 + // in the following tests, we must use the OutputLFLineBreak flag, to avoid 1.63 + // to have the default line break of the platform in the result, so the test 1.64 + // can pass on all platform 1.65 + 1.66 + //------------ no flags 1.67 + encoder.init(doc, "text/html", de.OutputLFLineBreak); 1.68 + encoder.setCharset("UTF-8"); 1.69 + out = encoder.encodeToString(); 1.70 + expected = loadFileContent("file_htmlserializer_ipv6_out.html"); 1.71 + isRoughly(out, expected, "test no flags"); 1.72 + //------------ OutputAbsoluteLinks 1.73 + encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks); 1.74 + encoder.setCharset("UTF-8"); 1.75 + out = encoder.encodeToString(); 1.76 + expected = loadFileContent("file_htmlserializer_ipv6_out.html"); 1.77 + isRoughly(out, expected, "test OutputAbsoluteLinks"); 1.78 + //------------ serializing a selection 1.79 + encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks); 1.80 + encoder.setNode(doc.links[0]); 1.81 + out = encoder.encodeToString(); 1.82 + expected = "<a href=\"http://[2001:4860:a003::68]/\">Test</a>"; 1.83 + isRoughly(out, expected, "test selection"); 1.84 + 1.85 + 1.86 + SimpleTest.finish(); 1.87 +} 1.88 + 1.89 + 1.90 +SimpleTest.waitForExplicitFinish(); 1.91 + 1.92 +addLoadEvent(testHtmlSerializer_1); 1.93 + 1.94 +</script> 1.95 +</pre> 1.96 + 1.97 +</body> 1.98 +</html> 1.99 + 1.100 +