ladybird/Tests/LibWeb/Text/input/DOM/range-get-client-rects.html
Andreas Kling 4d868d7d82 LibWeb: Handle Range rects starting after last child
A Range boundary can point after a non-text container's final child.
Range::getClientRects() treated that offset as a child index and bound a
reference to null before walking the selected nodes.

Start at the node after the container in that case, matching boundary
handling used by selection painting. Add a crash test for a collapsed
range at the end of an element.
2026-06-08 01:04:08 +02:00

39 lines
1.3 KiB
HTML

<!DOCTYPE html>
<!--refer to https://wpt.live/css/cssom-view/DOMRectList.html -->
<style>
#start-container {
display: inline-block;
}
#following {
display: inline-block;
margin-left: 100px;
}
</style>
<body>
<div id="x">x</div>
<div id="start-container"><span><span>old</span></span></div><span id="following">new</span>
<script src="../include.js"></script>
<script>
function print_class_string(object) {
println({}.toString.call(object));
}
test(() => {
const x = document.getElementById("x");
const range = document.createRange();
range.selectNodeContents(x);
const domRectList = range.getClientRects();
print_class_string(domRectList);
print_class_string(domRectList.item(0));
const startContainer = document.getElementById("start-container");
const following = document.getElementById("following");
range.setStart(startContainer, startContainer.childNodes.length);
range.setEnd(following.firstChild, following.firstChild.length);
const firstRangeRect = range.getClientRects()[0];
const followingRect = following.getBoundingClientRect();
println(firstRangeRect.left >= followingRect.left && firstRangeRect.left < followingRect.right ? "PASS" : "FAIL");
});
</script>
</body>