Source code
Revision control
Copy as Markdown
Other Tools
<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<title>Viewport: No scroll event fired on visualViewport when only the layout viewport scrolls</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body {
height: 500vh;
}
</style>
<script>
// At scale 1, "perform a scroll" of the viewport gives the visual viewport a
// zero delta and scrolls only the layout viewport, so per "scrolling events" no
// scroll event is queued for visualViewport. Such an event would be dispatched
// in the same run of the scroll steps as the window scroll event, so waiting for
// the next animation frame after the window scroll event is enough.
promise_test(async t => {
await new Promise(resolve => window.addEventListener("load", resolve, { once: true }));
assert_equals(window.scrollY, 0, "Must not be scrolled");
assert_equals(visualViewport.scale, 1, "Must not be zoomed in");
let visualViewportScrollEventCount = 0;
visualViewport.addEventListener("scroll", () => visualViewportScrollEventCount++);
const scrollPromise =
new Promise(resolve => window.addEventListener("scroll", resolve, { once: true }));
window.scrollTo(0, 100);
await scrollPromise;
await new Promise(resolve => requestAnimationFrame(resolve));
assert_equals(window.scrollY, 100);
assert_equals(visualViewport.pageTop, 100);
assert_equals(visualViewport.offsetTop, 0);
assert_equals(visualViewportScrollEventCount, 0);
}, "Scrolling the layout viewport while not zoomed in does not fire a scroll event on visualViewport");
</script>