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/shadow-dom/focus/text-selection-with-delegatesFocus.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/shadow-dom/focus/text-selection-with-delegatesFocus.html')
-rw-r--r-- | testing/web-platform/tests/shadow-dom/focus/text-selection-with-delegatesFocus.html | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shadow-dom/focus/text-selection-with-delegatesFocus.html b/testing/web-platform/tests/shadow-dom/focus/text-selection-with-delegatesFocus.html new file mode 100644 index 0000000000..7c92d35394 --- /dev/null +++ b/testing/web-platform/tests/shadow-dom/focus/text-selection-with-delegatesFocus.html @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-actions.js"></script> +<script src="/resources/testdriver-vendor.js"></script> + +<body> + <x-shadow id="withoutFocus"></x-shadow> + <x-shadow id="withFocus"></x-shadow> +</body> + +<script> +'use strict'; + +/** + * build shadow-root with delegates focus, a focusable element, and an (ideally) selectable text + */ +function buildShadowRootWithSelectableText( element, shouldDelegateFocus ) { + element.attachShadow({ mode: 'open', delegatesFocus: shouldDelegateFocus }); + const span = document.createElement('span'); + span.textContent = 'Example Text to Select '; + const button = document.createElement('button'); + button.textContent = 'Button'; + element.shadowRoot.append(span, button); +} + +/** + * command to select text in shadow-root + */ +function selectText(element, start, end) { + getSelection().empty(); + const actions = new test_driver.Actions(); + actions.pointerMove(start, 0, {origin: element}); + actions.pointerDown(); + actions.pointerMove(end, 0, {origin: element}); + actions.pointerUp(); + return actions.send(); +} + +promise_test(async () => { + const xShadow = document.getElementById('withoutFocus'); + buildShadowRootWithSelectableText(xShadow, false); + + // starting selection from the center of the element, and going right. + // The important part here is that we start the selection in the center + // (where mouse-down events may be delegated) + await selectText(xShadow, 0, 50) + const s = getSelection(); + + // because browsers may handle rendering differently, we can get different amounts of + // text selected, even when using the same start-end values. We opt in this case to + // verify just if any text is selected, since all we care about is if some text is + // selected. + assert_greater_than(s.toString().length, 0); +}, 'shadow root has selectable text when focus is not delegated'); + +promise_test(async () => { + const xShadow = document.getElementById('withFocus'); + buildShadowRootWithSelectableText(xShadow, true); + + await selectText(xShadow, 0, 50) + const s = getSelection(); + + assert_greater_than(s.toString().length, 0); +}, 'shadow root has selectable text when focus is delegated'); + +</script> |