tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7dca70eeb85d766163785ba966176f02e455289f
parent ee9718d44d073610b2e3b61e45636f27ec6e929e
Author: Orko Garai <orko@igalia.com>
Date:   Mon, 27 Oct 2025 10:07:51 +0000

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

Diffstat:
Dtesting/web-platform/tests/selection/Selection-direction-on-clicks.tentative.html | 78------------------------------------------------------------------------------
Atesting/web-platform/tests/selection/selection-direction-on-double-click.tentative.html | 39+++++++++++++++++++++++++++++++++++++++
Atesting/web-platform/tests/selection/selection-direction-on-single-click.html | 36++++++++++++++++++++++++++++++++++++
Atesting/web-platform/tests/selection/selection-direction-on-triple-click.tentative.html | 42++++++++++++++++++++++++++++++++++++++++++
4 files changed, 117 insertions(+), 78 deletions(-)

diff --git a/testing/web-platform/tests/selection/Selection-direction-on-clicks.tentative.html b/testing/web-platform/tests/selection/Selection-direction-on-clicks.tentative.html @@ -1,78 +0,0 @@ -<!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"></div> -<script> - -// Note: This test should remain tentative until Selection API issue 177 is -// resolved and direction for clicks are specified. - -promise_test(async () => { - container.innerHTML = 'hello, world'; - const doubleClick = new test_driver.Actions() - .pointerMove(0, 0, container.firstChild) - .pointerDown() - .pointerUp() - .pointerDown() - .pointerUp() - .send(); - await doubleClick; - - const sel = getSelection(); - assert_equals(sel.anchorNode, container.firstChild); - assert_equals(sel.anchorOffset, 0); - assert_equals(sel.focusNode, container.firstChild); - assert_equals(sel.focusOffset, 5); // hello - assert_equals(sel.direction, 'none'); -}, 'direction returns "none" when there is a double click selection(directionless)'); - -promise_test(async () => { - container.innerHTML = 'hello, world'; - const tripleClick = new test_driver.Actions() - .pointerMove(0, 0, container.firstChild) - .pointerDown() - .pointerUp() - .pointerDown() - .pointerUp() - .pointerDown() - .pointerUp() - .send(); - await tripleClick; - - const sel = getSelection(); - assert_equals(sel.anchorNode, container); - assert_equals(sel.anchorOffset, 0); - assert_equals(sel.focusNode, container); - assert_equals(sel.focusOffset, 1); - assert_equals(sel.direction, 'none'); -}, 'direction returns "none" when there is a triple click selection(directionless)'); - -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> diff --git a/testing/web-platform/tests/selection/selection-direction-on-double-click.tentative.html b/testing/web-platform/tests/selection/selection-direction-on-double-click.tentative.html @@ -0,0 +1,39 @@ +<!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> + +// Note: This test should remain tentative until Selection API issue 177 is +// resolved and direction for clicks are specified. + +promise_test(async () => { + const doubleClick = new test_driver.Actions() + .pointerMove(0, 0, container.firstChild) + .pointerDown() + .pointerUp() + .pointerDown() + .pointerUp() + .send(); + await doubleClick; + + const sel = getSelection(); + assert_equals(sel.anchorNode, container.firstChild); + assert_equals(sel.anchorOffset, 0); + assert_equals(sel.focusNode, container.firstChild); + assert_equals(sel.focusOffset, 5); // hello + assert_equals(sel.direction, 'none'); +}, 'direction returns "none" when there is a double click selection(directionless)'); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/selection/selection-direction-on-single-click.html b/testing/web-platform/tests/selection/selection-direction-on-single-click.html @@ -0,0 +1,36 @@ +<!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> diff --git a/testing/web-platform/tests/selection/selection-direction-on-triple-click.tentative.html b/testing/web-platform/tests/selection/selection-direction-on-triple-click.tentative.html @@ -0,0 +1,42 @@ +<!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> + +// Note: This test should remain tentative until Selection API issue 177 is +// resolved and direction for clicks are specified. + +promise_test(async () => { + container.innerHTML = 'hello, world'; + const tripleClick = new test_driver.Actions() + .pointerMove(0, 0, container.firstChild) + .pointerDown() + .pointerUp() + .pointerDown() + .pointerUp() + .pointerDown() + .pointerUp() + .send(); + await tripleClick; + + const sel = getSelection(); + assert_equals(sel.anchorNode, container); + assert_equals(sel.anchorOffset, 0); + assert_equals(sel.focusNode, container); + assert_equals(sel.focusOffset, 1); + assert_equals(sel.direction, 'none'); +}, 'direction returns "none" when there is a triple click selection(directionless)'); + +</script> +</body> +</html>