<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<head>
<script src="../../../resources/ui-helper.js"></script>
<script src="../../../resources/js-test.js"></script>
<meta name=viewport content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<style>
body, html {
    width: 100%;
    height: 100%;
    margin: 0;
}

p {
    font-size: 24px;
}

#target {
    border: 2px solid tomato;
    padding: 1px;
}
</style>
<script>
jsTestIsAsync = true;

addEventListener("load", async () => {
    description("This test verifies that interacting with selection handles doesn't trigger a synthetic click. To manually run the test, select a word in the paragraph above and then adjust either selection handle by a single letter. The selection should not disappear.");
    document.body.addEventListener("click", () => testFailed("Handled unexpected click event"));

    await UIHelper.longPressElement(document.getElementById("target"));
    await UIHelper.waitForSelectionToAppear();

    const rect = await UIHelper.getSelectionEndGrabberViewRect();
    const midpoint = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };

    await UIHelper.sendEventStream(new UIHelper.EventStreamBuilder()
        .begin(midpoint.x, midpoint.y)
        .move(midpoint.x - 20, midpoint.y, 0.1)
        .end()
        .takeResult());

    await UIHelper.ensurePresentationUpdate();
    firstSelectionRect = (await UIHelper.getUISelectionViewRects())[0];
    shouldBeTrue("firstSelectionRect.width > 0");
    shouldBeTrue("firstSelectionRect.height > 0");

    document.querySelector("p.text").remove();
    finishJSTest();
});
</script>
</head>
<body>
<p class="text">Here’s to the crazy ones. The misfits. The rebels. The <span id="target">troublemakers</span>. The round pegs in the square holes. The ones who see things differently.</p>
<pre id="description"></pre>
<pre id="console"></pre>
</body>
</html>
