<!DOCTYPE html>
<script src="../../resources/gesture-util.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/percent-based-util.js"></script>
<script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-actions.js"></script>
<script src="../../resources/testdriver-vendor.js"></script>
<style>
#scroller {
background-color: #ccc;
margin-top: 20px;
overflow: scroll;
}
#fracheight {
height: 1200.3px;
}
</style>
<div id="scroller">
<div id="fracheight"></div>
</div>
<script>
function accumulateWheelScrollDelta() {
return new Promise((resolve, reject) => {
let scrollAmount = 0;
const scrollendListener = () => {
if (!scrollAmount) {
reject('Expected wheel scroll');
} else {
resolve(scrollAmount);
}
};
const wheelListener = (event) => {
scrollAmount += event.deltaY;
};
document.addEventListener('scrollend', scrollendListener);
document.addEventListener('wheel', wheelListener);
});
}
promise_test(async () => {
// Not seeing wheel events if the scrollAccumulator is initialized
// immediately ahead of a wheel scroll. This likely has something to do with
// how the events are queued and synchronously handled once the gesture
// promise is resolved. As long as the wheel event listener is queued in an
// earlier frame than the wheel scroll, events are properly triggered.
const scrollAccumulator = accumulateWheelScrollDelta();
await waitForCompositorCommit();
const scroller = document.getElementById("scroller");
const center = pointInElement(scroller, 50, 50);
// Mouse click to ensure the element has focus before scrolling.
await mouseClick(center.x, center.y);
// Scroll 1 tick. The actual scroll amount may differ if percent-based
// scrolling is enabled.
const adjustedPixelsPerTick = calculateExpectedScroll(
document.scrollingElement, 0, pixelsPerTick()).y;
await wheelScroll(center.x, center.y, 0, adjustedPixelsPerTick, document);
const scrollDelta = await scrollAccumulator;
assert_approx_equals(window.scrollY, scrollDelta, 0.01);
assert_approx_equals(window.scrollY, adjustedPixelsPerTick, 0.01);
}, "Verify that wheel scrolls chain correctly from a fractional-height scroller to its parent.");
</script>