Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests.
  • Loading branch information
ditman committed Jun 26, 2024
commit 2fd629a69f9399a6e73c4ebf613d759cf5612977
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,59 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:video_player/video_player.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';

import 'video_player_test.dart' show FakeVideoPlayerPlatform;

void main() {
// This test needs to run first and therefore needs to be the only test
// in this file.
test('plugin initialized', () async {
TestWidgetsFlutterBinding.ensureInitialized();
final FakeVideoPlayerPlatform fakeVideoPlayerPlatform =
FakeVideoPlayerPlatform();
VideoPlayerPlatform.instance = fakeVideoPlayerPlatform;
TestWidgetsFlutterBinding.ensureInitialized();

late FakeVideoPlayerPlatform fakeVideoPlayerPlatform;

setUp(() {
VideoPlayerPlatform.instance =
fakeVideoPlayerPlatform = FakeVideoPlayerPlatform();
});

test('plugin initialized', () async {
final VideoPlayerController controller = VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
);
await controller.initialize();
expect(fakeVideoPlayerPlatform.calls.first, 'init');
});

test('web configuration is applied (web only)', () async {
const VideoPlayerWebOptions expected = VideoPlayerWebOptions(
allowContextMenu: false,
allowRemotePlayback: false,
controls: VideoPlayerWebOptionsControls.enabled(),
);

final VideoPlayerController controller = VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
videoPlayerOptions: VideoPlayerOptions(
webOptions: expected,
),
);
await controller.initialize();

expect(
() {
fakeVideoPlayerPlatform.calls.singleWhere(
(String call) => call == 'setWebOptions',
);
},
returnsNormally,
reason: 'setWebOptions must be called exactly once.',
);
expect(
fakeVideoPlayerPlatform.webOptions[controller.textureId],
expected,
reason: 'web options must be passed to the platform',
);
}, skip: !kIsWeb);
}
12 changes: 12 additions & 0 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,8 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
bool forceInitError = false;
int nextTextureId = 0;
final Map<int, Duration> _positions = <int, Duration>{};
final Map<int, VideoPlayerWebOptions> webOptions =
<int, VideoPlayerWebOptions>{};

@override
Future<int?> create(DataSource dataSource) async {
Expand Down Expand Up @@ -1392,4 +1394,14 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
Widget buildView(int textureId) {
return Texture(textureId: textureId);
}

@override
Future<void> setWebOptions(
int textureId, VideoPlayerWebOptions options) async {
if (!kIsWeb) {
throw UnimplementedError('setWebOptions() is only available in the web.');
}
calls.add('setWebOptions');
webOptions[textureId] = options;
}
}