@@ -11,6 +11,7 @@ import 'package:flutter/widgets.dart';
1111import 'package:video_player/video_player.dart' ;
1212import 'package:flutter_test/flutter_test.dart' ;
1313import 'package:video_player_platform_interface/video_player_platform_interface.dart' ;
14+ import 'package:video_player_platform_interface/messages.dart' ;
1415
1516class FakeController extends ValueNotifier <VideoPlayerValue >
1617 implements VideoPlayerController {
@@ -169,11 +170,9 @@ void main() {
169170 await controller.initialize ();
170171
171172 expect (
172- fakeVideoPlayerPlatform.dataSourceDescriptions[0 ],
173- < String , dynamic > {
174- 'asset' : 'a.avi' ,
175- 'package' : null ,
176- });
173+ fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].asset, 'a.avi' );
174+ expect (fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].packageName,
175+ null );
177176 });
178177
179178 test ('network' , () async {
@@ -182,12 +181,10 @@ void main() {
182181 );
183182 await controller.initialize ();
184183
184+ expect (fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].uri,
185+ 'https://127.0.0.1' );
185186 expect (
186- fakeVideoPlayerPlatform.dataSourceDescriptions[0 ],
187- < String , dynamic > {
188- 'uri' : 'https://127.0.0.1' ,
189- 'formatHint' : null ,
190- });
187+ fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].formatHint, null );
191188 });
192189
193190 test ('network with hint' , () async {
@@ -196,12 +193,10 @@ void main() {
196193 formatHint: VideoFormat .dash);
197194 await controller.initialize ();
198195
199- expect (
200- fakeVideoPlayerPlatform.dataSourceDescriptions[0 ],
201- < String , dynamic > {
202- 'uri' : 'https://127.0.0.1' ,
203- 'formatHint' : 'dash' ,
204- });
196+ expect (fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].uri,
197+ 'https://127.0.0.1' );
198+ expect (fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].formatHint,
199+ 'dash' );
205200 });
206201
207202 test ('init errors' , () async {
@@ -224,11 +219,8 @@ void main() {
224219 VideoPlayerController .file (File ('a.avi' ));
225220 await controller.initialize ();
226221
227- expect (
228- fakeVideoPlayerPlatform.dataSourceDescriptions[0 ],
229- < String , dynamic > {
230- 'uri' : 'file://a.avi' ,
231- });
222+ expect (fakeVideoPlayerPlatform.dataSourceDescriptions[0 ].uri,
223+ 'file://a.avi' );
232224 });
233225 });
234226
@@ -255,7 +247,7 @@ void main() {
255247 await controller.play ();
256248
257249 expect (controller.value.isPlaying, isTrue);
258- expect (fakeVideoPlayerPlatform.calls.last.method , 'play' );
250+ expect (fakeVideoPlayerPlatform.calls.last, 'play' );
259251 });
260252
261253 test ('setLooping' , () async {
@@ -280,7 +272,7 @@ void main() {
280272 await controller.pause ();
281273
282274 expect (controller.value.isPlaying, isFalse);
283- expect (fakeVideoPlayerPlatform.calls.last.method , 'pause' );
275+ expect (fakeVideoPlayerPlatform.calls.last, 'pause' );
284276 });
285277
286278 group ('seekTo' , () {
@@ -543,58 +535,73 @@ void main() {
543535 });
544536}
545537
546- class FakeVideoPlayerPlatform {
538+ class FakeVideoPlayerPlatform extends VideoPlayerApiTest {
547539 FakeVideoPlayerPlatform () {
548- _channel. setMockMethodCallHandler (onMethodCall );
540+ VideoPlayerApiTestSetup ( this );
549541 }
550542
551- final MethodChannel _channel = const MethodChannel ('flutter.io/videoPlayer' );
552-
553543 Completer <bool > initialized = Completer <bool >();
554- List <MethodCall > calls = < MethodCall > [];
555- List <Map < String , dynamic >> dataSourceDescriptions = < Map < String , dynamic > > [];
544+ List <String > calls = < String > [];
545+ List <CreateMessage > dataSourceDescriptions = < CreateMessage > [];
556546 final Map <int , FakeVideoEventStream > streams = < int , FakeVideoEventStream > {};
557547 bool forceInitError = false ;
558548 int nextTextureId = 0 ;
559549 final Map <int , Duration > _positions = < int , Duration > {};
560550
561- Future <dynamic > onMethodCall (MethodCall call) {
562- calls.add (call);
563- switch (call.method) {
564- case 'init' :
565- initialized.complete (true );
566- break ;
567- case 'create' :
568- streams[nextTextureId] = FakeVideoEventStream (nextTextureId, 100 , 100 ,
569- const Duration (seconds: 1 ), forceInitError);
570- final Map <dynamic , dynamic > dataSource = call.arguments;
571- dataSourceDescriptions.add (dataSource.cast <String , dynamic >());
572- return Future <Map <String , int >>.sync (() {
573- return < String , int > {
574- 'textureId' : nextTextureId++ ,
575- };
576- });
577- break ;
578- case 'position' :
579- final Duration position = _positions[call.arguments['textureId' ]] ??
580- const Duration (seconds: 0 );
581- return Future <int >.value (position.inMilliseconds);
582- break ;
583- case 'seekTo' :
584- _positions[call.arguments['textureId' ]] =
585- Duration (milliseconds: call.arguments['location' ]);
586- break ;
587- case 'dispose' :
588- case 'pause' :
589- case 'play' :
590- case 'setLooping' :
591- case 'setVolume' :
592- break ;
593- default :
594- throw UnimplementedError (
595- '${call .method } is not implemented by the FakeVideoPlayerPlatform' );
596- }
597- return Future <void >.sync (() {});
551+ @override
552+ TextureMessage create (CreateMessage arg) {
553+ calls.add ('create' );
554+ streams[nextTextureId] = FakeVideoEventStream (
555+ nextTextureId, 100 , 100 , const Duration (seconds: 1 ), forceInitError);
556+ TextureMessage result = TextureMessage ();
557+ result.textureId = nextTextureId++ ;
558+ dataSourceDescriptions.add (arg);
559+ return result;
560+ }
561+
562+ @override
563+ void dispose (TextureMessage arg) {
564+ calls.add ('dispose' );
565+ }
566+
567+ @override
568+ void initialize () {
569+ calls.add ('init' );
570+ initialized.complete (true );
571+ }
572+
573+ @override
574+ void pause (TextureMessage arg) {
575+ calls.add ('pause' );
576+ }
577+
578+ @override
579+ void play (TextureMessage arg) {
580+ calls.add ('play' );
581+ }
582+
583+ @override
584+ PositionMessage position (TextureMessage arg) {
585+ calls.add ('position' );
586+ final Duration position =
587+ _positions[arg.textureId] ?? const Duration (seconds: 0 );
588+ return PositionMessage ()..position = position.inMilliseconds;
589+ }
590+
591+ @override
592+ void seekTo (PositionMessage arg) {
593+ calls.add ('seekTo' );
594+ _positions[arg.textureId] = Duration (milliseconds: arg.position);
595+ }
596+
597+ @override
598+ void setLooping (LoopingMessage arg) {
599+ calls.add ('setLooping' );
600+ }
601+
602+ @override
603+ void setVolume (VolumeMessage arg) {
604+ calls.add ('setVolume' );
598605 }
599606}
600607
0 commit comments