<html >
<head>
<script src="../../../../../resources/js-test-pre.js"></script>
<style>
#scroller {
    border: 2px solid black;
    height: 400px;
    overflow: scroll;
    position: absolute;
}
        
#big {
    width: 50px;
    height: 2000px;
    background-color: purple;
    border: 15px solid green;
}
</style>
</head>

<body>
<div id="scroller">
    <div id="big"></div>
</div>

<script>
description("Test that preventing default on touchmove will prevent scrolling in overflow:scroll.");
window.jsTestIsAsync = true;

function getUIScript(startX, startY, endX, endY)
{
    return `
    (function() {
     var eventStream = {
     events : [
        {
        interpolate : "linear",
        timestep: 0.025,
        startEvent : {
        inputType : "hand",
        timeOffset : 0,
        touches : [
            {
            inputType : "finger",
            phase : "began",
            id : 1,
            x : ${startX},
            y : ${startY},
            pressure : 0
            }
        ]
        },
        endEvent : {
        inputType : "hand",
        timeOffset : 3.0,
        touches : [
            {
            inputType : "finger",
            phase : "stationary",
            id : 1,
            x : ${endX},
            y : ${endY},
            pressure : 500
            }
        ]
        }
    }
    ]
    };
     
    uiController.sendEventStream(JSON.stringify(eventStream), function() {
        uiController.uiScriptComplete();
    });
    })();`
}

function runTest()
{
    function touchmoveEventHandler(event) {
        event.preventDefault();
    }

    let eventTarget = document.getElementById("scroller");
    eventTarget.addEventListener("touchmove", touchmoveEventHandler);
    let clientRect = eventTarget.getBoundingClientRect();
    
    if (window.testRunner) {
        testRunner.runUIScript(getUIScript(clientRect.left + 10, clientRect.top + 200, clientRect.left + 10, clientRect.top + 10), function(result) {
                            shouldBe("document.getElementById('scroller').scrollTop", "0");
                            finishJSTest();
                               });
    }
}

window.addEventListener('load', runTest, false);
</script>
<script src="../../../../../resources/js-test-post.js"></script>
</body>
</html>
