Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: LayoutTests/http/tests/fetch/script-tests/response.js

Issue 1053503002: [Fetch] Response.clone should tee the body stream. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/fetch/script-tests/response.js
diff --git a/LayoutTests/http/tests/fetch/script-tests/response.js b/LayoutTests/http/tests/fetch/script-tests/response.js
index 8e836a1a949f1a675e5c911bfa3594befef3b78a..4fb92e8ec156af137b104f5fa6300decd9bafe02 100644
--- a/LayoutTests/http/tests/fetch/script-tests/response.js
+++ b/LayoutTests/http/tests/fetch/script-tests/response.js
@@ -24,17 +24,14 @@ function consume(reader) {
return rec(reader);
}
-function flatten(chunks) {
- var size = 0;
+function decode(chunks) {
+ var decoder = new TextDecoder();
+ var result = '';
for (var chunk of chunks) {
- size += chunk.byteLength;
+ result += decoder.decode(chunk, {stream: true});
}
- var buffer = new Uint8Array(size);
- var current = 0;
- for (var chunk of chunks) {
- buffer.set(chunk, 0);
- }
- return buffer;
+ result += decoder.decode(new Uint8Array(0));
+ return result;
}
test(function() {
@@ -296,9 +293,9 @@ test(function() {
promise_test(function(t) {
var res = new Response('hello');
return consume(res.body.getReader()).then(function(chunks) {
- return flatten(chunks);
- }).then(function(view) {
- assert_equals(new TextDecoder().decode(view), 'hello');
+ return decode(chunks);
+ }).then(function(text) {
+ assert_equals(text, 'hello');
return res.body.getReader().read();
}).then(function(r) {
assert_true(r.done);
@@ -349,12 +346,33 @@ promise_test(function(t) {
promise_test(function(t) {
var res = new Response('hello');
+ var body = res.body;
var clone = res.clone();
+ assert_not_equals(res.body, body);
+ assert_not_equals(res.body, clone.body);
+ assert_not_equals(body, clone.body);
+ assert_throws({name: 'TypeError'}, function() { body.getReader(); });
return Promise.all([res.text(), clone.text()]).then(function(r) {
assert_equals(r[0], 'hello');
assert_equals(r[1], 'hello');
});
- }, 'Clone on Response');
+ }, 'Clone on Response (text)');
+
+promise_test(function(t) {
+ var res = new Response('hello');
+ var body = res.body;
+ var clone = res.clone();
+ assert_not_equals(res.body, body);
+ assert_not_equals(res.body, clone.body);
+ assert_not_equals(body, clone.body);
+ assert_throws({name: 'TypeError'}, function() { body.getReader(); });
+ var reader1 = res.body.getReader();
+ var reader2 = clone.body.getReader();
+ return Promise.all([consume(reader1), consume(reader2)]).then(function(r) {
+ assert_equals(decode(r[0]), 'hello');
+ assert_equals(decode(r[1]), 'hello');
+ });
+ }, 'Clone on Response (manual read)');
promise_test(function(t) {
var res = new Response('hello');
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/request.js ('k') | LayoutTests/http/tests/fetch/script-tests/stream-reader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698