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

Unified 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: Rebased 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/files/blob-close-expected.txt ('k') | LayoutTests/fast/files/blob-close-read-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « LayoutTests/fast/files/blob-close-expected.txt ('k') | LayoutTests/fast/files/blob-close-read-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698