<!DOCTYPE html> <!-- webkit-test-runner [ MockScrollbarsEnabled=false AsyncOverflowScrollingEnabled=true AsyncFrameScrollingEnabled=true ] -->
<html>
<head>
    <style>
        body {
            height: 1000px;
        }
        iframe {
            width: 400px;
            height: 250px;
            border: 1px solid gray;
        }
    </style>
    <script src="../../../../resources/js-test-pre.js"></script>
    <script src="../../../../resources/ui-helper.js"></script>
    
    <script>
        jsTestIsAsync = true;

        if (window.internals)
            internals.setUsesOverlayScrollbars(true);

        async function doTest()
        {
            description('Test maybegin and cancelled on overflow inside an iframe');
            
            const iframe = document.getElementsByTagName('iframe')[0];
            const iframeWindow = iframe.contentWindow;
            const iframeBounds = iframe.getBoundingClientRect();

            const scroller = iframe.contentDocument.querySelector('.scroller');
            const scrollerBounds = scroller.getBoundingClientRect();

            const x = iframeBounds.left + scrollerBounds.right - 8;
            const y = iframeBounds.top + scrollerBounds.top + 10;

            if (!window.internals) {
                finishJSTest();
                return;
            }

            iframeWindow.internals.setUsesOverlayScrollbars(true);

            debug('Initial state');
            var scrollbarState = await UIHelper.verticalScrollbarState(scroller);
            debug(scrollbarState);

            debug('Hovering vertical scrollbar should show expanded scrollbar');
            await UIHelper.mouseWheelScrollAt(x, y);
            await UIHelper.waitForConditionAsync(async () => {
                let state = await UIHelper.verticalScrollbarState(scroller);
                let enabled = state.indexOf('enabled') != -1;
                let expanded = state.indexOf('expanded') != -1;
                if (enabled && expanded)
                    testPassed('Scrollbar state contains: enabled and expanded');
                return expanded;
            });

            debug('Unhovering vertical scrollbar should hide it');
            await UIHelper.moveMouseAndWaitForFrame(x - 10, y);
            await UIHelper.moveMouseAndWaitForFrame(x - 20, y);
            await UIHelper.waitForConditionAsync(async () => {
                let state = await UIHelper.verticalScrollbarState(scroller);
                let thumbHidden = state.indexOf('visible_thumb') == -1;
                let trackHidden = state.indexOf('visible_track') == -1;
                if (thumbHidden && trackHidden)
                    testPassed('Thumb and track hidden');
                return thumbHidden && trackHidden;
            });

            finishJSTest();
        }

        window.addEventListener('load', () => {
            doTest();
        }, false);
    </script>
</head>
<body>
    <iframe srcdoc="
        <style>
        body {
            height: 1000px;
        }
        .scroller {
            margin: 10px;
            width: 200px;
            height: 200px;
            border: 1px solid black;
            overflow: auto;
        }
        .contents {
            width: 100%;
            height: 200%;
        }
        </style>
        <div class='scroller'>
            <div class='contents'></div>
        </div>
    "></iframe>
    <div id="console"></div>
    <script src="../../../../resources/js-test-post.js"></script>
</body>
</html>
