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

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

Issue 1506023003: Response construction with a ReadableStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/serviceworker/response-stream-construction.html » ('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-stream-construction.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-stream-construction.js b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-stream-construction.js
new file mode 100644
index 0000000000000000000000000000000000000000..40b4da7868b0d7117c9d661c145451c5602bddb7
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response-stream-construction.js
@@ -0,0 +1,96 @@
+// This file contains tests for Response construction with a readable stream.
+// Move these tests to response.js once the feature gets stable.
+
+if (self.importScripts) {
+ importScripts('../resources/fetch-test-helpers.js');
+ importScripts('/streams/resources/rs-utils.js');
+}
+
+test(() => {
+ var controller;
+ var stream = new ReadableStream({start: c => controller = c});
+
+ var response = new Response(stream);
+ // TODO(yhirano): This should be assert_equals.
+ assert_not_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/serviceworker/response-stream-construction.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698