test_bug498433.html (3476B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 --> 5 <head> 6 <title>Test for HTML serializer</title> 7 <script 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"> 19 20 21 function loadFileContent(aFile, aCharset) { 22 if (aCharset == undefined) 23 aCharset = 'UTF-8'; 24 25 var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1'] 26 .createInstance(SpecialPowers.Ci.nsIURIMutator) 27 .setSpec(window.location.href) 28 .finalize(); 29 30 var ios = SpecialPowers.Services.io; 31 var chann = ios.newChannel(aFile, 32 aCharset, 33 baseUri, 34 null, // aLoadingNode 35 SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(), 36 null, // aTriggeringPrincipal 37 SpecialPowers.Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, 38 SpecialPowers.Ci.nsIContentPolicy.TYPE_OTHER); 39 40 var cis = SpecialPowers.Ci.nsIConverterInputStream; 41 42 var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"] 43 .createInstance(cis); 44 inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER); 45 var str = {}, content = ''; 46 while (inputStream.readString(4096, str) != 0) { 47 content += str.value; 48 } 49 return content; 50 } 51 52 function isRoughly(actual, expected, message) { 53 return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 54 expected, 55 message); 56 } 57 58 function testHtmlSerializer_1 () { 59 const de = SpecialPowers.Ci.nsIDocumentEncoder; 60 var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html"); 61 62 var doc = $("testframe").contentDocument; 63 var out, expected; 64 65 // in the following tests, we must use the OutputLFLineBreak flag, to avoid 66 // to have the default line break of the platform in the result, so the test 67 // can pass on all platform 68 69 //------------ no flags 70 encoder.init(doc, "text/html", de.OutputLFLineBreak); 71 encoder.setCharset("UTF-8"); 72 out = encoder.encodeToString(); 73 expected = loadFileContent("file_htmlserializer_ipv6_out.html"); 74 isRoughly(out, expected, "test no flags"); 75 //------------ OutputAbsoluteLinks 76 encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks); 77 encoder.setCharset("UTF-8"); 78 out = encoder.encodeToString(); 79 expected = loadFileContent("file_htmlserializer_ipv6_out.html"); 80 isRoughly(out, expected, "test OutputAbsoluteLinks"); 81 //------------ serializing a selection 82 encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks); 83 encoder.setNode(doc.links[0]); 84 out = encoder.encodeToString(); 85 expected = "<a href=\"http://[2001:4860:a003::68]/\">Test</a>"; 86 isRoughly(out, expected, "test selection"); 87 88 89 SimpleTest.finish(); 90 } 91 92 93 SimpleTest.waitForExplicitFinish(); 94 95 addLoadEvent(testHtmlSerializer_1); 96 97 </script> 98 </pre> 99 100 </body> 101 </html>