<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p>This tests for a drag select crasher.</p>
<div id="div" dir="RTL" style="-webkit-font-variant-ligatures: normal; -webkit-font-kerning: normal; font-size: 100px;"><span id="c" style="background: yellow;">&#1604;&#1575;&#1611;</span></div>
<div id="console"></div>

<script>
var sel;
var r;

function log(str) {
    var div = document.createElement("div");
    div.appendChild(document.createTextNode(str));
    var console = document.getElementById("console");
    console.appendChild(div);
}

function test() {
    if (window.eventSender && window.testRunner) {
        testRunner.dumpAsText();
        
        var div = document.getElementById("div");
        sel = window.getSelection();
        sel.setPosition(div, 0);
        
        var start = document.getElementById("c");
        var startx = start.offsetLeft + 1;
        var starty = start.offsetTop + start.offsetHeight / 2;
        eventSender.mouseMoveTo(startx, starty);
        eventSender.mouseDown();
    
        var end = document.getElementById("c");
        endx = end.offsetLeft + end.offsetWidth - 1;
        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();
    
        sel = window.getSelection();
        shouldBe("sel.rangeCount", "1");
        r = sel.getRangeAt(0);
        shouldBe("r.startContainer", "r.endContainer");
        shouldBe("r.startOffset", "0");
        shouldBe("r.endOffset", "3");
    } else {
        log("This uses the eventSender to perform a slow drag select.  To run it manually, click on the left half of the character and slowly drag to the right half of the character.");
    }
}

test();
</script>
</body>
</html>
