<!DOCTYPE html>
<html>
<head>
    <script src="../../../resources/ui-helper.js"></script>
    <script>
        if (window.testRunner) {
            testRunner.waitUntilDone();
            testRunner.dumpAsText();
        }

        async function frameLoaded(iframe)
        {
            iframe.contentWindow.addEventListener('wheel', function() {
                // Removing the window during event firing causes crash.
                window.document.body.removeChild(iframe);
                window.setTimeout(function() {
                    if (window.testRunner)
                        testRunner.notifyDone();
                }, 0);
            });

            if (!window.eventSender)
                return;

            var iframeTarget = document.getElementById('iframe');
            var iframeBounds = iframeTarget.getBoundingClientRect();

            await UIHelper.ensurePresentationUpdate();

            eventSender.mouseMoveTo(iframeBounds.left + 10, iframeBounds.top + 10);
            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'began', 'none');
            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'changed', 'none');
            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'changed', 'none');
            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
        }
    </script>
</head>
<body>
    <p>This test should not crash</p>
    <iframe id="iframe" onload="frameLoaded(this)" src="data:text/html,<body>Wheel here</body>"></iframe>
</body>
</html>
