<!DOCTYPE html>
<html>
<body>
<p>This tests dragging text within the same contenteditable element. To manually test, move the target below to the destination.
You should see dragstart, drop, and dragend in the log.</p>
<div contenteditable><span>Drag_and_drop_this_target to here, the_destination.</span></div>
<pre id="log">
Log:
</pre>
<script>

var log = document.getElementById('log');
var div = document.querySelector('div');
var eventLogs = [];

function logEvent(event) {
    eventLogs.push(event.type);
    log.innerText += event.type + '\n';
}

div.addEventListener('dragstart', logEvent, false);
div.addEventListener('dragend', logEvent, false);
div.addEventListener('drop', logEvent, false);

if (window.eventSender) {
    testRunner.dumpAsText();

    div.focus();
    getSelection().collapse(div, 0);
    getSelection().modify('extend', 'forward', 'word');

    var y = div.offsetTop + div.offsetHeight / 2;
    eventSender.dragMode = true;
    eventSender.mouseMoveTo(div.offsetLeft + div.firstChild.offsetWidth / 5, y);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    eventSender.mouseMoveTo(div.offsetLeft + div.firstChild.offsetWidth * 4 / 5, y);
    eventSender.mouseUp();

    div.style.display = 'none'; // The resultant text will be different depending on font metrics so hide it.

    log.innerHTML += '\n' + (eventLogs.join('') == ['dragstart', 'drop', 'dragend'].join('') ? 'PASS' : 'FAIL');
}

</script>
</body>
</html>