Skip to content

Commit

Permalink
Bug 1912163 [wpt PR 47523] - [Selection API] Change getComposedRanges…
Browse files Browse the repository at this point in the history
…() from rest parameter to a dictionary, a=testonly

Automatic update from web-platform-tests
[Selection API] Change getComposedRanges() from rest parameter to a dictionary

Per w3c/selection-api#176, we should update
selection.getComposedRanges() from using a rest `shadowRoots` parameter
to using a dictionary that contains the array `shadowRoots`.

Change-Id: I6b5b3fed786cf6d75fa4a20c0b2a583635cd2aca
Bug: 40286116
Fixed: 355577223
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5770701
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Reviewed-by: Siye Liu <siliu@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1338832}

--

wpt-commits: 57e20404dde0cc210bbedfaf1955bad34decb16b
wpt-pr: 47523
  • Loading branch information
dizhang168 authored and moz-wptsync-bot committed Aug 9, 2024
1 parent 5567c1c commit f5ece9a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

window.getSelection().setBaseAndExtent(start.firstChild, 3, end.firstChild, 3);

const composedRange = window.getSelection().getComposedRanges(shadowRoot)[0];
const composedRange = window.getSelection().getComposedRanges({ shadowRoots: [shadowRoot] })[0];
// Sanity check to make sure we have selected something across the shadow boundary.
assert_true(composedRange.startContainer == start.firstChild);
assert_true(composedRange.startOffset == 3);
Expand All @@ -40,7 +40,6 @@
}, "isPointInRange() test for collapsed selection");

test(function() {
assert_implements(window.getSelection().getComposedRanges, "GetComposedRanges is not supported");
const start = document.getElementById("start");
const shadowRoot = document.getElementById("host").shadowRoot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
assert_equals(sel.focusNode, outer.firstChild);
assert_equals(sel.focusOffset, 2);

const composedRange = sel.getComposedRanges(host.shadowRoot)[0];
const composedRange = sel.getComposedRanges({ shadowRoots: [host.shadowRoot] })[0];
assert_equals(composedRange.startContainer, slotted.firstChild);
assert_equals(composedRange.startOffset, 3);
assert_equals(composedRange.endContainer, outer.firstChild);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, textNode);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -34,7 +34,7 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 0);
}, 'collapse abort steps when called with a disconnected node inside a shadow tree');

Expand All @@ -46,10 +46,10 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
let ranges = getSelection().getComposedRanges(shadowRoot);
let ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
getSelection().extend(textNode, 11);
ranges = getSelection().getComposedRanges(shadowRoot);
ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, textNode);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -66,7 +66,7 @@
getSelection().removeAllRanges();
getSelection().collapse(container, 0);
getSelection().extend(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, container);
assert_equals(ranges[0].startOffset, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@
assert_equals(sel.getComposedRanges()[0].endContainer, container);
assert_equals(sel.getComposedRanges()[0].endOffset, 4);

assert_equals(sel.getComposedRanges(c)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c)[0].endContainer, container);
assert_equals(sel.getComposedRanges(c)[0].endOffset, 4);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].endContainer, container);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].endOffset, 4);

assert_equals(sel.getComposedRanges(d)[0].startContainer, container);
assert_equals(sel.getComposedRanges(d)[0].startOffset, 1);
assert_equals(sel.getComposedRanges(d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].startContainer, container);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].startOffset, 1);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].endOffset, 0);

assert_equals(sel.getComposedRanges(c, d)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c, d)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c, d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(c, d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endOffset, 0);

// Re-setting the same range should never change the output
sel.setBaseAndExtent(c, 0, d, 0);
Expand All @@ -73,9 +73,9 @@
assert_equals(sel.getRangeAt(0).endContainer, d);
assert_equals(sel.getRangeAt(0).endOffset, 0);

assert_equals(sel.getComposedRanges(c, d)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c, d)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c, d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(c, d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endOffset, 0);
}, 'Setting the range to nodes in different shadow trees collapses ordinary ranges, but does not collapse composed ranges.');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
container.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(container.firstChild, 0, container.firstChild, 5);
try {
getSelection().getComposedRanges(container);
getSelection().getComposedRanges({ shadowRoots: [container] });
assert_unreached('executed without error; want error');
} catch (e) {
assert_equals(e.message, "Failed to execute 'getComposedRanges' on 'Selection': parameter 1 is not of type 'ShadowRoot'.");
assert_equals(e.message, "Failed to execute 'getComposedRanges' on 'Selection': Failed to read the 'shadowRoots' property from 'GetComposedRangesOptions': Failed to convert value to 'ShadowRoot'.");
}
}, 'getComposedRanges should fail if argument is not a shadow root');

Expand Down Expand Up @@ -53,7 +53,7 @@
const shadowRoot = host.attachShadow({mode: 'closed'});
shadowRoot.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(shadowRoot.firstChild, 0, shadowRoot.firstChild, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, shadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 0);
Expand Down Expand Up @@ -95,7 +95,7 @@
const shadowRoot = host.attachShadow({mode: 'closed'});
shadowRoot.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(shadowRoot.firstChild, 7, container, 2);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, shadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 7);
Expand Down Expand Up @@ -129,7 +129,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(innerShadowRoot.firstChild, 5, innerShadowRoot.firstChild, 9);
const ranges = getSelection().getComposedRanges(innerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [innerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, innerShadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -146,7 +146,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(innerShadowRoot.firstChild, 5, innerShadowRoot.firstChild, 9);
const ranges = getSelection().getComposedRanges(outerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [outerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, outerShadowRoot);
assert_equals(ranges[0].startOffset, 0);
Expand All @@ -163,7 +163,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(container.firstChild, 0, outerShadowRoot, 0);
const ranges = getSelection().getComposedRanges(innerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [innerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, container.firstChild, "A");
assert_equals(ranges[0].startOffset, 0, "B");
Expand Down

0 comments on commit f5ece9a

Please sign in to comment.