summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/selection/contenteditable/modify.tentative.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/selection/contenteditable/modify.tentative.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/selection/contenteditable/modify.tentative.html')
-rw-r--r--testing/web-platform/tests/selection/contenteditable/modify.tentative.html60
1 files changed, 60 insertions, 0 deletions
diff --git a/testing/web-platform/tests/selection/contenteditable/modify.tentative.html b/testing/web-platform/tests/selection/contenteditable/modify.tentative.html
new file mode 100644
index 0000000000..a3afd52ea2
--- /dev/null
+++ b/testing/web-platform/tests/selection/contenteditable/modify.tentative.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Selection.modify() inside contenteditable</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div contenteditable id="host">Editable</div>
+<div>Non-editable</div>
+<div id="inlinehosts">
+ Prefix: <span contenteditable title="inline">Editable</span>: Suffix<br>
+ Prefix: <span contenteditable style="display:inline-block;" title="inline-block">Editable</span>: Suffix<br>
+ <span contenteditable title="suffix only">Editable</span>: Suffix<br>
+ Prefix: <span contenteditable title="prefix only">Editable</span><br>
+ <span contenteditable title="standalone">Editable</span><br>
+ Prefix: <span contenteditable title="inline linebreak">Edit<br>able</span>: Suffix<br>
+ Prefix: <span contenteditable style="display:inline-block;" title="inline-block linebreak">Edit<br>able</span>:
+ Suffix<br>
+</div>
+<script>
+ /** @param {Node} parent */
+ function* textNodeEntries(parent) {
+ for (const [i, node] of parent.childNodes.entries()) {
+ if (node.nodeType === Node.TEXT_NODE) {
+ yield [i, node];
+ }
+ }
+ }
+
+ const selection = getSelection();
+ test(() => {
+ selection.collapse(host);
+ selection.modify('extend', 'forward', 'word');
+ selection.modify('extend', 'forward', 'word');
+ assert_equals(selection.focusNode.parentElement, host);
+ }, "Selection.modify() must not select outside of the host");
+
+ /** @type {NodeListOf<HTMLElement>} */
+ const hosts = inlinehosts.querySelectorAll("span[contenteditable]");
+ for (const host of hosts) {
+ test(() => {
+ for (const [i, text] of textNodeEntries(host)) {
+ selection.collapse(text, 1);
+ selection.modify("move", "forward", "lineboundary");
+ if (selection.focusNode === host) {
+ assert_equals(selection.focusOffset, i + 1, "focusOffset should be after the text node");
+ } else {
+ assert_equals(selection.focusNode, text, "focusNode should be the text node");
+ assert_equals(selection.focusOffset, text.textContent.length, "focusOffset should be the length of the text node");
+ }
+ }
+ }, `Selection.modify('move', 'forward', 'lineboundary') must be within the inline editing host: ${host.title}`);
+ test(() => {
+ for (const [i, text] of textNodeEntries(host)) {
+ selection.collapse(text, 1);
+ selection.modify("move", "backward", "lineboundary");
+ assert_equals(selection.focusNode, text, "focusNode should be the text node");
+ assert_equals(selection.focusOffset, 0, "focusOffset should be 0");
+ }
+ }, `Selection.modify('move', 'backward', 'lineboundary') must be within the inline editing host: ${host.title}`);
+ }
+</script>