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