content/base/test/test_bug422403-1.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:06b941db84be
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 -->
5 <head>
6 <title>Test for XHTML serializer</title>
7 <script type="text/javascript" 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=422043">Mozilla Bug </a>
12 <p id="display"></p>
13 <div id="content" style="display: none">
14 <iframe id="testframe" src="file_xhtmlserializer_1.xhtml">
15 </iframe>
16 </div>
17 <pre id="test">
18 <script class="testbody" type="text/javascript">
19
20
21 function loadFileContent(aFile, aCharset) {
22 //if(aAsIso == undefined) aAsIso = false;
23 if(aCharset == undefined)
24 aCharset = 'UTF-8';
25
26 var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
27 .createInstance(SpecialPowers.Ci.nsIURI);
28 baseUri.spec = window.location.href;
29
30 var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
31 .getService(SpecialPowers.Ci.nsIIOService);
32 var chann = ios.newChannel(aFile, aCharset, baseUri);
33
34 var cis = SpecialPowers.Ci.nsIConverterInputStream;
35
36 var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
37 .createInstance(cis);
38 inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
39 var str = {}, content = '';
40 while (inputStream.readString(4096, str) != 0) {
41 content += str.value;
42 }
43 return content;
44 }
45
46
47 function testHtmlSerializer_1 () {
48 const de = SpecialPowers.Ci.nsIDocumentEncoder
49 var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
50 .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
51
52 var doc = SpecialPowers.wrap($("testframe")).contentDocument;
53 var out, expected;
54
55 // in the following tests, we must use the OutputLFLineBreak flag, to avoid
56 // to have the default line break of the platform in the result, so the test
57 // can pass on all platform
58
59 //------------ no flags
60 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
61 encoder.setCharset("UTF-8");
62 out = encoder.encodeToString();
63 expected = loadFileContent("file_xhtmlserializer_1_noflag.xhtml");
64 is(out, expected, "test no flags");
65
66 //------------- unsupported flags
67 // since the following flags are not supported, we should
68 // have a result like the one without flag
69 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputPreformatted);
70 out = encoder.encodeToString();
71 is(out, expected, "test OutputPreformatted");
72
73 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatFlowed);
74 out = encoder.encodeToString();
75 is(out, expected, "test OutputFormatFlowed");
76
77 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoScriptContent);
78 out = encoder.encodeToString();
79 is(out, expected, "test OutputNoScriptContent");
80
81 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFramesContent);
82 out = encoder.encodeToString();
83 is(out, expected, "test OutputNoFramesContent");
84
85
86 //------------ OutputWrap
87 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputWrap);
88 out = encoder.encodeToString();
89 expected = loadFileContent("file_xhtmlserializer_1_wrap.xhtml");
90 is(out, expected, "test OutputWrap");
91
92 //------------ OutputFormatted
93 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputFormatted);
94 out = encoder.encodeToString();
95 expected = loadFileContent("file_xhtmlserializer_1_format.xhtml");
96 is(out, expected, "test OutputFormatted");
97
98 //------------ OutputRaw
99 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputRaw);
100 out = encoder.encodeToString();
101 expected = loadFileContent("file_xhtmlserializer_1_raw.xhtml");
102 is(out, expected, "test OutputRaw");
103
104 //------------ OutputBodyOnly
105 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
106 out = encoder.encodeToString();
107 expected = loadFileContent("file_xhtmlserializer_1_bodyonly.xhtml");
108 is(out, expected, "test OutputBodyOnly");
109
110
111 //------------ OutputAbsoluteLinks
112 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
113 out = encoder.encodeToString();
114 expected = loadFileContent("file_xhtmlserializer_1_links.xhtml").trim('\n');
115 is(out, expected, "test OutputAbsoluteLinks");
116
117 //------------ OutputLFLineBreak
118 encoder.init(doc, "application/xhtml+xml",de.OutputLFLineBreak);
119 out = encoder.encodeToString();
120 expected = loadFileContent("file_xhtmlserializer_1_linebreak.xhtml");
121 is(out, expected, "test OutputLFLineBreak");
122
123 //------------ OutputCRLineBreak
124 encoder.init(doc, "application/xhtml+xml",de.OutputCRLineBreak);
125 out = encoder.encodeToString();
126 expected = expected.replace(/\n/mg, "\r");
127 is(out, expected, "test OutputCRLineBreak");
128
129 //------------ OutputLFLineBreak + OutputCRLineBreak
130 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputCRLineBreak);
131 out = encoder.encodeToString();
132 expected = expected.replace(/\r/mg, "\r\n");
133 is(out, expected, "test OutputLFLineBreak + OutputCRLineBreak");
134
135 //------------ OutputNoFormattingInPre
136 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputNoFormattingInPre);
137 out = encoder.encodeToString();
138 expected = loadFileContent("file_xhtmlserializer_1_noformatpre.xhtml");
139 is(out, expected, "test OutputNoFormattingInPre");
140
141 // ------------- nested body elements
142 var body2 = doc.createElement('body');
143 var p = doc.createElement('p');
144 p.appendChild(doc.createTextNode("this is an other body element"));
145 body2.appendChild(p);
146 var body = doc.getElementsByTagName('body')[0];
147 body.appendChild(body2);
148
149 is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
150
151 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
152 encoder.setCharset("UTF-8");
153 out = encoder.encodeToString();
154 expected = loadFileContent("file_xhtmlserializer_1_nested_body.xhtml");
155 is(out, expected, "test with two nested body elements");
156
157 // ------------- two body elements
158 body.parentNode.insertBefore(body2, body);
159
160 is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
161 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
162 encoder.setCharset("UTF-8");
163 out = encoder.encodeToString();
164 expected = loadFileContent("file_xhtmlserializer_1_sibling_body.xhtml");
165 is(out, expected, "test with two body elements");
166
167 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
168 encoder.setCharset("UTF-8");
169 out = encoder.encodeToString();
170 expected = loadFileContent("file_xhtmlserializer_1_sibling_body_only_body.xhtml");
171 is(out, expected, "test with two body elements, and output body only");
172
173 // --------------- no body element
174 doc.documentElement.removeChild(body);
175 doc.documentElement.removeChild(body2);
176
177 encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
178 encoder.setCharset("UTF-8");
179 out = encoder.encodeToString();
180 expected = loadFileContent("file_xhtmlserializer_1_no_body.xhtml");
181 is(out, expected, "test with no body element");
182
183 SimpleTest.finish();
184 }
185
186
187 SimpleTest.waitForExplicitFinish();
188
189 addLoadEvent(testHtmlSerializer_1);
190
191 </script>
192 </pre>
193 </body>
194 </html>
195
196

mercurial