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

"use strict";

/**
 * The goal of this test is check the that "tab-icon-overlay" image is
 * showing when the tab is using PiP.
 *
 * The browser will create a tab and open a video using PiP
 * then the tests check that the tab icon overlay image is showing*
 *
 *
 */
add_task(async () => {
  let videoID = "with-controls";
  await BrowserTestUtils.withNewTab(
    {
      url: TEST_PAGE_WITH_SOUND,
      gBrowser,
    },
    async browser => {
      await ensureVideosReady(browser);

      let audioPromise = BrowserTestUtils.waitForEvent(
        browser,
        "DOMAudioPlaybackStarted"
      );

      await SpecialPowers.spawn(browser, [videoID], async videoID => {
        await content.document.getElementById(videoID).play();
      });

      // Check that video is playing
      ok(!(await isVideoPaused(browser, videoID)), "The video is not paused.");
      await audioPromise;

      // Need tab to access the tab-icon-overlay element
      let tab = gBrowser.getTabForBrowser(browser);

      // Use tab to get the tab-icon-overlay element
      let tabIconOverlay = tab.getElementsByClassName("tab-icon-overlay")[0];

      // Not in PiP yet so the tab-icon-overlay does not have "pictureinpicture" attribute
      ok(!tabIconOverlay.hasAttribute("pictureinpicture"), "Not using PiP");

      // Sound is playing so tab should have "soundplaying" attribute
      ok(tabIconOverlay.hasAttribute("soundplaying"), "Sound is playing");

      // Start the PiP
      let pipWin = await triggerPictureInPicture(browser, videoID);
      ok(pipWin, "Got Picture-in-Picture window.");

      // Check that video is still playing
      ok(!(await isVideoPaused(browser, videoID)), "The video is not paused.");

      // Video is still playing so the tab-icon-overlay should have "soundplaying" as an attribute
      ok(
        tabIconOverlay.hasAttribute("soundplaying"),
        "Tab knows sound is playing"
      );

      // Now in PiP. "pictureinpicture" is an attribute
      ok(
        tabIconOverlay.hasAttribute("pictureinpicture"),
        "Tab knows were using PiP"
      );

      // We know the tab has sound playing and it is using PiP so we can check the
      // tab-icon-overlay image is showing
      let style = window.getComputedStyle(tabIconOverlay);
      Assert.equal(
        style.listStyleImage,
        'url("chrome://browser/skin/tabbrowser/tab-audio-playing-small.svg")',
        "Got the tab-icon-overlay image"
      );

      // Check tab is not muted
      ok(!tabIconOverlay.hasAttribute("muted"), "Tab is not muted");

      // Click on tab icon overlay to mute tab and check it is muted
      tabIconOverlay.click();
      ok(tabIconOverlay.hasAttribute("muted"), "Tab is muted");

      // Click on tab icon overlay to unmute tab and check it is not muted
      tabIconOverlay.click();
      ok(!tabIconOverlay.hasAttribute("muted"), "Tab is not muted");
    }
  );
});