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

Side by Side Diff: LayoutTests/http/tests/fetch/script-tests/stream-reader.js

Issue 1018243002: [Fetch] Support various operations after reading data partially. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@async-read
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | Source/modules/fetch/Body.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/fetch/resources/fetch-test-helpers.js'); 2 importScripts('/fetch/resources/fetch-test-helpers.js');
3 } 3 }
4 4
5 function read_until_end(reader) { 5 function read_until_end(reader) {
6 var chunks = []; 6 var chunks = [];
7 function consume() { 7 function consume() {
8 return reader.read().then(function(r) { 8 return reader.read().then(function(r) {
9 if (r.done) { 9 if (r.done) {
10 return chunks; 10 return chunks;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 res.body; 68 res.body;
69 assert_false(res.bodyUsed); 69 assert_false(res.bodyUsed);
70 res.text(); 70 res.text();
71 assert_true(res.bodyUsed); 71 assert_true(res.bodyUsed);
72 // FIXME: Getting a reader should throw, but it doesn't because the 72 // FIXME: Getting a reader should throw, but it doesn't because the
73 // current implementation closes the body. 73 // current implementation closes the body.
74 // assert_throws({name: 'TypeError'}, function() { res.body.getReader() }); 74 // assert_throws({name: 'TypeError'}, function() { res.body.getReader() });
75 }); 75 });
76 }, 'Setting bodyUsed means the body is locked.'); 76 }, 'Setting bodyUsed means the body is locked.');
77 77
78 sequential_promise_test(function(t) {
79 var reader;
80 var read = 0;
81 var original;
82 return fetch('/fetch/resources/progressive.php').then(function(res) {
83 original = res;
84 reader = res.body.getReader();
85 return reader.read();
86 }).then(function(r) {
87 assert_false(r.done);
88 read += r.value.byteLength;
89 // Make sure that we received something but we didn't receive all.
90 assert_not_equals(read, 0);
91 assert_not_equals(read, 190);
92
93 reader.releaseLock();
94 return read_until_end(original.clone().body.getReader());
95 }).then(function(chunks) {
96 for (var chunk of chunks) {
97 read += chunk.byteLength;
98 }
99 // Make sure that we received all data in total.
100 assert_equals(read, 190);
101 });
102 }, 'Clone after reading partially');
103
78 sequential_promise_test_done(); 104 sequential_promise_test_done();
79 done(); 105 done();
OLDNEW
« no previous file with comments | « no previous file | Source/modules/fetch/Body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698