<p>This tests for a drag select crasher.</p>
<div id="div" contenteditable="true"><span id="start">Start here.</span> <input id="end" type="text"></div>
<ul id="console"></ul>

<script>
function log(str) {
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    var console = document.getElementById("console");
    console.appendChild(li);
}
function shouldBe(expected, actual) {
    if (expected != actual)
        log("Failure. Expected: " + expected + ", Actual: " + actual);
    else
        log("Passed");
}
alert( 5 / 29);
if (window.layoutTestController) {
    
    var div = document.getElementById("div");
    var sel = window.getSelection();
    sel.setPosition(div, 0);
    
    var start = document.getElementById("start");
    var startx = -8 + start.offsetLeft + start.offsetWidth / 2;
    var starty = start.offsetTop + start.offsetHeight / 2;
    eventSender.mouseMoveTo(startx, starty);
    eventSender.mouseDown();

    var end = document.getElementById("end");
    endx = -8 + end.offsetLeft + end.offsetWidth / 2;
    endy = end.offsetTop + end.offsetHeight / 2;

    var steps = 20;
    for (var i = 1; i <= steps; i++) {
        eventSender.mouseMoveTo(startx + Math.abs(startx - endx) * (i / steps), starty + Math.abs(starty - endy) * (i / steps));
    }

    eventSender.mouseMoveTo(endx, endy);
    eventSender.mouseUp();

    
} else {
    log("This uses the eventSender to perform a drag select.  To run it manually, mouse down over 'start here' and drag to the left, over the input field.");
}
</script>
