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

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

Issue 2671213003: BodyStreamBuffer should take care the case where endRead returns Done (Closed)
Patch Set: fix 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/Source/modules/fetch/BodyStreamBuffer.cpp » ('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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 assert_false(stream.locked); 483 assert_false(stream.locked);
484 var response = new Response(stream); 484 var response = new Response(stream);
485 var p = response.text().then(t => { 485 var p = response.text().then(t => {
486 assert_equals(t, 'helloworld'); 486 assert_equals(t, 'helloworld');
487 }); 487 });
488 assert_true(stream.locked); 488 assert_true(stream.locked);
489 return p; 489 return p;
490 }, 'Response constructed with a stream'); 490 }, 'Response constructed with a stream');
491 491
492 promise_test(() => { 492 promise_test(() => {
493 var response = new Response('helloworld');
494 return readableStreamToArray(response.body).then(chunks => {
495 const decoder = new TextDecoder('utf-8');
496 let r = '';
497 for (const chunk of chunks) {
498 r += decoder.decode(chunk, {stream: true});
499 }
500 r += decoder.decode();
501 assert_equals(r, 'helloworld');
502 });
503 }, 'Response constructed with a String / Read from body stream');
504
505 promise_test(() => {
493 var controller; 506 var controller;
494 var stream = new ReadableStream({start: c => controller = c}); 507 var stream = new ReadableStream({start: c => controller = c});
495 controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])); 508 controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
496 controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64])); 509 controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
497 controller.close(); 510 controller.close();
498 511
499 var response = new Response(stream); 512 var response = new Response(stream);
500 return readableStreamToArray(response.body).then(chunks => { 513 return readableStreamToArray(response.body).then(chunks => {
501 var decoder = new TextDecoder('utf-8'); 514 var decoder = new TextDecoder('utf-8');
502 var r = ''; 515 var r = '';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 559
547 promise_test(t => { 560 promise_test(t => {
548 var controller; 561 var controller;
549 var stream = new ReadableStream({start: c => controller = c}); 562 var stream = new ReadableStream({start: c => controller = c});
550 setTimeout(() => controller.enqueue('hello'), 1); 563 setTimeout(() => controller.enqueue('hello'), 1);
551 var response = new Response(stream); 564 var response = new Response(stream);
552 return promise_rejects(t, TypeError(), response.text()); 565 return promise_rejects(t, TypeError(), response.text());
553 }, 'Response constructed stream with a string chunk'); 566 }, 'Response constructed stream with a string chunk');
554 567
555 done(); 568 done();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698