| 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 importScripts('/streams/resources/rs-utils.js'); | 3 importScripts('/streams/resources/rs-utils.js'); |
| 4 } | 4 } |
| 5 | 5 |
| 6 promise_test(function(t) { | 6 promise_test(function(t) { |
| 7 return fetch('/fetch/resources/doctype.html').then(function(res) { | 7 return fetch('/fetch/resources/doctype.html').then(function(res) { |
| 8 var stream = res.body; | 8 var stream = res.body; |
| 9 var reader = stream.getReader(); | 9 var reader = stream.getReader(); |
| 10 assert_throws({name: 'TypeError'}, function() { stream.getReader() }); | 10 assert_throws({name: 'TypeError'}, function() { stream.getReader() }); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 for (var chunk of chunks) { | 30 for (var chunk of chunks) { |
| 31 buffer.set(new Uint8Array(chunk), offset); | 31 buffer.set(new Uint8Array(chunk), offset); |
| 32 offset += chunk.byteLength; | 32 offset += chunk.byteLength; |
| 33 } | 33 } |
| 34 return new TextDecoder().decode(buffer); | 34 return new TextDecoder().decode(buffer); |
| 35 }).then(function(string) { | 35 }).then(function(string) { |
| 36 assert_equals(string, '<!DOCTYPE html>\n'); | 36 assert_equals(string, '<!DOCTYPE html>\n'); |
| 37 }); | 37 }); |
| 38 }, 'read contents with ReadableStreamReader'); | 38 }, 'read contents with ReadableStreamReader'); |
| 39 | 39 |
| 40 promise_test(() => { |
| 41 let reader; |
| 42 return fetch('/fetch/resources/progressive.php').then(res => { |
| 43 reader = res.body.getReader(); |
| 44 return Promise.all([reader.read(), reader.read(), reader.read()]); |
| 45 }).then(() => { |
| 46 reader.releaseLock(); |
| 47 // We expect the test finishes without crashing. |
| 48 }); |
| 49 }, 'parallel read'); |
| 50 |
| 40 promise_test(function(t) { | 51 promise_test(function(t) { |
| 41 return fetch('/fetch/resources/progressive.php').then(function(res) { | 52 return fetch('/fetch/resources/progressive.php').then(function(res) { |
| 42 assert_false(res.bodyUsed); | 53 assert_false(res.bodyUsed); |
| 43 var reader = res.body.getReader(); | 54 var reader = res.body.getReader(); |
| 44 assert_false(res.bodyUsed); | 55 assert_false(res.bodyUsed); |
| 45 return res.text().then(unreached_fulfillment(t), function() { | 56 return res.text().then(unreached_fulfillment(t), function() { |
| 46 // text() should fail because the body is locked. | 57 // text() should fail because the body is locked. |
| 47 // TODO(yhirano): Use finally once it gets available. | 58 // TODO(yhirano): Use finally once it gets available. |
| 48 reader.releaseLock(); | 59 reader.releaseLock(); |
| 49 }); | 60 }); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 79 assert_true(res.bodyUsed); | 90 assert_true(res.bodyUsed); |
| 80 assert_false(clone.bodyUsed); | 91 assert_false(clone.bodyUsed); |
| 81 return clone.arrayBuffer(); | 92 return clone.arrayBuffer(); |
| 82 }).then(function(r) { | 93 }).then(function(r) { |
| 83 assert_equals(r.byteLength, 190); | 94 assert_equals(r.byteLength, 190); |
| 84 assert_true(clone.bodyUsed); | 95 assert_true(clone.bodyUsed); |
| 85 }); | 96 }); |
| 86 }, 'Cancelling stream should not affect cloned one.'); | 97 }, 'Cancelling stream should not affect cloned one.'); |
| 87 | 98 |
| 88 done(); | 99 done(); |
| OLD | NEW |