blob: 6773ee7cfa342c5718cfa9b16126c6c8ffcba620 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../../resources/basic-gestures.js"></script>
<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('target').getBoundingClientRect();
var pressPointX = targetRect.x + targetRect.width / 2;
var pressPointY = targetRect.y + targetRect.height / 2;
var fontHeight = 30;
var selectionChangedCount = 0;
var lastSelectionChangeCount = 0;
document.addEventListener("selectionchange", () => {
selectionChangedCount++;
});
await longPressAtPoint(pressPointX, pressPointY);
await UIHelper.waitForSelectionToAppear();
if (document.getSelection().toString() != "")
output += 'PASS: Has Selection';
else
output += 'FAIL: failed to select a word as a result of a long press.';
output += '<br>';
lastSelectionChangeCount = selectionChangedCount;
var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y + (fontHeight * 2));
if (selectionChangedCount > lastSelectionChangeCount)
output += 'PASS: Selection Changed </br>';
else
output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
lastSelectionChangeCount = selectionChangedCount;
grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y - (fontHeight));
if (selectionChangedCount > lastSelectionChangeCount)
output += 'PASS: Selection Changed </br>';
else
output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
lastSelectionChangeCount = selectionChangedCount;
grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 4));
if (selectionChangedCount > lastSelectionChangeCount)
output += 'PASS: Selection Changed </br>';
else
output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
document.getElementById('target').innerHTML = output;
testRunner.notifyDone();
}
window.addEventListener('load', runTest, false);
</script>
<style>
#target {
height: 50px;
width: 300px;
background-color: silver;
font-family: monospace;
font-size: 18px;
}
#editable {
height: 300px;
width: 300px;
background-color: silver;
font-family: monospace;
font-size: 30px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="target">
<p>Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes.</p>
<p>This test requires UIScriptController to run.</p>
</div>
</body>
</html>