Files
sousa-gecko/testing/web-platform/tests/selection/selection-direction-on-single-click.html
T
Orko Garai 7dca70eeb8 Bug 1996296 [wpt PR 55640] - selection: direction return "none" when selection is collapsed, a=testonly
Automatic update from web-platform-tests
selection: direction return "none" when selection is collapsed

This change addresses two issues:
- A chromium issue that incorrectly returned direction "forward"
even for collapsed selections.
- A WPT test issue due to previous tests affecting subsequent tests.

When selection is collapsed, ensure selection.direction returns "none".
In order to check selection is collapsed
`Selection().GetSelectionInDOMTree().IsCaret()` is used instead of
`isCollapsed()`, similar to the `type()` implementation. This ensures
direction is still returned for selections that cross shadow boundaries
while returning "none" for normal cases.

Selection-direction-on-clicks.tentative.html wpt test with 3 tests for
double, triple and single clicks respectively, the double clicks and
single clicks were inadvertently affecting assertions in subsequent
tests. So fix that by simply splitting them into 3 separate test files
so that they are hermetic.

Bug: 40373561, 40502558
Change-Id: I930b878b650a58a9106132c90644f101e3aa65aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7055926
Reviewed-by: Koji Ishii <kojii@chromium.org>
Commit-Queue: Orko Garai <orko@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1534972}

--

wpt-commits: 6f86903c03dedbe8ca812e4fbdbc9f0fc356bad8
wpt-pr: 55640
2025-10-30 09:25:19 +00:00

37 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<body>
<meta name="author" title="Sean Feng" href="mailto:sean@seanfeng.dev">
<meta name="assert" content="Selection on clicks: direction should return none, forwad, or backward">
<link rel="help" href="https://w3c.github.io/selection-api/#dom-selection-direction">
<link rel="help" href="https://github.com/w3c/selection-api/issues/177">
<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>
<div id="container">hello, world</div>
<script>
promise_test(async () => {
container.innerHTML = 'hello, world';
const click = new test_driver.Actions()
.pointerMove(0, 0, container.firstChild)
.pointerDown()
.pointerUp()
.send();
await click;
const sel = getSelection();
assert_equals(sel.anchorNode, container.firstChild);
assert_equals(sel.anchorOffset, 0);
assert_equals(sel.focusNode, container.firstChild);
assert_equals(sel.focusOffset, 0);
assert_true(sel.isCollapsed);
assert_equals(sel.direction, 'none');
}, 'direction returns "none" when the selection is collapsed');
</script>
</body>
</html>