OLD | NEW |
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 Loading... |
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(); |
OLD | NEW |