From a6b4c16fe4762f0a6a7414c025c454de5b6a44d1 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 28 Apr 2023 14:46:29 -0700 Subject: [PATCH] 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 --- .../the-input-element/selection-pointer.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/html/semantics/forms/the-input-element/selection-pointer.html b/html/semantics/forms/the-input-element/selection-pointer.html index 8cb0ead44148dfb..7f06ae24a2d5d86 100644 --- a/html/semantics/forms/the-input-element/selection-pointer.html +++ b/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`); }