LibWeb: Add test for hit testing after visual viewport horizontal scroll

This commit is contained in:
Aliaksandr Kalenik 2026-01-31 18:36:34 +01:00 committed by Alexander Kalenik
parent 2738f6c9c6
commit 5f0540f800
2 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,5 @@
scale: 2
offsetLeft before scroll: 0
before scroll: left
offsetLeft after scroll: 400
after scroll: left

View file

@ -0,0 +1,60 @@
<!DOCTYPE html>
<style>
body {
margin: 0;
}
.row {
display: flex;
}
#left, #right {
width: 400px;
height: 300px;
}
#left { background: red; }
#right { background: blue; }
.spacer { height: 2000px; }
</style>
<div class="row">
<div id="left"></div>
<div id="right"></div>
</div>
<div class="spacer"></div>
<script src="include.js"></script>
<script>
asyncTest(done => {
const vv = window.visualViewport;
vv.addEventListener("resize", function onResize() {
vv.removeEventListener("resize", onResize);
const results = [];
results.push(`scale: ${vv.scale}`);
results.push(`offsetLeft before scroll: ${vv.offsetLeft}`);
// At zoom=2 with offset (0,0), screen (200, 150) maps to layout (100, 75) -> inside #left
let hit = internals.hitTest(200, 150);
results.push(`before scroll: ${hit.node.id}`);
// Scroll right by 400 to pan the visual viewport to the right half
internals.wheel(200, 150, 400, 0);
// Do not call println() here — DOM mutation triggers layout which
// rebuilds AccumulatedVisualContext, masking bugs in scroll invalidation.
results.push(`offsetLeft after scroll: ${vv.offsetLeft}`);
// After scrolling, screen (200, 150) should map to layout (500, 75) -> inside #right
hit = internals.hitTest(200, 150);
results.push(`after scroll: ${hit.node.id}`);
// Print all results at the end
for (const r of results) println(r);
done();
});
requestAnimationFrame(() => {
internals.pinch(0, 0, 1.0);
});
});
</script>