Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
const iframe = document.querySelector("iframe");
const doc = iframe.contentDocument;
const win = iframe.contentWindow;
doc.designMode = "on";
// Ensure focus
await new Promise(resolve => {
doc.addEventListener("focus", resolve, {once: true});
iframe.focus();
});
function getHTMLEditor() {
const editingSession = SpecialPowers.wrap(win).docShell.editingSession;
if (!editingSession) {
return null;
}
const editor = editingSession.getEditorForWindow(win);
if (!editor) {
return null;
}
return editor.QueryInterface(SpecialPowers.Ci.nsIHTMLEditor);
}
const nsIEditor = SpecialPowers.Ci.nsIEditor;
const htmlEditor = getHTMLEditor();
htmlEditor.flags |=
nsIEditor.eEditorPlaintextMask
| nsIEditor.eEditorMailMask
| nsIEditor.eEditorEnableWrapHackMask;
doc.execCommand("defaultParagraphSeparator", false, "br");
win.getSelection().collapse(doc.body, doc.body.childNodes.length);
is(
doc.body.innerHTML,
"<br>",
"Initially, the <body> should have a <br>"
);
htmlEditor.insertLineBreak();
is(
doc.body.innerHTML,
"<br><br>",
"Insert line break in the <body> should insert 2 <br> elements"
);
is(
win.getSelection().focusNode,
doc.body,
"Selection container should be the <body> after the call of insertLineBreak()"
);
is(
win.getSelection().focusOffset,
1,
"Selection should be collapsed after the first <br> after the call of insertLineBreak()"
);
const wrapperDiv = htmlEditor.createElementWithDefaults("div");
wrapperDiv.appendChild(doc.createTextNode("-- "));
wrapperDiv.appendChild(htmlEditor.createElementWithDefaults("br"));
wrapperDiv.appendChild(doc.createTextNode("Plaintext signature"));
wrapperDiv.appendChild(htmlEditor.createElementWithDefaults("br"));
htmlEditor.insertElementAtSelection(wrapperDiv, true);
is(
doc.body.innerHTML.trim(),
"<br><div>-- <br>Plaintext signature<br></div><br>",
"The signature block should follow a <br>"
);
SimpleTest.finish();
});
</script>
</head>
<body><iframe srcdoc='<body style="font-family: -moz-fixed; white-space: pre-wrap; width: 72ch;"></body>'></iframe></body>
</html>