content/base/test/test_bug422403-1.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 XHTML 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=422043">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_xhtmlserializer_1.xhtml">
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
michael@0 47 function testHtmlSerializer_1 () {
michael@0 48 const de = SpecialPowers.Ci.nsIDocumentEncoder
michael@0 49 var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
michael@0 50 .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
michael@0 51
michael@0 52 var doc = SpecialPowers.wrap($("testframe")).contentDocument;
michael@0 53 var out, expected;
michael@0 54
michael@0 55 // in the following tests, we must use the OutputLFLineBreak flag, to avoid
michael@0 56 // to have the default line break of the platform in the result, so the test
michael@0 57 // can pass on all platform
michael@0 58
michael@0 59 //------------ no flags
michael@0 60 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
michael@0 61 encoder.setCharset("UTF-8");
michael@0 62 out = encoder.encodeToString();
michael@0 63 expected = loadFileContent("file_xhtmlserializer_1_noflag.xhtml");
michael@0 64 is(out, expected, "test no flags");
michael@0 65
michael@0 66 //------------- unsupported flags
michael@0 67 // since the following flags are not supported, we should
michael@0 68 // have a result like the one without flag
michael@0 69 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputPreformatted);
michael@0 70 out = encoder.encodeToString();
michael@0 71 is(out, expected, "test OutputPreformatted");
michael@0 72
michael@0 73 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatFlowed);
michael@0 74 out = encoder.encodeToString();
michael@0 75 is(out, expected, "test OutputFormatFlowed");
michael@0 76
michael@0 77 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoScriptContent);
michael@0 78 out = encoder.encodeToString();
michael@0 79 is(out, expected, "test OutputNoScriptContent");
michael@0 80
michael@0 81 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFramesContent);
michael@0 82 out = encoder.encodeToString();
michael@0 83 is(out, expected, "test OutputNoFramesContent");
michael@0 84
michael@0 85
michael@0 86 //------------ OutputWrap
michael@0 87 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputWrap);
michael@0 88 out = encoder.encodeToString();
michael@0 89 expected = loadFileContent("file_xhtmlserializer_1_wrap.xhtml");
michael@0 90 is(out, expected, "test OutputWrap");
michael@0 91
michael@0 92 //------------ OutputFormatted
michael@0 93 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatted);
michael@0 94 out = encoder.encodeToString();
michael@0 95 expected = loadFileContent("file_xhtmlserializer_1_format.xhtml");
michael@0 96 is(out, expected, "test OutputFormatted");
michael@0 97
michael@0 98 //------------ OutputRaw
michael@0 99 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputRaw);
michael@0 100 out = encoder.encodeToString();
michael@0 101 expected = loadFileContent("file_xhtmlserializer_1_raw.xhtml");
michael@0 102 is(out, expected, "test OutputRaw");
michael@0 103
michael@0 104 //------------ OutputBodyOnly
michael@0 105 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
michael@0 106 out = encoder.encodeToString();
michael@0 107 expected = loadFileContent("file_xhtmlserializer_1_bodyonly.xhtml");
michael@0 108 is(out, expected, "test OutputBodyOnly");
michael@0 109
michael@0 110
michael@0 111 //------------ OutputAbsoluteLinks
michael@0 112 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
michael@0 113 out = encoder.encodeToString();
michael@0 114 expected = loadFileContent("file_xhtmlserializer_1_links.xhtml").trim('\n');
michael@0 115 is(out, expected, "test OutputAbsoluteLinks");
michael@0 116
michael@0 117 //------------ OutputLFLineBreak
michael@0 118 encoder.init(doc, "application/xhtml+xml",de.OutputLFLineBreak);
michael@0 119 out = encoder.encodeToString();
michael@0 120 expected = loadFileContent("file_xhtmlserializer_1_linebreak.xhtml");
michael@0 121 is(out, expected, "test OutputLFLineBreak");
michael@0 122
michael@0 123 //------------ OutputCRLineBreak
michael@0 124 encoder.init(doc, "application/xhtml+xml",de.OutputCRLineBreak);
michael@0 125 out = encoder.encodeToString();
michael@0 126 expected = expected.replace(/\n/mg, "\r");
michael@0 127 is(out, expected, "test OutputCRLineBreak");
michael@0 128
michael@0 129 //------------ OutputLFLineBreak + OutputCRLineBreak
michael@0 130 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputCRLineBreak);
michael@0 131 out = encoder.encodeToString();
michael@0 132 expected = expected.replace(/\r/mg, "\r\n");
michael@0 133 is(out, expected, "test OutputLFLineBreak + OutputCRLineBreak");
michael@0 134
michael@0 135 //------------ OutputNoFormattingInPre
michael@0 136 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFormattingInPre);
michael@0 137 out = encoder.encodeToString();
michael@0 138 expected = loadFileContent("file_xhtmlserializer_1_noformatpre.xhtml");
michael@0 139 is(out, expected, "test OutputNoFormattingInPre");
michael@0 140
michael@0 141 // ------------- nested body elements
michael@0 142 var body2 = doc.createElement('body');
michael@0 143 var p = doc.createElement('p');
michael@0 144 p.appendChild(doc.createTextNode("this is an other body element"));
michael@0 145 body2.appendChild(p);
michael@0 146 var body = doc.getElementsByTagName('body')[0];
michael@0 147 body.appendChild(body2);
michael@0 148
michael@0 149 is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
michael@0 150
michael@0 151 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
michael@0 152 encoder.setCharset("UTF-8");
michael@0 153 out = encoder.encodeToString();
michael@0 154 expected = loadFileContent("file_xhtmlserializer_1_nested_body.xhtml");
michael@0 155 is(out, expected, "test with two nested body elements");
michael@0 156
michael@0 157 // ------------- two body elements
michael@0 158 body.parentNode.insertBefore(body2, body);
michael@0 159
michael@0 160 is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
michael@0 161 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
michael@0 162 encoder.setCharset("UTF-8");
michael@0 163 out = encoder.encodeToString();
michael@0 164 expected = loadFileContent("file_xhtmlserializer_1_sibling_body.xhtml");
michael@0 165 is(out, expected, "test with two body elements");
michael@0 166
michael@0 167 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
michael@0 168 encoder.setCharset("UTF-8");
michael@0 169 out = encoder.encodeToString();
michael@0 170 expected = loadFileContent("file_xhtmlserializer_1_sibling_body_only_body.xhtml");
michael@0 171 is(out, expected, "test with two body elements, and output body only");
michael@0 172
michael@0 173 // --------------- no body element
michael@0 174 doc.documentElement.removeChild(body);
michael@0 175 doc.documentElement.removeChild(body2);
michael@0 176
michael@0 177 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
michael@0 178 encoder.setCharset("UTF-8");
michael@0 179 out = encoder.encodeToString();
michael@0 180 expected = loadFileContent("file_xhtmlserializer_1_no_body.xhtml");
michael@0 181 is(out, expected, "test with no body element");
michael@0 182
michael@0 183 SimpleTest.finish();
michael@0 184 }
michael@0 185
michael@0 186
michael@0 187 SimpleTest.waitForExplicitFinish();
michael@0 188
michael@0 189 addLoadEvent(testHtmlSerializer_1);
michael@0 190
michael@0 191 </script>
michael@0 192 </pre>
michael@0 193 </body>
michael@0 194 </html>
michael@0 195
michael@0 196

mercurial