Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Preceding &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("This is a mail cite", "", false)
);
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; This is a mail cite<br><br></span><br><br>`,
"nsIEditorMailSupport.insertAsCitedQuotation() should insert a mailcite span"
);
// Split paragraph between "a " and "mail cite".
win.getSelection().collapse(mailcite.firstChild, "> This is a ".length);
doc.execCommand("insertParagraph");
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; This is a <br></span><br><span style="${mailciteStyle}">mail cite<br><br></span><br><br>`,
"insertParagraph in a mailcite should split the mailcite and insert an empty line"
);
// Then, type a character. The <br> before the latter mailcite should be
// preserved for the serializer to insert a line break before the latter
// mailcite.
doc.execCommand("insertText", false, "X");
is(
doc.body.innerHTML,
`<span style="${mailciteStyle}">&gt; This is a <br></span>X<br><span style="${mailciteStyle}">mail cite<br><br></span><br><br>`,
"Typing text into the empty line should preserve the preceding <br> of the latter mailcite"
);
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>