<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../../../resources/js-test-pre.js"></script>
</head>
<body>
<div id=description></div>
<input type=file id=dropTarget></div>
<div id=console></div>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

description("Test that bundles are automatically zipped when uploaded with XMLHttpRequest. To test manually, please drag a file bundle to a \"Choose File\" input below.");
jsTestIsAsync = true;

window.onload = function()
{
    var dropTarget = document.getElementById("dropTarget");

    dropTarget.addEventListener("drop", ondrop, true);
    dropTarget.addEventListener("click", function() { event.preventDefault(); }, true);

    if (!window.eventSender)
        return;

    var endX = dropTarget.offsetLeft + dropTarget.offsetWidth / 2;
    var endY = dropTarget.offsetTop + dropTarget.offsetHeight / 2
    eventSender.beginDragWithFiles(["resources/document.rtfd"]);
    eventSender.mouseMoveTo(endX, endY);
    eventSender.mouseUp();
}

function ondrop(event)
{
    event.preventDefault();
    var file = event.dataTransfer.files.item(0);
    var xhr = new XMLHttpRequest;
    xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/post-echo.cgi", true);
    xhr.responseType = "arraybuffer";
    xhr.send(file);
    xhr.onloadend = function() {
        responseArray = new Uint8Array(xhr.response);
        shouldBe("String.fromCharCode(responseArray[0], responseArray[1])", "'PK'");
        finishJSTest();
    }
}
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>
