Files
serenity/Tests/LibWeb/Text/input/is-collapsed.html
John Diamond f22b32652e LibWeb: Compare anchor/focus offsets in selection.isCollapsed
The "isCollapsed" attribute on a selection must "return true if and only
if the anchor and focus are the same".

In addition to checking that the anchor and focus belonged to the same
DOM node, we now also check that they refer to the same position within
the node.

With this change Ladybird passes all the subtests in the "isCollapsed"
WPT suite.

https://wpt.live/selection/isCollapsed.html
(cherry picked from commit fadb14d31d0d3127e80121ac695fe839908efaa1)
2024-11-25 08:50:54 -05:00

28 lines
797 B
HTML

<script src="include.js"></script>
<p id="a">Simply selectable</p>
<script>
test(() => {
var selection = window.getSelection();
var range = document.createRange();
range.setStart(a.firstChild, 0);
range.setEnd(a.firstChild, 1);
selection.addRange(range);
if (selection.isCollapsed) {
println(`FAIL: "${selection}" is not collapsed`);
return;
}
selection.collapseToStart();
if (!selection.isCollapsed) {
println(`FAIL: "${selection}" is collapsed`);
return;
}
selection.removeAllRanges();
if (!selection.isCollapsed) {
println(`FAIL: "${selection}" is collapsed`);
return;
}
println("PASS");
})
</script>