--- a/browser/base/content/test/general/browser_audioTabIcon.js
+++ b/browser/base/content/test/general/browser_audioTabIcon.js
@@ -265,48 +265,78 @@ async function test_playing_icon_on_tab(
// Make sure it's possible to mute using the context menu.
await test_muting_using_menu(tab, false);
// Make sure it's possible to unmute using the context menu.
await test_muting_using_menu(tab, true);
}
async function test_playing_icon_on_hidden_tab(tab) {
- let icon = document.getAnonymousElementByAttribute(tab, "anonid", "soundplaying-icon");
- let isActiveTab = tab === gBrowser.selectedTab;
-
- await play(tab);
-
- await test_tooltip(icon, "Mute tab", isActiveTab);
-
+ let oldSelectedTab = gBrowser.selectedTab;
+ let otherTabs = [
+ await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE, true, true),
+ await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE, true, true),
+ ];
+ let tabContainer = tab.parentNode;
let alltabsButton = document.getElementById("alltabs-button");
let alltabsBadge = document.getAnonymousElementByAttribute(
alltabsButton, "class", "toolbarbutton-badge");
- is(getComputedStyle(alltabsBadge).backgroundImage, "none", "The audio playing icon is hidden");
- ok(!tab.parentNode.hasAttribute("hiddensoundplaying"), "There are no hidden audio tabs");
+ function assertIconShowing() {
+ is(getComputedStyle(alltabsBadge).backgroundImage,
+ 'url("chrome://browser/skin/tabbrowser/badge-audio-playing.svg")',
+ "The audio playing icon is shown");
+ is(tabContainer.getAttribute("hiddensoundplaying"), "true", "There are hidden audio tabs");
+ }
- await hide_tab(tab);
+ function assertIconHidden() {
+ is(getComputedStyle(alltabsBadge).backgroundImage, "none", "The audio playing icon is hidden");
+ ok(!tabContainer.hasAttribute("hiddensoundplaying"), "There are no hidden audio tabs");
+ }
- is(getComputedStyle(alltabsBadge).backgroundImage,
- 'url("chrome://browser/skin/tabbrowser/badge-audio-playing.svg")',
- "The audio playing icon is shown");
- is(tab.parentNode.getAttribute("hiddensoundplaying"), "true", "There are hidden audio tabs");
+ // Keep the passed in tab selected.
+ gBrowser.selectedTab = tab;
+
+ // Play sound in the other two (visible) tabs.
+ await play(otherTabs[0]);
+ await play(otherTabs[1]);
+ assertIconHidden();
+
+ // Hide one of the noisy tabs, we see the icon.
+ await hide_tab(otherTabs[0]);
+ assertIconShowing();
- await pause(tab);
+ // Hiding the other tab keeps the icon.
+ await hide_tab(otherTabs[1]);
+ assertIconShowing();
- is(getComputedStyle(alltabsBadge).backgroundImage, "none", "The audio playing icon is hidden");
- ok(!tab.parentNode.hasAttribute("hiddensoundplaying"), "There are no hidden audio tabs");
+ // Pausing both tabs will hide the icon.
+ await pause(otherTabs[0]);
+ assertIconShowing();
+ await pause(otherTabs[1]);
+ assertIconHidden();
- await show_tab(tab);
+ // The icon returns when audio starts again.
+ await play(otherTabs[0]);
+ await play(otherTabs[1]);
+ assertIconShowing();
+
+ // There is still an icon after hiding one tab.
+ await show_tab(otherTabs[0]);
+ assertIconShowing();
- is(getComputedStyle(alltabsBadge).backgroundImage, "none", "The audio playing icon is hidden");
- ok(!tab.parentNode.hasAttribute("hiddensoundplaying"), "There are no hidden audio tabs");
+ // The icon is hidden when both of the tabs are shown.
+ await show_tab(otherTabs[1]);
+ assertIconHidden();
- await play(tab);
+ await BrowserTestUtils.removeTab(otherTabs[0]);
+ await BrowserTestUtils.removeTab(otherTabs[1]);
+
+ // Make sure we didn't change the selected tab.
+ gBrowser.selectedTab = oldSelectedTab;
}
async function test_swapped_browser_while_playing(oldTab, newBrowser) {
// The tab was muted so it won't have soundplaying attribute even it's playing.
ok(oldTab.hasAttribute("muted"), "Expected the correct muted attribute on the old tab");
is(oldTab.muteReason, null, "Expected the correct muteReason attribute on the old tab");
ok(!oldTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the old tab");
@@ -504,40 +534,38 @@ async function test_mute_keybinding() {
}
await BrowserTestUtils.withNewTab({
gBrowser,
url: PAGE
}, taskFn);
}
-async function test_on_browser(browser, lastTab) {
+async function test_on_browser(browser) {
let tab = gBrowser.getTabForBrowser(browser);
// Test the icon in a normal tab.
await test_playing_icon_on_tab(tab, browser, false);
gBrowser.pinTab(tab);
// Test the icon in a pinned tab.
await test_playing_icon_on_tab(tab, browser, true);
gBrowser.unpinTab(tab);
- if (lastTab) {
- // Test for the hidden tabs icon, this must be tested on a background tab.
- await test_playing_icon_on_hidden_tab(lastTab);
- }
+ // Test the sound playing icon for hidden tabs.
+ await test_playing_icon_on_hidden_tab(tab);
// Retest with another browser in the foreground tab
if (gBrowser.selectedBrowser.currentURI.spec == PAGE) {
await BrowserTestUtils.withNewTab({
gBrowser,
url: "data:text/html,test"
- }, () => test_on_browser(browser, tab));
+ }, () => test_on_browser(browser));
} else {
await test_browser_swapping(tab, browser);
}
}
async function test_delayed_tabattr_removal() {
async function taskFn(browser) {
let tab = gBrowser.getTabForBrowser(browser);