Skip to content

Commit c89c8e7

Browse files
committed
chore: Add tests
1 parent 9c255f3 commit c89c8e7

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

packages/video_player/video_player_web/example/integration_test/video_player_test.dart

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,149 @@ void main() {
213213
expect(events[0].duration, equals(jsCompatibleTimeUnset));
214214
});
215215
});
216+
217+
group('VideoPlayerWebOptions', () {
218+
late VideoPlayer player;
219+
220+
setUp(() {
221+
video = html.VideoElement();
222+
player = VideoPlayer(videoElement: video)..initialize();
223+
});
224+
225+
group('VideoPlayerWebOptionsControls', () {
226+
testWidgets('when disabled expect no controls',
227+
(WidgetTester tester) async {
228+
await player.setOptions(
229+
const VideoPlayerWebOptions(
230+
// ignore: avoid_redundant_argument_values
231+
controls: VideoPlayerWebOptionsControls.disabled(),
232+
),
233+
);
234+
235+
expect(video.controls, isFalse);
236+
expect(video.controlsList, isNotNull);
237+
expect(video.controlsList?.length, isZero);
238+
});
239+
240+
group('when enabled', () {
241+
testWidgets('expect controls', (WidgetTester tester) async {
242+
await player.setOptions(
243+
const VideoPlayerWebOptions(
244+
controls: VideoPlayerWebOptionsControls.enabled(),
245+
),
246+
);
247+
248+
expect(video.controls, isTrue);
249+
expect(video.controlsList, isNotNull);
250+
expect(video.controlsList?.length, isZero);
251+
expect(video.controlsList?.contains('nodownload'), isFalse);
252+
expect(video.controlsList?.contains('nofullscreen'), isFalse);
253+
expect(video.controlsList?.contains('noplaybackrate'), isFalse);
254+
expect(video.getAttribute('disablePictureInPicture'), isNull);
255+
});
256+
257+
testWidgets('and no download expect correct controls',
258+
(WidgetTester tester) async {
259+
await player.setOptions(
260+
const VideoPlayerWebOptions(
261+
controls: VideoPlayerWebOptionsControls.enabled(
262+
allowDownload: false,
263+
),
264+
),
265+
);
266+
267+
expect(video.controls, isTrue);
268+
expect(video.controlsList, isNotNull);
269+
expect(video.controlsList?.length, 1);
270+
expect(video.controlsList?.contains('nodownload'), isTrue);
271+
expect(video.controlsList?.contains('nofullscreen'), isFalse);
272+
expect(video.controlsList?.contains('noplaybackrate'), isFalse);
273+
expect(video.getAttribute('disablePictureInPicture'), isNull);
274+
});
275+
276+
testWidgets('and no fullscreen expect correct controls',
277+
(WidgetTester tester) async {
278+
await player.setOptions(
279+
const VideoPlayerWebOptions(
280+
controls: VideoPlayerWebOptionsControls.enabled(
281+
allowFullscreen: false,
282+
),
283+
),
284+
);
285+
286+
expect(video.controls, isTrue);
287+
expect(video.controlsList, isNotNull);
288+
expect(video.controlsList?.length, 1);
289+
expect(video.controlsList?.contains('nodownload'), isFalse);
290+
expect(video.controlsList?.contains('nofullscreen'), isTrue);
291+
expect(video.controlsList?.contains('noplaybackrate'), isFalse);
292+
expect(video.getAttribute('disablePictureInPicture'), isNull);
293+
});
294+
295+
testWidgets('and no playback rate expect correct controls',
296+
(WidgetTester tester) async {
297+
await player.setOptions(
298+
const VideoPlayerWebOptions(
299+
controls: VideoPlayerWebOptionsControls.enabled(
300+
allowPlaybackRate: false,
301+
),
302+
),
303+
);
304+
305+
expect(video.controls, isTrue);
306+
expect(video.controlsList, isNotNull);
307+
expect(video.controlsList?.length, 1);
308+
expect(video.controlsList?.contains('nodownload'), isFalse);
309+
expect(video.controlsList?.contains('nofullscreen'), isFalse);
310+
expect(video.controlsList?.contains('noplaybackrate'), isTrue);
311+
expect(video.getAttribute('disablePictureInPicture'), isNull);
312+
});
313+
314+
testWidgets('and no picture in picture expect correct controls',
315+
(WidgetTester tester) async {
316+
await player.setOptions(
317+
const VideoPlayerWebOptions(
318+
controls: VideoPlayerWebOptionsControls.enabled(
319+
allowPictureInPicture: false,
320+
),
321+
),
322+
);
323+
324+
expect(video.controls, isTrue);
325+
expect(video.controlsList, isNotNull);
326+
expect(video.controlsList?.length, 0);
327+
expect(video.controlsList?.contains('nodownload'), isFalse);
328+
expect(video.controlsList?.contains('nofullscreen'), isFalse);
329+
expect(video.controlsList?.contains('noplaybackrate'), isFalse);
330+
expect(video.getAttribute('disablePictureInPicture'), 'true');
331+
});
332+
});
333+
});
334+
335+
group('allowRemotePlayback', () {
336+
testWidgets('when enabled expect no attribute',
337+
(WidgetTester tester) async {
338+
await player.setOptions(
339+
const VideoPlayerWebOptions(
340+
// ignore: avoid_redundant_argument_values
341+
allowRemotePlayback: true,
342+
),
343+
);
344+
345+
expect(video.getAttribute('disableRemotePlayback'), isNull);
346+
});
347+
348+
testWidgets('when disabled expect attribute',
349+
(WidgetTester tester) async {
350+
await player.setOptions(
351+
const VideoPlayerWebOptions(
352+
allowRemotePlayback: false,
353+
),
354+
);
355+
356+
expect(video.getAttribute('disableRemotePlayback'), 'true');
357+
});
358+
});
359+
});
216360
});
217361
}

packages/video_player/video_player_web/example/integration_test/video_player_web_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,15 @@ void main() {
239239
VideoEventType.bufferingEnd,
240240
]));
241241
});
242+
243+
testWidgets('can set web options', (WidgetTester tester) async {
244+
expect(
245+
VideoPlayerPlatform.instance.setWebOptions(
246+
await textureId,
247+
const VideoPlayerWebOptions(),
248+
),
249+
completes,
250+
);
251+
});
242252
});
243253
}

0 commit comments

Comments
 (0)