4 <p>Test that FileReader.result returns the same result regardless of whether it's from cache or not by getting it twice.
</p>
5 <script src=
"../../resources/testharness.js"></script>
6 <script src=
"../../resources/testharnessreport.js"></script>
7 <script type=
"text/javascript">
8 function setupHandlers(test
, reader
, expectedResult
)
10 reader
.onabort
= test
.step_func(function() {
11 assert_unreached("onabort invoked on reader");
13 reader
.onerror
= test
.step_func(function() {
14 assert_unreached("onerror invoked on reader");
16 reader
.onloadend
= test
.step_func(function() {
17 assert_equals(reader
.readyState
, reader
.DONE
,
19 assert_equals(reader
.error
, null, "reader.error");
20 // Read result attribute twice to go through Blink's code path for
21 // caching converted result and reading from the cache.
22 assert_equals(reader
.result
, expectedResult
, "reader.result");
23 assert_equals(reader
.result
, expectedResult
, "reader.result");
28 var blob
= new Blob(["HelloWorld"], {"type": "text/plain;charset=us-ascii"});
30 var testBinaryString
= async_test("Read from a blob as a binary string");
31 testBinaryString
.step(function() {
32 var reader
= new FileReader();
33 reader
.readAsBinaryString(blob
);
34 setupHandlers(testBinaryString
, reader
, "HelloWorld");
37 var testText
= async_test("Read from a blob as a text");
38 testText
.step(function() {
39 var reader
= new FileReader();
40 reader
.readAsText(blob
);
41 setupHandlers(testText
, reader
, "HelloWorld");
44 var testDataURL
= async_test("Read from a blob as a data URL");
45 testDataURL
.step(function() {
46 var reader
= new FileReader();
47 reader
.readAsDataURL(blob
);
48 setupHandlers(testDataURL
, reader
, "data:text/plain;charset=us-ascii;base64,SGVsbG9Xb3JsZA==");