picture-in-picture.js (862B)
1 function async_pip_test(func, name) { 2 async_test(t => { 3 assert_true('pictureInPictureEnabled' in document, 'Picture-in-Picture API is available'); 4 func(t); 5 }, name); 6 } 7 8 function promise_pip_test(func, name) { 9 promise_test(async t => { 10 assert_true('pictureInPictureEnabled' in document, 'Picture-in-Picture API is available'); 11 return func(t); 12 }, name); 13 } 14 15 function isPictureInPictureAllowed() { 16 return new Promise(resolve => { 17 let video = document.createElement('video'); 18 video.src = getVideoURI('/media/movie_5'); 19 video.onloadedmetadata = () => { 20 video.requestPictureInPicture() 21 .then(() => resolve(document.pictureInPictureEnabled)) 22 .catch(e => { 23 if (e.name == 'NotAllowedError') 24 resolve(document.pictureInPictureEnabled); 25 else 26 resolve(false); 27 }); 28 }; 29 }); 30 }