From 33ae9ec3b678eefb2192faf08a6e68247f459b07 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Wed, 17 May 2023 13:02:03 +0000 Subject: [PATCH] Bug 1830579 [wpt PR 39753] - Update the-input-element/selection-pointer.html to support multi-range, a=testonly Automatic update from web-platform-tests Update the-input-element/selection-pointer.html to support multi-range See [1] for context. This CL makes this test pass in the case that multiple range support is present *and* selecting across an `` creates multiple ranges. Note that in my local testing, only a single range is created on all rendering engines (Blink, WebKit, and Gecko) when the user selects across an ``. Thus, I was not able to test the newly added code here. I did attempt to verify that it would work correctly, however, and I believe it will. [1] https://github.com/web-platform-tests/interop/issues/313 Change-Id: I88c88fcca47da627a0be9de518b76bbbcc07964b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4492089 Reviewed-by: Di Zhang Auto-Submit: Mason Freed Commit-Queue: Mason Freed Cr-Commit-Position: refs/heads/main@{#1137412} -- wpt-commits: 655997d590b0d2c50a08e565e0cbab272b4b00e4 wpt-pr: 39753 --- .../the-input-element/selection-pointer.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/testing/web-platform/tests/html/semantics/forms/the-input-element/selection-pointer.html b/testing/web-platform/tests/html/semantics/forms/the-input-element/selection-pointer.html index 8cb0ead44148d..7f06ae24a2d5d 100644 --- a/testing/web-platform/tests/html/semantics/forms/the-input-element/selection-pointer.html +++ b/testing/web-platform/tests/html/semantics/forms/the-input-element/selection-pointer.html @@ -37,8 +37,20 @@ .pointerMove(0, 0, {origin: bar}) .pointerUp() .send(); - assert_equals(selection.anchorNode, foo.childNodes[0], "anchorNode"); - assert_equals(selection.focusNode, bar.childNodes[0], "focusNode"); + const nRanges = selection.rangeCount; + assert_true(nRanges > 0); + const expectedStart = foo.childNodes[0]; + const expectedEnd = bar.childNodes[0]; + if (nRanges === 1) { + assert_equals(selection.anchorNode, expectedStart, "anchorNode"); + assert_equals(selection.focusNode, expectedEnd, "focusNode"); + } else { + // In case multiple ranges are supported, make sure the set of ranges + // spans the full selection, across the input. + const ranges = [...Array(nRanges).keys()].map(n => selection.getRangeAt(n)); + assert_true(ranges.some(r => r.startContainer === expectedStart),"startContainer"); + assert_true(ranges.some(r => r.endContainer === expectedEnd),"endContainer"); + } }, `Selecting texts across should not cancel selection`); }