Bug 486262 - Part 4: Add automated tests; r=dao
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 18 Jul 2015 21:52:54 -0400
changeset 281628 e5137e5dc19db750781699836ccfcafc519940e4
parent 281627 5cd6a05586826583b22d51352d99eacc4b55bd70
child 281629 1878dfd5a1931e50442cd132426a0e088cbdefed
push id3894
push usermconley@mozilla.com
push dateThu, 30 Jul 2015 00:27:47 +0000
reviewersdao
bugs486262
milestone42.0a1
Bug 486262 - Part 4: Add automated tests; r=dao
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_audioTabIcon.js
browser/base/content/test/general/file_mediaPlayback.html
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -2,16 +2,17 @@
 support-files =
   POSTSearchEngine.xml
   accounts_testRemoteCommands.html
   alltabslistener.html
   app_bug575561.html
   app_subframe_bug575561.html
   authenticate.sjs
   aboutHome_content_script.js
+  audio.ogg
   browser_bug479408_sample.html
   browser_bug678392-1.html
   browser_bug678392-2.html
   browser_bug970746.xhtml
   browser_fxa_oauth.html
   browser_fxa_oauth_with_keys.html
   browser_fxa_web_channel.html
   browser_registerProtocolHandler_notification.html
@@ -45,16 +46,17 @@ support-files =
   file_bug902156_2.html
   file_bug902156_3.html
   file_bug906190_1.html
   file_bug906190_2.html
   file_bug906190_3_4.html
   file_bug906190_redirected.html
   file_bug906190.js
   file_bug906190.sjs
+  file_mediaPlayback.html
   file_mixedContentFromOnunload.html
   file_mixedContentFromOnunload_test1.html
   file_mixedContentFromOnunload_test2.html
   file_bug970276_popup1.html
   file_bug970276_popup2.html
   file_bug970276_favicon1.ico
   file_bug970276_favicon2.ico
   file_documentnavigation_frameset.html
@@ -126,16 +128,17 @@ skip-if = os == "linux" # Bug 924307
 skip-if = e10s # Bug 1093153 - no about:home support yet
 [browser_action_keyword.js]
 [browser_action_keyword_override.js]
 [browser_action_searchengine.js]
 [browser_action_searchengine_alias.js]
 [browser_addKeywordSearch.js]
 [browser_search_favicon.js]
 [browser_alltabslistener.js]
+[browser_audioTabIcon.js]
 [browser_autocomplete_a11y_label.js]
 skip-if = e10s # Bug 1101993 - times out for unknown reasons when run in the dir (works on its own)
 [browser_autocomplete_cursor.js]
 [browser_autocomplete_edit_completed.js]
 [browser_autocomplete_enter_race.js]
 [browser_autocomplete_no_title.js]
 [browser_autocomplete_autoselect.js]
 [browser_autocomplete_oldschool_wrap.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_audioTabIcon.js
@@ -0,0 +1,108 @@
+const PAGE = "https://example.com/browser/browser/base/content/test/general/file_mediaPlayback.html";
+
+function* wait_for_tab_playing_event(tab, expectPlaying) {
+  yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
+    if (event.detail.changed.indexOf("soundplaying") >= 0) {
+      is(tab.hasAttribute("soundplaying"), expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
+      return true;
+    }
+    return false;
+  });
+}
+
+function* test_tooltip(icon, expectedTooltip) {
+  function disable_non_test_mouse(disable) {
+    let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                      .getInterface(Ci.nsIDOMWindowUtils);
+    utils.disableNonTestMouseEvents(disable);
+  }
+
+  let tooltip = document.getElementById("tabbrowser-tab-tooltip");
+
+  disable_non_test_mouse(true);
+
+  let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
+  EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
+  EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
+  EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
+  EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
+  yield popupShownPromise;
+
+  is(tooltip.getAttribute("label"), expectedTooltip, "Correct tooltip expected");
+
+  EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
+
+  disable_non_test_mouse(false);
+}
+
+function* test_mute_tab(tab, icon, expectMuted) {
+  let mutedPromise = BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
+    if (event.detail.changed.indexOf("muted") >= 0) {
+      is(tab.hasAttribute("muted"), expectMuted, "The tab should " + (expectMuted ? "" : "not ") + "be muted");
+      return true;
+    }
+    return false;
+  });
+
+  EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
+
+  return mutedPromise;
+}
+
+function* test_playing_icon_on_tab(tab, browser, isPinned) {
+  let icon = document.getAnonymousElementByAttribute(tab, "anonid",
+                                                     isPinned ? "overlay-icon" : "soundplaying-icon");
+
+  yield ContentTask.spawn(browser, {}, function* () {
+    let audio = content.document.querySelector("audio");
+    audio.play();
+  });
+
+  yield wait_for_tab_playing_event(tab, true);
+
+  yield test_tooltip(icon, "This tab is playing audio");
+
+  yield test_mute_tab(tab, icon, true);
+
+  yield test_tooltip(icon, "This tab has been muted");
+
+  yield test_mute_tab(tab, icon, false);
+
+  yield test_tooltip(icon, "This tab is playing audio");
+
+  yield ContentTask.spawn(browser, {}, function* () {
+    let audio = content.document.querySelector("audio");
+    audio.pause();
+  });
+  yield wait_for_tab_playing_event(tab, false);
+}
+
+function* test_on_browser(browser) {
+  let tab = gBrowser.getTabForBrowser(browser);
+
+  // Test the icon in a normal tab.
+  yield test_playing_icon_on_tab(tab, browser, false);
+
+  gBrowser.pinTab(tab);
+
+  // Test the icon in a pinned tab.
+  yield test_playing_icon_on_tab(tab, browser, true);
+
+  gBrowser.unpinTab(tab);
+}
+
+add_task(function*() {
+  yield new Promise((resolve) => {
+    SpecialPowers.pushPrefEnv({"set": [
+                                ["media.useAudioChannelService", true],
+                                ["browser.tabs.showAudioPlayingIcon", true],
+                              ]}, resolve);
+  });
+});
+
+add_task(function* test_page() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE
+  }, test_on_browser);
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_mediaPlayback.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<audio src="audio.ogg" controls loop>