summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_sendSelectionSetEvent_with_same_range.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/test/test_sendSelectionSetEvent_with_same_range.html')
-rw-r--r--dom/base/test/test_sendSelectionSetEvent_with_same_range.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/dom/base/test/test_sendSelectionSetEvent_with_same_range.html b/dom/base/test/test_sendSelectionSetEvent_with_same_range.html
new file mode 100644
index 0000000000..0f3235b3c1
--- /dev/null
+++ b/dom/base/test/test_sendSelectionSetEvent_with_same_range.html
@@ -0,0 +1,102 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Testing nsIDOMWindowUtils.sendSelectionSetEvent not update selection if result range is same in serialized text within the ContentEventHandler rules</title>
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+<script>
+"use strict";
+const { AppConstants } = ChromeUtils.importESModule(
+ "resource://gre/modules/AppConstants.sys.mjs"
+);
+const kLineBreak = navigator.platform.indexOf("Win") == 0 && false ? "\r\n" : "\n";
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async () => {
+ const editingHost = document.querySelector("div[contenteditable]");
+
+ function waitForFlushingIMEContentObserver() {
+ return new Promise(resolve => requestAnimationFrame(
+ () => requestAnimationFrame(resolve)
+ ));
+ }
+
+ await (async function test_setSelection_when_selection_collapsed_at_end_of_inline_element() {
+ editingHost.innerHTML = "<b>abc</b>def";
+ getSelection().collapse(editingHost.querySelector("b").firstChild, "abc".length);
+ await waitForFlushingIMEContentObserver();
+ const ret = windowUtils.sendSelectionSetEvent(
+ 3,
+ 0,
+ SpecialPowers.Ci.nsIDOMWindowUtils.SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK
+ );
+ ok(
+ ret,
+ "test_setSelection_when_selection_collapsed_at_end_of_inline_element: eSetSelection event should be succeeded"
+ );
+ is(
+ getSelection().focusNode,
+ editingHost.querySelector("b").firstChild,
+ "test_setSelection_when_selection_collapsed_at_end_of_inline_element: focus node should not be changed from the text node in the <b>"
+ );
+ is(
+ getSelection().focusOffset,
+ "abc".length,
+ "test_setSelection_when_selection_collapsed_at_end_of_inline_element: focus offset should not be changed from end of the text node"
+ );
+ })();
+
+ await (async function test_setSelection_when_selection_collapsed_after_inline_element() {
+ editingHost.innerHTML = "<b>abc</b>def";
+ getSelection().collapse(editingHost.querySelector("b").nextSibling, 0);
+ await waitForFlushingIMEContentObserver();
+ const ret = windowUtils.sendSelectionSetEvent(
+ 3,
+ 0,
+ SpecialPowers.Ci.nsIDOMWindowUtils.SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK
+ );
+ ok(
+ ret,
+ "test_setSelection_when_selection_collapsed_after_inline_element: eSetSelection event should be succeeded"
+ );
+ is(
+ getSelection().focusNode,
+ editingHost.querySelector("b").nextSibling,
+ "test_setSelection_when_selection_collapsed_after_inline_element: focus node should not be changed from the text node after the <b>"
+ );
+ is(
+ getSelection().focusOffset,
+ 0,
+ "test_setSelection_when_selection_collapsed_after_inline_element: focus offset should not be changed from start of the text node"
+ );
+ })();
+
+ await (async function test_setSelection_when_selection_collapsed_in_empty_block_element() {
+ editingHost.innerHTML = "<p style=\"width:1em;height:1em;\"></p>\n";
+ getSelection().collapse(editingHost.querySelector("p"), 0);
+ await waitForFlushingIMEContentObserver();
+ const ret = windowUtils.sendSelectionSetEvent(
+ kLineBreak.length,
+ 0,
+ SpecialPowers.Ci.nsIDOMWindowUtils.SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK
+ );
+ ok(
+ ret,
+ "test_setSelection_when_selection_collapsed_in_empty_block_element: eSetSelection event should be succeeded"
+ );
+ is(
+ getSelection().focusNode,
+ editingHost.querySelector("p"),
+ "test_setSelection_when_selection_collapsed_in_empty_block_element: focus node should not be changed from the empty <div>"
+ );
+ })();
+
+ SimpleTest.finish();
+});
+</script>
+</head>
+<body>
+<div contenteditable></div>
+</body>
+</html>