<html>
<body>
<script>
function debug(msg) {
  var console = document.getElementById('console');
  var line = document.createElement('div');
  line.textContent = msg;
  console.appendChild(line);
}

function editingTest() {
    if (!window.testRunner)
        return;

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

    // Drag a word in the textarea
    var textarea = document.getElementById("textarea");
    textarea.setSelectionRange(0, 4);
    x = textarea.offsetLeft + 10;
    y = textarea.offsetTop + textarea.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    // and drop it off to the input field
    var input = document.getElementById("destination");
    eventSender.leapForward(500);
    eventSender.mouseMoveTo(input.offsetLeft + 10, input.offsetTop + input.offsetHeight / 2);
    eventSender.mouseUp();

    var result = input.value;
    debug(result == 'What' ? 'PASS: to input' : 'FAIL: expected value="What", actual value="' + result + '"');

    // Drag from the input to the textarea.
    textarea.value = '';
    input.focus();
    input.setSelectionRange(0, 4);
    eventSender.mouseMoveTo(input.offsetLeft + 10, input.offsetTop + input.offsetHeight / 2);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    eventSender.mouseMoveTo(textarea.offsetLeft + 10, textarea.offsetTop + 10);
    eventSender.mouseUp();
    var result = textarea.value;
    debug(result == 'What' ? 'PASS: to textarea' : 'FAIL: expected value="What", actual value="' + result + '"');
    
    testRunner.notifyDone();
}
</script>
<p>This tests text selection drag from a textarea and drop to an input, and vice versa.
  There was a bug of an assertion failure in a case of the selected text was
  longer than the destination text.</p>
<div id=console></div>
<input id=destination>
<textarea id=textarea rows=1>What steps will reproduce the problem?
</textarea>
<script>editingTest();</script>
</body>
</html>
