function testHtmlSerializer_1 () {
const de = SpecialPowers.Ci.nsIDocumentEncoder; var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
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");
isRoughly(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, "text/html", de.OutputLFLineBreak | de.OutputPreformatted);
out = encoder.encodeToString();
isRoughly(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, "text/html", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_htmlserializer_1_nested_body.html");
isRoughly(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, "text/html", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_htmlserializer_1_sibling_body.html");
isRoughly(out, expected, "test with two body elements");
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");
isRoughly(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, "text/html", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
out = encoder.encodeToString();
expected = loadFileContent("file_htmlserializer_1_no_body.html");
isRoughly(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.