2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- @TestOn ('browser' )
6
-
7
5
import 'dart:async' ;
8
6
9
7
import 'package:flutter/services.dart' ;
10
8
import 'package:flutter/widgets.dart' ;
11
9
import 'package:flutter_test/flutter_test.dart' ;
10
+ import 'package:integration_test/integration_test.dart' ;
12
11
import 'package:video_player_platform_interface/video_player_platform_interface.dart' ;
13
12
import 'package:video_player_web/video_player_web.dart' ;
14
13
15
14
void main () {
15
+ IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
16
+
16
17
group ('VideoPlayer for Web' , () {
17
- late int textureId;
18
+ late Future < int > textureId;
18
19
19
- setUp (() async {
20
+ setUp (() {
20
21
VideoPlayerPlatform .instance = VideoPlayerPlugin ();
21
- textureId = (await VideoPlayerPlatform .instance.create (
22
- DataSource (
23
- sourceType: DataSourceType .network,
24
- uri:
25
- 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' ),
26
- ))! ;
27
- });
28
-
29
- test ('$VideoPlayerPlugin is the live instance' , () {
30
- expect (VideoPlayerPlatform .instance, isA <VideoPlayerPlugin >());
22
+ textureId = VideoPlayerPlatform .instance
23
+ .create (
24
+ DataSource (
25
+ sourceType: DataSourceType .network,
26
+ uri:
27
+ 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' ,
28
+ ),
29
+ )
30
+ .then ((textureId) => textureId! );
31
31
});
32
32
33
- test ('can init' , () {
33
+ testWidgets ('can init' , (WidgetTester tester) async {
34
34
expect (VideoPlayerPlatform .instance.init (), completes);
35
35
});
36
36
37
- test ('can create from network' , () {
37
+ testWidgets ('can create from network' , (WidgetTester tester) async {
38
38
expect (
39
39
VideoPlayerPlatform .instance.create (
40
40
DataSource (
@@ -45,7 +45,7 @@ void main() {
45
45
completion (isNonZero));
46
46
});
47
47
48
- test ('can create from asset' , () {
48
+ testWidgets ('can create from asset' , (WidgetTester tester) async {
49
49
expect (
50
50
VideoPlayerPlatform .instance.create (
51
51
DataSource (
@@ -57,7 +57,7 @@ void main() {
57
57
completion (isNonZero));
58
58
});
59
59
60
- test ('cannot create from file' , () {
60
+ testWidgets ('cannot create from file' , (WidgetTester tester) async {
61
61
expect (
62
62
VideoPlayerPlatform .instance.create (
63
63
DataSource (
@@ -68,22 +68,25 @@ void main() {
68
68
throwsUnimplementedError);
69
69
});
70
70
71
- test ('can dispose' , () {
72
- expect (VideoPlayerPlatform .instance.dispose (textureId), completes);
71
+ testWidgets ('can dispose' , (WidgetTester tester) async {
72
+ expect (VideoPlayerPlatform .instance.dispose (await textureId), completes);
73
73
});
74
74
75
- test ('can set looping' , () {
75
+ testWidgets ('can set looping' , (WidgetTester tester) async {
76
76
expect (
77
- VideoPlayerPlatform .instance.setLooping (textureId, true ), completes);
77
+ VideoPlayerPlatform .instance.setLooping (await textureId, true ),
78
+ completes,
79
+ );
78
80
});
79
81
80
- test ('can play' , () async {
82
+ testWidgets ('can play' , (WidgetTester tester ) async {
81
83
// Mute video to allow autoplay (See https://goo.gl/xX8pDD)
82
- await VideoPlayerPlatform .instance.setVolume (textureId, 0 );
83
- expect (VideoPlayerPlatform .instance.play (textureId), completes);
84
+ await VideoPlayerPlatform .instance.setVolume (await textureId, 0 );
85
+ expect (VideoPlayerPlatform .instance.play (await textureId), completes);
84
86
});
85
87
86
- test ('throws PlatformException when playing bad media' , () async {
88
+ testWidgets ('throws PlatformException when playing bad media' ,
89
+ (WidgetTester tester) async {
87
90
int videoPlayerId = (await VideoPlayerPlatform .instance.create (
88
91
DataSource (
89
92
sourceType: DataSourceType .network,
@@ -103,43 +106,50 @@ void main() {
103
106
}, throwsA (isA <PlatformException >()));
104
107
});
105
108
106
- test ('can pause' , () {
107
- expect (VideoPlayerPlatform .instance.pause (textureId), completes);
109
+ testWidgets ('can pause' , (WidgetTester tester) async {
110
+ expect (VideoPlayerPlatform .instance.pause (await textureId), completes);
108
111
});
109
112
110
- test ('can set volume' , () {
111
- expect (VideoPlayerPlatform .instance.setVolume (textureId, 0.8 ), completes);
113
+ testWidgets ('can set volume' , (WidgetTester tester) async {
114
+ expect (
115
+ VideoPlayerPlatform .instance.setVolume (await textureId, 0.8 ),
116
+ completes,
117
+ );
112
118
});
113
119
114
- test ('can set playback speed' , () {
120
+ testWidgets ('can set playback speed' , (WidgetTester tester) async {
115
121
expect (
116
- VideoPlayerPlatform .instance.setPlaybackSpeed (textureId, 2.0 ),
122
+ VideoPlayerPlatform .instance.setPlaybackSpeed (await textureId, 2.0 ),
117
123
completes,
118
124
);
119
125
});
120
126
121
- test ('can seek to position' , () {
127
+ testWidgets ('can seek to position' , (WidgetTester tester) async {
122
128
expect (
123
- VideoPlayerPlatform .instance.seekTo (textureId, Duration (seconds: 1 )),
124
- completes);
129
+ VideoPlayerPlatform .instance.seekTo (
130
+ await textureId,
131
+ Duration (seconds: 1 ),
132
+ ),
133
+ completes,
134
+ );
125
135
});
126
136
127
- test ('can get position' , () {
128
- expect (VideoPlayerPlatform .instance.getPosition (textureId),
137
+ testWidgets ('can get position' , (WidgetTester tester) async {
138
+ expect (VideoPlayerPlatform .instance.getPosition (await textureId),
129
139
completion (isInstanceOf <Duration >()));
130
140
});
131
141
132
- test ('can get video event stream' , () {
133
- expect (VideoPlayerPlatform .instance.videoEventsFor (textureId),
142
+ testWidgets ('can get video event stream' , (WidgetTester tester) async {
143
+ expect (VideoPlayerPlatform .instance.videoEventsFor (await textureId),
134
144
isInstanceOf <Stream <VideoEvent >>());
135
145
});
136
146
137
- test ('can build view' , () {
138
- expect (VideoPlayerPlatform .instance.buildView (textureId),
147
+ testWidgets ('can build view' , (WidgetTester tester) async {
148
+ expect (VideoPlayerPlatform .instance.buildView (await textureId),
139
149
isInstanceOf <Widget >());
140
150
});
141
151
142
- test ('ignores setting mixWithOthers' , () {
152
+ testWidgets ('ignores setting mixWithOthers' , (WidgetTester tester) async {
143
153
expect (VideoPlayerPlatform .instance.setMixWithOthers (true ), completes);
144
154
expect (VideoPlayerPlatform .instance.setMixWithOthers (false ), completes);
145
155
});
0 commit comments