Bug 1458530 - Fix hidden audio indicator hiding early r=dao
authorMark Striemer <mstriemer@mozilla.com>
Wed, 02 May 2018 23:19:24 -0500
changeset 472901 0ca2a1a6d39bcfa78f078a5b2858048747883e21
parent 472900 718d6eca69f2d23f532367c9d8a8f13482bd9b5a
child 472902 b1ff16c658636afb61c07765ea3c6470857bfefd
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1458530
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458530 - Fix hidden audio indicator hiding early r=dao MozReview-Commit-ID: JgWghGAIHmS
browser/base/content/tabbrowser.xml
browser/base/content/test/general/browser_audioTabIcon.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -921,20 +921,20 @@
       </method>
 
       <method name="_hiddenSoundPlayingStatusChanged">
         <parameter name="tab"/>
         <parameter name="opts"/>
         <body><![CDATA[
           let closed = opts && opts.closed;
           if (!closed && tab.soundPlaying && tab.hidden) {
-            this._hiddenSoundPlayingTabs.add(tab.id);
+            this._hiddenSoundPlayingTabs.add(tab);
             this.setAttribute("hiddensoundplaying", "true");
           } else {
-            this._hiddenSoundPlayingTabs.delete(tab.id);
+            this._hiddenSoundPlayingTabs.delete(tab);
             if (this._hiddenSoundPlayingTabs.size == 0) {
               this.removeAttribute("hiddensoundplaying");
             }
           }
         ]]></body>
       </method>
     </implementation>
 
--- 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);