<script>
if (window.layoutTestController)
     layoutTestController.dumpEditingCallbacks();
</script>
<div>This test checks that links dragged into editable regions preserve their title and URL.</div>

<div contenteditable="true" id="destination">Hello</div>

<div><a href="http://apple.com" id="grabme">This is a link</a></div>

<ul id="console"></ul>

<div>To run this test manually, drag the link into the box with 'hello' in it, and then click on the button.<br><input type="button" value="Verify" onClick="verifier()"></div>

<script>

function log(message) {
    var console = document.getElementById("console");
    var li = document.createElement("li");
    var pre = document.createElement("pre");
    pre.appendChild(document.createTextNode(message));
    li.appendChild(pre);
    console.appendChild(li);
}

function runTest() {
    if (!window.layoutTestController)
        return;
    
    var anchorToDrag = document.getElementById("grabme");
    var x = anchorToDrag.offsetLeft + anchorToDrag.offsetWidth / 2;
    var y = anchorToDrag.offsetTop + anchorToDrag.offsetHeight / 2;

    eventSender.mouseMoveTo(x, y);

    eventSender.mouseDown();
    // Wait a moment so that the mouseDown will kick off a drag instead of navigating to the link
    eventSender.leapForward(400);
    
    var destinationObject = document.getElementById("destination");
    var x = destinationObject.offsetLeft + destinationObject.offsetWidth / 2;
    var y = destinationObject.offsetTop + destinationObject.offsetHeight / 2;


    eventSender.mouseMoveTo(x, y);
    eventSender.mouseUp();

    verifier();
}

function verifier() {
    var anchorToDrag = document.getElementById("grabme");

    var originalTarget = anchorToDrag.href;
    var originalText = anchorToDrag.innerText;
    var anchorParent = anchorToDrag.parentNode;
    anchorParent.removeChild(anchorToDrag);
    
    var anchors = document.getElementsByTagName("a");
    if (anchors.length != 1) {
        log("Failure, incorrect number of anchor tags present");
    } else {
        log("Link is " + anchors[0].href);
        var passed = true;
        if (anchors[0].href != originalTarget) {
            log("Failure! Link targets differ");
            passed = false;
        }
        if (anchors[0].innerText != originalText) {
            log("Failure! Link texts differ");
            passed = false;
        }
        if (passed)
            log("Success!");
    }
}

runTest();
</script>
