<html>
<head>
  <script src="../../resources/platform-helper.js"></script>
</head>
<body>
<script>
function log(msg) {
  var console = document.getElementById('console');
  var line = document.createElement('div');
  line.textContent = msg;
  console.appendChild(line);
}

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

    testRunner.dumpAsText();

    // 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);
    if (isGtk())
      eventSender.mouseUp(0, ['ctrlKey']);
    else
      eventSender.mouseUp(0, ['altKey']);

    var result = input.value;
    log(result == 'Text' ? 'PASS: input' : 'FAIL: expected value="Text", actual value="' + result + '"');
    var result = textarea.value;
    log(result == 'Text!' ? 'PASS: textarea' : 'FAIL: expected value="Text!", actual value="' + result + '"');
}
</script>
<p>This tests the generic drag and drop where the copy of the content is
requested (pressing Control on WebKitGTK+ or Alt on Mac when dropping the
content) instead of the move. To manually run the test, select the "Text"
in the textarea and drag it to the input on the left. When dropping the
content request the copy operation. The test is passed if the input will
contain "Text" and the textarea "Text!" strings.</p>
<div id=console></div>
<input id=destination>
<textarea id=textarea rows=1>Text!</textarea>
<script>runTest();</script>
</body>
</html>
