Skip to content

Commit d90144e

Browse files
gaaclarkeEgor
authored andcommitted
[video_player]: fixed platform_interface unit tests (flutter#2745)
1 parent fb7dabd commit d90144e

File tree

3 files changed

+100
-114
lines changed

3 files changed

+100
-114
lines changed

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.2
2+
3+
* Migrated tests to use pigeon correctly.
4+
15
## 2.0.1
26

37
* Updated minimum Dart version.

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the video_player plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 2.0.1
6+
version: 2.0.2
77

88
dependencies:
99
flutter:

packages/video_player/video_player_platform_interface/test/method_channel_video_player_test.dart

Lines changed: 95 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,71 @@ import 'package:flutter_test/flutter_test.dart';
1010

1111
import 'package:video_player_platform_interface/method_channel_video_player.dart';
1212
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+
}
1378

1479
void main() {
1580
TestWidgetsFlutterBinding.ensureInitialized();
@@ -39,182 +104,99 @@ void main() {
39104
});
40105

41106
group('$MethodChannelVideoPlayer', () {
42-
const MethodChannel channel = MethodChannel('flutter.io/videoPlayer');
43-
final List<MethodCall> log = <MethodCall>[];
44107
final MethodChannelVideoPlayer player = MethodChannelVideoPlayer();
108+
_ApiLogger log;
45109

46110
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);
54113
});
55114

56115
test('init', () async {
57116
await player.init();
58117
expect(
59-
log,
60-
<Matcher>[isMethodCall('init', arguments: null)],
118+
log.log.last,
119+
'init',
61120
);
62121
});
63122

64123
test('dispose', () async {
65124
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);
74127
});
75128

76129
test('create with asset', () async {
77-
channel.setMockMethodCallHandler((MethodCall methodCall) async {
78-
log.add(methodCall);
79-
return <String, dynamic>{'textureId': 3};
80-
});
81130
final int textureId = await player.create(DataSource(
82131
sourceType: DataSourceType.asset,
83132
asset: 'someAsset',
84133
package: 'somePackage',
85134
));
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');
95138
expect(textureId, 3);
96139
});
97140

98141
test('create with network', () async {
99-
channel.setMockMethodCallHandler((MethodCall methodCall) async {
100-
log.add(methodCall);
101-
return <String, dynamic>{'textureId': 3};
102-
});
103142
final int textureId = await player.create(DataSource(
104143
sourceType: DataSourceType.network,
105144
uri: 'someUri',
106145
formatHint: VideoFormat.dash,
107146
));
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');
117150
expect(textureId, 3);
118151
});
119152

120153
test('create with file', () async {
121-
channel.setMockMethodCallHandler((MethodCall methodCall) async {
122-
log.add(methodCall);
123-
return <String, dynamic>{'textureId': 3};
124-
});
125154
final int textureId = await player.create(DataSource(
126155
sourceType: DataSourceType.file,
127156
uri: 'someUri',
128157
));
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');
137160
expect(textureId, 3);
138161
});
139162

140163
test('setLooping', () async {
141164
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);
151168
});
152169

153170
test('play', () async {
154171
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);
163174
});
164175

165176
test('pause', () async {
166177
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);
175180
});
176181

177182
test('setVolume', () async {
178183
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);
188187
});
189188

190189
test('seekTo', () async {
191190
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);
201194
});
202195

203196
test('getPosition', () async {
204-
channel.setMockMethodCallHandler((MethodCall methodCall) async {
205-
log.add(methodCall);
206-
return 234;
207-
});
208-
209197
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);
218200
expect(position, const Duration(milliseconds: 234));
219201
});
220202

0 commit comments

Comments
 (0)