@@ -16,37 +16,43 @@ import '../model/binding.dart';
16
16
class FakeVideoPlayerPlatform extends Fake
17
17
with MockPlatformInterfaceMixin
18
18
implements VideoPlayerPlatform {
19
- static const int _textureId = 0xffffffff ;
20
-
21
- static StreamController <VideoEvent > _streamController = StreamController <VideoEvent >();
22
- static bool initialized = false ;
23
- static bool isPlaying = false ;
19
+ static final FakeVideoPlayerPlatform instance = FakeVideoPlayerPlatform ();
24
20
25
21
static void registerWith () {
26
- VideoPlayerPlatform .instance = FakeVideoPlayerPlatform () ;
22
+ VideoPlayerPlatform .instance = instance ;
27
23
}
28
24
29
- static void reset () {
25
+ static const int _textureId = 0xffffffff ;
26
+
27
+ StreamController <VideoEvent > _streamController = StreamController <VideoEvent >();
28
+
29
+ bool get initialized => _initialized;
30
+ bool _initialized = false ;
31
+
32
+ bool get isPlaying => _isPlaying;
33
+ bool _isPlaying = false ;
34
+
35
+ void reset () {
30
36
_streamController.close ();
31
37
_streamController = StreamController <VideoEvent >();
32
- initialized = false ;
33
- isPlaying = false ;
38
+ _initialized = false ;
39
+ _isPlaying = false ;
34
40
}
35
41
36
42
@override
37
43
Future <void > init () async {}
38
44
39
45
@override
40
46
Future <void > dispose (int textureId) async {
41
- assert (initialized );
47
+ assert (_initialized );
42
48
assert (textureId == _textureId);
43
- initialized = false ;
49
+ _initialized = false ;
44
50
}
45
51
46
52
@override
47
53
Future <int ?> create (DataSource dataSource) async {
48
- assert (! initialized );
49
- initialized = true ;
54
+ assert (! _initialized );
55
+ _initialized = true ;
50
56
_streamController.add (VideoEvent (
51
57
eventType: VideoEventType .initialized,
52
58
duration: const Duration (seconds: 1 ),
@@ -71,7 +77,7 @@ class FakeVideoPlayerPlatform extends Fake
71
77
@override
72
78
Future <void > play (int textureId) async {
73
79
assert (textureId == _textureId);
74
- isPlaying = true ;
80
+ _isPlaying = true ;
75
81
_streamController.add (VideoEvent (
76
82
eventType: VideoEventType .isPlayingStateUpdate,
77
83
isPlaying: true ,
@@ -81,7 +87,7 @@ class FakeVideoPlayerPlatform extends Fake
81
87
@override
82
88
Future <void > pause (int textureId) async {
83
89
assert (textureId == _textureId);
84
- isPlaying = false ;
90
+ _isPlaying = false ;
85
91
_streamController.add (VideoEvent (
86
92
eventType: VideoEventType .isPlayingStateUpdate,
87
93
isPlaying: false ,
@@ -134,13 +140,14 @@ void main() {
134
140
135
141
group ("VideoLightboxPage" , () {
136
142
FakeVideoPlayerPlatform .registerWith ();
143
+ final platform = FakeVideoPlayerPlatform .instance;
137
144
138
145
Future <void > setupPage (WidgetTester tester, {
139
146
required Uri videoSrc,
140
147
}) async {
141
148
addTearDown (testBinding.reset);
142
149
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
143
- addTearDown (FakeVideoPlayerPlatform .reset);
150
+ addTearDown (platform .reset);
144
151
145
152
await tester.pumpWidget (GlobalStoreWidget (child: MaterialApp (
146
153
localizationsDelegates: ZulipLocalizations .localizationsDelegates,
@@ -157,24 +164,24 @@ void main() {
157
164
testWidgets ('shows a VideoPlayer, and video is playing' , (tester) async {
158
165
await setupPage (tester, videoSrc: Uri .parse ('https://a/b.mp4' ));
159
166
160
- check (FakeVideoPlayerPlatform .initialized).isTrue ();
161
- check (FakeVideoPlayerPlatform .isPlaying).isTrue ();
167
+ check (platform .initialized).isTrue ();
168
+ check (platform .isPlaying).isTrue ();
162
169
163
170
await tester.ensureVisible (find.byType (VideoPlayer ));
164
171
});
165
172
166
173
testWidgets ('toggles between play and pause' , (tester) async {
167
174
await setupPage (tester, videoSrc: Uri .parse ('https://a/b.mp4' ));
168
- check (FakeVideoPlayerPlatform .isPlaying).isTrue ();
175
+ check (platform .isPlaying).isTrue ();
169
176
170
177
await tester.tap (find.byIcon (Icons .pause_circle_rounded));
171
- check (FakeVideoPlayerPlatform .isPlaying).isFalse ();
178
+ check (platform .isPlaying).isFalse ();
172
179
173
180
// re-render to update player controls
174
181
await tester.pump ();
175
182
176
183
await tester.tap (find.byIcon (Icons .play_circle_rounded));
177
- check (FakeVideoPlayerPlatform .isPlaying).isTrue ();
184
+ check (platform .isPlaying).isTrue ();
178
185
});
179
186
});
180
187
}
0 commit comments