blob: afb43b9bf26af8baf5b9d3fe307ee4cbee2241a0 [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 editableTargetRect = document.getElementById('editable').getBoundingClientRect();
var pressPointX = editableTargetRect.x + editableTargetRect.width / 2;
var pressPointY = editableTargetRect.y + editableTargetRect.height * .65;
var dragDistance = 60;
var selectionChangedCount = 0;
var lastSelectionChangeCount;
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>';
var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x + dragDistance, grabberMidpoint.y);
if (selectionChangedCount >= 2)
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 - dragDistance, grabberMidpoint.y);
if (selectionChangedCount >= lastSelectionChangeCount + 1)
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 - dragDistance, grabberMidpoint.y);
if (selectionChangedCount >= lastSelectionChangeCount + 1)
output += 'PASS: Selection Changed </br>';
else
output += 'FAIL: Selection changed <br>' + selectionChangedCount;
var editableElement = document.getElementById('editable');
editableElement.parentNode.removeChild(editableElement);
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">
This test requires UIScriptController to run.
</div>
<div id="editable" contenteditable>
<p>Here's to the crazy ones. The misfits. The rebels. The trouble makers. The round pegs in the square holes.</p>
</div>
</body>
</html>