<html> 
<head>
<script src=../editing.js type="text/javascript"></script>
<script>

var framex;
var framey;

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

    window.testRunner.waitUntilDone();
    
    var t = document.getElementById("targetframe");
    framex = t.offsetLeft + 10;
    framey = t.offsetTop + t.offsetHeight / 2;
    
    // Drag 'hello'
    dragDropIt1();
}


function dragDropIt1() {
    var e = document.getElementById("dragme");
    window.getSelection().setBaseAndExtent(e, 0, e, 1);
    x = e.offsetLeft + 10;
    y = e.offsetTop + e.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    
    eventSender.leapForward(500);
    eventSender.mouseMoveTo(framex, framey);
    setTimeout(dropIt1, 100);
}

function dropIt1() {

    // Drop it off to the frame
    eventSender.mouseUp();
    setTimeout(deleteFrameAndDrop, 1000);
}

function deleteFrameAndDrop() {

    // Delete the frame where we just dragged somet stuff
    var f = document.getElementById("targetframe");
    f.parentNode.removeChild(f);
    
    // Do drag drop again
    var e = document.getElementById("dragme");
    x = e.offsetLeft + 10;
    y = e.offsetTop + e.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    eventSender.mouseMoveTo(framex, framey);
    setTimeout(dropIt2, 100);
}

function dropIt2() {
    // Drop it off to somewhere
    eventSender.mouseUp();
    window.testRunner.notifyDone();
}



</script>
<title>Check you don't crash when your previous drag target frame is deleted</title> 
</head> 
<body>

<p>Check you don't crash when your previous drag target frame is deleted &lt;rdar://problem/5049842&gt;</p>
<div><span id="dragme">hello</span></div>
<iframe id=targetframe src="resources/editable-iframe.html" onload="runEditingTest()"></iframe>
</body>
</html>
