@@ -10,6 +10,71 @@ import 'package:flutter_test/flutter_test.dart';
10
10
11
11
import 'package:video_player_platform_interface/method_channel_video_player.dart' ;
12
12
import 'package:video_player_platform_interface/video_player_platform_interface.dart' ;
13
+ import 'package:video_player_platform_interface/messages.dart' ;
14
+
15
+ class _ApiLogger implements VideoPlayerApiTest {
16
+ final List <String > log = [];
17
+ TextureMessage textureMessage;
18
+ CreateMessage createMessage;
19
+ PositionMessage positionMessage;
20
+ LoopingMessage loopingMessage;
21
+ VolumeMessage volumeMessage;
22
+
23
+ @override
24
+ TextureMessage create (CreateMessage arg) {
25
+ log.add ('create' );
26
+ createMessage = arg;
27
+ return TextureMessage ()..textureId = 3 ;
28
+ }
29
+
30
+ @override
31
+ void dispose (TextureMessage arg) {
32
+ log.add ('dispose' );
33
+ textureMessage = arg;
34
+ }
35
+
36
+ @override
37
+ void initialize () {
38
+ log.add ('init' );
39
+ }
40
+
41
+ @override
42
+ void pause (TextureMessage arg) {
43
+ log.add ('pause' );
44
+ textureMessage = arg;
45
+ }
46
+
47
+ @override
48
+ void play (TextureMessage arg) {
49
+ log.add ('play' );
50
+ textureMessage = arg;
51
+ }
52
+
53
+ @override
54
+ PositionMessage position (TextureMessage arg) {
55
+ log.add ('position' );
56
+ textureMessage = arg;
57
+ return PositionMessage ()..position = 234 ;
58
+ }
59
+
60
+ @override
61
+ void seekTo (PositionMessage arg) {
62
+ log.add ('seekTo' );
63
+ positionMessage = arg;
64
+ }
65
+
66
+ @override
67
+ void setLooping (LoopingMessage arg) {
68
+ log.add ('setLooping' );
69
+ loopingMessage = arg;
70
+ }
71
+
72
+ @override
73
+ void setVolume (VolumeMessage arg) {
74
+ log.add ('setVolume' );
75
+ volumeMessage = arg;
76
+ }
77
+ }
13
78
14
79
void main () {
15
80
TestWidgetsFlutterBinding .ensureInitialized ();
@@ -39,182 +104,99 @@ void main() {
39
104
});
40
105
41
106
group ('$MethodChannelVideoPlayer ' , () {
42
- const MethodChannel channel = MethodChannel ('flutter.io/videoPlayer' );
43
- final List <MethodCall > log = < MethodCall > [];
44
107
final MethodChannelVideoPlayer player = MethodChannelVideoPlayer ();
108
+ _ApiLogger log;
45
109
46
110
setUp (() {
47
- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
48
- log.add (methodCall);
49
- });
50
- });
51
-
52
- tearDown (() {
53
- log.clear ();
111
+ log = _ApiLogger ();
112
+ VideoPlayerApiTestSetup (log);
54
113
});
55
114
56
115
test ('init' , () async {
57
116
await player.init ();
58
117
expect (
59
- log,
60
- < Matcher > [ isMethodCall ( 'init' , arguments : null )] ,
118
+ log.log.last ,
119
+ 'init' ,
61
120
);
62
121
});
63
122
64
123
test ('dispose' , () async {
65
124
await player.dispose (1 );
66
- expect (
67
- log,
68
- < Matcher > [
69
- isMethodCall ('dispose' , arguments: < String , Object > {
70
- 'textureId' : 1 ,
71
- })
72
- ],
73
- );
125
+ expect (log.log.last, 'dispose' );
126
+ expect (log.textureMessage.textureId, 1 );
74
127
});
75
128
76
129
test ('create with asset' , () async {
77
- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
78
- log.add (methodCall);
79
- return < String , dynamic > {'textureId' : 3 };
80
- });
81
130
final int textureId = await player.create (DataSource (
82
131
sourceType: DataSourceType .asset,
83
132
asset: 'someAsset' ,
84
133
package: 'somePackage' ,
85
134
));
86
- expect (
87
- log,
88
- < Matcher > [
89
- isMethodCall ('create' , arguments: < String , Object > {
90
- 'asset' : 'someAsset' ,
91
- 'package' : 'somePackage' ,
92
- })
93
- ],
94
- );
135
+ expect (log.log.last, 'create' );
136
+ expect (log.createMessage.asset, 'someAsset' );
137
+ expect (log.createMessage.packageName, 'somePackage' );
95
138
expect (textureId, 3 );
96
139
});
97
140
98
141
test ('create with network' , () async {
99
- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
100
- log.add (methodCall);
101
- return < String , dynamic > {'textureId' : 3 };
102
- });
103
142
final int textureId = await player.create (DataSource (
104
143
sourceType: DataSourceType .network,
105
144
uri: 'someUri' ,
106
145
formatHint: VideoFormat .dash,
107
146
));
108
- expect (
109
- log,
110
- < Matcher > [
111
- isMethodCall ('create' , arguments: < String , Object > {
112
- 'uri' : 'someUri' ,
113
- 'formatHint' : 'dash'
114
- })
115
- ],
116
- );
147
+ expect (log.log.last, 'create' );
148
+ expect (log.createMessage.uri, 'someUri' );
149
+ expect (log.createMessage.formatHint, 'dash' );
117
150
expect (textureId, 3 );
118
151
});
119
152
120
153
test ('create with file' , () async {
121
- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
122
- log.add (methodCall);
123
- return < String , dynamic > {'textureId' : 3 };
124
- });
125
154
final int textureId = await player.create (DataSource (
126
155
sourceType: DataSourceType .file,
127
156
uri: 'someUri' ,
128
157
));
129
- expect (
130
- log,
131
- < Matcher > [
132
- isMethodCall ('create' , arguments: < String , Object > {
133
- 'uri' : 'someUri' ,
134
- })
135
- ],
136
- );
158
+ expect (log.log.last, 'create' );
159
+ expect (log.createMessage.uri, 'someUri' );
137
160
expect (textureId, 3 );
138
161
});
139
162
140
163
test ('setLooping' , () async {
141
164
await player.setLooping (1 , true );
142
- expect (
143
- log,
144
- < Matcher > [
145
- isMethodCall ('setLooping' , arguments: < String , Object > {
146
- 'textureId' : 1 ,
147
- 'looping' : true ,
148
- })
149
- ],
150
- );
165
+ expect (log.log.last, 'setLooping' );
166
+ expect (log.loopingMessage.textureId, 1 );
167
+ expect (log.loopingMessage.isLooping, true );
151
168
});
152
169
153
170
test ('play' , () async {
154
171
await player.play (1 );
155
- expect (
156
- log,
157
- < Matcher > [
158
- isMethodCall ('play' , arguments: < String , Object > {
159
- 'textureId' : 1 ,
160
- })
161
- ],
162
- );
172
+ expect (log.log.last, 'play' );
173
+ expect (log.textureMessage.textureId, 1 );
163
174
});
164
175
165
176
test ('pause' , () async {
166
177
await player.pause (1 );
167
- expect (
168
- log,
169
- < Matcher > [
170
- isMethodCall ('pause' , arguments: < String , Object > {
171
- 'textureId' : 1 ,
172
- })
173
- ],
174
- );
178
+ expect (log.log.last, 'pause' );
179
+ expect (log.textureMessage.textureId, 1 );
175
180
});
176
181
177
182
test ('setVolume' , () async {
178
183
await player.setVolume (1 , 0.7 );
179
- expect (
180
- log,
181
- < Matcher > [
182
- isMethodCall ('setVolume' , arguments: < String , Object > {
183
- 'textureId' : 1 ,
184
- 'volume' : 0.7 ,
185
- })
186
- ],
187
- );
184
+ expect (log.log.last, 'setVolume' );
185
+ expect (log.volumeMessage.textureId, 1 );
186
+ expect (log.volumeMessage.volume, 0.7 );
188
187
});
189
188
190
189
test ('seekTo' , () async {
191
190
await player.seekTo (1 , const Duration (milliseconds: 12345 ));
192
- expect (
193
- log,
194
- < Matcher > [
195
- isMethodCall ('seekTo' , arguments: < String , Object > {
196
- 'textureId' : 1 ,
197
- 'location' : 12345 ,
198
- })
199
- ],
200
- );
191
+ expect (log.log.last, 'seekTo' );
192
+ expect (log.positionMessage.textureId, 1 );
193
+ expect (log.positionMessage.position, 12345 );
201
194
});
202
195
203
196
test ('getPosition' , () async {
204
- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
205
- log.add (methodCall);
206
- return 234 ;
207
- });
208
-
209
197
final Duration position = await player.getPosition (1 );
210
- expect (
211
- log,
212
- < Matcher > [
213
- isMethodCall ('position' , arguments: < String , Object > {
214
- 'textureId' : 1 ,
215
- })
216
- ],
217
- );
198
+ expect (log.log.last, 'position' );
199
+ expect (log.textureMessage.textureId, 1 );
218
200
expect (position, const Duration (milliseconds: 234 ));
219
201
});
220
202
0 commit comments