From d64d0bff8a5f8461eb9310759f6e573e5b79d4a2 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Thu, 7 May 2020 22:35:41 -0700 Subject: [PATCH] [video_player]: fixed platform_interface unit tests (#2745) --- .../CHANGELOG.md | 4 + .../pubspec.yaml | 2 +- .../method_channel_video_player_test.dart | 208 ++++++++---------- 3 files changed, 100 insertions(+), 114 deletions(-) diff --git a/packages/video_player/video_player_platform_interface/CHANGELOG.md b/packages/video_player/video_player_platform_interface/CHANGELOG.md index f1c48d8f61d0..f5aa5208e93c 100644 --- a/packages/video_player/video_player_platform_interface/CHANGELOG.md +++ b/packages/video_player/video_player_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.2 + +* Migrated tests to use pigeon correctly. + ## 2.0.1 * Updated minimum Dart version. diff --git a/packages/video_player/video_player_platform_interface/pubspec.yaml b/packages/video_player/video_player_platform_interface/pubspec.yaml index 911fc7814131..b4462679fcfc 100644 --- a/packages/video_player/video_player_platform_interface/pubspec.yaml +++ b/packages/video_player/video_player_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the video_player plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.0.1 +version: 2.0.2 dependencies: flutter: diff --git a/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart b/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart index a5fdbbc257de..e7bcf26e9d26 100644 --- a/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart +++ b/packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart @@ -10,6 +10,71 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:video_player_platform_interface/method_channel_video_player.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; +import 'package:video_player_platform_interface/messages.dart'; + +class _ApiLogger implements VideoPlayerApiTest { + final List log = []; + TextureMessage textureMessage; + CreateMessage createMessage; + PositionMessage positionMessage; + LoopingMessage loopingMessage; + VolumeMessage volumeMessage; + + @override + TextureMessage create(CreateMessage arg) { + log.add('create'); + createMessage = arg; + return TextureMessage()..textureId = 3; + } + + @override + void dispose(TextureMessage arg) { + log.add('dispose'); + textureMessage = arg; + } + + @override + void initialize() { + log.add('init'); + } + + @override + void pause(TextureMessage arg) { + log.add('pause'); + textureMessage = arg; + } + + @override + void play(TextureMessage arg) { + log.add('play'); + textureMessage = arg; + } + + @override + PositionMessage position(TextureMessage arg) { + log.add('position'); + textureMessage = arg; + return PositionMessage()..position = 234; + } + + @override + void seekTo(PositionMessage arg) { + log.add('seekTo'); + positionMessage = arg; + } + + @override + void setLooping(LoopingMessage arg) { + log.add('setLooping'); + loopingMessage = arg; + } + + @override + void setVolume(VolumeMessage arg) { + log.add('setVolume'); + volumeMessage = arg; + } +} void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -39,182 +104,99 @@ void main() { }); group('$MethodChannelVideoPlayer', () { - const MethodChannel channel = MethodChannel('flutter.io/videoPlayer'); - final List log = []; final MethodChannelVideoPlayer player = MethodChannelVideoPlayer(); + _ApiLogger log; setUp(() { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - }); - }); - - tearDown(() { - log.clear(); + log = _ApiLogger(); + VideoPlayerApiTestSetup(log); }); test('init', () async { await player.init(); expect( - log, - [isMethodCall('init', arguments: null)], + log.log.last, + 'init', ); }); test('dispose', () async { await player.dispose(1); - expect( - log, - [ - isMethodCall('dispose', arguments: { - 'textureId': 1, - }) - ], - ); + expect(log.log.last, 'dispose'); + expect(log.textureMessage.textureId, 1); }); test('create with asset', () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - return {'textureId': 3}; - }); final int textureId = await player.create(DataSource( sourceType: DataSourceType.asset, asset: 'someAsset', package: 'somePackage', )); - expect( - log, - [ - isMethodCall('create', arguments: { - 'asset': 'someAsset', - 'package': 'somePackage', - }) - ], - ); + expect(log.log.last, 'create'); + expect(log.createMessage.asset, 'someAsset'); + expect(log.createMessage.packageName, 'somePackage'); expect(textureId, 3); }); test('create with network', () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - return {'textureId': 3}; - }); final int textureId = await player.create(DataSource( sourceType: DataSourceType.network, uri: 'someUri', formatHint: VideoFormat.dash, )); - expect( - log, - [ - isMethodCall('create', arguments: { - 'uri': 'someUri', - 'formatHint': 'dash' - }) - ], - ); + expect(log.log.last, 'create'); + expect(log.createMessage.uri, 'someUri'); + expect(log.createMessage.formatHint, 'dash'); expect(textureId, 3); }); test('create with file', () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - return {'textureId': 3}; - }); final int textureId = await player.create(DataSource( sourceType: DataSourceType.file, uri: 'someUri', )); - expect( - log, - [ - isMethodCall('create', arguments: { - 'uri': 'someUri', - }) - ], - ); + expect(log.log.last, 'create'); + expect(log.createMessage.uri, 'someUri'); expect(textureId, 3); }); test('setLooping', () async { await player.setLooping(1, true); - expect( - log, - [ - isMethodCall('setLooping', arguments: { - 'textureId': 1, - 'looping': true, - }) - ], - ); + expect(log.log.last, 'setLooping'); + expect(log.loopingMessage.textureId, 1); + expect(log.loopingMessage.isLooping, true); }); test('play', () async { await player.play(1); - expect( - log, - [ - isMethodCall('play', arguments: { - 'textureId': 1, - }) - ], - ); + expect(log.log.last, 'play'); + expect(log.textureMessage.textureId, 1); }); test('pause', () async { await player.pause(1); - expect( - log, - [ - isMethodCall('pause', arguments: { - 'textureId': 1, - }) - ], - ); + expect(log.log.last, 'pause'); + expect(log.textureMessage.textureId, 1); }); test('setVolume', () async { await player.setVolume(1, 0.7); - expect( - log, - [ - isMethodCall('setVolume', arguments: { - 'textureId': 1, - 'volume': 0.7, - }) - ], - ); + expect(log.log.last, 'setVolume'); + expect(log.volumeMessage.textureId, 1); + expect(log.volumeMessage.volume, 0.7); }); test('seekTo', () async { await player.seekTo(1, const Duration(milliseconds: 12345)); - expect( - log, - [ - isMethodCall('seekTo', arguments: { - 'textureId': 1, - 'location': 12345, - }) - ], - ); + expect(log.log.last, 'seekTo'); + expect(log.positionMessage.textureId, 1); + expect(log.positionMessage.position, 12345); }); test('getPosition', () async { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - return 234; - }); - final Duration position = await player.getPosition(1); - expect( - log, - [ - isMethodCall('position', arguments: { - 'textureId': 1, - }) - ], - ); + expect(log.log.last, 'position'); + expect(log.textureMessage.textureId, 1); expect(position, const Duration(milliseconds: 234)); });