<!DOCTYPE html>
<html>
<body>
<input type="file" name="file" id="file" onchange="onInputFileChange()">
<img id='imgToReplace' src=''>
<pre id='console'></pre>

<script>
function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

function onInputFileChange()
{
    var file = document.getElementById("file").files[0];
    var img = document.getElementById('imgToReplace');
    log("Old image: " + img.width + " x " + img.height);
    img.onload = onImgLoad;
    img.src = window.URL.createObjectURL(file);
}

function onImgLoad()
{
    var img = document.getElementById('imgToReplace');
    log("New image: " + img.width + " x " + img.height);
    log("DONE");
    if (testRunner.notifyDone)
        testRunner.notifyDone();
}

function moveMouseToCenterOfElement(element)
{
    var centerX = element.offsetLeft + element.offsetWidth / 2;
    var centerY = element.offsetTop + element.offsetHeight / 2;
    eventSender.mouseMoveTo(centerX, centerY);
}

function runTests()
{
    eventSender.beginDragWithFiles(['resources/abe.png']);
    moveMouseToCenterOfElement(document.getElementById('file'));
    eventSender.mouseUp();
}

if (window.eventSender) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
    window.onload = runTests;
}
</script>
</body>
</html>
