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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/general.js

Issue 1902673003: Reflect recent spec changes to V8 Extra ReadableStream impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build Created 4 years, 7 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
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 self.importScripts('../resources/test-utils.js'); 4 self.importScripts('../resources/test-utils.js');
5 self.importScripts('../resources/rs-utils.js'); 5 self.importScripts('../resources/rs-utils.js');
6 self.importScripts('/resources/testharness.js'); 6 self.importScripts('/resources/testharness.js');
7 } 7 }
8 8
9 test(() => { 9 test(() => {
10 10
11 new ReadableStream(); // ReadableStream constructed with no parameters 11 new ReadableStream(); // ReadableStream constructed with no parameters
12 new ReadableStream({ }); // ReadableStream constructed with an empty object as parameter 12 new ReadableStream({ }); // ReadableStream constructed with an empty object as parameter
13 new ReadableStream({ type: undefined }); // ReadableStream constructed with un defined type
13 new ReadableStream(undefined); // ReadableStream constructed with undefined as parameter 14 new ReadableStream(undefined); // ReadableStream constructed with undefined as parameter
14 15
15 let x; 16 let x;
16 new ReadableStream(x); // ReadableStream constructed with an undefined variabl e as parameter 17 new ReadableStream(x); // ReadableStream constructed with an undefined variabl e as parameter
17 18
18 }, 'ReadableStream can be constructed with no errors'); 19 }, 'ReadableStream can be constructed with no errors');
19 20
20 test(() => { 21 test(() => {
21 22
22 assert_throws(new TypeError(), () => new ReadableStream(null), 'constructor sh ould throw when the source is null'); 23 assert_throws(new TypeError(), () => new ReadableStream(null), 'constructor sh ould throw when the source is null');
23 24
24 }, 'ReadableStream can\'t be constructed with garbage'); 25 }, 'ReadableStream can\'t be constructed with garbage');
25 26
26 test(() => { 27 test(() => {
27 28
29 assert_throws(new RangeError(), () => new ReadableStream({ type: null }),
30 'constructor should throw when the type is null');
31 assert_throws(new RangeError(), () => new ReadableStream({ type: '' }),
32 'constructor should throw when the type is empty string');
33 assert_throws(new RangeError(), () => new ReadableStream({ type: 'asdf' }),
34 'constructor should throw when the type is asdf');
35
36 }, 'ReadableStream can\'t be constructed with an invalid type');
37
38 test(() => {
39
28 const methods = ['cancel', 'constructor', 'getReader', 'tee']; 40 const methods = ['cancel', 'constructor', 'getReader', 'tee'];
29 const properties = methods.concat(['locked']).sort(); 41 const properties = methods.concat(['locked']).sort();
30 42
31 const rs = new ReadableStream(); 43 const rs = new ReadableStream();
32 const proto = Object.getPrototypeOf(rs); 44 const proto = Object.getPrototypeOf(rs);
33 45
34 assert_array_equals(Object.getOwnPropertyNames(proto).sort(), properties, 'sho uld have all the correct methods'); 46 assert_array_equals(Object.getOwnPropertyNames(proto).sort(), properties, 'sho uld have all the correct methods');
35 47
36 for (const m of methods) { 48 for (const m of methods) {
37 const propDesc = Object.getOwnPropertyDescriptor(proto, m); 49 const propDesc = Object.getOwnPropertyDescriptor(proto, m);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 111 }
100 112
101 const desiredSizePropDesc = Object.getOwnPropertyDescriptor(proto, 'desire dSize'); 113 const desiredSizePropDesc = Object.getOwnPropertyDescriptor(proto, 'desire dSize');
102 assert_false(desiredSizePropDesc.enumerable, 'desiredSize should be non-en umerable'); 114 assert_false(desiredSizePropDesc.enumerable, 'desiredSize should be non-en umerable');
103 assert_equals(desiredSizePropDesc.writable, undefined, 'desiredSize should not be a data property'); 115 assert_equals(desiredSizePropDesc.writable, undefined, 'desiredSize should not be a data property');
104 assert_equals(typeof desiredSizePropDesc.get, 'function', 'desiredSize sho uld have a getter'); 116 assert_equals(typeof desiredSizePropDesc.get, 'function', 'desiredSize sho uld have a getter');
105 assert_equals(desiredSizePropDesc.set, undefined, 'desiredSize should not have a setter'); 117 assert_equals(desiredSizePropDesc.set, undefined, 'desiredSize should not have a setter');
106 assert_true(desiredSizePropDesc.configurable, 'desiredSize should be confi gurable'); 118 assert_true(desiredSizePropDesc.configurable, 'desiredSize should be confi gurable');
107 119
108 assert_equals(controller.close.length, 0, 'close should have no parameters '); 120 assert_equals(controller.close.length, 0, 'close should have no parameters ');
109 assert_equals(controller.constructor.length, 1, 'constructor should have 1 parameter'); 121 assert_equals(controller.constructor.length, 5, 'constructor should have 4 parameter');
110 assert_equals(controller.enqueue.length, 1, 'enqueue should have 1 paramet er'); 122 assert_equals(controller.enqueue.length, 1, 'enqueue should have 1 paramet er');
111 assert_equals(controller.error.length, 1, 'error should have 1 parameter') ; 123 assert_equals(controller.error.length, 1, 'error should have 1 parameter') ;
112 124
113 startCalled = true; 125 startCalled = true;
114 } 126 }
115 }; 127 };
116 128
117 new ReadableStream(source); 129 new ReadableStream(source);
118 assert_true(startCalled); 130 assert_true(startCalled);
119 131
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 611 }
600 }); 612 });
601 613
602 const reader = rs.getReader(); 614 const reader = rs.getReader();
603 return reader.closed.then(() => { 615 return reader.closed.then(() => {
604 assert_true(pullCalled); 616 assert_true(pullCalled);
605 }); 617 });
606 618
607 }, 'ReadableStream pull should be able to close a stream.'); 619 }, 'ReadableStream pull should be able to close a stream.');
608 620
609 test(() => { 621 promise_test(t => {
610 622
611 let startCalled = false; 623 const controllerError = { name: 'controller error' };
612 624
613 new ReadableStream({ 625 const rs = new ReadableStream({
614 start(c) { 626 pull(c) {
615 assert_equals(c.enqueue('a'), undefined, 'the first enqueue should return undefined'); 627 c.error(controllerError);
616 c.close();
617
618 assert_throws(new TypeError(), () => c.enqueue('b'), 'enqueue after close should throw a TypeError');
619 startCalled = true;
620 } 628 }
621 }); 629 });
622 630
623 assert_true(startCalled); 631 return promise_rejects(t, controllerError, rs.getReader().closed);
624 632
625 }, 'ReadableStream: enqueue should throw when the stream is readable but drainin g'); 633 }, 'ReadableStream pull should be able to error a stream.');
634
635 promise_test(t => {
636
637 const controllerError = { name: 'controller error' };
638 const thrownError = { name: 'thrown error' };
639
640 const rs = new ReadableStream({
641 pull(c) {
642 c.error(controllerError);
643 throw thrownError;
644 }
645 });
646
647 return promise_rejects(t, controllerError, rs.getReader().closed);
648
649 }, 'ReadableStream pull should be able to error a stream and throw.');
626 650
627 test(() => { 651 test(() => {
628 652
629 let startCalled = false; 653 let startCalled = false;
630 654
631 new ReadableStream({ 655 new ReadableStream({
632 start(c) { 656 start(c) {
657 assert_equals(c.enqueue('a'), undefined, 'the first enqueue should return undefined');
658 c.close();
659
660 assert_throws(new TypeError(), () => c.enqueue('b'), 'enqueue after close should throw a TypeError');
661 startCalled = true;
662 }
663 });
664
665 assert_true(startCalled);
666
667 }, 'ReadableStream: enqueue should throw when the stream is readable but drainin g');
668
669 test(() => {
670
671 let startCalled = false;
672
673 new ReadableStream({
674 start(c) {
633 c.close(); 675 c.close();
634 676
635 assert_throws(new TypeError(), () => c.enqueue('a'), 'enqueue after close should throw a TypeError'); 677 assert_throws(new TypeError(), () => c.enqueue('a'), 'enqueue after close should throw a TypeError');
636 startCalled = true; 678 startCalled = true;
637 } 679 }
638 }); 680 });
639 681
640 assert_true(startCalled); 682 assert_true(startCalled);
641 683
642 }, 'ReadableStream: enqueue should throw when the stream is closed'); 684 }, 'ReadableStream: enqueue should throw when the stream is closed');
643 685
644 test(() => {
645
646 let startCalled = false;
647 const expectedError = new Error('i am sad');
648
649 new ReadableStream({
650 start(c) {
651 c.error(expectedError);
652
653 assert_throws(expectedError, () => c.enqueue('a'), 'enqueue after error sh ould throw that error');
654 startCalled = true;
655 }
656 });
657
658 assert_true(startCalled);
659
660 }, 'ReadableStream: enqueue should throw the stored error when the stream is err ored');
661
662 promise_test(() => { 686 promise_test(() => {
663 687
664 let startCalled = 0; 688 let startCalled = 0;
665 let pullCalled = 0; 689 let pullCalled = 0;
666 let cancelCalled = 0; 690 let cancelCalled = 0;
667 691
668 /* eslint-disable no-use-before-define */ 692 /* eslint-disable no-use-before-define */
669 class Source { 693 class Source {
670 start(c) { 694 start(c) {
671 startCalled++; 695 startCalled++;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 const rs = sequentialReadableStream(10, { async: true }); 844 const rs = sequentialReadableStream(10, { async: true });
821 845
822 return readableStreamToArray(rs).then(chunks => { 846 return readableStreamToArray(rs).then(chunks => {
823 assert_true(rs.source.closed, 'source should be closed after all chunks are read'); 847 assert_true(rs.source.closed, 'source should be closed after all chunks are read');
824 assert_array_equals(chunks, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'the expected 1 0 chunks should be read'); 848 assert_array_equals(chunks, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'the expected 1 0 chunks should be read');
825 }); 849 });
826 850
827 }, 'ReadableStream integration test: adapting an async pull source'); 851 }, 'ReadableStream integration test: adapting an async pull source');
828 852
829 done(); 853 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698