<html>
    <head>
        <script>
            function log(msg)
            {
                var console = document.getElementById('console');
                console.innerHTML = console.innerHTML + msg + "<br>";
            }
            
            function buttonClick()
            {
                log("<br>clicking button");

                // click the button
                var button = document.getElementById('button');
                eventSender.mouseMoveTo(button.offsetLeft + 20, button.offsetTop + 7);
                eventSender.mouseDown();
                eventSender.mouseUp();

                testRunner.notifyDone();
            }
            
            function deleteSearch()
            {
                // delete the search
                log("<br>deleting search input");
                var search = document.getElementById('search');
                search.parentNode.removeChild(search);

                setTimeout(buttonClick, 10);
            }
            
            function drag()
            {
                if (!window.testRunner)
                    return;

                testRunner.dumpAsText();
                testRunner.waitUntilDone();

                var search = document.getElementById('search');
                var x = search.offsetLeft + search.offsetWidth - 6;
                var y = search.offsetTop + search.offsetHeight / 2;

                // drag slider, leave the mouse down
                log("clicking in cancel");
                eventSender.mouseMoveTo(x, y);
                eventSender.mouseDown();

                setTimeout(deleteSearch, 10);
            }
        </script>
    </head>
    <body onload="drag()">
        This tests that events don't continue to target a search cancel button if it is deleted while mouse is down.
        <br>
        <input type="button" id="button" value="Click Me!" onmouseup="log('button click!')"> 
        <br>
        <input id="search" type="search" value="foo">
        <div id="console"></div>
    </body>
</html>
