Skip to content

Truly independent web browser

1.8 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    body {
        margin: 0;
        height: 2000px;
    }
</style>
<script>
    promiseTest(async () => {
        let wheelEvents = 0;
        let cancelableWheelEvents = 0;
        window.addEventListener("wheel", event => {
            ++wheelEvents;
            if (event.cancelable)
                ++cancelableWheelEvents;
            if (wheelEvents === 1)
                event.preventDefault();
        }, { passive: false });
        await animationFrame();
        await animationFrame();

        // The page cancels the first step, which neither scrolls nor stretches anything.
        await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");
        println(`after the canceled step: viewport stretch=${internals.compositorScrollState().stretch.y} window.scrollY=${window.scrollY}`);

        // The page can cancel the next step too. Once it lets a step through, that step and the rest of the gesture
        // stretch the page without asking the page again.
        await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");
        await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");
        println(`after the steps let through: viewport stretch=${internals.compositorScrollState().stretch.y} window.scrollY=${window.scrollY}`);
        println(`wheel events the page could have canceled: ${cancelableWheelEvents} of ${wheelEvents}`);

        await internals.wheelThroughUIProcess(400, 300, 0, 0, true, "ended");
        while (internals.compositorScrollState().stretch.y !== 0)
            await animationFrame();
        println(`sprung back: viewport stretch=${internals.compositorScrollState().stretch.y} window.scrollY=${window.scrollY}`);
    });
</script>