Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / files / blob-close-read.html
blobbd17f0c584b3294efa359276bcce09f1e46146e7
1 <!doctype html>
2 <script src="../../resources/js-test.js"></script>
3 <script src="resources/read-common.js"></script>
4 <script>
5 description("Test the Blob.close() method, reading.");
7 window.jsTestIsAsync = true;
9 var blobContents = ['0123456789abcdef'];
11 var blob;
12 var sliced;
13 var reader;
14 var reader2;
15 var result;
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)");
27 runNextTest();
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");
36 blob.close();
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");
45 runNextTest();
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.
60 blob.close();
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");
71 runNextTest();
73 reader.onerror = function(event) {
74 testFailed("Received error event: " + event.target.error.code);
75 runNextTest();
77 reader.readAsText(blob);
80 var tests = [
81 testReadAfterClose,
82 testContinuedReadAfterClose,
83 testSlicedReadAfterClose ];
85 function runNextTest()
87 if (!tests.length) {
88 finishJSTest();
89 return;
91 tests.shift()();
94 runNextTest();
95 </script>