Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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=424359">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_1.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(aAsIso == undefined) aAsIso = false; |
michael@0 | 23 | if(aCharset == undefined) |
michael@0 | 24 | aCharset = 'UTF-8'; |
michael@0 | 25 | |
michael@0 | 26 | var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1'] |
michael@0 | 27 | .createInstance(SpecialPowers.Ci.nsIURI); |
michael@0 | 28 | baseUri.spec = window.location.href; |
michael@0 | 29 | |
michael@0 | 30 | var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1'] |
michael@0 | 31 | .getService(SpecialPowers.Ci.nsIIOService); |
michael@0 | 32 | var chann = ios.newChannel(aFile, aCharset, baseUri); |
michael@0 | 33 | |
michael@0 | 34 | var cis = SpecialPowers.Ci.nsIConverterInputStream; |
michael@0 | 35 | |
michael@0 | 36 | var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"] |
michael@0 | 37 | .createInstance(cis); |
michael@0 | 38 | inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER); |
michael@0 | 39 | var str = {}, content = ''; |
michael@0 | 40 | while (inputStream.readString(4096, str) != 0) { |
michael@0 | 41 | content += str.value; |
michael@0 | 42 | } |
michael@0 | 43 | return content; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function isRoughly(actual, expected, message) { |
michael@0 | 47 | return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), |
michael@0 | 48 | expected, |
michael@0 | 49 | message); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function testHtmlSerializer_1 () { |
michael@0 | 53 | const de = SpecialPowers.Ci.nsIDocumentEncoder; |
michael@0 | 54 | var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"] |
michael@0 | 55 | .createInstance(SpecialPowers.Ci.nsIDocumentEncoder); |
michael@0 | 56 | |
michael@0 | 57 | var doc = $("testframe").contentDocument; |
michael@0 | 58 | var out, expected; |
michael@0 | 59 | |
michael@0 | 60 | // in the following tests, we must use the OutputLFLineBreak flag, to avoid |
michael@0 | 61 | // to have the default line break of the platform in the result, so the test |
michael@0 | 62 | // can pass on all platform |
michael@0 | 63 | |
michael@0 | 64 | //------------ no flags |
michael@0 | 65 | encoder.init(doc, "text/html", de.OutputLFLineBreak); |
michael@0 | 66 | encoder.setCharset("UTF-8"); |
michael@0 | 67 | out = encoder.encodeToString(); |
michael@0 | 68 | expected = loadFileContent("file_htmlserializer_1_noflag.html"); |
michael@0 | 69 | isRoughly(out, expected, "test no flags"); |
michael@0 | 70 | |
michael@0 | 71 | //------------- unsupported flags |
michael@0 | 72 | // since the following flags are not supported, we should |
michael@0 | 73 | // have a result like the one without flag |
michael@0 | 74 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputPreformatted); |
michael@0 | 75 | out = encoder.encodeToString(); |
michael@0 | 76 | isRoughly(out, expected, "test OutputPreformatted"); |
michael@0 | 77 | |
michael@0 | 78 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatFlowed); |
michael@0 | 79 | out = encoder.encodeToString(); |
michael@0 | 80 | isRoughly(out, expected, "test OutputFormatFlowed"); |
michael@0 | 81 | |
michael@0 | 82 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoScriptContent); |
michael@0 | 83 | out = encoder.encodeToString(); |
michael@0 | 84 | isRoughly(out, expected, "test OutputNoScriptContent"); |
michael@0 | 85 | |
michael@0 | 86 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFramesContent); |
michael@0 | 87 | out = encoder.encodeToString(); |
michael@0 | 88 | isRoughly(out, expected, "test OutputNoFramesContent"); |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | //------------ OutputWrap |
michael@0 | 92 | encoder.init(doc, "text/html", de.OutputLFLineBreak |de.OutputWrap); |
michael@0 | 93 | out = encoder.encodeToString(); |
michael@0 | 94 | expected = loadFileContent("file_htmlserializer_1_wrap.html"); |
michael@0 | 95 | isRoughly(out, expected, "test OutputWrap"); |
michael@0 | 96 | |
michael@0 | 97 | //------------ OutputFormatted |
michael@0 | 98 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatted); |
michael@0 | 99 | out = encoder.encodeToString(); |
michael@0 | 100 | expected = loadFileContent("file_htmlserializer_1_format.html"); |
michael@0 | 101 | isRoughly(out, expected, "test OutputFormatted"); |
michael@0 | 102 | |
michael@0 | 103 | //------------ OutputRaw |
michael@0 | 104 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputRaw); |
michael@0 | 105 | out = encoder.encodeToString(); |
michael@0 | 106 | expected = loadFileContent("file_htmlserializer_1_raw.html"); |
michael@0 | 107 | isRoughly(out, expected, "test OutputRaw"); |
michael@0 | 108 | |
michael@0 | 109 | //------------ OutputBodyOnly |
michael@0 | 110 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly); |
michael@0 | 111 | out = encoder.encodeToString(); |
michael@0 | 112 | expected = loadFileContent("file_htmlserializer_1_bodyonly.html"); |
michael@0 | 113 | isRoughly(out, expected, "test OutputBodyOnly"); |
michael@0 | 114 | |
michael@0 | 115 | |
michael@0 | 116 | |
michael@0 | 117 | //------------ OutputAbsoluteLinks |
michael@0 | 118 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks); |
michael@0 | 119 | out = encoder.encodeToString(); |
michael@0 | 120 | expected = loadFileContent("file_htmlserializer_1_links.html").trim('\n'); |
michael@0 | 121 | isRoughly(out, expected, "test OutputAbsoluteLinks"); |
michael@0 | 122 | |
michael@0 | 123 | //------------ OutputLFLineBreak |
michael@0 | 124 | encoder.init(doc, "text/html",de.OutputLFLineBreak); |
michael@0 | 125 | out = encoder.encodeToString(); |
michael@0 | 126 | expected = loadFileContent("file_htmlserializer_1_linebreak.html"); |
michael@0 | 127 | isRoughly(out, expected, "test OutputLFLineBreak"); |
michael@0 | 128 | |
michael@0 | 129 | //------------ OutputCRLineBreak |
michael@0 | 130 | encoder.init(doc, "text/html",de.OutputCRLineBreak); |
michael@0 | 131 | out = encoder.encodeToString(); |
michael@0 | 132 | expected = expected.replace(/\n/mg, "\r"); |
michael@0 | 133 | isRoughly(out, expected, "test OutputCRLineBreak"); |
michael@0 | 134 | |
michael@0 | 135 | //------------ OutputLFLineBreak + OutputCRLineBreak |
michael@0 | 136 | encoder.init(doc, "text/html",de.OutputLFLineBreak | de.OutputCRLineBreak); |
michael@0 | 137 | out = encoder.encodeToString(); |
michael@0 | 138 | expected = expected.replace(/\r/mg, "\r\n"); |
michael@0 | 139 | isRoughly(out, expected, "test OutputLFLineBreak + OutputCRLineBreak"); |
michael@0 | 140 | |
michael@0 | 141 | //------------ OutputNoFormattingInPre |
michael@0 | 142 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFormattingInPre); |
michael@0 | 143 | out = encoder.encodeToString(); |
michael@0 | 144 | expected = loadFileContent("file_htmlserializer_1_noformatpre.html"); |
michael@0 | 145 | isRoughly(out, expected, "test OutputNoFormattingInPre"); |
michael@0 | 146 | |
michael@0 | 147 | // ------------- nested body elements |
michael@0 | 148 | var body2 = doc.createElement('body'); |
michael@0 | 149 | var p = doc.createElement('p'); |
michael@0 | 150 | p.appendChild(doc.createTextNode("this is an other body element")); |
michael@0 | 151 | body2.appendChild(p); |
michael@0 | 152 | var body = doc.getElementsByTagName('body')[0]; |
michael@0 | 153 | body.appendChild(body2); |
michael@0 | 154 | |
michael@0 | 155 | is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements |
michael@0 | 156 | |
michael@0 | 157 | encoder.init(doc, "text/html", de.OutputLFLineBreak); |
michael@0 | 158 | encoder.setCharset("UTF-8"); |
michael@0 | 159 | out = encoder.encodeToString(); |
michael@0 | 160 | expected = loadFileContent("file_htmlserializer_1_nested_body.html"); |
michael@0 | 161 | isRoughly(out, expected, "test with two nested body elements"); |
michael@0 | 162 | |
michael@0 | 163 | // ------------- two body elements |
michael@0 | 164 | body.parentNode.insertBefore(body2, body); |
michael@0 | 165 | |
michael@0 | 166 | is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements |
michael@0 | 167 | encoder.init(doc, "text/html", de.OutputLFLineBreak); |
michael@0 | 168 | encoder.setCharset("UTF-8"); |
michael@0 | 169 | out = encoder.encodeToString(); |
michael@0 | 170 | expected = loadFileContent("file_htmlserializer_1_sibling_body.html"); |
michael@0 | 171 | isRoughly(out, expected, "test with two body elements"); |
michael@0 | 172 | |
michael@0 | 173 | encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly); |
michael@0 | 174 | encoder.setCharset("UTF-8"); |
michael@0 | 175 | out = encoder.encodeToString(); |
michael@0 | 176 | expected = loadFileContent("file_htmlserializer_1_sibling_body_only_body.html"); |
michael@0 | 177 | isRoughly(out, expected, "test with two body elements, and output body only"); |
michael@0 | 178 | |
michael@0 | 179 | // --------------- no body element |
michael@0 | 180 | doc.documentElement.removeChild(body); |
michael@0 | 181 | doc.documentElement.removeChild(body2); |
michael@0 | 182 | |
michael@0 | 183 | encoder.init(doc, "text/html", de.OutputLFLineBreak); |
michael@0 | 184 | encoder.setCharset("UTF-8"); |
michael@0 | 185 | out = encoder.encodeToString(); |
michael@0 | 186 | expected = loadFileContent("file_htmlserializer_1_no_body.html"); |
michael@0 | 187 | isRoughly(out, expected, "test with no body element"); |
michael@0 | 188 | |
michael@0 | 189 | SimpleTest.finish(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | |
michael@0 | 193 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 194 | |
michael@0 | 195 | addLoadEvent(testHtmlSerializer_1); |
michael@0 | 196 | |
michael@0 | 197 | </script> |
michael@0 | 198 | </pre> |
michael@0 | 199 | <!--<h1>1</h1><h2>result</h2><textarea id="t1" cols="80" rows="20"></textarea> |
michael@0 | 200 | <h2>expected</h2><textarea id="t1e" cols="80" rows="20"></textarea>--> |
michael@0 | 201 | |
michael@0 | 202 | </body> |
michael@0 | 203 | </html> |
michael@0 | 204 | |
michael@0 | 205 |