2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/read-common.js"></script>
5 description("Test the Blob.close() method, reading.");
7 window
.jsTestIsAsync
= true;
9 var blobContents
= ['0123456789abcdef'];
17 function testReadAfterClose()
19 debug("Testing that the reading of closed Blobs fail.");
20 blob
= new Blob(blobContents
);
21 shouldBe("blob.close(); blob.size", "0");
22 reader
= new FileReader();
23 shouldThrow("reader.readAsArrayBuffer(blob)");
24 shouldThrow("reader.readAsBinaryString(blob)");
25 shouldThrow("reader.readAsText(blob)");
26 shouldThrow("reader.readAsDataURL(blob)");
30 function testSlicedReadAfterClose()
32 debug("Testing that sliced reads aren't affected by close() on 'parent' Blob.");
33 blob
= new Blob(blobContents
);
34 sliced
= blob
.slice(2);
35 shouldBe("sliced.size", "14");
37 var reader
= new FileReader();
38 reader
.onload = function(event
) {
39 result
= event
.target
.result
;
40 shouldBeEqualToString("result", blobContents
[0].slice(2));
42 reader
.onloadend = function() {
43 testPassed("readAsText() completed");
44 shouldBe("sliced.size", "14");
47 reader
.onerror = function(event
) {
48 testFailed("Received error event: " + event
.target
.error
.code
);
50 reader
.readAsText(sliced
);
53 function testContinuedReadAfterClose()
55 debug("Testing that ongoing async reads aren't interrupted by close()");
56 blob
= new Blob(blobContents
);
57 var reader
= new FileReader();
58 reader
.onloadstart = function(event
) {
59 // Close the Blob being read.
61 reader2
= new FileReader();
62 shouldThrow("reader2.readAsArrayBuffer(blob)");
63 shouldBe("blob.size", "0");
65 reader
.onload = function(event
) {
66 testPassed("FileReader loaded: " + event
.target
.result
);
68 reader
.onloadend = function() {
69 testPassed("readAsText() completed");
70 shouldBe("blob.size", "0");
73 reader
.onerror = function(event
) {
74 testFailed("Received error event: " + event
.target
.error
.code
);
77 reader
.readAsText(blob
);
82 testContinuedReadAfterClose
,
83 testSlicedReadAfterClose
];
85 function runNextTest()