chromium/third_party/blink/web_tests/fast/files/file-reader-result-twice.html

<!DOCTYPE html>
<html>
<title>Test that FileReader.result returns the same result regardless of whether it's from cache or not by getting it twice.</title>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="text/javascript">
function setupHandlers(test, reader, expectedResult)
{
    reader.onabort = test.step_func(function() {
        assert_unreached("onabort invoked on reader");
    });
    reader.onerror = test.step_func(function() {
        assert_unreached("onerror invoked on reader");
    });
    reader.onloadend = test.step_func(function() {
        assert_equals(reader.readyState, reader.DONE,
                      "reader.readyState");
        assert_equals(reader.error, null, "reader.error");
        // Read result attribute twice to go through Blink's code path for
        // caching converted result and reading from the cache.
        assert_equals(reader.result, expectedResult, "reader.result");
        assert_equals(reader.result, expectedResult, "reader.result");
        test.done();
    });
}

var blob = new Blob(["HelloWorld"], {"type": "text/plain;charset=us-ascii"});

var testBinaryString = async_test("Read from a blob as a binary string");
testBinaryString.step(function() {
    var reader = new FileReader();
    reader.readAsBinaryString(blob);
    setupHandlers(testBinaryString, reader, "HelloWorld");
});

var testText = async_test("Read from a blob as a text");
testText.step(function() {
    var reader = new FileReader();
    reader.readAsText(blob);
    setupHandlers(testText, reader, "HelloWorld");
});

var testDataURL = async_test("Read from a blob as a data URL");
testDataURL.step(function() {
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    setupHandlers(testDataURL, reader, "data:text/plain;charset=us-ascii;base64,SGVsbG9Xb3JsZA==");
});
</script>
</body>
</html>