diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/editing/run/caretnavigation.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/editing/run/caretnavigation.html')
-rw-r--r-- | testing/web-platform/tests/editing/run/caretnavigation.html | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/testing/web-platform/tests/editing/run/caretnavigation.html b/testing/web-platform/tests/editing/run/caretnavigation.html new file mode 100644 index 0000000000..c0a8eca4ac --- /dev/null +++ b/testing/web-platform/tests/editing/run/caretnavigation.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Caret navigation</title> + +<link rel="stylesheet" href="../support/reset.css"> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="/resources/testdriver-actions.js"></script> + +<script> +const KEY_CODE_MAP = { + 'ArrowLeft': '\uE012', + 'ArrowUp': '\uE013', + 'ArrowRight': '\uE014', + 'ArrowDown': '\uE015', +}; + +/** + * Send key event to the target element using test driver. Supports human + * friendly key names for common keyboard scroll operations e.g., arrow keys, + * page keys, etc. + * @param {Node} target + * @param {string} key + * @returns {Promise} + */ +function keyPress(target, key) { + const code = KEY_CODE_MAP[key]; + return test_driver.send_keys(target, code); +} +</script> + +<div id="container"> + <div contenteditable data-title="Move with ArrowLeft to BR following a div"> + <div>line 1</div> + <br> + <div class="caret">line 2</div> + </div> + <div contenteditable data-title="Move with ArrowLeft to BR following an img"> + <img style="display:block;width:100px;height:100px"> + <br> + <div class="caret">line 2</div> + </div> +</div> + +<script> +const container = document.getElementById("container"); + +for (const test of container.children) { + promise_test(async t => { + test.focus(); + getSelection().collapse(test.querySelector(".caret")); + await keyPress(test, "ArrowLeft"); + + const range = getSelection().getRangeAt(0); + + assert_equals(range.commonAncestorContainer.localName, "div"); + assert_equals(range.startOffset, 3); + assert_equals(range.commonAncestorContainer.childNodes[range.startOffset].localName, "br"); + }, test.dataset.title); +} +</script> |