diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/editing/run/caretnavigation.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.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/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> |