Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/stream-reader.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/stream-reader.js b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/stream-reader.js |
| index 0508ae808a86a6a44fb7e541c6f624ffb6e2245a..562782c057e8a99dbc361554a2d9c6fbcc78a34d 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/stream-reader.js |
| +++ b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/stream-reader.js |
| @@ -62,109 +62,38 @@ promise_test(function(t) { |
| }, 'acquiring a reader should set bodyUsed.'); |
| promise_test(function(t) { |
| + var reader; |
| var response; |
| return fetch('/fetch/resources/progressive.php').then(function(res) { |
| response = res; |
| - assert_false(res.bodyUsed); |
| - var p = res.arrayBuffer(); |
| - assert_true(res.bodyUsed); |
| - assert_throws({name: 'TypeError'}, function() { res.body.getReader() }); |
| - return p; |
| - }).then(function(buffer) { |
| - assert_equals(buffer.byteLength, 190); |
| - // Now we can obtain a (closed) reader. |
| - return response.body.getReader().closed; |
| - }); |
| - }, 'Setting bodyUsed means the body is locked.'); |
| - |
| -promise_test(function(t) { |
| - return fetch('/fetch/resources/slow-failure.cgi').then(function(res) { |
| - return res.text().then(function() { |
| - assert_unreached('text() should fail'); |
| - }, function(e) { |
| - return res.body.getReader().closed.then(function() { |
| - assert_unreached('res.body should be errored'); |
| - }, function(e) {}); |
| - }); |
| - }); |
| - }, 'Error in text() should be propagated to the body stream.'); |
| - |
| -promise_test(function(t) { |
| - var reader; |
| - var read = 0; |
| - var original; |
| - return fetch('/fetch/resources/progressive.php').then(function(res) { |
| - original = res; |
| reader = res.body.getReader(); |
| return reader.read(); |
| - }).then(function(r) { |
| - assert_false(r.done); |
| - read += r.value.byteLength; |
| - // Make sure that we received something but we didn't receive all. |
| - assert_not_equals(read, 0); |
| - assert_not_equals(read, 190); |
| - |
| + }).then(() => { |
| reader.releaseLock(); |
| - var original_body = original.body; |
| - var clone = original.clone(); |
| - assert_not_equals(original.body, clone.body); |
| - assert_not_equals(original.body, original_body); |
| - assert_not_equals(clone.body, original_body); |
| - assert_throws({name: 'TypeError'}, function() { |
| - original_body.getReader(); |
| - }); |
| - var reader1 = original.body.getReader(); |
| - var reader2 = clone.body.getReader(); |
| - return Promise.all([read_until_end(reader1), read_until_end(reader2)]); |
| - }).then(function(r) { |
| - var read1 = 0; |
| - var read2 = 0; |
| - for (var chunk of r[0]) { |
| - read1 += chunk.byteLength; |
| - } |
| - for (var chunk of r[1]) { |
| - read2 += chunk.byteLength; |
| - } |
| - // Make sure that we received all data in total. |
| - assert_equals(read + read1, 190); |
| - assert_equals(read + read2, 190); |
| + assert_true(response.bodyUsed); |
| + assert_throws(new TypeError, () => { response.clone(); }); |
| }); |
| - }, 'Clone after reading partially'); |
| + }, 'Clone after reading'); |
| promise_test(function(t) { |
| return fetch('/fetch/resources/progressive.php').then(function(res) { |
| res.body.cancel(); |
| - return res.text(); |
| - }).then(function(text) { |
| - assert_equals(text, ''); |
| + assert_true(res.bodyUsed); |
| }); |
| }, 'Cancelling stream stops downloading.'); |
| promise_test(function(t) { |
| + var clone; |
| return fetch('/fetch/resources/progressive.php').then(function(res) { |
| - var clone = res.clone(); |
| + clone = res.clone(); |
| res.body.cancel(); |
| - return Promise.all([res.arrayBuffer(), clone.arrayBuffer()]); |
| + assert_true(res.bodyUsed); |
| + assert_false(clone.bodyUsed); |
| + return clone.arrayBuffer(); |
| }).then(function(r) { |
| - assert_equals(r[0].byteLength, 0); |
| - assert_equals(r[1].byteLength, 190); |
| + assert_equals(r.byteLength, 190); |
| + assert_true(clone.bodyUsed); |
| }); |
| }, 'Cancelling stream should not affect cloned one.'); |
|
tyoshino (SeeGerritForStatus)
2015/11/18 09:55:36
how about moving these to response.js as it's not
yhirano
2015/11/19 08:41:29
request.js and response.js don't contain tests usi
|
| -promise_test(function(t) { |
| - var stream; |
| - return fetch('/fetch/resources/progressive.php').then(function(res) { |
| - var p = res.text(); |
| - stream = res.body; |
| - assert_throws({name: 'TypeError'}, function() { stream.getReader() }); |
| - return p; |
| - }).then(function(text) { |
| - assert_equals(text.length, 190); |
| - return stream.getReader().read(); |
| - }).then(function(r) { |
| - assert_true(r.done); |
| - assert_equals(r.value, undefined); |
| - }); |
| - }, 'Accessing body when processing text().'); |
| - |
| done(); |