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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/streams/writable-streams/aborting.js

Issue 2668783003: Import wpt@767dc2a4f049c761bd146d61de2ea860a895a624 (Closed)
Patch Set: Update test expectations and baselines. 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
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 self.importScripts('/resources/testharness.js'); 4 self.importScripts('/resources/testharness.js');
5 self.importScripts('../resources/test-utils.js'); 5 self.importScripts('../resources/test-utils.js');
6 self.importScripts('../resources/recording-streams.js'); 6 self.importScripts('../resources/recording-streams.js');
7 } 7 }
8 8
9 const error1 = new Error('error1'); 9 const error1 = new Error('error1');
10 error1.name = 'error1'; 10 error1.name = 'error1';
(...skipping 14 matching lines...) Expand all
25 const readyPromise = writer.ready; 25 const readyPromise = writer.ready;
26 26
27 writer.abort(error1); 27 writer.abort(error1);
28 28
29 assert_equals(writer.ready, readyPromise, 'the ready promise property should n ot change'); 29 assert_equals(writer.ready, readyPromise, 'the ready promise property should n ot change');
30 30
31 return Promise.all([ 31 return Promise.all([
32 promise_rejects(t, new TypeError(), readyPromise, 'the ready promise should reject with a TypeError'), 32 promise_rejects(t, new TypeError(), readyPromise, 'the ready promise should reject with a TypeError'),
33 promise_rejects(t, new TypeError(), writePromise, 'the write() promise shoul d reject with a TypeError') 33 promise_rejects(t, new TypeError(), writePromise, 'the write() promise shoul d reject with a TypeError')
34 ]); 34 ]);
35 }, 'Aborting a WritableStream should cause the writer\'s unsettled ready promise to reject'); 35 }, 'Aborting a WritableStream before it starts should cause the writer\'s unsett led ready promise to reject');
36 36
37 promise_test(t => { 37 promise_test(t => {
38 const ws = new WritableStream(); 38 const ws = new WritableStream();
39 39
40 const writer = ws.getWriter(); 40 const writer = ws.getWriter();
41 writer.write('a'); 41 writer.write('a');
42 42
43 const readyPromise = writer.ready; 43 const readyPromise = writer.ready;
44 44
45 return readyPromise.then(() => { 45 return readyPromise.then(() => {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 assert_array_equals(ws.events, ['abort', error1]); 178 assert_array_equals(ws.events, ['abort', error1]);
179 }, 'Aborting a WritableStream passes through the given reason'); 179 }, 'Aborting a WritableStream passes through the given reason');
180 180
181 promise_test(t => { 181 promise_test(t => {
182 const ws = new WritableStream(); 182 const ws = new WritableStream();
183 const writer = ws.getWriter(); 183 const writer = ws.getWriter();
184 184
185 writer.abort(error1); 185 writer.abort(error1);
186 186
187 const events = [];
188 writer.ready.catch(() => {
189 events.push('ready');
190 });
191 writer.closed.catch(() => {
192 events.push('closed');
193 });
194
187 return Promise.all([ 195 return Promise.all([
188 promise_rejects(t, new TypeError(), writer.write(), 'writing should reject w ith a TypeError'), 196 promise_rejects(t, new TypeError(), writer.write(), 'writing should reject w ith a TypeError'),
189 promise_rejects(t, new TypeError(), writer.close(), 'closing should reject w ith a TypeError'), 197 promise_rejects(t, new TypeError(), writer.close(), 'closing should reject w ith a TypeError'),
190 promise_rejects(t, new TypeError(), writer.abort(), 'aborting should reject with a TypeError'), 198 promise_rejects(t, new TypeError(), writer.abort(), 'aborting should reject with a TypeError'),
199 promise_rejects(t, new TypeError(), writer.ready, 'ready should reject with a TypeError'),
191 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject wit h a TypeError') 200 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject wit h a TypeError')
192 ]); 201 ]).then(() => {
202 assert_array_equals(['ready', 'closed'], events, 'ready should reject before closed');
203 });
193 }, 'Aborting a WritableStream puts it in an errored state, with a TypeError as t he stored error'); 204 }, 'Aborting a WritableStream puts it in an errored state, with a TypeError as t he stored error');
194 205
195 promise_test(t => { 206 promise_test(t => {
196 const ws = new WritableStream(); 207 const ws = new WritableStream();
197 const writer = ws.getWriter(); 208 const writer = ws.getWriter();
198 209
199 const writePromise = promise_rejects(t, new TypeError(), writer.write('a'), 210 const writePromise = promise_rejects(t, new TypeError(), writer.write('a'),
200 'writing should reject with a TypeError'); 211 'writing should reject with a TypeError');
201 212
202 writer.abort(error1); 213 writer.abort(error1);
(...skipping 21 matching lines...) Expand all
224 return new Promise(resolve => { 235 return new Promise(resolve => {
225 resolveClose = resolve; 236 resolveClose = resolve;
226 }); 237 });
227 } 238 }
228 }); 239 });
229 const writer = ws.getWriter(); 240 const writer = ws.getWriter();
230 241
231 const closePromise = writer.close(); 242 const closePromise = writer.close();
232 243
233 return delay(0).then(() => { 244 return delay(0).then(() => {
234 writer.abort(error1); 245 const abortPromise = writer.abort(error1);
235 resolveClose(); 246 resolveClose();
236 return Promise.all([ 247 return Promise.all([
237 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject w ith a TypeError'), 248 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject w ith a TypeError'),
249 abortPromise,
238 closePromise 250 closePromise
239 ]); 251 ]);
240 }); 252 });
241 }, 'Closing a WritableStream and aborting it while it closes causes the stream t o error'); 253 }, 'Closing a WritableStream and aborting it while it closes causes the stream t o error');
242 254
243 promise_test(() => { 255 promise_test(() => {
244 const ws = new WritableStream(); 256 const ws = new WritableStream();
245 const writer = ws.getWriter(); 257 const writer = ws.getWriter();
246 258
247 writer.close(); 259 writer.close();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 534 }
523 }); 535 });
524 const writer = ws.getWriter(); 536 const writer = ws.getWriter();
525 return writer.ready.then(() => { 537 return writer.ready.then(() => {
526 writer.write('a'); 538 writer.write('a');
527 return promise_rejects(t, error1, writer.ready, 'writer.ready should reject' ); 539 return promise_rejects(t, error1, writer.ready, 'writer.ready should reject' );
528 }); 540 });
529 }, 'writer.ready should reject on controller error without waiting for underlyin g write'); 541 }, 'writer.ready should reject on controller error without waiting for underlyin g write');
530 542
531 promise_test(t => { 543 promise_test(t => {
544 let rejectWrite;
545 const ws = new WritableStream({
546 write() {
547 return new Promise((resolve, reject) => {
548 rejectWrite = reject;
549 });
550 }
551 });
552
553 let writePromise;
554 let abortPromise;
555
556 const events = [];
557
558 const writer = ws.getWriter();
559
560 writer.closed.catch(() => {
561 events.push('closed');
562 });
563
564 // Wait for ws to start
565 return flushAsyncEvents().then(() => {
566 writePromise = writer.write('a');
567 writePromise.catch(() => {
568 events.push('writePromise');
569 });
570
571 abortPromise = writer.abort(error1);
572 abortPromise.catch(() => {
573 events.push('abortPromise');
574 });
575
576 const writePromise2 = writer.write('a');
577
578 return Promise.all([
579 promise_rejects(t, new TypeError(), writePromise2, 'writePromise2 must rej ect with an error indicating abort'),
580 promise_rejects(t, new TypeError(), writer.ready, 'writer.ready must rejec t with an error indicating abort'),
581 flushAsyncEvents()
582 ]);
583 }).then(() => {
584 assert_array_equals(events, [], 'writePromise, abortPromise and writer.close d must not be rejected yet');
585
586 rejectWrite(error2);
587
588 return Promise.all([
589 promise_rejects(t, error2, writePromise,
590 'writePromise must reject with the error returned from the sink\'s write method'),
591 promise_rejects(t, error2, abortPromise,
592 'abortPromise must reject with the error returned from the sink\'s write method'),
593 promise_rejects(t, error2, writer.closed,
594 'writer.closed must reject with the error returned from th e sink\'s write method'),
595 flushAsyncEvents()
596 ]);
597 }).then(() => {
598 assert_array_equals(events, ['writePromise', 'abortPromise', 'closed'],
599 'writePromise, abortPromise and writer.closed must rejec t');
600
601 const writePromise3 = writer.write('a');
602
603 return Promise.all([
604 promise_rejects(t, new TypeError(), writePromise3,
605 'writePromise3 must reject with an error indicating the st ream has already been errored'),
606 promise_rejects(t, new TypeError(), writer.ready,
607 'writer.ready must be still rejected with the error indica ting abort')
608 ]);
609 }).then(() => {
610 writer.releaseLock();
611
612 return Promise.all([
613 promise_rejects(t, new TypeError(), writer.ready,
614 'writer.ready must be rejected with an error indicating re lease'),
615 promise_rejects(t, new TypeError(), writer.closed,
616 'writer.closed must be rejected with an error indicating r elease')
617 ]);
618 });
619 }, 'writer.abort() while there is a pending write, and then finish the write wit h rejection');
620
621 promise_test(t => {
532 let resolveWrite; 622 let resolveWrite;
623 let controller;
624 const ws = new WritableStream({
625 write(chunk, c) {
626 controller = c;
627 return new Promise(resolve => {
628 resolveWrite = resolve;
629 });
630 }
631 });
632
633 let writePromise;
634 let abortPromise;
635
636 const events = [];
637
638 const writer = ws.getWriter();
639
640 writer.closed.catch(() => {
641 events.push('closed');
642 });
643
644 // Wait for ws to start
645 return flushAsyncEvents().then(() => {
646 writePromise = writer.write('a');
647 writePromise.then(() => {
648 events.push('writePromise');
649 });
650
651 abortPromise = writer.abort(error1);
652 abortPromise.catch(() => {
653 events.push('abortPromise');
654 });
655
656 const writePromise2 = writer.write('a');
657
658 return Promise.all([
659 promise_rejects(t, new TypeError(), writePromise2, 'writePromise2 must rej ect with an error indicating abort'),
660 promise_rejects(t, new TypeError(), writer.ready, 'writer.ready must rejec t with an error indicating abort'),
661 flushAsyncEvents()
662 ]);
663 }).then(() => {
664 assert_array_equals(events, [], 'writePromise, abortPromise and writer.close d must not be fulfilled/rejected yet');
665
666 controller.error(error2);
667
668 const writePromise3 = writer.write('a');
669
670 return Promise.all([
671 promise_rejects(t, new TypeError(), writePromise3,
672 'writePromise3 must reject with an error indicating the st ream has already been errored'),
673 promise_rejects(t, new TypeError(), writer.ready,
674 'writer.ready must be still rejected with the error indica ting abort'),
675 flushAsyncEvents()
676 ]);
677 }).then(() => {
678 assert_array_equals(
679 events, [],
680 'writePromise, abortPromise and writer.closed must not be fulfilled/reje cted yet even after '
681 + 'controller.error() call');
682
683 resolveWrite();
684
685 return Promise.all([
686 writePromise,
687 promise_rejects(t, error2, abortPromise,
688 'abortPromise must reject with the error passed to the con troller\'s error method'),
689 promise_rejects(t, error2, writer.closed,
690 'writer.closed must reject with the error passed to the co ntroller\'s error method'),
691 flushAsyncEvents()
692 ]);
693 }).then(() => {
694 assert_array_equals(events, ['writePromise', 'abortPromise', 'closed'],
695 'writePromise, abortPromise and writer.closed must rejec t');
696
697 const writePromise4 = writer.write('a');
698
699 return Promise.all([
700 writePromise,
701 promise_rejects(t, new TypeError(), writePromise4,
702 'writePromise4 must reject with an error indicating that t he stream has already been errored'),
703 promise_rejects(t, new TypeError(), writer.ready,
704 'writer.ready must be still rejected with the error indica ting abort')
705 ]);
706 }).then(() => {
707 writer.releaseLock();
708
709 return Promise.all([
710 promise_rejects(t, new TypeError(), writer.ready,
711 'writer.ready must be rejected with an error indicating re lease'),
712 promise_rejects(t, new TypeError(), writer.closed,
713 'writer.closed must be rejected with an error indicating r elease')
714 ]);
715 });
716 }, 'writer.abort(), controller.error() while there is a pending write, and then finish the write');
717
718 promise_test(t => {
719 let resolveWrite;
720 let controller;
721 const ws = new WritableStream({
722 write(chunk, c) {
723 controller = c;
724 return new Promise(resolve => {
725 resolveWrite = resolve;
726 });
727 }
728 });
729
730 let writePromise;
731 let abortPromise;
732
733 const events = [];
734
735 const writer = ws.getWriter();
736
737 writer.closed.catch(() => {
738 events.push('closed');
739 });
740
741 // Wait for ws to start
742 return flushAsyncEvents().then(() => {
743 writePromise = writer.write('a');
744 writePromise.then(() => {
745 events.push('writePromise');
746 });
747
748 controller.error(error2);
749
750 const writePromise2 = writer.write('a');
751
752 return Promise.all([
753 promise_rejects(t, new TypeError(), writePromise2,
754 'writePromise2 must reject with an error indicating the st ream has already been errored'),
755 promise_rejects(t, error2, writer.ready,
756 'writer.ready must reject with the error passed to the con troller\'s error method'),
757 flushAsyncEvents()
758 ]);
759 }).then(() => {
760 assert_array_equals(events, [], 'writePromise and writer.closed must not be fulfilled/rejected yet');
761
762 abortPromise = writer.abort(error1);
763 abortPromise.catch(() => {
764 events.push('abortPromise');
765 });
766
767 const writePromise3 = writer.write('a');
768
769 return Promise.all([
770 promise_rejects(t, error2, abortPromise,
771 'abortPromise must reject with the error passed to the con troller\'s error method'),
772 promise_rejects(t, new TypeError(), writePromise3,
773 'writePromise3 must reject with an error indicating the st ream has already been errored'),
774 flushAsyncEvents()
775 ]);
776 }).then(() => {
777 assert_array_equals(
778 events, ['abortPromise'],
779 'writePromise and writer.closed must not be fulfilled/rejected yet even after writer.abort()');
780
781 resolveWrite();
782
783 return Promise.all([
784 promise_rejects(t, error2, writer.closed,
785 'writer.closed must reject with the error passed to the co ntroller\'s error method'),
786 flushAsyncEvents()
787 ]);
788 }).then(() => {
789 assert_array_equals(events, ['abortPromise', 'writePromise', 'closed'],
790 'writePromise, abortPromise and writer.closed must fulfi ll/reject');
791
792 const writePromise4 = writer.write('a');
793
794 return Promise.all([
795 writePromise,
796 promise_rejects(t, new TypeError(), writePromise4,
797 'writePromise4 must reject with an error indicating that t he stream has already been errored'),
798 promise_rejects(t, error2, writer.ready,
799 'writer.ready must be still rejected with the error passed to the controller\'s error method')
800 ]);
801 }).then(() => {
802 writer.releaseLock();
803
804 return Promise.all([
805 promise_rejects(t, new TypeError(), writer.ready,
806 'writer.ready must be rejected with an error indicating re lease'),
807 promise_rejects(t, new TypeError(), writer.closed,
808 'writer.closed must be rejected with an error indicating r elease')
809 ]);
810 });
811 }, 'controller.error(), writer.abort() while there is a pending write, and then finish the write');
812
813 promise_test(t => {
814 let resolveWrite;
533 const ws = new WritableStream({ 815 const ws = new WritableStream({
534 write() { 816 write() {
535 return new Promise(resolve => { 817 return new Promise(resolve => {
536 resolveWrite = resolve; 818 resolveWrite = resolve;
537 }); 819 });
538 } 820 }
539 }); 821 });
540 const writer = ws.getWriter(); 822 const writer = ws.getWriter();
541 return writer.ready.then(() => { 823 return writer.ready.then(() => {
542 const writePromise = writer.write('a'); 824 const writePromise = writer.write('a');
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 return Promise.all([ 866 return Promise.all([
585 writePromise, 867 writePromise,
586 abortPromise, 868 abortPromise,
587 promise_rejects(t, new TypeError(), closed, 'original closed should reje ct'), 869 promise_rejects(t, new TypeError(), closed, 'original closed should reje ct'),
588 promise_rejects(t, new TypeError(), writer.closed, 'new closed should re ject')]); 870 promise_rejects(t, new TypeError(), writer.closed, 'new closed should re ject')]);
589 }); 871 });
590 }); 872 });
591 }, 'releaseLock() during delayed async abort() should create a new rejected clos ed promise'); 873 }, 'releaseLock() during delayed async abort() should create a new rejected clos ed promise');
592 874
593 done(); 875 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698