<!DOCTYPE html>

<html>
<head>
    <script src="../../../../resources/ui-helper.js"></script>
    <script>
        if (window.testRunner) {
            testRunner.dumpAsText();
            testRunner.waitUntilDone();
        }

        async function runTest()
        {
            if (!testRunner.runUIScript)
                return;

            var output = '';
            var targetRect = document.getElementById('selection').getBoundingClientRect();
            
            var pressPointX = targetRect.x + targetRect.width / 2;
            var pressPointY = targetRect.y + targetRect.height / 2;
            
            var result = await UIHelper.longPressAtPoint(pressPointX, pressPointY);
            if (document.getSelection().toString() == "PressMe")
                output += 'PASS: Correct Selection';
            else
                output += 'FAIL: failed to select a word as a result of a long press';
            output += '<br>';
            output += result;
            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">
	<p><span id="selection">PressMe</span></p>
    This test requires UIScriptController to run.
</div>
</body>
</html>
