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

Commit 02e0e9b

Browse files
committed
[video_player_web] Move tests to integration_test style so they run in CI.
1 parent 25ff344 commit 02e0e9b

File tree

9 files changed

+179
-42
lines changed

9 files changed

+179
-42
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Testing
2+
3+
This package utilizes the `integration_test` package to run its tests in a web browser.
4+
5+
See [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) for more info.
6+
7+
## Running the tests
8+
9+
Make sure you have updated to the latest Flutter master.
10+
11+
1. Check what version of Chrome is running on the machine you're running tests on.
12+
13+
2. Download and install driver for that version from here:
14+
* <https://chromedriver.chromium.org/downloads>
15+
16+
3. Start the driver using `chromedriver --port=4444`
17+
18+
4. Run tests: `flutter drive -d web-server --browser-name=chrome --driver=test_driver/integration_driver.dart --target=integration_test/TEST_NAME.dart`, or (in Linux):
19+
20+
* Single: `./run_test.sh integration_test/TEST_NAME.dart`
21+
* All: `./run_test.sh`

packages/video_player/video_player_web/test/video_player_web_test.dart renamed to packages/video_player/video_player_web/example/integration_test/video_player_web_test.dart

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@TestOn('browser')
6-
75
import 'dart:async';
86

97
import 'package:flutter/services.dart';
108
import 'package:flutter/widgets.dart';
119
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:integration_test/integration_test.dart';
1211
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
1312
import 'package:video_player_web/video_player_web.dart';
1413

1514
void main() {
15+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
16+
1617
group('VideoPlayer for Web', () {
17-
late int textureId;
18+
late Future<int> textureId;
1819

19-
setUp(() async {
20+
setUp(() {
2021
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!);
3131
});
3232

33-
test('can init', () {
33+
testWidgets('can init', (WidgetTester tester) async {
3434
expect(VideoPlayerPlatform.instance.init(), completes);
3535
});
3636

37-
test('can create from network', () {
37+
testWidgets('can create from network', (WidgetTester tester) async {
3838
expect(
3939
VideoPlayerPlatform.instance.create(
4040
DataSource(
@@ -45,7 +45,7 @@ void main() {
4545
completion(isNonZero));
4646
});
4747

48-
test('can create from asset', () {
48+
testWidgets('can create from asset', (WidgetTester tester) async {
4949
expect(
5050
VideoPlayerPlatform.instance.create(
5151
DataSource(
@@ -57,7 +57,7 @@ void main() {
5757
completion(isNonZero));
5858
});
5959

60-
test('cannot create from file', () {
60+
testWidgets('cannot create from file', (WidgetTester tester) async {
6161
expect(
6262
VideoPlayerPlatform.instance.create(
6363
DataSource(
@@ -68,22 +68,25 @@ void main() {
6868
throwsUnimplementedError);
6969
});
7070

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);
7373
});
7474

75-
test('can set looping', () {
75+
testWidgets('can set looping', (WidgetTester tester) async {
7676
expect(
77-
VideoPlayerPlatform.instance.setLooping(textureId, true), completes);
77+
VideoPlayerPlatform.instance.setLooping(await textureId, true),
78+
completes,
79+
);
7880
});
7981

80-
test('can play', () async {
82+
testWidgets('can play', (WidgetTester tester) async {
8183
// 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);
8486
});
8587

86-
test('throws PlatformException when playing bad media', () async {
88+
testWidgets('throws PlatformException when playing bad media',
89+
(WidgetTester tester) async {
8790
int videoPlayerId = (await VideoPlayerPlatform.instance.create(
8891
DataSource(
8992
sourceType: DataSourceType.network,
@@ -103,43 +106,50 @@ void main() {
103106
}, throwsA(isA<PlatformException>()));
104107
});
105108

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);
108111
});
109112

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+
);
112118
});
113119

114-
test('can set playback speed', () {
120+
testWidgets('can set playback speed', (WidgetTester tester) async {
115121
expect(
116-
VideoPlayerPlatform.instance.setPlaybackSpeed(textureId, 2.0),
122+
VideoPlayerPlatform.instance.setPlaybackSpeed(await textureId, 2.0),
117123
completes,
118124
);
119125
});
120126

121-
test('can seek to position', () {
127+
testWidgets('can seek to position', (WidgetTester tester) async {
122128
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+
);
125135
});
126136

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),
129139
completion(isInstanceOf<Duration>()));
130140
});
131141

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),
134144
isInstanceOf<Stream<VideoEvent>>());
135145
});
136146

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),
139149
isInstanceOf<Widget>());
140150
});
141151

142-
test('ignores setting mixWithOthers', () {
152+
testWidgets('ignores setting mixWithOthers', (WidgetTester tester) async {
143153
expect(VideoPlayerPlatform.instance.setMixWithOthers(true), completes);
144154
expect(VideoPlayerPlatform.instance.setMixWithOthers(false), completes);
145155
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() {
8+
runApp(MyApp());
9+
}
10+
11+
/// App for testing
12+
class MyApp extends StatefulWidget {
13+
@override
14+
_MyAppState createState() => _MyAppState();
15+
}
16+
17+
class _MyAppState extends State<MyApp> {
18+
@override
19+
Widget build(BuildContext context) {
20+
return Directionality(
21+
textDirection: TextDirection.ltr,
22+
child: Text('Testing... Look at the console output for results!'),
23+
);
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: connectivity_for_web_integration_tests
2+
publish_to: none
3+
4+
environment:
5+
sdk: ">=2.12.0 <3.0.0"
6+
flutter: ">=2.2.0"
7+
8+
dependencies:
9+
video_player_web:
10+
path: ../
11+
flutter:
12+
sdk: flutter
13+
14+
dev_dependencies:
15+
flutter_test:
16+
sdk: flutter
17+
flutter_driver:
18+
sdk: flutter
19+
integration_test:
20+
sdk: flutter
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/bash
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
if pgrep -lf chromedriver > /dev/null; then
7+
echo "chromedriver is running."
8+
9+
if [ $# -eq 0 ]; then
10+
echo "No target specified, running all tests..."
11+
find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target='{}'
12+
else
13+
echo "Running test target: $1..."
14+
set -x
15+
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target=$1
16+
fi
17+
18+
else
19+
echo "chromedriver is not running."
20+
echo "Please, check the README.md for instructions on how to use run_test.sh"
21+
fi
22+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:integration_test/integration_test_driver.dart';
6+
7+
Future<void> main() => integrationDriver();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<!-- Copyright 2013 The Flutter Authors. All rights reserved.
3+
Use of this source code is governed by a BSD-style license that can be
4+
found in the LICENSE file. -->
5+
<html>
6+
<head>
7+
<meta charset="UTF-8">
8+
<title>example</title>
9+
</head>
10+
<body>
11+
<script src="main.dart.js" type="application/javascript"></script>
12+
</body>
13+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## test
2+
3+
This package uses integration tests for testing.
4+
5+
See `example/README.md` for more info.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
test('Tell the user where to find the real tests', () {
9+
print('---');
10+
print('This package uses integration_test for its tests.');
11+
print('See `example/README.md` for more info.');
12+
print('---');
13+
});
14+
}

0 commit comments

Comments
 (0)