Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Trailing &lt;br&gt; of a mailcite which is a blocked &lt;span&gt;</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script>
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
const iframe = document.querySelector("iframe");
await new Promise(resolve => {
if (iframe.contentDocument?.readyState == "complete") {
resolve();
return;
}
iframe.addEventListener("load", resolve, {once: true});
});
const win = iframe.contentWindow;
getEditor(win).flags |=
SpecialPowers.Ci.nsIEditor.eEditorMailMask | SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask;
const doc = iframe.contentDocument;
const mailEditor = getEditorMailSupport(win);
win.focus();
doc.body.focus();
const mailciteStyle = "white-space: pre-wrap; display: block; width: 98vw;";
const mailcite = SpecialPowers.unwrap(
mailEditor.insertAsCitedQuotation("Hi there,\nHow are you doing.", "", false)
);
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there,<br>&gt; How are you doing.<br><br></span><br><br>`,
"nsIEditorMailSupport.insertAsCitedQuotation() should insert a mailcite span"
);
// Delete the second line.
win.getSelection().setBaseAndExtent(
mailcite.firstChild,
mailcite.firstChild.length,
mailcite.parentNode,
1
);
doc.execCommand("delete");
// Then, move caret outside the mailcite and type a character.
win.getSelection().modify("move", "forward", "line");
doc.execCommand("insertText", false, "m");
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; Hi there,<br></span>m`,
"insert paragraph should split the mailcite and put <br> to the end of it"
);
SimpleTest.finish();
});
function getEditor(aWindow) {
const editingSession = SpecialPowers.wrap(aWindow).docShell.editingSession;
return editingSession.getEditorForWindow(aWindow);
}
function getEditorMailSupport(aWindow) {
return getEditor(aWindow).QueryInterface(SpecialPowers.Ci.nsIEditorMailSupport);
}
</script>
</head>
<body>
<iframe srcdoc="<body contenteditable><br><br></body>"></iframe>
</body>
</html>