Bug 1227320 - Need to wait two TabAttrModified events to ensure soundplaying attribue is updated. r=ehsan a=test-only
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 29 Dec 2015 16:13:00 -0800
changeset 310680 5cec8821c39b7552d905c56299ae49ec9a043f60
parent 310679 889d9def7224520a72751ae332913b37a7549dd2
child 310681 258a4acf095d5e2679437748885c6f7577d2c309
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, test-only
bugs1227320
milestone45.0a2
Bug 1227320 - Need to wait two TabAttrModified events to ensure soundplaying attribue is updated. r=ehsan a=test-only We need to receive two TabAttrModified events with 'soundplaying'. The first one comes from nsDocument::OnPageHide, the second one comes from nsDocument::OnPageShow. Moreover 'audio-playback' notification is not passed to chrome process on E10S so we should wait 'audiochannel-activity-normal' instead.
browser/base/content/test/general/browser_audioTabIcon.js
--- a/browser/base/content/test/general/browser_audioTabIcon.js
+++ b/browser/base/content/test/general/browser_audioTabIcon.js
@@ -176,47 +176,81 @@ function* test_playing_icon_on_tab(tab, 
 
   // Make sure it's possible to mute using the context menu.
   yield test_muting_using_menu(tab, false);
 
   // Make sure it's possible to unmute using the context menu.
   yield test_muting_using_menu(tab, true);
 }
 
-function* test_swapped_browser(oldTab, newBrowser, isPlaying) {
+function* test_swapped_browser_while_playing(oldTab, newBrowser) {
   ok(oldTab.hasAttribute("muted"), "Expected the correct muted attribute on the old tab");
-  is(oldTab.hasAttribute("soundplaying"), isPlaying, "Expected the correct soundplaying attribute on the old tab");
+  ok(oldTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the old tab");
 
   let newTab = gBrowser.getTabForBrowser(newBrowser);
   let AttrChangePromise = BrowserTestUtils.waitForEvent(newTab, "TabAttrModified", false, event => {
-    return (event.detail.changed.indexOf("soundplaying") >= 0 || !isPlaying) &&
+    return event.detail.changed.indexOf("soundplaying") >= 0 &&
            event.detail.changed.indexOf("muted") >= 0;
   });
+
+  gBrowser.swapBrowsersAndCloseOther(newTab, oldTab);
+  yield AttrChangePromise;
+
+  ok(newTab.hasAttribute("muted"), "Expected the correct muted attribute on the new tab");
+  ok(newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
+
+  let receivedSoundPlaying = 0;
+  // We need to receive two TabAttrModified events with 'soundplaying'
+  // because swapBrowsersAndCloseOther involves nsDocument::OnPageHide and
+  // nsDocument::OnPageShow. Each methods lead to TabAttrModified event.
+  yield BrowserTestUtils.waitForEvent(newTab, "TabAttrModified", false, event => {
+    if (event.detail.changed.indexOf("soundplaying") >= 0) {
+      return (++receivedSoundPlaying == 2);
+    }
+  });
+
+  ok(newTab.hasAttribute("muted"), "Expected the correct muted attribute on the new tab");
+  ok(newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
+
+  let icon = document.getAnonymousElementByAttribute(newTab, "anonid",
+                                                     "soundplaying-icon");
+  yield test_tooltip(icon, "Unmute tab", true);
+}
+
+function* test_swapped_browser_while_not_playing(oldTab, newBrowser) {
+  ok(oldTab.hasAttribute("muted"), "Expected the correct muted attribute on the old tab");
+  ok(!oldTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the old tab");
+
+  let newTab = gBrowser.getTabForBrowser(newBrowser);
+  let AttrChangePromise = BrowserTestUtils.waitForEvent(newTab, "TabAttrModified", false, event => {
+    return event.detail.changed.indexOf("muted") >= 0;
+  });
+
   let AudioPlaybackPromise = new Promise(resolve => {
     let observer = (subject, topic, data) => {
-      ok(true, "Should see an audio-playback notification");
+      ok(false, "Should not see an audio-playback notification");
     };
-    Services.obs.addObserver(observer, "audio-playback", false);
+    Services.obs.addObserver(observer, "audiochannel-activity-normal", false);
     setTimeout(() => {
-      Services.obs.removeObserver(observer, "audio-playback");
+      Services.obs.removeObserver(observer, "audiochannel-activity-normal");
       resolve();
     }, 100);
   });
 
   gBrowser.swapBrowsersAndCloseOther(newTab, oldTab);
   yield AttrChangePromise;
 
   ok(newTab.hasAttribute("muted"), "Expected the correct muted attribute on the new tab");
-  is(newTab.hasAttribute("soundplaying"), isPlaying, "Expected the correct soundplaying attribute on the new tab");
+  ok(!newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
 
   // Wait to see if an audio-playback event is dispatched.
   yield AudioPlaybackPromise;
 
   ok(newTab.hasAttribute("muted"), "Expected the correct muted attribute on the new tab");
-  is(newTab.hasAttribute("soundplaying"), isPlaying, "Expected the correct soundplaying attribute on the new tab");
+  ok(!newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
 
   let icon = document.getAnonymousElementByAttribute(newTab, "anonid",
                                                      "soundplaying-icon");
   yield test_tooltip(icon, "Unmute tab", true);
 }
 
 function* test_browser_swapping(tab, browser) {
   // First, test swapping with a playing but muted tab.
@@ -225,27 +259,27 @@ function* test_browser_swapping(tab, bro
   let icon = document.getAnonymousElementByAttribute(tab, "anonid",
                                                      "soundplaying-icon");
   yield test_mute_tab(tab, icon, true);
 
   yield BrowserTestUtils.withNewTab({
     gBrowser,
     url: "about:blank",
   }, function*(newBrowser) {
-    yield test_swapped_browser(tab, newBrowser, true)
+    yield test_swapped_browser_while_playing(tab, newBrowser)
 
     // Now, test swapping with a muted but not playing tab.
     // Note that the tab remains muted, so we only need to pause playback.
     tab = gBrowser.getTabForBrowser(newBrowser);
     yield pause(tab);
 
     yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "about:blank",
-    }, newBrowser => test_swapped_browser(tab, newBrowser, false));
+    }, newBrowser => test_swapped_browser_while_not_playing(tab, newBrowser));
   });
 }
 
 function* test_click_on_pinned_tab_after_mute() {
   function* test_on_browser(browser) {
     let tab = gBrowser.getTabForBrowser(browser);
 
     gBrowser.selectedTab = originallySelectedTab;