Bug 1341062 - part2 : remove duplicated codes. r=baku
authorAlastor Wu <alwu@mozilla.com>
Thu, 02 Mar 2017 17:38:56 +0800
changeset 345581 19350704484da94b554dfa4722587eae5072dfea
parent 345580 5304ef02b51f89a520075d42b5bcc0ae3f1dbc75
child 345582 133ad85684a1c0d7247ca3d2277477bd603ec2cd
push id31440
push userkwierso@gmail.com
push dateThu, 02 Mar 2017 21:09:24 +0000
treeherdermozilla-central@c54c652af04c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1341062
milestone54.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 1341062 - part2 : remove duplicated codes. r=baku MozReview-Commit-ID: C6N1itQAVcF
toolkit/content/tests/browser/browser_audioCompeting.js
toolkit/content/tests/browser/browser_block_autoplay_media.js
toolkit/content/tests/browser/browser_block_silentAudioTrack_media.js
--- a/toolkit/content/tests/browser/browser_audioCompeting.js
+++ b/toolkit/content/tests/browser/browser_audioCompeting.js
@@ -1,24 +1,10 @@
 const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_multipleAudio.html";
 
-function* wait_for_tab_playing_event(tab, expectPlaying) {
-  if (tab.soundPlaying == expectPlaying) {
-    ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-  } else {
-    yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
-      if (event.detail.changed.indexOf("soundplaying") >= 0) {
-        is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-        return true;
-      }
-      return false;
-    });
-  }
-}
-
 function play_audio_from_invisible_tab() {
   return new Promise(resolve => {
     var autoPlay = content.document.getElementById("autoplay");
     if (!autoPlay) {
       ok(false, "Can't get the audio element!");
     }
 
     is(autoPlay.paused, true, "Audio in tab 1 was paused by audio competing.");
@@ -68,23 +54,23 @@ add_task(function* setup_test_preference
     ]});
 });
 
 add_task(function* cross_tabs_audio_competing() {
   info("- open tab 1 in foreground -");
   let tab1 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
                                                          "about:blank");
   tab1.linkedBrowser.loadURI(PAGE);
-  yield wait_for_tab_playing_event(tab1, true);
+  yield waitForTabPlayingEvent(tab1, true);
 
   info("- open tab 2 in foreground -");
   let tab2 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
                                                         "about:blank");
   tab2.linkedBrowser.loadURI(PAGE);
-  yield wait_for_tab_playing_event(tab1, false);
+  yield waitForTabPlayingEvent(tab1, false);
 
   info("- open tab 3 in foreground -");
   let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
                                                          "about:blank");
   yield ContentTask.spawn(tab2.linkedBrowser, null,
                           audio_should_keep_playing_even_go_to_background);
 
   info("- play audio from background tab 1 -");
@@ -97,17 +83,17 @@ add_task(function* cross_tabs_audio_comp
   yield BrowserTestUtils.removeTab(tab3);
 });
 
 add_task(function* within_one_tab_audio_competing() {
   info("- open tab and play audio1 -");
   let tab = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
                                                         "about:blank");
   tab.linkedBrowser.loadURI(PAGE);
-  yield wait_for_tab_playing_event(tab, true);
+  yield waitForTabPlayingEvent(tab, true);
 
   info("- play audio2 in the same tab -");
   yield ContentTask.spawn(tab.linkedBrowser, null,
                           play_non_autoplay_audio);
 
   info("- remove tab -");
   yield BrowserTestUtils.removeTab(tab);
 });
--- a/toolkit/content/tests/browser/browser_block_autoplay_media.js
+++ b/toolkit/content/tests/browser/browser_block_autoplay_media.js
@@ -2,30 +2,16 @@ const PAGE = "https://example.com/browse
 
 var SuspendedType = {
   NONE_SUSPENDED             : 0,
   SUSPENDED_PAUSE            : 1,
   SUSPENDED_BLOCK            : 2,
   SUSPENDED_PAUSE_DISPOSABLE : 3
 };
 
-function* wait_for_tab_playing_event(tab, expectPlaying) {
-  if (tab.soundPlaying == expectPlaying) {
-    ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-  } else {
-    yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
-      if (event.detail.changed.indexOf("soundplaying") >= 0) {
-        is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-        return true;
-      }
-      return false;
-    });
-  }
-}
-
 function check_audio_suspended(suspendedType) {
   var autoPlay = content.document.getElementById("autoplay");
   if (!autoPlay) {
     ok(false, "Can't get the audio element!");
   }
 
   is(autoPlay.computedSuspended, suspendedType,
      "The suspeded state of autoplay audio is correct.");
@@ -56,30 +42,30 @@ add_task(function* block_autoplay_media(
   info("- should block autoplay for non-visited tab2 -");
   yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
                           check_audio_suspended);
 
   info("- select tab1 as foreground tab -");
   yield BrowserTestUtils.switchTab(window.gBrowser, tab1);
 
   info("- media should be unblocked because the tab was visited -");
-  yield wait_for_tab_playing_event(tab1, true);
+  yield waitForTabPlayingEvent(tab1, true);
   yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- open another new foreground tab3 -");
   let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
                                                          "about:blank");
   info("- should still play media from tab1 -");
-  yield wait_for_tab_playing_event(tab1, true);
+  yield waitForTabPlayingEvent(tab1, true);
   yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- should still block media from tab2 -");
-  yield wait_for_tab_playing_event(tab2, false);
+  yield waitForTabPlayingEvent(tab2, false);
   yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
                           check_audio_suspended);
 
   info("- remove tabs -");
   yield BrowserTestUtils.removeTab(tab1);
   yield BrowserTestUtils.removeTab(tab2);
   yield BrowserTestUtils.removeTab(tab3);
 });
--- a/toolkit/content/tests/browser/browser_block_silentAudioTrack_media.js
+++ b/toolkit/content/tests/browser/browser_block_silentAudioTrack_media.js
@@ -2,31 +2,16 @@ const PAGE = "https://example.com/browse
 
 var SuspendedType = {
   NONE_SUSPENDED             : 0,
   SUSPENDED_PAUSE            : 1,
   SUSPENDED_BLOCK            : 2,
   SUSPENDED_PAUSE_DISPOSABLE : 3
 };
 
-function* wait_for_tab_playing_event(tab, expectPlaying) {
-  if (tab.soundPlaying == expectPlaying) {
-    ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-  } else {
-    info("Playing state doens't match, wait for attributes changes.");
-    yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
-      if (event.detail.changed.indexOf("soundplaying") >= 0) {
-        is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
-        return true;
-      }
-      return false;
-    });
-  }
-}
-
 function disable_non_test_mouse(disable) {
   let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIDOMWindowUtils);
   utils.disableNonTestMouseEvents(disable);
 }
 
 function* hover_icon(icon, tooltip) {
   disable_non_test_mouse(true);
@@ -92,17 +77,17 @@ add_task(function* unblock_icon_should_d
   info("- the suspend state of tab should be none-suspend -");
   yield ContentTask.spawn(tab.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- should not display unblocking icon -");
   yield waitForTabBlockEvent(tab, false);
 
   info("- should not display sound indicator icon -");
-  yield wait_for_tab_playing_event(tab, false);
+  yield waitForTabPlayingEvent(tab, false);
 
   info("- remove tab -");
   yield BrowserTestUtils.removeTab(tab);
 });
 
 add_task(function* should_not_show_sound_indicator_after_resume_tab() {
   info("- open new background tab -");
   let tab = window.gBrowser.addTab("about:blank");
@@ -122,13 +107,13 @@ add_task(function* should_not_show_sound
   info("- the suspend state of tab should be none-suspend -");
   yield ContentTask.spawn(tab.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- should not display unblocking icon -");
   yield waitForTabBlockEvent(tab, false);
 
   info("- should not display sound indicator icon -");
-  yield wait_for_tab_playing_event(tab, false);
+  yield waitForTabPlayingEvent(tab, false);
 
   info("- remove tab -");
   yield BrowserTestUtils.removeTab(tab);
 });