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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('../resources/fetch-test-helpers.js'); 2 importScripts('../resources/fetch-test-helpers.js');
3 importScripts('/streams/resources/rs-utils.js'); 3 importScripts('/streams/resources/rs-utils.js');
4 } 4 }
5 5
6 function decode(chunks) { 6 function decode(chunks) {
7 var decoder = new TextDecoder(); 7 var decoder = new TextDecoder();
8 var result = ''; 8 var result = '';
9 for (var chunk of chunks) { 9 for (var chunk of chunks) {
10 result += decoder.decode(chunk, {stream: true}); 10 result += decoder.decode(chunk, {stream: true});
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 459
460 test(function() { 460 test(function() {
461 ['http://ex\x0aample.com', 461 ['http://ex\x0aample.com',
462 'http://ex\x0dample.com'].forEach(function(url) { 462 'http://ex\x0dample.com'].forEach(function(url) {
463 assert_equals(Response.redirect(url).headers.get('Location'), 463 assert_equals(Response.redirect(url).headers.get('Location'),
464 'http://example.com/', 464 'http://example.com/',
465 'Location header value must not contain CR or LF'); 465 'Location header value must not contain CR or LF');
466 }); 466 });
467 }, 'Response.redirect() with URLs with CR or LF'); 467 }, 'Response.redirect() with URLs with CR or LF');
468 468
469 test(() => {
470 var controller;
471 var stream = new ReadableStream({start: c => controller = c});
472
473 var response = new Response(stream);
474 assert_equals(response.body, stream);
475 }, 'Response constructed with a stream');
476
477 promise_test(() => {
478 var controller;
479 var stream = new ReadableStream({start: c => controller = c});
480 controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
481 controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
482 controller.close();
483 assert_false(stream.locked);
484 var response = new Response(stream);
485 var p = response.text().then(t => {
486 assert_equals(t, 'helloworld');
487 });
488 assert_true(stream.locked);
489 return p;
490 }, 'Response constructed with a stream');
491
492 promise_test(() => {
493 var controller;
494 var stream = new ReadableStream({start: c => controller = c});
495 controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
496 controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
497 controller.close();
498
499 var response = new Response(stream);
500 return readableStreamToArray(response.body).then(chunks => {
501 var decoder = new TextDecoder('utf-8');
502 var r = '';
503 for (var chunk of chunks) {
504 r += decoder.decode(chunk, {stream: true});
505 }
506 r += decoder.decode();
507 assert_equals(r, 'helloworld');
508 });
509 }, 'Response constructed with a stream / Read from body stream');
510
511 promise_test(t => {
512 var controller;
513 var stream = new ReadableStream({start: c => controller = c});
514 setTimeout(() => {
515 controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
516 controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
517 controller.error();
518 }, 1);
519 var response = new Response(stream);
520 return promise_rejects(t, TypeError(), response.text());
521 }, 'Response constructed with an errored stream');
522
523 promise_test(t => {
524 var controller;
525 var stream = new ReadableStream({start: c => controller = c});
526 stream.getReader();
527 var response = new Response(stream);
528 return promise_rejects(t, TypeError(), response.text());
529 }, 'Response constructed with a locked stream');
530
531 promise_test(t => {
532 var controller;
533 var stream = new ReadableStream({start: c => controller = c});
534 setTimeout(() => controller.enqueue(), 1);
535 var response = new Response(stream);
536 return promise_rejects(t, TypeError(), response.text());
537 }, 'Response constructed stream with an undefined chunk');
538
539 promise_test(t => {
540 var controller;
541 var stream = new ReadableStream({start: c => controller = c});
542 setTimeout(() => controller.enqueue(null), 1);
543 var response = new Response(stream);
544 return promise_rejects(t, TypeError(), response.text());
545 }, 'Response constructed stream with a null chunk');
546
547 promise_test(t => {
548 var controller;
549 var stream = new ReadableStream({start: c => controller = c});
550 setTimeout(() => controller.enqueue('hello'), 1);
551 var response = new Response(stream);
552 return promise_rejects(t, TypeError(), response.text());
553 }, 'Response constructed stream with a string chunk');
554
469 done(); 555 done();
OLDNEW
« 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