summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug1310912.html
diff options
context:
space:
mode:
Diffstat (limited to 'editor/libeditor/tests/test_bug1310912.html')
-rw-r--r--editor/libeditor/tests/test_bug1310912.html121
1 files changed, 121 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_bug1310912.html b/editor/libeditor/tests/test_bug1310912.html
new file mode 100644
index 0000000000..1581a1bec9
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1310912.html
@@ -0,0 +1,121 @@
+<!DOCTYPE html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1310912
+-->
+<html>
+<head>
+ <title>Test for Bug 1310912</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=1310912">Mozilla Bug 1310912</a>
+<p id="display"></p>
+<div id="content" style="display: none;">
+
+</div>
+
+<div contenteditable>ABC</div>
+<pre id="test">
+
+<script class="testbody" type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+ let editor = document.querySelector("div[contenteditable]");
+
+ editor.focus();
+ let sel = window.getSelection();
+ sel.collapse(editor.childNodes[0], editor.textContent.length);
+
+ synthesizeCompositionChange({
+ composition: {
+ string: "DEF",
+ clauses: [
+ { length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE },
+ ],
+ },
+ caret: { start: 3, length: 0 },
+ });
+ is(editor.textContent, "ABCDEF", "composing text should be set");
+
+ window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
+ synthesizeCompositionChange({
+ composition: {
+ string: "GHI",
+ clauses: [
+ { length: 3, attr: COMPOSITION_ATTR_CONVERTED_CLAUSE },
+ ],
+ },
+ caret: { start: 0, length: 0 },
+ });
+ is(editor.textContent, "ABCGHI", "composing text should be replaced");
+
+ window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
+ synthesizeCompositionChange({
+ composition: {
+ string: "JKL",
+ clauses: [
+ { length: 3, attr: COMPOSITION_ATTR_CONVERTED_CLAUSE },
+ ],
+ },
+ caret: { start: 0, length: 0 },
+ });
+ is(editor.textContent, "ABCJKL", "composing text should be replaced");
+
+ window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
+ synthesizeCompositionChange({
+ composition: {
+ string: "MNO",
+ clauses: [
+ { length: 3, attr: COMPOSITION_ATTR_CONVERTED_CLAUSE },
+ ],
+ },
+ caret: { start: 1, length: 0 },
+ });
+ is(editor.textContent, "ABCMNO", "composing text should be replaced");
+
+ // Normal selection is the caret, therefore, inserting empty text node
+ // creates the following DOM tree:
+ // <div contenteditable>
+ // |- #text ("ABCM")
+ // |- #text ("")
+ // +- #text ("NO")
+ window.getSelection().getRangeAt(0).insertNode(document.createTextNode(""));
+ is(editor.childNodes[0].data, "ABCM",
+ "First text node should only have \"M\" of the composition string");
+ is(editor.childNodes[1].data, "",
+ "Second text node should be the inserted empty text node");
+ is(editor.childNodes[2].data, "NO",
+ "Third text node should have the remaining composition string");
+ todo_is(editor.childNodes[3].nodeName, "BR",
+ "Forth node is empty text node, but I don't where this comes from");
+
+ // Then, committing composition makes the commit string into the first
+ // text node and makes the following text nodes empty.
+ // XXX I don't know whether the empty text nodes should be removed or not
+ // at this moment.
+ synthesizeComposition({ type: "compositioncommitasis" });
+ is(editor.textContent, "ABCMNO",
+ "composing text should be committed");
+ is(editor.childNodes[0].data, "ABCMNO",
+ "First text node should have the committed string");
+
+ synthesizeKey("Z", { accelKey: true });
+ is(editor.textContent, "ABC",
+ "text should be undone (commit string should've gone");
+ is(editor.childNodes[0].data, "ABC",
+ "First text node should have the committed string after undone");
+
+ synthesizeKey("Z", { accelKey: true, shiftKey: true });
+ is(editor.textContent, "ABCMNO",
+ "text should be redone (commit string should've be back");
+ is(editor.childNodes[0].data, "ABCMNO",
+ "First text node should have the committed string after redone");
+
+ SimpleTest.finish();
+});
+</script>
+</pre>
+</body>
+</html>