<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<script>
window.jsTestIsAsync = true;
function onLoad() {
    setTimeout(runTest, 0);
}

function runTest() {
    if (!window.internals) {
        testFailed('This test requires window.internals.');
        return;
    }

    var onChangeFired = 0;
    var input1 = document.getElementById('fileinput1');
    input1.onchange = function() {
        ++onChangeFired;
    };
    var input2 = document.getElementById('fileinput2');
    input2.onchange = function() {
        ++onChangeFired;
    };

    eventSender.beginDragWithFiles(['testpath1/testfile1.txt']);
    var centerX = input1.offsetLeft + input1.offsetWidth / 2;
    var centerY = input1.offsetTop + input1.offsetHeight / 2;
    eventSender.mouseMoveTo(centerX, centerY);
    eventSender.mouseUp();

    eventSender.beginDragWithFiles(['testpath2/testfile2.txt']);
    centerX = input2.offsetLeft + input2.offsetWidth / 2;
    centerY = input2.offsetTop + input2.offsetHeight / 2;
    eventSender.mouseMoveTo(centerX, centerY);
    eventSender.mouseUp();

    if (onChangeFired != 2) {
        testFailed('onchange fired unexpected times: ' + onChangeFired);
    }

    var files = internals.getReferencedFilePaths();
    files.sort();
    if (files.length == 2 &&
        files[0].indexOf('testfile1.txt') != -1 &&
        files[0].indexOf('testpath1') != -1 &&
        files[1].indexOf('testfile2.txt') != -1 &&
        files[1].indexOf('testpath2') != -1) {
        testPassed('');
    } else {
        testFailed('Unexpected files: ' + files);
    }
    finishJSTest();
}
</script>
</head>
<body onload="onLoad();">
<p id="description">Tests that selected files in file input elements are correctly retrieved by FormController::getReferencedFilePaths.</p>
<div id="container">
<form id="form1">
<input id="fileinput1" type="file" />
</form>
<form id="form2">
<input id="fileinput2" type="file" />
</form>
</div>
<div id="console"></div>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
