| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 reader = res.body.getReader(); | 98 reader = res.body.getReader(); |
| 99 return reader.read(); | 99 return reader.read(); |
| 100 }).then(function(r) { | 100 }).then(function(r) { |
| 101 assert_false(r.done); | 101 assert_false(r.done); |
| 102 read += r.value.byteLength; | 102 read += r.value.byteLength; |
| 103 // Make sure that we received something but we didn't receive all. | 103 // Make sure that we received something but we didn't receive all. |
| 104 assert_not_equals(read, 0); | 104 assert_not_equals(read, 0); |
| 105 assert_not_equals(read, 190); | 105 assert_not_equals(read, 190); |
| 106 | 106 |
| 107 reader.releaseLock(); | 107 reader.releaseLock(); |
| 108 return read_until_end(original.clone().body.getReader()); | 108 var original_body = original.body; |
| 109 }).then(function(chunks) { | 109 var clone = original.clone(); |
| 110 for (var chunk of chunks) { | 110 assert_not_equals(original.body, clone.body); |
| 111 read += chunk.byteLength; | 111 assert_not_equals(original.body, original_body); |
| 112 assert_not_equals(clone.body, original_body); |
| 113 assert_throws({name: 'TypeError'}, function() { |
| 114 original_body.getReader(); |
| 115 }); |
| 116 var reader1 = original.body.getReader(); |
| 117 var reader2 = clone.body.getReader(); |
| 118 return Promise.all([read_until_end(reader1), read_until_end(reader2)]); |
| 119 }).then(function(r) { |
| 120 var read1 = 0; |
| 121 var read2 = 0; |
| 122 for (var chunk of r[0]) { |
| 123 read1 += chunk.byteLength; |
| 124 } |
| 125 for (var chunk of r[1]) { |
| 126 read2 += chunk.byteLength; |
| 112 } | 127 } |
| 113 // Make sure that we received all data in total. | 128 // Make sure that we received all data in total. |
| 114 assert_equals(read, 190); | 129 assert_equals(read + read1, 190); |
| 130 assert_equals(read + read2, 190); |
| 115 }); | 131 }); |
| 116 }, 'Clone after reading partially'); | 132 }, 'Clone after reading partially'); |
| 117 | 133 |
| 118 sequential_promise_test(function(t) { | 134 sequential_promise_test(function(t) { |
| 119 return fetch('/fetch/resources/progressive.php').then(function(res) { | 135 return fetch('/fetch/resources/progressive.php').then(function(res) { |
| 120 res.body.cancel(); | 136 res.body.cancel(); |
| 121 return res.text(); | 137 return res.text(); |
| 122 }).then(function(text) { | 138 }).then(function(text) { |
| 123 assert_equals(text, ''); | 139 assert_equals(text, ''); |
| 124 }); | 140 }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 146 assert_equals(text.length, 190); | 162 assert_equals(text.length, 190); |
| 147 return stream.getReader().read(); | 163 return stream.getReader().read(); |
| 148 }).then(function(r) { | 164 }).then(function(r) { |
| 149 assert_true(r.done); | 165 assert_true(r.done); |
| 150 assert_equals(r.value, undefined); | 166 assert_equals(r.value, undefined); |
| 151 }); | 167 }); |
| 152 }, 'Accessing body when processing text().'); | 168 }, 'Accessing body when processing text().'); |
| 153 | 169 |
| 154 sequential_promise_test_done(); | 170 sequential_promise_test_done(); |
| 155 done(); | 171 done(); |
| OLD | NEW |