summaryrefslogtreecommitdiffstats
path: root/toolkit/components/pictureinpicture/tests/browser_fullscreen.js
blob: 5f80c56307d034ded924e26a2334a70ebeac1d69 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const VIDEOS = ["with-controls", "no-controls"];

/**
 * Tests that the Picture-in-Picture toggle is hidden when
 * a video with or without controls is made fullscreen.
 */
add_task(async () => {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async browser => {
      for (let videoID of VIDEOS) {
        await promiseFullscreenEntered(window, async () => {
          await SpecialPowers.spawn(browser, [videoID], async videoID => {
            let video = this.content.document.getElementById(videoID);
            video.requestFullscreen();
          });
        });

        await BrowserTestUtils.synthesizeMouseAtCenter(
          `#${videoID}`,
          {
            type: "mouseover",
          },
          browser
        );

        let args = { videoID, toggleID: DEFAULT_TOGGLE_STYLES.rootID };

        await promiseFullscreenExited(window, async () => {
          await SpecialPowers.spawn(browser, [args], async args => {
            let { videoID, toggleID } = args;
            let video = this.content.document.getElementById(videoID);
            let toggle = video.openOrClosedShadowRoot.getElementById(toggleID);
            ok(
              ContentTaskUtils.is_hidden(toggle),
              "Toggle should be hidden in fullscreen mode."
            );
            this.content.document.exitFullscreen();
          });
        });
      }
    }
  );
});

/**
 * Tests that the Picture-in-Picture toggle is hidden if an
 * ancestor of a video (in this case, the document body) is made
 * to be the fullscreen element.
 */
add_task(async () => {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async browser => {
      await promiseFullscreenEntered(window, async () => {
        await SpecialPowers.spawn(browser, [], async () => {
          this.content.document.body.requestFullscreen();
        });
      });

      for (let videoID of VIDEOS) {
        await BrowserTestUtils.synthesizeMouseAtCenter(
          `#${videoID}`,
          {
            type: "mouseover",
          },
          browser
        );

        let args = { videoID, toggleID: DEFAULT_TOGGLE_STYLES.rootID };

        await SpecialPowers.spawn(browser, [args], async args => {
          let { videoID, toggleID } = args;
          let video = this.content.document.getElementById(videoID);
          let toggle = video.openOrClosedShadowRoot.getElementById(toggleID);
          ok(
            ContentTaskUtils.is_hidden(toggle),
            "Toggle should be hidden in fullscreen mode."
          );
        });
      }

      await promiseFullscreenExited(window, async () => {
        await SpecialPowers.spawn(browser, [], async () => {
          this.content.document.exitFullscreen();
        });
      });
    }
  );
});

/**
 * Tests that the Picture-In-Picture window is closed when something
 * is fullscreened
 */
add_task(async () => {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async browser => {
      await ensureVideosReady(browser);

      for (let videoId of VIDEOS) {
        let pipWin = await triggerPictureInPicture(browser, videoId);
        ok(pipWin, "Got Picture-In-Picture window.");

        let pipClosed = BrowserTestUtils.domWindowClosed(pipWin);

        // need to focus first, since fullscreen request will be blocked otherwise
        await SimpleTest.promiseFocus(window);

        await promiseFullscreenEntered(window, async () => {
          await SpecialPowers.spawn(browser, [], async () => {
            this.content.document.body.requestFullscreen();
          });
        });

        await pipClosed;
        ok(pipWin.closed, "Picture-In-Picture successfully closed.");

        await promiseFullscreenExited(window, async () => {
          await SpecialPowers.spawn(browser, [], async () => {
            this.content.document.exitFullscreen();
          });
        });
      }
    }
  );
});