Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[video_player]: fixed platform_interface unit tests (#2745)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored May 8, 2020
1 parent 9f307e7 commit d64d0bf
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

* Migrated tests to use pigeon correctly.

## 2.0.1

* Updated minimum Dart version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand Down Expand Up @@ -39,182 +104,99 @@ void main() {
});

group('$MethodChannelVideoPlayer', () {
const MethodChannel channel = MethodChannel('flutter.io/videoPlayer');
final List<MethodCall> log = <MethodCall>[];
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,
<Matcher>[isMethodCall('init', arguments: null)],
log.log.last,
'init',
);
});

test('dispose', () async {
await player.dispose(1);
expect(
log,
<Matcher>[
isMethodCall('dispose', arguments: <String, Object>{
'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 <String, dynamic>{'textureId': 3};
});
final int textureId = await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: 'someAsset',
package: 'somePackage',
));
expect(
log,
<Matcher>[
isMethodCall('create', arguments: <String, Object>{
'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 <String, dynamic>{'textureId': 3};
});
final int textureId = await player.create(DataSource(
sourceType: DataSourceType.network,
uri: 'someUri',
formatHint: VideoFormat.dash,
));
expect(
log,
<Matcher>[
isMethodCall('create', arguments: <String, Object>{
'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 <String, dynamic>{'textureId': 3};
});
final int textureId = await player.create(DataSource(
sourceType: DataSourceType.file,
uri: 'someUri',
));
expect(
log,
<Matcher>[
isMethodCall('create', arguments: <String, Object>{
'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,
<Matcher>[
isMethodCall('setLooping', arguments: <String, Object>{
'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,
<Matcher>[
isMethodCall('play', arguments: <String, Object>{
'textureId': 1,
})
],
);
expect(log.log.last, 'play');
expect(log.textureMessage.textureId, 1);
});

test('pause', () async {
await player.pause(1);
expect(
log,
<Matcher>[
isMethodCall('pause', arguments: <String, Object>{
'textureId': 1,
})
],
);
expect(log.log.last, 'pause');
expect(log.textureMessage.textureId, 1);
});

test('setVolume', () async {
await player.setVolume(1, 0.7);
expect(
log,
<Matcher>[
isMethodCall('setVolume', arguments: <String, Object>{
'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,
<Matcher>[
isMethodCall('seekTo', arguments: <String, Object>{
'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,
<Matcher>[
isMethodCall('position', arguments: <String, Object>{
'textureId': 1,
})
],
);
expect(log.log.last, 'position');
expect(log.textureMessage.textureId, 1);
expect(position, const Duration(milliseconds: 234));
});

Expand Down

0 comments on commit d64d0bf

Please sign in to comment.