[Web Animations] Update WPT tests related to Web Animations and remove imported Mozil...
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / picture-in-picture / disable-picture-in-picture.html
1 <!DOCTYPE html>
2 <title>Test disable Picture-in-Picture</title>
3 <script src="/common/media.js"></script>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script src="/resources/testdriver.js"></script>
7 <script src="/resources/testdriver-vendor.js"></script>
8 <script src="resources/picture-in-picture-helpers.js"></script>
9 <body></body>
10 <script>
11 test(t => {
12   const video = document.createElement('video');
13   assert_false(video.disablePictureInPicture); // default value
14
15   video.setAttribute('disablepictureinpicture', 'foo');
16   assert_true(video.disablePictureInPicture);
17
18   video.removeAttribute('disablepictureinpicture');
19   assert_false(video.disablePictureInPicture);
20
21   video.disablePictureInPicture = true;
22   assert_equals(video.getAttribute('disablepictureinpicture'), '');
23
24   video.disablePictureInPicture = false;
25   assert_equals(video.getAttribute('disablepictureinpicture'), null);
26 }, 'Test disablePictureInPicture IDL attribute');
27
28 promise_test(async t => {
29   const video = await loadVideo();
30   video.disablePictureInPicture = true;
31   return promise_rejects(t, 'InvalidStateError',
32       requestPictureInPictureWithTrustedClick(video));
33 }, 'Request Picture-in-Picture rejects if disablePictureInPicture is true');
34
35 promise_test(async t => {
36   const video = await loadVideo();
37   await test_driver.bless('request Picture-in-Picture');
38   const promise = video.requestPictureInPicture();
39   video.disablePictureInPicture = true;
40   await promise_rejects(t, 'InvalidStateError', promise);
41   assert_equals(document.pictureInPictureElement, null);
42 }, 'Request Picture-in-Picture rejects if disablePictureInPicture becomes ' +
43    'true before promise resolves.');
44
45 promise_test(async t => {
46   const video = await loadVideo();
47   return requestPictureInPictureWithTrustedClick(video)
48   .then(() => {
49     video.disablePictureInPicture = true;
50     video.addEventListener('leavepictureinpicture', t.step_func(() => {
51       assert_equals(document.pictureInPictureElement, null);
52     }));
53   });
54 }, 'pictureInPictureElement is unset if disablePictureInPicture becomes true');
55
56 promise_test(async t => {
57   const video = await loadVideo();
58   return requestPictureInPictureWithTrustedClick(video)
59   .then(() => {
60     video.disablePictureInPicture = false;
61     assert_equals(document.pictureInPictureElement, video);
62   });
63 }, 'pictureInPictureElement is unchanged if disablePictureInPicture becomes false');
64
65 promise_test(async t => {
66   const video = await loadVideo();
67   return requestPictureInPictureWithTrustedClick(video)
68   .then(() => {
69     document.createElement('video').disablePictureInPicture = true;
70     assert_equals(document.pictureInPictureElement, video);
71   });
72 }, 'pictureInPictureElement is unchanged if disablePictureInPicture becomes ' +
73    'true for another video');
74 </script>