Chromium Code Reviews| 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 let body; | |
|
tyoshino (SeeGerritForStatus)
2016/09/06 10:58:06
body no longer need to be declared outside?
yhirano
2016/09/06 11:03:07
Done.
| |
| 43 return fetch('/fetch/resources/progressive.php').then(res => { | |
| 44 body = res.body; | |
|
tyoshino (SeeGerritForStatus)
2016/09/06 10:58:06
ah, this line itself is no longer needed.
yhirano
2016/09/06 11:03:07
Done.
| |
| 45 reader = res.body.getReader(); | |
| 46 return Promise.all([reader.read(), reader.read(), reader.read()]); | |
| 47 }).then(() => { | |
| 48 reader.releaseLock(); | |
| 49 // We expect the test finishes without crashing. | |
| 50 }); | |
| 51 }, 'parallel read'); | |
| 52 | |
| 40 promise_test(function(t) { | 53 promise_test(function(t) { |
| 41 return fetch('/fetch/resources/progressive.php').then(function(res) { | 54 return fetch('/fetch/resources/progressive.php').then(function(res) { |
| 42 assert_false(res.bodyUsed); | 55 assert_false(res.bodyUsed); |
| 43 var reader = res.body.getReader(); | 56 var reader = res.body.getReader(); |
| 44 assert_false(res.bodyUsed); | 57 assert_false(res.bodyUsed); |
| 45 return res.text().then(unreached_fulfillment(t), function() { | 58 return res.text().then(unreached_fulfillment(t), function() { |
| 46 // text() should fail because the body is locked. | 59 // text() should fail because the body is locked. |
| 47 // TODO(yhirano): Use finally once it gets available. | 60 // TODO(yhirano): Use finally once it gets available. |
| 48 reader.releaseLock(); | 61 reader.releaseLock(); |
| 49 }); | 62 }); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 79 assert_true(res.bodyUsed); | 92 assert_true(res.bodyUsed); |
| 80 assert_false(clone.bodyUsed); | 93 assert_false(clone.bodyUsed); |
| 81 return clone.arrayBuffer(); | 94 return clone.arrayBuffer(); |
| 82 }).then(function(r) { | 95 }).then(function(r) { |
| 83 assert_equals(r.byteLength, 190); | 96 assert_equals(r.byteLength, 190); |
| 84 assert_true(clone.bodyUsed); | 97 assert_true(clone.bodyUsed); |
| 85 }); | 98 }); |
| 86 }, 'Cancelling stream should not affect cloned one.'); | 99 }, 'Cancelling stream should not affect cloned one.'); |
| 87 | 100 |
| 88 done(); | 101 done(); |
| OLD | NEW |