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