<!DOCTYPE html> <!-- webkit-test-runner [ MockScrollbarsEnabled=false AsyncOverflowScrollingEnabled=true ] -->
<html>
<head>
    <style>
        body {
            height: 1000px;
        }
        select {
            display: block;
            font-size: 12pt;
            margin: 10px;
            border: 1px solid black;
        }
    </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 a scrolling list');
            if (!window.internals) {
                finishJSTest();
                return;
            }
            
            const select = document.getElementsByTagName('select')[0];
            const selectBounds = select.getBoundingClientRect();
            const x = selectBounds.left + 10;
            const y = selectBounds.top + 10;

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

            debug('MayBegin should show the scrollbar');
            await UIHelper.mouseWheelMayBeginAt(x, y);
            await UIHelper.waitForConditionAsync(async () => {
                let state = await UIHelper.verticalScrollbarState(select);
                let visible = state.indexOf('visible_thumb') != -1;
                if (visible)
                    testPassed('Scrollbar state: ' + state);
                return visible;
            });

            debug('Cancelled should hide the scrollbar');
            await UIHelper.mouseWheelCancelAt(x, y);

            await UIHelper.waitForConditionAsync(async () => {
                let state = await UIHelper.verticalScrollbarState(select);
                let hidden = state.indexOf('visible_thumb') == -1;
                if (hidden)
                    testPassed('Scrollbar state: ' + state);
                return hidden;
            });

            finishJSTest();
        }

        window.addEventListener('load', () => {
            doTest();
        }, false);
    </script>
</head>
<body>
    <select size="5">
        <option>January</option>
        <option>February</option>
        <option>March</option>
        <option>April</option>
        <option>May</option>
        <option>June</option>
        <option>July</option>
        <option>August</option>
        <option>September</option>
        <option>October</option>
        <option>November</option>
        <option>December</option>
    </select>
    <div id="console"></div>
    <script src="../../../../resources/js-test-post.js"></script>
</body>
</html>
