summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_password_per_word_operation.html
diff options
context:
space:
mode:
Diffstat (limited to 'editor/libeditor/tests/test_password_per_word_operation.html')
-rw-r--r--editor/libeditor/tests/test_password_per_word_operation.html148
1 files changed, 148 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_password_per_word_operation.html b/editor/libeditor/tests/test_password_per_word_operation.html
new file mode 100644
index 0000000000..847f2e9854
--- /dev/null
+++ b/editor/libeditor/tests/test_password_per_word_operation.html
@@ -0,0 +1,148 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for operations in a password field</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<input type="password" value="abcdef ghijk" size="50">
+<script>
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [["layout.word_select.eat_space_to_next_word", false]],
+ });
+ // Double click on the anonymous text node
+ let input = document.getElementsByTagName("input")[0];
+ let editor = SpecialPowers.wrap(input).editor;
+ let anonymousDiv = editor.rootElement;
+ input.select();
+ const kTextNodeRectInAnonymousDiv = {
+ left: editor.selection.getRangeAt(0).getBoundingClientRect().left - anonymousDiv.getBoundingClientRect().left,
+ top: editor.selection.getRangeAt(0).getBoundingClientRect().top - anonymousDiv.getBoundingClientRect().top,
+ width: editor.selection.getRangeAt(0).getBoundingClientRect().width,
+ height: editor.selection.getRangeAt(0).getBoundingClientRect().height,
+ };
+ kTextNodeRectInAnonymousDiv.right = kTextNodeRectInAnonymousDiv.left + kTextNodeRectInAnonymousDiv.width;
+ kTextNodeRectInAnonymousDiv.bottom = kTextNodeRectInAnonymousDiv.top + kTextNodeRectInAnonymousDiv.height;
+ input.setSelectionRange(0, 0);
+ const kHalfHeightOfAnonymousDiv = anonymousDiv.getBoundingClientRect().height / 2;
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 5, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 5, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
+ is(input.selectionStart, 0,
+ "Double clicking on the anonymous text node in a password field should select all");
+ is(input.selectionEnd, input.value.length,
+ "Double clicking on the anonymous text node in a password field should select all");
+
+ // Double click on the anonymous div element
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
+ is(input.selectionStart, 0,
+ "Double clicking on the anonymous div element in a password field should select all");
+ is(input.selectionEnd, input.value.length,
+ "Double clicking on the anonymous div element in a password field should select all");
+
+ // Move caret per word
+ let selectionController = editor.selectionController;
+ input.focus();
+ input.setSelectionRange(12, 12);
+ selectionController.wordMove(false, false);
+ is(input.selectionStart, 0,
+ "Moving caret one word from the end should move caret to the start");
+ input.setSelectionRange(0, 0);
+ selectionController.wordMove(true, false);
+ is(input.selectionStart, 12,
+ "Moving caret one word from the start should move caret to the end");
+
+ // Expand selection per word
+ input.setSelectionRange(12, 12);
+ selectionController.wordMove(false, true);
+ is(input.selectionStart, 0,
+ "Selecting one word from the end should move selection start to the start");
+ input.setSelectionRange(0, 0);
+ selectionController.wordMove(true, true);
+ is(input.selectionEnd, 12,
+ "Selecting one word from the start should move selection end to the end");
+
+ // Delete one word
+ input.setSelectionRange(12, 12);
+ editor.deleteSelection(editor.ePreviousWord, editor.eStrip);
+ is(input.value, "",
+ "Deleting one word from the end should delete all characters");
+ input.value = "abcdef ghijk";
+ document.documentElement.scrollTop; // Flush frames for setting the value.
+ input.setSelectionRange(0, 0);
+ editor.deleteSelection(editor.eNextWord, editor.eStrip);
+ is(input.value, "",
+ "Deleting one word from the start should delete all characters");
+ input.value = "abcdef ghijk";
+ document.documentElement.scrollTop; // Flush frames for setting the value.
+
+ // Test same things when the space is unmasked.
+
+ // Double click on the anonymous text node
+ editor.unmask(6, 7);
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
+ is(input.selectionStart, 0,
+ "Double clicking on the first word should select it");
+ is(input.selectionEnd, 6,
+ "Double clicking on the first word should select it");
+
+ // Double click on the anonymous div element
+ editor.unmask(6, 7);
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
+ synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
+ is(input.selectionStart, 7,
+ "Double clicking on the anonymous div element in a password field should select the last word");
+ is(input.selectionEnd, input.value.length,
+ "Double clicking on the anonymous div element in a password field should select the last word");
+
+ // Move caret per word
+ input.focus();
+ input.setSelectionRange(12, 12);
+ editor.unmask(6, 7);
+ selectionController.wordMove(false, false);
+ is(input.selectionStart, 6,
+ "Moving caret one word from the end should move caret to end of the first word");
+ input.setSelectionRange(0, 0);
+ editor.unmask(6, 7);
+ selectionController.wordMove(true, false);
+ is(input.selectionStart, 7,
+ "Moving caret one word from the start should move caret to start of the last word");
+
+ // Expand selection per word
+ input.setSelectionRange(12, 12);
+ editor.unmask(6, 7);
+ selectionController.wordMove(false, true);
+ is(input.selectionStart, 6,
+ "Selecting one word from the end should move selection start to end of the first word");
+ input.setSelectionRange(0, 0);
+ editor.unmask(6, 7);
+ selectionController.wordMove(true, true);
+ is(input.selectionEnd, 7,
+ "Selecting one word from the start should move selection end to start of the last word");
+
+ // Delete one word
+ input.setSelectionRange(12, 12);
+ editor.unmask(6, 7);
+ editor.deleteSelection(editor.ePreviousWord, editor.eStrip);
+ is(input.value, "abcdef",
+ "Deleting one word from the end should delete the last word");
+ input.value = "abcdef ghijk";
+ document.documentElement.scrollTop; // Flush frames for setting the value.
+ input.setSelectionRange(0, 0);
+ editor.unmask(6, 7);
+ editor.deleteSelection(editor.eNextWord, editor.eStrip);
+ is(input.value, "ghijk",
+ "Deleting one word from the start should delete the first word");
+ input.value = "abcdef ghijk";
+ document.documentElement.scrollTop; // Flush frames for setting the value.
+
+ SimpleTest.finish();
+});
+</script>
+</body>
+</html>