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 rec(resolve, reject) { | 7 function rec(resolve, reject) { |
8 while (reader.state === 'readable') { | 8 while (reader.state === 'readable') { |
9 chunks.push(reader.read()); | 9 chunks.push(reader.read()); |
10 } | 10 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 for (var chunk of chunks) { | 81 for (var chunk of chunks) { |
82 buffer.set(new Uint8Array(chunk), offset); | 82 buffer.set(new Uint8Array(chunk), offset); |
83 offset += chunk.byteLength; | 83 offset += chunk.byteLength; |
84 } | 84 } |
85 return new TextDecoder().decode(buffer); | 85 return new TextDecoder().decode(buffer); |
86 }).then(function(string) { | 86 }).then(function(string) { |
87 assert_equals(string, '<!DOCTYPE html>\n'); | 87 assert_equals(string, '<!DOCTYPE html>\n'); |
88 }); | 88 }); |
89 }, 'read contents with ExclusiveStreamReader'); | 89 }, 'read contents with ExclusiveStreamReader'); |
90 | 90 |
| 91 sequential_promise_test(function(t) { |
| 92 return fetch('/fetch/resources/progressive.php').then(function(res) { |
| 93 assert_false(res.bodyUsed); |
| 94 var reader = res.body.getReader(); |
| 95 assert_true(res.bodyUsed); |
| 96 return res; |
| 97 }).then(function(res) { |
| 98 return res.text(); |
| 99 }).then(unreached_rejection(t), function() { |
| 100 // text() should fail because bodyUsed is set. |
| 101 }); |
| 102 }, 'acquiring a reader should set bodyUsed.'); |
| 103 |
| 104 sequential_promise_test(function(t) { |
| 105 return fetch('/fetch/resources/progressive.php').then(function(res) { |
| 106 // We need to access body attribute to start the stream. |
| 107 res.body; |
| 108 assert_false(res.bodyUsed); |
| 109 res.text(); |
| 110 assert_true(res.bodyUsed); |
| 111 assert_throws({name: 'TypeError'}, function() { res.body.getReader() }); |
| 112 }); |
| 113 }, 'Setting bodyUsed means the body is locked.'); |
| 114 |
91 sequential_promise_test_done(); | 115 sequential_promise_test_done(); |
92 done(); | 116 done(); |
OLD | NEW |