summaryrefslogtreecommitdiffstats
path: root/toolkit/components/pictureinpicture/tests/browser_toggle_videocontrols.js
blob: 248f816fba2ebe2b9f8ad639745bdf037d3d5da0 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that the Picture-in-Picture toggle is hidden when opening the closed captions menu
 * and is visible when closing the closed captions menu.
 */
add_task(async () => {
  await SpecialPowers.pushPrefEnv({
    set: [
      [
        "media.videocontrols.picture-in-picture.display-text-tracks.enabled",
        true,
      ],
      ["media.videocontrols.picture-in-picture.video-toggle.enabled", true],
    ],
  });
  let videoID = "with-controls";

  await BrowserTestUtils.withNewTab(
    {
      url: TEST_PAGE_WITH_WEBVTT,
      gBrowser,
    },
    async browser => {
      await prepareVideosAndWebVTTTracks(browser, videoID, -1);
      await prepareForToggleClick(browser, videoID);

      let args = {
        videoID,
        DEFAULT_TOGGLE_STYLES,
      };

      await SpecialPowers.spawn(browser, [args], async args => {
        let { videoID, DEFAULT_TOGGLE_STYLES } = args;
        let video = this.content.document.getElementById(videoID);
        let shadowRoot = video.openOrClosedShadowRoot;
        let closedCaptionButton = shadowRoot.querySelector(
          "#closedCaptionButton"
        );
        let toggle = shadowRoot.querySelector(
          `#${DEFAULT_TOGGLE_STYLES.rootID}`
        );
        let textTrackListContainer = shadowRoot.querySelector(
          "#textTrackListContainer"
        );

        Assert.ok(!toggle.hidden, "Toggle should be visible");
        Assert.ok(
          textTrackListContainer.hidden,
          "textTrackListContainer should be hidden"
        );

        info("Opening text track list from cc button");
        closedCaptionButton.click();

        Assert.ok(toggle.hidden, "Toggle should be hidden");
        Assert.ok(
          !textTrackListContainer.hidden,
          "textTrackListContainer should be visible"
        );

        info("Clicking the cc button again to close it");
        closedCaptionButton.click();

        Assert.ok(!toggle.hidden, "Toggle should be visible again");
        Assert.ok(
          textTrackListContainer.hidden,
          "textTrackListContainer should be hidden again"
        );
      });
    }
  );
});