summaryrefslogtreecommitdiffstats
path: root/browser/components/firefoxview/tests/browser/browser_opentabs_tab_indicators.js
blob: 1375052125cd553e1e79a803369b5e2f40432b3d (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

const { NonPrivateTabs } = ChromeUtils.importESModule(
  "resource:///modules/OpenTabs.sys.mjs"
);

let pageWithAlert =
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  "http://example.com/browser/browser/base/content/test/tabPrompts/openPromptOffTimeout.html";
let pageWithSound =
  "http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html";

function cleanup() {
  // Cleanup
  while (gBrowser.tabs.length > 1) {
    BrowserTestUtils.removeTab(gBrowser.tabs[0]);
  }
}

add_task(async function test_notification_dot_indicator() {
  await withFirefoxView({}, async browser => {
    const { document } = browser.contentWindow;
    let win = browser.ownerGlobal;
    await navigateToCategoryAndWait(document, "opentabs");
    // load page that opens prompt when page is hidden
    let openedTab = await BrowserTestUtils.openNewForegroundTab(
      gBrowser,
      pageWithAlert,
      true
    );
    let openedTabGotAttentionPromise = BrowserTestUtils.waitForAttribute(
      "attention",
      openedTab
    );

    let tabChangeRaised = BrowserTestUtils.waitForEvent(
      NonPrivateTabs,
      "TabChange"
    );

    await switchToFxViewTab();

    let openTabs = document.querySelector("view-opentabs[name=opentabs]");

    await openedTabGotAttentionPromise;
    await tabChangeRaised;
    await openTabs.updateComplete;

    await TestUtils.waitForCondition(
      () => openTabs.viewCards[0].tabList.rowEls[1].attention,
      "The opened tab doesn't have the attention property, so no notification dot is shown."
    );

    info("The newly opened tab has a notification dot.");

    // Switch back to other tab to close prompt before cleanup
    await BrowserTestUtils.switchTab(gBrowser, openedTab);
    EventUtils.synthesizeKey("KEY_Enter", {}, win);

    cleanup();
  });
});

add_task(async function test_container_indicator() {
  await withFirefoxView({}, async browser => {
    const { document } = browser.contentWindow;
    let win = browser.ownerGlobal;

    // Load a page in a container tab
    let userContextId = 1;
    let containerTab = BrowserTestUtils.addTab(win.gBrowser, URLs[0], {
      userContextId,
    });

    await BrowserTestUtils.browserLoaded(
      containerTab.linkedBrowser,
      false,
      URLs[0]
    );

    await navigateToCategoryAndWait(document, "opentabs");

    let openTabs = document.querySelector("view-opentabs[name=opentabs]");

    await TestUtils.waitForCondition(
      () =>
        containerTab.getAttribute("usercontextid") === userContextId.toString(),
      "The container tab doesn't have the usercontextid attribute."
    );
    await openTabs.updateComplete;
    await TestUtils.waitForCondition(
      () => openTabs.viewCards[0].tabList?.rowEls.length,
      "The tab list hasn't rendered."
    );
    info("openTabs component has finished updating.");

    let containerTabElem = openTabs.viewCards[0].tabList.rowEls[1];

    await TestUtils.waitForCondition(
      () => containerTabElem.containerObj,
      "The container tab element isn't marked in Fx View."
    );

    ok(
      containerTabElem.shadowRoot
        .querySelector(".fxview-tab-row-container-indicator")
        .classList.contains("identity-color-blue"),
      "The container color is blue."
    );

    info("The newly opened tab is marked as a container tab.");

    cleanup();
  });
});

add_task(async function test_sound_playing_muted_indicator() {
  await withFirefoxView({}, async browser => {
    const { document } = browser.contentWindow;
    await navigateToCategoryAndWait(document, "opentabs");

    // Load a page in a container tab
    let soundTab = await BrowserTestUtils.openNewForegroundTab(
      gBrowser,
      pageWithSound,
      true
    );

    let tabChangeRaised = BrowserTestUtils.waitForEvent(
      NonPrivateTabs,
      "TabChange"
    );

    await switchToFxViewTab();

    let openTabs = document.querySelector("view-opentabs[name=opentabs]");

    await TestUtils.waitForCondition(() =>
      soundTab.hasAttribute("soundplaying")
    );
    await tabChangeRaised;
    await openTabs.updateComplete;
    await TestUtils.waitForCondition(
      () => openTabs.viewCards[0].tabList?.rowEls.length,
      "The tab list hasn't rendered."
    );

    let soundPlayingTabElem = openTabs.viewCards[0].tabList.rowEls[1];

    await TestUtils.waitForCondition(() => soundPlayingTabElem.soundPlaying);

    ok(
      soundPlayingTabElem.mediaButtonEl,
      "The tab has the mute button showing."
    );

    tabChangeRaised = BrowserTestUtils.waitForEvent(
      NonPrivateTabs,
      "TabChange"
    );

    // Mute the tab
    EventUtils.synthesizeMouseAtCenter(
      soundPlayingTabElem.mediaButtonEl,
      {},
      content
    );

    await TestUtils.waitForCondition(
      () => soundTab.hasAttribute("muted"),
      "The tab doesn't have the muted attribute."
    );
    await tabChangeRaised;
    await openTabs.updateComplete;

    await TestUtils.waitForCondition(() => soundPlayingTabElem.muted);

    ok(
      soundPlayingTabElem.mediaButtonEl,
      "The tab has the unmute button showing."
    );

    // Mute and unmute the tab and make sure the element in Fx View updates
    soundTab.toggleMuteAudio();
    await tabChangeRaised;
    await openTabs.updateComplete;
    await TestUtils.waitForCondition(() => soundPlayingTabElem.soundPlaying);

    ok(
      soundPlayingTabElem.mediaButtonEl,
      "The tab has the mute button showing."
    );

    soundTab.toggleMuteAudio();
    await tabChangeRaised;
    await openTabs.updateComplete;
    await TestUtils.waitForCondition(() => soundPlayingTabElem.muted);

    ok(
      soundPlayingTabElem.mediaButtonEl,
      "The tab has the unmute button showing."
    );

    cleanup();
  });
});