gecko-dev/editor/libeditor/tests/test_bug449243.html
Brian Grinstead ede8c44ef2 Bug 1544322 - Part 2.1 - Remove the [type] attribute for one-liner <script> tags loading files in /tests/SimpleTest/ in everything except for dom/ r=bzbarsky
This excludes dom/, otherwise the file size is too large for phabricator to handle.

This is an autogenerated commit to handle scripts loading mochitest harness files, in
the simple case where the script src is on the same line as the tag.

This was generated with https://bug1544322.bmoattachments.org/attachment.cgi?id=9058170
using the `--part 2` argument.

Differential Revision: https://phabricator.services.mozilla.com/D27456

--HG--
extra : moz-landing-system : lando
2019-04-16 03:50:44 +00:00

147 lines
4.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=449243
-->
<head>
<title>Test for Bug 449243</title>
<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"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=449243">Mozilla Bug 449243</a>
<p id="display"></p>
<div id="content" contenteditable>
<h2>This is a title</h2>
<ul>
<li>this is a</li>
<li>bullet list</li>
</ul>
<ol>
<li>this is a</li>
<li>numbered list</li>
</ol>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 449243 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests);
const CARET_BEGIN = 0;
const CARET_MIDDLE = 1;
const CARET_END = 2;
function split(element, caretPos, nbKeyPresses) {
// put the caret on the requested position
var sel = window.getSelection();
var len = element.textContent.length;
var pos = -1;
switch (caretPos) {
case CARET_BEGIN:
pos = 0;
break;
case CARET_MIDDLE:
pos = Math.floor(len / 2);
break;
case CARET_END:
pos = len;
break;
}
sel.collapse(element.firstChild, pos);
// simulates a [Return] keypress
for (var i = 0; i < nbKeyPresses; i++)
synthesizeKey("KEY_Enter");
}
function undo(nbKeyPresses) {
for (var i = 0; i < nbKeyPresses; i++)
document.execCommand("Undo", false, null);
}
function SameTypeAsPreviousSibling(element) {
var sibling = element.previousSibling;
while (sibling && sibling.nodeType != Node.ELEMENT_NODE) {
sibling = element.previousSibling;
}
return (element.nodeName == sibling.nodeName);
}
function isType(element, type) {
return element.nodeName.toLowerCase() == type;
}
function runTests() {
const content = document.querySelector("[contenteditable]");
const header = content.querySelector("h2");
const ulItem = content.querySelector("ul > li:last-child");
const olItem = content.querySelector("ol > li:last-child");
content.focus();
// beginning of selection: split current node
split(header, CARET_BEGIN, 1);
ok(SameTypeAsPreviousSibling(header),
"Pressing [Return] at the beginning of a header " +
"should create another header.");
split(ulItem, CARET_BEGIN, 2);
ok(SameTypeAsPreviousSibling(ulItem),
"Pressing [Return] at the beginning of an unordered list item " +
"should create another list item.");
split(olItem, CARET_BEGIN, 2);
ok(SameTypeAsPreviousSibling(olItem),
"Pressing [Return] at the beginning of an ordered list item " +
"should create another list item.");
undo(3);
// middle of selection: split current node
split(header, CARET_MIDDLE, 1);
ok(SameTypeAsPreviousSibling(header),
"Pressing [Return] at the middle of a header " +
"should create another header.");
split(ulItem, CARET_MIDDLE, 2);
ok(SameTypeAsPreviousSibling(ulItem),
"Pressing [Return] at the middle of an unordered list item " +
"should create another list item.");
split(olItem, CARET_MIDDLE, 2);
ok(SameTypeAsPreviousSibling(olItem),
"Pressing [Return] at the middle of an ordered list item " +
"should create another list item.");
undo(3);
// end of selection: create a new div/paragraph
function testEndOfSelection(expected) {
split(header, CARET_END, 1);
ok(isType(content.querySelector("h2+*"), expected),
"Pressing [Return] at the end of a header " +
"should create a new " + expected);
split(ulItem, CARET_END, 2);
ok(isType(content.querySelector("ul+*"), expected),
"Pressing [Return] twice at the end of an unordered list item " +
"should create a new " + expected);
split(olItem, CARET_END, 2);
ok(isType(content.querySelector("ol+*"), expected),
"Pressing [Return] twice at the end of an ordered list item " +
"should create a new " + expected);
undo(3);
}
document.execCommand("defaultParagraphSeparator", false, "div");
testEndOfSelection("div");
document.execCommand("defaultParagraphSeparator", false, "p");
testEndOfSelection("p");
document.execCommand("defaultParagraphSeparator", false, "br");
testEndOfSelection("p");
// done
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>