summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/files/file-reader-result-twice.html
blob: 8e144bef3f42ba1fe52dbd01bb4780e827264cf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<body>
<p>Test that FileReader.result returns the same result regardless of whether it's from cache or not by getting it twice.</p>
<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>