<!DOCTYPE html>

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

        function getPressScript()
        {
            return `
            (function() {
                uiController.longPressAtPoint(30, 20, function() {
                    uiController.uiScriptComplete();
                });
            })();`
        }
    
        function runTest()
        {
            if (!testRunner.runUIScript)
                return;

            var output = '';
            var target = document.getElementById('target');
            if (testRunner.runUIScript) {
                testRunner.runUIScript(getPressScript(), function(result) {
                    var selectionText = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
                    if (selectionText == "PressMe")
                        output += 'PASS: Selected: ' + selectionText;
                    else
                        output += 'FAILED: no selection made';
                    output += '<br>';
                    document.getElementById('target').innerHTML = output;
                    testRunner.notifyDone();
                });
            }
        }

        window.addEventListener('load', runTest, false);
    </script>
    <style>
        #target {
            height: 100px;
            width: 200px;
            background-color: silver;
        }
    </style>
    <meta name="viewport" content="initial-scale=1">
</head>
<body>
<div id="target">
	<textarea id="textarea">PressMe</textarea>
    This test requires UIScriptController to run.
</div>
</body>
</html>
