Index: LayoutTests/fast/files/blob-close-read.html |
diff --git a/LayoutTests/fast/files/blob-close-read.html b/LayoutTests/fast/files/blob-close-read.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bd17f0c584b3294efa359276bcce09f1e46146e7 |
--- /dev/null |
+++ b/LayoutTests/fast/files/blob-close-read.html |
@@ -0,0 +1,95 @@ |
+<!doctype html> |
+<script src="../../resources/js-test.js"></script> |
+<script src="resources/read-common.js"></script> |
+<script> |
+description("Test the Blob.close() method, reading."); |
+ |
+window.jsTestIsAsync = true; |
+ |
+var blobContents = ['0123456789abcdef']; |
+ |
+var blob; |
+var sliced; |
+var reader; |
+var reader2; |
+var result; |
+ |
+function testReadAfterClose() |
+{ |
+ debug("Testing that the reading of closed Blobs fail."); |
+ blob = new Blob(blobContents); |
+ shouldBe("blob.close(); blob.size", "0"); |
+ reader = new FileReader(); |
+ shouldThrow("reader.readAsArrayBuffer(blob)"); |
+ shouldThrow("reader.readAsBinaryString(blob)"); |
+ shouldThrow("reader.readAsText(blob)"); |
+ shouldThrow("reader.readAsDataURL(blob)"); |
+ runNextTest(); |
+} |
+ |
+function testSlicedReadAfterClose() |
+{ |
+ debug("Testing that sliced reads aren't affected by close() on 'parent' Blob."); |
+ blob = new Blob(blobContents); |
+ sliced = blob.slice(2); |
+ shouldBe("sliced.size", "14"); |
+ blob.close(); |
+ var reader = new FileReader(); |
+ reader.onload = function(event) { |
+ result = event.target.result; |
+ shouldBeEqualToString("result", blobContents[0].slice(2)); |
+ } |
+ reader.onloadend = function() { |
+ testPassed("readAsText() completed"); |
+ shouldBe("sliced.size", "14"); |
+ runNextTest(); |
+ } |
+ reader.onerror = function(event) { |
+ testFailed("Received error event: " + event.target.error.code); |
+ }; |
+ reader.readAsText(sliced); |
+} |
+ |
+function testContinuedReadAfterClose() |
+{ |
+ debug("Testing that ongoing async reads aren't interrupted by close()"); |
+ blob = new Blob(blobContents); |
+ var reader = new FileReader(); |
+ reader.onloadstart = function(event) { |
+ // Close the Blob being read. |
+ blob.close(); |
+ reader2 = new FileReader(); |
+ shouldThrow("reader2.readAsArrayBuffer(blob)"); |
+ shouldBe("blob.size", "0"); |
+ } |
+ reader.onload = function(event) { |
+ testPassed("FileReader loaded: " + event.target.result); |
+ } |
+ reader.onloadend = function() { |
+ testPassed("readAsText() completed"); |
+ shouldBe("blob.size", "0"); |
+ runNextTest(); |
+ } |
+ reader.onerror = function(event) { |
+ testFailed("Received error event: " + event.target.error.code); |
+ runNextTest(); |
+ }; |
+ reader.readAsText(blob); |
+} |
+ |
+var tests = [ |
+ testReadAfterClose, |
+ testContinuedReadAfterClose, |
+ testSlicedReadAfterClose ]; |
+ |
+function runNextTest() |
+{ |
+ if (!tests.length) { |
+ finishJSTest(); |
+ return; |
+ } |
+ tests.shift()(); |
+} |
+ |
+runNextTest(); |
+</script> |