summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/feature-policy/resources/picture-in-picture.js
blob: 1bf3c1c12a8a9209ee9956955fd3a75d148897f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function async_pip_test(func, name) {
  async_test(t => {
    assert_true('pictureInPictureEnabled' in document, 'Picture-in-Picture API is available');
    func(t);
  }, name);
}

function promise_pip_test(func, name) {
  promise_test(async t => {
    assert_true('pictureInPictureEnabled' in document, 'Picture-in-Picture API is available');
    return func(t);
  }, name);
}

function isPictureInPictureAllowed() {
  return new Promise(resolve => {
    let video = document.createElement('video');
    video.src = getVideoURI('/media/movie_5');
    video.onloadedmetadata = () => {
      video.requestPictureInPicture()
      .then(() => resolve(document.pictureInPictureEnabled))
      .catch(e => {
        if (e.name == 'NotAllowedError')
          resolve(document.pictureInPictureEnabled);
        else
          resolve(false);
      });
    };
  });
}