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

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

Issue 2675163003: Merge response-stream-construction.js to response.js (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-stream-construction.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js
index 3dd2c68bc48734f8b1b94ff35265dc1ed06e0a92..b0d9c4022f0b8eb18c3a587b087b21aeea0de83c 100644
--- a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js
+++ b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js
@@ -466,4 +466,90 @@ test(function() {
});
}, 'Response.redirect() with URLs with CR or LF');
+test(() => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+
+ var response = new Response(stream);
+ assert_equals(response.body, stream);
+ }, 'Response constructed with a stream');
+
+promise_test(() => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
+ controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
+ controller.close();
+ assert_false(stream.locked);
+ var response = new Response(stream);
+ var p = response.text().then(t => {
+ assert_equals(t, 'helloworld');
+ });
+ assert_true(stream.locked);
+ return p;
+ }, 'Response constructed with a stream');
+
+promise_test(() => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
+ controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
+ controller.close();
+
+ var response = new Response(stream);
+ return readableStreamToArray(response.body).then(chunks => {
+ var decoder = new TextDecoder('utf-8');
+ var r = '';
+ for (var chunk of chunks) {
+ r += decoder.decode(chunk, {stream: true});
+ }
+ r += decoder.decode();
+ assert_equals(r, 'helloworld');
+ });
+ }, 'Response constructed with a stream / Read from body stream');
+
+promise_test(t => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ setTimeout(() => {
+ controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
+ controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
+ controller.error();
+ }, 1);
+ var response = new Response(stream);
+ return promise_rejects(t, TypeError(), response.text());
+ }, 'Response constructed with an errored stream');
+
+promise_test(t => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ stream.getReader();
+ var response = new Response(stream);
+ return promise_rejects(t, TypeError(), response.text());
+ }, 'Response constructed with a locked stream');
+
+promise_test(t => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ setTimeout(() => controller.enqueue(), 1);
+ var response = new Response(stream);
+ return promise_rejects(t, TypeError(), response.text());
+ }, 'Response constructed stream with an undefined chunk');
+
+promise_test(t => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ setTimeout(() => controller.enqueue(null), 1);
+ var response = new Response(stream);
+ return promise_rejects(t, TypeError(), response.text());
+ }, 'Response constructed stream with a null chunk');
+
+promise_test(t => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+ setTimeout(() => controller.enqueue('hello'), 1);
+ var response = new Response(stream);
+ return promise_rejects(t, TypeError(), response.text());
+ }, 'Response constructed stream with a string chunk');
+
done();
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-stream-construction.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698