tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

picture-in-picture-window.html (3395B)


      1 <!DOCTYPE html>
      2 <title>Test Picture-in-Picture window</title>
      3 <meta name="timeout" content="long">
      4 <script src="/common/media.js"></script>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-vendor.js"></script>
      9 <script src="resources/picture-in-picture-helpers.js"></script>
     10 <body></body>
     11 <script>
     12 promise_test(async t => {
     13  const video = await loadVideo();
     14  return requestPictureInPictureWithTrustedClick(video)
     15  .then(pipWindow => {
     16    assert_not_equals(pipWindow.width, 0);
     17    assert_not_equals(pipWindow.height, 0);
     18    const videoAspectRatio = video.videoWidth / video.videoHeight;
     19    const pipWindowAspectRatio = pipWindow.width / pipWindow.height;
     20    assert_approx_equals(videoAspectRatio, pipWindowAspectRatio, 0.01);
     21  });
     22 }, 'Picture-in-Picture window dimensions are set after entering Picture-in-Picture');
     23 
     24 promise_test(async t => {
     25  const video1 = await loadVideo();
     26  const video2 = await loadVideo();
     27  return requestPictureInPictureWithTrustedClick(video1)
     28  .then(pipWindow1 => {
     29    return requestPictureInPictureWithTrustedClick(video2)
     30    .then(pipWindow2 => {
     31      assert_equals(pipWindow1.width, 0);
     32      assert_equals(pipWindow1.height, 0);
     33      assert_not_equals(pipWindow2.width, 0);
     34      assert_not_equals(pipWindow2.height, 0);
     35    });
     36  });
     37 }, 'Picture-in-Picture window dimensions are set to 0 after entering ' +
     38   'Picture-in-Picture for another video');
     39 
     40 promise_test(async t => {
     41  const video = await loadVideo();
     42 
     43  video.addEventListener('leavepictureinpicture', t.step_func_done(event => {
     44    assert_unreached('leavepictureinpicture event should not fire.')
     45  }));
     46 
     47  let enterCounts = 0;
     48  video.addEventListener('enterpictureinpicture', event => {
     49    enterCounts++;
     50  });
     51 
     52  return requestPictureInPictureWithTrustedClick(video)
     53  .then(pipWindow1 => {
     54    pipWindow1.onresize = function foo() {};
     55    return requestPictureInPictureWithTrustedClick(video)
     56    .then(pipWindow2 => {
     57      assert_equals(pipWindow1, pipWindow2);
     58      assert_equals(pipWindow1.width, pipWindow2.width);
     59      assert_equals(pipWindow1.height, pipWindow2.height);
     60      assert_equals(pipWindow1.onresize, pipWindow2.onresize);
     61      assert_equals(enterCounts, 1);
     62    });
     63  });
     64 }, 'Picture-in-Picture window is unchanged after entering ' +
     65   'Picture-in-Picture for video already in Picture-in-Picture');
     66 
     67 promise_test(async t => {
     68  const video = await loadVideo();
     69 
     70  return requestPictureInPictureWithTrustedClick(video)
     71  .then(pipWindow => {
     72    return document.exitPictureInPicture()
     73    .then(() => {
     74      assert_equals(pipWindow.width, 0);
     75      assert_equals(pipWindow.height, 0);
     76    });
     77  });
     78 }, 'Picture-in-Picture window dimensions are set to 0 after exiting Picture-in-Picture');
     79 
     80 promise_test(async t => {
     81  const video = await loadVideo();
     82  let thePipWindow;
     83 
     84  video.addEventListener('leavepictureinpicture', t.step_func_done(event => {
     85    assert_equals(thePipWindow.width, 0);
     86    assert_equals(thePipWindow.height, 0);
     87  }));
     88 
     89  return requestPictureInPictureWithTrustedClick(video)
     90  .then(pipWindow => {
     91    thePipWindow = pipWindow;
     92    video.disablePictureInPicture = true;
     93  });
     94 }, 'Picture-in-Picture window dimensions are set to 0 if ' +
     95   'disablePictureInPicture becomes true');
     96 </script>