var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();
var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService); var chann = ios.newChannel(aFile,
aCharset,
baseUri,
null, // aLoadingNode
SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
SpecialPowers.Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
SpecialPowers.Ci.nsIContentPolicy.TYPE_OTHER);
var cis = SpecialPowers.Ci.nsIConverterInputStream;
var inputStream = SpecialPowers.Cc["@mozilla.org/intl/converter-input-stream;1"]
.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;
}
function testHtmlSerializer_1 () {
const de = SpecialPowers.Ci.nsIDocumentEncoder var encoder = SpecialPowers.Cu.createDocumentEncoder("application/xhtml+xml");
var doc = SpecialPowers.wrap($("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, "application/xhtml+xml", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_xhtmlserializer_1_noflag.xhtml");
is(out, expected, "test no flags");
//------------- unsupported flags
// since the following flags are not supported, we should
// have a result like the one without flag
encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputPreformatted);
out = encoder.encodeToString();
is(out, expected, "test OutputPreformatted");
// ------------- 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); varbody = doc.getElementsByTagName('body')[0]; body.appendChild(body2);
is(doc.getElementsByTagName('body').length, 2); // to be sure we have two body elements
encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_xhtmlserializer_1_nested_body.xhtml");
is(out, expected, "test with two nested body elements");
// ------------- 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, "application/xhtml+xml", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_xhtmlserializer_1_sibling_body.xhtml");
is(out, expected, "test with two body elements");
encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak | de.OutputBodyOnly);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_xhtmlserializer_1_sibling_body_only_body.xhtml");
is(out, expected, "test with two body elements, and output body only");
// --------------- no body element
doc.documentElement.removeChild(body);
doc.documentElement.removeChild(body2);
encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_xhtmlserializer_1_no_body.xhtml");
is(out, expected, "test with no body element");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.