<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function getUIScript()
{
    return `
    (function() {
        uiController.dragFromPointToPoint(50, 250, 50, 30, 0.1, function() {
            uiController.uiScriptComplete("Done");
        });
    })();`
}

function runTest()
{
    let output = "";
    window.addEventListener("touchstart", function(event) {
        event.preventDefault();
        output += `touchstart on window - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    window.addEventListener("touchend", function(event) {
        event.preventDefault();
        output += `touchend on window - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    document.addEventListener("touchstart", function(event) {
        event.preventDefault();
        output += `touchstart on document - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    document.addEventListener("touchend", function(event) {
        event.preventDefault();
        output += `touchend on document - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    document.documentElement.addEventListener("touchstart", function(event) {
        event.preventDefault();
        output += `touchstart on documentElement - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    document.documentElement.addEventListener("touchend", function(event) {
        event.preventDefault();
        output += `touchend on documentElement - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    let body = document.querySelector("body");

    body.addEventListener("touchstart", function(event) {
        event.preventDefault();
        output += `touchstart on body - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    body.addEventListener("touchend", function(event) {
        event.preventDefault();
        output += `touchend on body - cancelable: ${event.cancelable} defaultPrevented: ${event.defaultPrevented} <br>`;
    }, false);

    if (testRunner.runUIScript) {
        testRunner.runUIScript(getUIScript(), function(result) {
            output += result;
            document.getElementById("output").innerHTML = output;
            testRunner.notifyDone();
        });
    }
}

window.addEventListener('load', runTest, false);
</script>
<body style="height: 500vh">
<div id=output>
This test requires UIScriptController to run.
</div>
</body>
