2008-10-22 00:41:28 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for HTML serializer</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=424359">Mozilla Bug </a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
<iframe id="testframe" src="file_htmlserializer_1.html">
|
|
|
|
</iframe>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
|
|
|
|
function loadFileContent(aFile, aCharset) {
|
|
|
|
//if(aAsIso == undefined) aAsIso = false;
|
|
|
|
if(aCharset == undefined)
|
|
|
|
aCharset = 'UTF-8';
|
|
|
|
|
2013-09-04 20:02:34 +04:00
|
|
|
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
|
|
|
|
.createInstance(SpecialPowers.Ci.nsIURI);
|
2008-10-22 00:41:28 +04:00
|
|
|
baseUri.spec = window.location.href;
|
|
|
|
|
2013-09-04 20:02:34 +04:00
|
|
|
var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
|
|
|
|
.getService(SpecialPowers.Ci.nsIIOService);
|
2015-02-03 07:08:34 +03:00
|
|
|
var chann = ios.newChannel2(aFile,
|
|
|
|
aCharset,
|
|
|
|
baseUri,
|
|
|
|
null, // aLoadingNode
|
|
|
|
SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(),
|
|
|
|
null, // aTriggeringPrincipal
|
|
|
|
SpecialPowers.Ci.nsILoadInfo.SEC_NORMAL,
|
|
|
|
SpecialPowers.Ci.nsIContentPolicy.TYPE_OTHER);
|
2008-10-22 00:41:28 +04:00
|
|
|
|
2013-09-04 20:02:34 +04:00
|
|
|
var cis = SpecialPowers.Ci.nsIConverterInputStream;
|
2008-10-22 00:41:28 +04:00
|
|
|
|
2013-09-04 20:02:34 +04:00
|
|
|
var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
|
2008-10-22 00:41:28 +04:00
|
|
|
.createInstance(cis);
|
|
|
|
inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
|
|
|
|
var str = {}, content = '';
|
|
|
|
while (inputStream.readString(4096, str) != 0) {
|
|
|
|
content += str.value;
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2009-12-21 14:39:00 +03:00
|
|
|
function isRoughly(actual, expected, message) {
|
|
|
|
return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"),
|
|
|
|
expected,
|
|
|
|
message);
|
|
|
|
}
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
function testHtmlSerializer_1 () {
|
2013-09-04 20:02:34 +04:00
|
|
|
const de = SpecialPowers.Ci.nsIDocumentEncoder;
|
|
|
|
var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
|
|
|
|
.createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
var doc = $("testframe").contentDocument;
|
|
|
|
var out, expected;
|
|
|
|
|
|
|
|
// in the following tests, we must use the OutputLFLineBreak flag, to avoid
|
|
|
|
// to have the default line break of the platform in the result, so the test
|
|
|
|
// can pass on all platform
|
|
|
|
|
|
|
|
//------------ no flags
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak);
|
|
|
|
encoder.setCharset("UTF-8");
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_noflag.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test no flags");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------- unsupported flags
|
|
|
|
// since the following flags are not supported, we should
|
|
|
|
// have a result like the one without flag
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputPreformatted);
|
|
|
|
out = encoder.encodeToString();
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputPreformatted");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatFlowed);
|
|
|
|
out = encoder.encodeToString();
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputFormatFlowed");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoScriptContent);
|
|
|
|
out = encoder.encodeToString();
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputNoScriptContent");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFramesContent);
|
|
|
|
out = encoder.encodeToString();
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputNoFramesContent");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
|
2009-04-25 13:00:14 +04:00
|
|
|
//------------ OutputWrap
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak |de.OutputWrap);
|
|
|
|
out = encoder.encodeToString();
|
2010-04-03 16:51:17 +04:00
|
|
|
expected = loadFileContent("file_htmlserializer_1_wrap.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputWrap");
|
2009-04-25 13:00:14 +04:00
|
|
|
|
2008-10-22 00:41:28 +04:00
|
|
|
//------------ OutputFormatted
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputFormatted);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_format.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputFormatted");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputRaw
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputRaw);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_raw.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputRaw");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputBodyOnly
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_bodyonly.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputBodyOnly");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------ OutputAbsoluteLinks
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks);
|
|
|
|
out = encoder.encodeToString();
|
2010-03-13 00:53:36 +03:00
|
|
|
expected = loadFileContent("file_htmlserializer_1_links.html").trim('\n');
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputAbsoluteLinks");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputLFLineBreak
|
|
|
|
encoder.init(doc, "text/html",de.OutputLFLineBreak);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_linebreak.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputLFLineBreak");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputCRLineBreak
|
|
|
|
encoder.init(doc, "text/html",de.OutputCRLineBreak);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = expected.replace(/\n/mg, "\r");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputCRLineBreak");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputLFLineBreak + OutputCRLineBreak
|
|
|
|
encoder.init(doc, "text/html",de.OutputLFLineBreak | de.OutputCRLineBreak);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = expected.replace(/\r/mg, "\r\n");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputLFLineBreak + OutputCRLineBreak");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
//------------ OutputNoFormattingInPre
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputNoFormattingInPre);
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_noformatpre.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test OutputNoFormattingInPre");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
// ------------- nested body elements
|
|
|
|
var body2 = doc.createElement('body');
|
|
|
|
var p = doc.createElement('p');
|
|
|
|
p.appendChild(doc.createTextNode("this is an other body element"));
|
|
|
|
body2.appendChild(p);
|
|
|
|
var body = doc.getElementsByTagName('body')[0];
|
|
|
|
body.appendChild(body2);
|
|
|
|
|
|
|
|
is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
|
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak);
|
|
|
|
encoder.setCharset("UTF-8");
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_nested_body.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test with two nested body elements");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
// ------------- two body elements
|
|
|
|
body.parentNode.insertBefore(body2, body);
|
|
|
|
|
|
|
|
is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak);
|
|
|
|
encoder.setCharset("UTF-8");
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_sibling_body.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test with two body elements");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak | de.OutputBodyOnly);
|
|
|
|
encoder.setCharset("UTF-8");
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_sibling_body_only_body.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test with two body elements, and output body only");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
// --------------- no body element
|
|
|
|
doc.documentElement.removeChild(body);
|
|
|
|
doc.documentElement.removeChild(body2);
|
|
|
|
|
|
|
|
encoder.init(doc, "text/html", de.OutputLFLineBreak);
|
|
|
|
encoder.setCharset("UTF-8");
|
|
|
|
out = encoder.encodeToString();
|
|
|
|
expected = loadFileContent("file_htmlserializer_1_no_body.html");
|
2009-12-21 14:39:00 +03:00
|
|
|
isRoughly(out, expected, "test with no body element");
|
2008-10-22 00:41:28 +04:00
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
addLoadEvent(testHtmlSerializer_1);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
<!--<h1>1</h1><h2>result</h2><textarea id="t1" cols="80" rows="20"></textarea>
|
|
|
|
<h2>expected</h2><textarea id="t1e" cols="80" rows="20"></textarea>-->
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
|