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

Side by Side Diff: tests/lib/async/stream_controller_test.dart

Issue 1278873008: Add getters for callbacks on StreamController. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix incorrect return type on broadcast stream controller. Created 5 years, 4 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 | « sdk/lib/async/stream_controller.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Test the basic StreamController and StreamController.singleSubscription. 5 // Test the basic StreamController and StreamController.singleSubscription.
6 library stream_controller_test; 6 library stream_controller_test;
7 7
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import "package:async_helper/async_helper.dart"; 9 import "package:async_helper/async_helper.dart";
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 void testSettingCallbacks() { 722 void testSettingCallbacks() {
723 const int initial = 0; 723 const int initial = 0;
724 const int running = 1; 724 const int running = 1;
725 const int paused = 2; 725 const int paused = 2;
726 const int canceled = 3; 726 const int canceled = 3;
727 727
728 var controller = new StreamController(); 728 var controller = new StreamController();
729 var stream = controller.stream; 729 var stream = controller.stream;
730 var state = initial; 730 var state = initial;
731 731
732 controller..onListen = () { state = running; } 732 var onListen = () { state = running; };
733 ..onPause = () { state = paused; } 733 var onPause = () { state = paused; };
734 ..onResume = () { state = running; } 734 var onResume = () { state = running; };
735 ..onCancel = () { state = canceled; }; 735 var onCancel = () { state = canceled; };
736
737 Expect.isNull(controller.onListen);
738 Expect.isNull(controller.onPause);
739 Expect.isNull(controller.onResume);
740 Expect.isNull(controller.onCancel);
741
742 controller..onListen = onListen
743 ..onPause = onPause
744 ..onResume = onResume
745 ..onCancel = onCancel;
746
747 Expect.equals(onListen, controller.onListen);
748 Expect.equals(onPause, controller.onPause);
749 Expect.equals(onResume, controller.onResume);
750 Expect.equals(onCancel, controller.onCancel);
736 751
737 Expect.equals(initial, state); 752 Expect.equals(initial, state);
738 var sub = stream.listen(null); 753 var sub = stream.listen(null);
739 Expect.equals(running, state); 754 Expect.equals(running, state);
740 sub.pause(); 755 sub.pause();
741 Expect.equals(paused, state); 756 Expect.equals(paused, state);
742 Expect.isTrue(controller.isPaused); 757 Expect.isTrue(controller.isPaused);
743 sub.resume(); 758 sub.resume();
744 Expect.equals(running, state); 759 Expect.equals(running, state);
745 Expect.isFalse(controller.isPaused); 760 Expect.isFalse(controller.isPaused);
746 761
762 var onListen2 = () { state = -running; };
763 var onPause2 = () { state = -paused; };
764 var onResume2 = () { state = -running; };
765 var onCancel2 = () { state = -canceled; };
747 // Changing them later does make a difference. 766 // Changing them later does make a difference.
748 controller..onListen = () { throw "Second listen?"; } 767 controller..onListen = onListen2
749 ..onPause = () { state = -paused; } 768 ..onPause = onPause2
750 ..onResume = () { state = -running; } 769 ..onResume = onResume2
751 ..onCancel = () { state = -canceled; }; 770 ..onCancel = onCancel2;
771
772 Expect.equals(onListen2, controller.onListen);
773 Expect.equals(onPause2, controller.onPause);
774 Expect.equals(onResume2, controller.onResume);
775 Expect.equals(onCancel2, controller.onCancel);
752 776
753 Expect.equals(running, state); 777 Expect.equals(running, state);
754 sub.pause(); 778 sub.pause();
755 Expect.equals(-paused, state); 779 Expect.equals(-paused, state);
756 Expect.isTrue(controller.isPaused); 780 Expect.isTrue(controller.isPaused);
757 sub.resume(); 781 sub.resume();
758 Expect.equals(-running, state); 782 Expect.equals(-running, state);
759 Expect.isFalse(controller.isPaused); 783 Expect.isFalse(controller.isPaused);
760 sub.cancel(); 784 sub.cancel();
761 Expect.equals(-canceled, state); 785 Expect.equals(-canceled, state);
762 } 786 }
763 787
764 void testSettingNullCallbacks() { 788 void testSettingNullCallbacks() {
765 failCallback() => fail("Callback should not be called"); 789 failCallback() => fail("Callback should not be called");
766 var controller = new StreamController(onListen: failCallback, 790 var controller = new StreamController(onListen: failCallback,
767 onPause : failCallback, 791 onPause : failCallback,
768 onResume: failCallback, 792 onResume: failCallback,
769 onCancel: failCallback); 793 onCancel: failCallback);
770 794
771 var stream = controller.stream; 795 var stream = controller.stream;
772 796
773 Expect.isFalse(controller.hasListener); 797 Expect.isFalse(controller.hasListener);
774 Expect.isTrue(controller.isPaused); 798 Expect.isTrue(controller.isPaused);
775 799
800 Expect.isNotNull(controller.onListen);
776 controller.onListen = null; 801 controller.onListen = null;
802 Expect.isNull(controller.onListen);
777 803
778 var sub = stream.listen(null); 804 var sub = stream.listen(null);
779 805
780 Expect.isTrue(controller.hasListener); 806 Expect.isTrue(controller.hasListener);
781 Expect.isFalse(controller.isPaused); 807 Expect.isFalse(controller.isPaused);
782 808
809 Expect.isNotNull(controller.onPause);
783 controller.onPause = null; 810 controller.onPause = null;
811 Expect.isNull(controller.onPause);
784 812
785 sub.pause(); 813 sub.pause();
786 814
787 Expect.isTrue(controller.hasListener); 815 Expect.isTrue(controller.hasListener);
788 Expect.isTrue(controller.isPaused); 816 Expect.isTrue(controller.isPaused);
789 817
818 Expect.isNotNull(controller.onResume);
790 controller.onResume = null; 819 controller.onResume = null;
820 Expect.isNull(controller.onResume);
791 821
792 sub.resume(); 822 sub.resume();
793 823
794 Expect.isTrue(controller.hasListener); 824 Expect.isTrue(controller.hasListener);
795 Expect.isFalse(controller.isPaused); 825 Expect.isFalse(controller.isPaused);
796 826
827 Expect.isNotNull(controller.onCancel);
797 controller.onCancel = null; 828 controller.onCancel = null;
829 Expect.isNull(controller.onCancel);
798 830
799 sub.cancel(); 831 sub.cancel();
800 832
801 Expect.isFalse(controller.hasListener); 833 Expect.isFalse(controller.hasListener);
802 Expect.isFalse(controller.isPaused); 834 Expect.isFalse(controller.isPaused);
803 } 835 }
804 836
805 void testBroadcastSettingCallbacks() { 837 void testBroadcastSettingCallbacks() {
806 const int initial = 0; 838 const int initial = 0;
807 const int running = 1; 839 const int running = 1;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 testAsBroadcastListenAfterClose(); 907 testAsBroadcastListenAfterClose();
876 testAsBroadcastListenAfterClosePaused(); 908 testAsBroadcastListenAfterClosePaused();
877 testEventInListen(); 909 testEventInListen();
878 testSyncControllerNotReentrant(); 910 testSyncControllerNotReentrant();
879 testSettingCallbacks(); 911 testSettingCallbacks();
880 testSettingNullCallbacks(); 912 testSettingNullCallbacks();
881 testBroadcastSettingCallbacks(); 913 testBroadcastSettingCallbacks();
882 testBroadcastSettingNullCallbacks(); 914 testBroadcastSettingNullCallbacks();
883 asyncEnd(); 915 asyncEnd();
884 } 916 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_controller.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698