ladybird/Tests/LibWeb/Text/input/is-collapsed.html
John Diamond fadb14d31d 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
2024-10-12 15:00:35 +02:00

27 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>