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 test, 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
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = 'This is a draggable bit of text.';
is(out, expected, "test selection");
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(null);
encoder.setContainerNode(node);
out = encoder.encodeToString();
expected = 'This is a draggable bit of text.';
is(out, expected, "test container node");
Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class
\n
aptent taciti
\n";
is(out, expected, "test list node");
var liList = node.getElementsByTagName("li"); var range = document.createRange();
// selection start at the first child of the ol, and end after the element ol
range.setStart(node, 1);
range.setEnd(node.parentNode, 2); select.removeAllRanges(); select.addRange(range);
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
Lorem ipsum dolor
\n
sit amet, consectetuer
\n
adipiscing elit
\n
Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class
\n
aptent taciti
\n';
is(out, expected, "test list selection with range: selection start at the first child of the ol, and end after the element ol");
// selection start at the third child of the ol, and end after the element ol
range.setStart(node, 3);
range.setEnd(node.parentNode, 2);
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
sit amet, consectetuer
\n
adipiscing elit
\n
Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class
\n
aptent taciti
\n';
is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol");
// selection start at the third child of the ol, and end after the element ol + ol start at the value 5
range.setStart(node, 3);
range.setEnd(node.parentNode, 2);
node.setAttribute("start","5");
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
sit amet, consectetuer
\n
adipiscing elit
\n
Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class
\n
aptent taciti
\n';
is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol + ol start at the value 5");
// selection contains only some child of the ol
node.removeAttribute("start");
range.setStart(node, 3);
range.setEnd(node, 5);
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
sit amet, consectetuer
\n ';
is(out, expected, "test list selection with range: selection contains only some child of the ol");
// selection contains only some child of the ol + ol start at the value 5
node.setAttribute("start","5");
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
sit amet, consectetuer
\n ';
is(out, expected, "test list selection with range: selection contains only some child of the ol + ol start at the value 5");
// selection contains only some child of the ol + a value is set on the first li
node.removeAttribute("start");
liList[0].setAttribute("value","8");
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly);
encoder.setSelection(select);
out = encoder.encodeToString();
expected = '
sit amet, consectetuer
\n ';
is(out, expected, "test list selection with range: selection contains only some child of the ol + ol start at the value 5");
// test on short attributes
node = document.getElementById('shortattr1');
encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly | de.OutputRaw);
encoder.setNode(node);
out = encoder.encodeToString();
expected = '';
is(out, expected, "test short attr #1");