chromium/third_party/blink/web_tests/fast/files/file-reader-event-listener.html

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

<script>
var fileReader;
var receivedProgressEvent = false;

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

function onLoadStart()
{
    log("Received loadstart event");

    fileReader.removeEventListener("abort", onAbort, false);

    var event = document.createEvent("Events");
    event.initEvent("foo", false, false);
    fileReader.dispatchEvent(event);
}

function onProgress()
{
    receivedProgressEvent = true;
}

function onLoad()
{
    if (receivedProgressEvent)
        log("Received progress event");
    log("Received load event");
}

function onLoadEnd()
{
    log("Received loadend event");
    log("DONE");
    
    fileReader.removeEventListener("loadstart", onLoadStart, false);
    fileReader.removeEventListener("load", onLoad, false);
    fileReader.removeEventListener("error", onError, false);

    if (window.testRunner)
        testRunner.notifyDone();
}

function onAbort()
{
    log("Received abort event");
}

function onError(event)
{
    log("Received error event: " + event.target.error.code);
}

function onFoo()
{
    log("Received foo event");
}

function onInputFileChange()
{
    log("Test that FileReader's event listener works.");

    var file = document.getElementById("file").files[0];
    fileReader = new FileReader();
    fileReader.readAsText(file);
    fileReader.addEventListener("loadstart", onLoadStart, false);
    fileReader.addEventListener("progress", onProgress, false);
    fileReader.addEventListener("load", onLoad, false);
    fileReader.addEventListener("loadend", onLoadEnd, false);
    fileReader.addEventListener("abort", onAbort, false);
    fileReader.addEventListener("error", onError, false);
    fileReader.addEventListener("foo", onFoo, false);
}

function runTests()
{
    eventSender.beginDragWithFiles(['resources/UTF8.txt']);
    eventSender.mouseMoveTo(10, 10);
    eventSender.mouseUp();
}

if (window.eventSender) {
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }
    window.onload = runTests;
} else {
    log("eventSender is not present.");
}
</script>
</body>
</html>