Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: LayoutTests/fast/files/blob-close-read.html

Issue 157363003: Implement Blob.close(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Avoid warning from PHP's fread() on empty reads Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.");
6
7 window.jsTestIsAsync = true;
8
9 var blobContents = ['0123456789abcdef'];
10
11 var blob;
12 var sliced;
13 var reader;
14 var reader2;
15 var result;
16
17 function testReadAfterClose()
18 {
19 debug("Testing that the reading of closed Blobs fail.");
20 blob = buildBlob(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();
28 }
29
30 function testSlicedReadAfterClose()
31 {
32 debug("Testing that sliced reads aren't affected by close() on 'parent' Blob .");
33 blob = buildBlob(blobContents);
34 sliced = blob.slice(2);
35 blob.close();
36 var reader = new FileReader();
37 reader.onload = function(event) {
38 result = event.target.result;
39 shouldBeEqualToString("result", blobContents[0].slice(2));
40 }
41 reader.onloadend = function() {
42 testPassed("readAsText() completed");
43 shouldBe("sliced.size", "14");
44 runNextTest();
45 }
46 reader.onerror = function(event) {
47 testFailed("Received error event: " + event.target.error.code);
48 };
49 reader.readAsText(sliced);
50 }
51
52 function testContinuedReadAfterClose()
53 {
54 debug("Testing that ongoing async reads aren't interrupted by close()");
55 blob = buildBlob(blobContents);
56 var reader = new FileReader();
57 reader.onloadstart = function(event) {
58 // Close the Blob being read.
59 blob.close();
60 reader2 = new FileReader();
61 shouldThrow("reader2.readAsArrayBuffer(blob)");
62 shouldBe("blob.size", "0");
63 }
64 reader.onload = function(event) {
65 testPassed("FileReader loaded: " + event.target.result);
66 }
67 reader.onloadend = function() {
68 testPassed("readAsText() completed");
69 shouldBe("blob.size", "0");
70 runNextTest();
71 }
72 reader.onerror = function(event) {
73 testFailed("Received error event: " + event.target.error.code);
74 runNextTest();
75 };
76 reader.readAsText(blob);
77 }
78
79 var tests = [
80 testReadAfterClose,
81 testContinuedReadAfterClose,
82 testSlicedReadAfterClose ];
83
84 function runNextTest()
85 {
86 if (!tests.length) {
87 finishJSTest();
88 return;
89 }
90 tests.shift()();
91 }
92
93 runNextTest();
94 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698