@@ -213,5 +213,199 @@ void main() {
213
213
expect (events[0 ].duration, equals (jsCompatibleTimeUnset));
214
214
});
215
215
});
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
+
360
+ group ('when called first time' , () {
361
+ testWidgets ('expect correct options' , (WidgetTester tester) async {
362
+ await player.setOptions (
363
+ const VideoPlayerWebOptions (
364
+ controls: VideoPlayerWebOptionsControls .enabled (
365
+ allowDownload: false ,
366
+ allowFullscreen: false ,
367
+ allowPlaybackRate: false ,
368
+ allowPictureInPicture: false ,
369
+ ),
370
+ allowContextMenu: false ,
371
+ allowRemotePlayback: false ,
372
+ ),
373
+ );
374
+
375
+ expect (video.controls, isTrue);
376
+ expect (video.controlsList, isNotNull);
377
+ expect (video.controlsList? .length, 3 );
378
+ expect (video.controlsList? .contains ('nodownload' ), isTrue);
379
+ expect (video.controlsList? .contains ('nofullscreen' ), isTrue);
380
+ expect (video.controlsList? .contains ('noplaybackrate' ), isTrue);
381
+ expect (video.getAttribute ('disablePictureInPicture' ), 'true' );
382
+ expect (video.getAttribute ('disableRemotePlayback' ), 'true' );
383
+ });
384
+
385
+ group ('when called once more' , () {
386
+ testWidgets ('expect correct options' , (WidgetTester tester) async {
387
+ await player.setOptions (
388
+ const VideoPlayerWebOptions (
389
+ // ignore: avoid_redundant_argument_values
390
+ controls: VideoPlayerWebOptionsControls .disabled (),
391
+ // ignore: avoid_redundant_argument_values
392
+ allowContextMenu: true ,
393
+ // ignore: avoid_redundant_argument_values
394
+ allowRemotePlayback: true ,
395
+ ),
396
+ );
397
+
398
+ expect (video.controls, isFalse);
399
+ expect (video.controlsList, isNotNull);
400
+ expect (video.controlsList? .length, 0 );
401
+ expect (video.controlsList? .contains ('nodownload' ), isFalse);
402
+ expect (video.controlsList? .contains ('nofullscreen' ), isFalse);
403
+ expect (video.controlsList? .contains ('noplaybackrate' ), isFalse);
404
+ expect (video.getAttribute ('disablePictureInPicture' ), isNull);
405
+ expect (video.getAttribute ('disableRemotePlayback' ), isNull);
406
+ });
407
+ });
408
+ });
409
+ });
216
410
});
217
411
}
0 commit comments