<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<head>
    <script src="../../../resources/basic-gestures.js"></script>
    <script src="../../../resources/ui-helper.js"></script>
    <style>
    body {
        margin: 0;
    }

    #target {
        font-size: 100px;
    }

    #clickTarget {
        width: 100px;
        height: 100px;
        background-color: green;
    }
    </style>
    <script>
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    async function run()
    {
        if (!window.testRunner)
            return;

        function didChangeSelection()
        {
            result.textContent = window.getSelection().toString()
        }

        document.addEventListener("selectionchange", didChangeSelection);

        var clickTarget = document.getElementById("clickTarget");

        clickTarget.addEventListener("mousedown", event => {
            event.preventDefault();
            setTimeout(() => testRunner.notifyDone(), 0);
        });

        var target = document.getElementById("target");
        window.getSelection().setBaseAndExtent(target, 0, target, 1);

        await UIHelper.activateElement(clickTarget);

        document.activeElement.blur();
        await UIHelper.waitForKeyboardToHide();

        testRunner.notifyDone();
    }
    </script>
</head>
<body onload="run()">
    <div id="target">WebKit</div>
    <div id="clickTarget"></div>
    <pre>The selected text is: "<span id="result"></span>"</pre>
    <p>This test verifies that the DOM selection is not dismissed when tapping on an element that preventDefault()s the mousedown event.</p>
</body>
</html>
