summaryrefslogtreecommitdiffstats
path: root/toolkit/components/pictureinpicture/tests/browser_closePipPause.js
blob: b87888e411dc75bbf62075348a1e84161c755a1a (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test checks that MediaStream videos are not paused when closing
 * the PiP window.
 */
add_task(async function test_close_mediaStreamVideos() {
  await BrowserTestUtils.withNewTab(
    {
      url: TEST_ROOT + "test-media-stream.html",
      gBrowser,
    },
    async browser => {
      await SpecialPowers.spawn(browser, [], async () => {
        // Construct a new video element, and capture a stream from it
        // to redirect to both testing videos
        let newVideo = content.document.createElement("video");
        newVideo.src = "test-video.mp4";
        newVideo.id = "media-stream-video";
        content.document.body.appendChild(newVideo);
        newVideo.loop = true;
      });
      await ensureVideosReady(browser);

      // Modify both the "with-controls" and "no-controls" videos so that they mirror
      // the new video that we just added via MediaStream.
      await SpecialPowers.spawn(browser, [], async () => {
        let newVideo = content.document.getElementById("media-stream-video");
        newVideo.play();

        for (let videoID of ["with-controls", "no-controls"]) {
          let testedVideo = content.document.createElement("video");
          testedVideo.id = videoID;
          testedVideo.srcObject = newVideo.mozCaptureStream().clone();
          content.document.body.prepend(testedVideo);
          if (
            testedVideo.readyState < content.HTMLMediaElement.HAVE_ENOUGH_DATA
          ) {
            info(`Waiting for 'canplaythrough' for '${testedVideo.id}'`);
            await ContentTaskUtils.waitForEvent(testedVideo, "canplaythrough");
          }
          testedVideo.play();
        }
      });

      for (let videoID of ["with-controls", "no-controls"]) {
        let pipWin = await triggerPictureInPicture(browser, videoID);
        ok(pipWin, "Got Picture-in-Picture window.");
        ok(
          !(await isVideoPaused(browser, videoID)),
          "The video is not paused in PiP window."
        );

        let pipClosed = BrowserTestUtils.domWindowClosed(pipWin);
        let closeButton = pipWin.document.getElementById("close");
        EventUtils.synthesizeMouseAtCenter(closeButton, {}, pipWin);
        await pipClosed;
        ok(
          !(await isVideoPaused(browser, videoID)),
          "The video is not paused after closing PiP window."
        );
      }
    }
  );
});