Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: editor/libeditor/tests/mochitest.toml
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<meta charset="utf-8">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style> .pre { white-space: pre } </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=772796">Mozilla Bug 1330796</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<div id="editable" contenteditable></div>
<pre id="test">
<script type="application/javascript">
// We want to test what happens when the user splits a mail cite by clicking
// at the start, the middle and the end of the cite and hitting the enter key.
// The _moz_quote attribute is used to give the cite a blue color via CSS.
// As an internal attribute, it's not returned from the innerHTML.
// To the user the tests look like:
// > mailcite
// This text is 10 characters long, so we position at 0, 5 and 10.
// the tests are repeated also for inline display.
// Each entry of the 'tests' array has the original HTML, the offset to click
// at and the expected result HTML.
var tests = [
// With style="display: block;".
[ "<span _moz_quote=true style=\"display: block;\">> mailcite<br></span>", 0,
"x<br><span style=\"display: block;\">> mailcite<br></span>" ],
[ "<span _moz_quote=true style=\"display: block;\">> mailcite<br></span>", 5,
"<span style=\"display: block;\">> mai<br></span>x<br><span style=\"display: block;\">lcite<br></span>"],
[ "<span _moz_quote=true style=\"display: block;\">> mailcite<br></span>", 10,
"<span style=\"display: block;\">> mailcite<br></span>x<br>" ],
// No <br> at the end to simulate prior deletion to the end of the quote.
[ "<span _moz_quote=true style=\"display: block;\">> mailcite</span>", 10,
"<span style=\"display: block;\">> mailcite<br></span>x<br>" ],
// Without style="display: block;".
[ "<span _moz_quote=true>> mailcite<br></span>", 0,
"x<br><span>> mailcite<br></span>" ],
[ "<span _moz_quote=true>> mailcite<br></span>", 5,
"<span>> mai</span><br>x<br><span>lcite<br></span>" ],
[ "<span _moz_quote=true>> mailcite<br></span>", 10,
"<span>> mailcite<br></span>x<br>" ],
// No <br> at the end to simulate prior deletion to the end of the quote.
[ "<span _moz_quote=true>> mailcite</span>", 10,
"<span>> mailcite</span><br>x<br>" ],
];
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var sel = window.getSelection();
var theEdit = document.getElementById("editable");
makeMailEditor();
for (let i = 0; i < tests.length; i++) {
theEdit.innerHTML = tests[i][0];
theEdit.focus();
var theText = theEdit.firstChild.firstChild;
// Position set at the beginning , middle and end of the text.
sel.collapse(theText, tests[i][1]);
synthesizeKey("KEY_Enter");
sendString("x");
is(theEdit.innerHTML, tests[i][2], "unexpected HTML for test " + i.toString());
}
SimpleTest.finish();
});
function makeMailEditor() {
var Ci = SpecialPowers.Ci;
var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
var editor = editingSession.getEditorForWindow(window);
editor.flags |= Ci.nsIEditor.eEditorMailMask;
}
</script>
</pre>
</body>
</html>