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
+ textureId = VideoPlayerPlatform .instance.create (
22
23
DataSource (
23
24
sourceType: DataSourceType .network,
24
25
uri:
25
26
'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 >());
27
+ ).then ((textureId) => textureId! );
31
28
});
32
29
33
- test ('can init' , () {
30
+ testWidgets ('can init' , (WidgetTester tester) async {
34
31
expect (VideoPlayerPlatform .instance.init (), completes);
35
32
});
36
33
37
- test ('can create from network' , () {
34
+ testWidgets ('can create from network' , (WidgetTester tester) async {
38
35
expect (
39
36
VideoPlayerPlatform .instance.create (
40
37
DataSource (
@@ -45,7 +42,7 @@ void main() {
45
42
completion (isNonZero));
46
43
});
47
44
48
- test ('can create from asset' , () {
45
+ testWidgets ('can create from asset' , (WidgetTester tester) async {
49
46
expect (
50
47
VideoPlayerPlatform .instance.create (
51
48
DataSource (
@@ -57,7 +54,7 @@ void main() {
57
54
completion (isNonZero));
58
55
});
59
56
60
- test ('cannot create from file' , () {
57
+ testWidgets ('cannot create from file' , (WidgetTester tester) async {
61
58
expect (
62
59
VideoPlayerPlatform .instance.create (
63
60
DataSource (
@@ -68,22 +65,22 @@ void main() {
68
65
throwsUnimplementedError);
69
66
});
70
67
71
- test ('can dispose' , () {
72
- expect (VideoPlayerPlatform .instance.dispose (textureId), completes);
68
+ testWidgets ('can dispose' , (WidgetTester tester) async {
69
+ expect (VideoPlayerPlatform .instance.dispose (await textureId), completes);
73
70
});
74
71
75
- test ('can set looping' , () {
72
+ testWidgets ('can set looping' , (WidgetTester tester) async {
76
73
expect (
77
- VideoPlayerPlatform .instance.setLooping (textureId, true ), completes);
74
+ VideoPlayerPlatform .instance.setLooping (await textureId, true ), completes);
78
75
});
79
76
80
- test ('can play' , () async {
77
+ testWidgets ('can play' , (WidgetTester tester ) async {
81
78
// Mute video to allow autoplay (See https://goo.gl/xX8pDD)
82
- await VideoPlayerPlatform .instance.setVolume (textureId, 0 );
83
- expect (VideoPlayerPlatform .instance.play (textureId), completes);
79
+ await VideoPlayerPlatform .instance.setVolume (await textureId, 0 );
80
+ expect (VideoPlayerPlatform .instance.play (await textureId), completes);
84
81
});
85
82
86
- test ('throws PlatformException when playing bad media' , () async {
83
+ testWidgets ('throws PlatformException when playing bad media' , (WidgetTester tester ) async {
87
84
int videoPlayerId = (await VideoPlayerPlatform .instance.create (
88
85
DataSource (
89
86
sourceType: DataSourceType .network,
@@ -103,43 +100,43 @@ void main() {
103
100
}, throwsA (isA <PlatformException >()));
104
101
});
105
102
106
- test ('can pause' , () {
107
- expect (VideoPlayerPlatform .instance.pause (textureId), completes);
103
+ testWidgets ('can pause' , (WidgetTester tester) async {
104
+ expect (VideoPlayerPlatform .instance.pause (await textureId), completes);
108
105
});
109
106
110
- test ('can set volume' , () {
111
- expect (VideoPlayerPlatform .instance.setVolume (textureId, 0.8 ), completes);
107
+ testWidgets ('can set volume' , (WidgetTester tester) async {
108
+ expect (VideoPlayerPlatform .instance.setVolume (await textureId, 0.8 ), completes);
112
109
});
113
110
114
- test ('can set playback speed' , () {
111
+ testWidgets ('can set playback speed' , (WidgetTester tester) async {
115
112
expect (
116
- VideoPlayerPlatform .instance.setPlaybackSpeed (textureId, 2.0 ),
113
+ VideoPlayerPlatform .instance.setPlaybackSpeed (await textureId, 2.0 ),
117
114
completes,
118
115
);
119
116
});
120
117
121
- test ('can seek to position' , () {
118
+ testWidgets ('can seek to position' , (WidgetTester tester) async {
122
119
expect (
123
- VideoPlayerPlatform .instance.seekTo (textureId, Duration (seconds: 1 )),
120
+ VideoPlayerPlatform .instance.seekTo (await textureId, Duration (seconds: 1 )),
124
121
completes);
125
122
});
126
123
127
- test ('can get position' , () {
128
- expect (VideoPlayerPlatform .instance.getPosition (textureId),
124
+ testWidgets ('can get position' , (WidgetTester tester) async {
125
+ expect (VideoPlayerPlatform .instance.getPosition (await textureId),
129
126
completion (isInstanceOf <Duration >()));
130
127
});
131
128
132
- test ('can get video event stream' , () {
133
- expect (VideoPlayerPlatform .instance.videoEventsFor (textureId),
129
+ testWidgets ('can get video event stream' , (WidgetTester tester) async {
130
+ expect (VideoPlayerPlatform .instance.videoEventsFor (await textureId),
134
131
isInstanceOf <Stream <VideoEvent >>());
135
132
});
136
133
137
- test ('can build view' , () {
138
- expect (VideoPlayerPlatform .instance.buildView (textureId),
134
+ testWidgets ('can build view' , (WidgetTester tester) async {
135
+ expect (VideoPlayerPlatform .instance.buildView (await textureId),
139
136
isInstanceOf <Widget >());
140
137
});
141
138
142
- test ('ignores setting mixWithOthers' , () {
139
+ testWidgets ('ignores setting mixWithOthers' , (WidgetTester tester) async {
143
140
expect (VideoPlayerPlatform .instance.setMixWithOthers (true ), completes);
144
141
expect (VideoPlayerPlatform .instance.setMixWithOthers (false ), completes);
145
142
});
0 commit comments