Bug 1351925 - remove blockMedia() and related tests. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 30 Jun 2017 12:16:43 -0700
changeset 602805 3b0335c07f921723d35e36b09fa97d21cd2bda5c
parent 602698 0b5603017c25e943ba3ab97cb46d88adf1e6a3e4
child 635719 a52dcacba4d6d3e061711d244aceef25b36e07d7
push id66557
push useralwu@mozilla.com
push dateFri, 30 Jun 2017 19:25:25 +0000
bugs1351925
milestone56.0a1
Bug 1351925 - remove blockMedia() and related tests. The intermittent failure is caused by the innate drawback of the present test, it doesn't be consistent with the behavior how we actually block the media. Since we always block media implicit, it would be set in nsGlobalWindow's ctor. We would never call blockMedia directly, so we can remove the function. MozReview-Commit-ID: IjYJi5OHQ3X
browser/base/content/tabbrowser.xml
browser/components/sessionstore/SessionStore.jsm
toolkit/content/browser-content.js
toolkit/content/tests/browser/browser.ini
toolkit/content/tests/browser/browser_block_multipleMedia.js
toolkit/content/tests/browser/browser_mediaPlayback_suspended.js
toolkit/content/tests/browser/browser_mediaPlayback_suspended_multipleAudio.js
toolkit/content/widgets/browser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2155,17 +2155,17 @@
         "canGoBack", "canGoForward", "goBack", "goForward", "permitUnload",
         "reload", "reloadWithFlags", "stop", "loadURI", "loadURIWithFlags",
         "goHome", "homePage", "gotoIndex", "currentURI", "documentURI",
         "preferences", "imageDocument", "isRemoteBrowser", "messageManager",
         "getTabBrowser", "finder", "fastFind", "sessionHistory", "contentTitle",
         "characterSet", "fullZoom", "textZoom", "webProgress",
         "addProgressListener", "removeProgressListener", "audioPlaybackStarted",
         "audioPlaybackStopped", "pauseMedia", "stopMedia",
-        "blockMedia", "resumeMedia", "mute", "unmute", "blockedPopups", "lastURI",
+        "resumeMedia", "mute", "unmute", "blockedPopups", "lastURI",
         "purgeSessionHistory", "stopScroll", "startScroll",
         "userTypedValue", "userTypedClear", "mediaBlocked"
       ]</field>
 
       <method name="_createLazyBrowser">
         <parameter name="aTab"/>
         <body>
           <![CDATA[
@@ -2221,17 +2221,16 @@
                       // initializing the reload.
                       aTab.addEventListener("SSTabRestoring", () => {
                         browser[name](params);
                       }, { once: true });
                       gBrowser._insertBrowser(aTab);
                     };
                   };
                   break;
-                case "blockMedia":
                 case "resumeMedia":
                   getter = () => {
                     return () => {
                       // No need to insert a browser, so we just call the browser's
                       // method.
                       aTab.addEventListener("SSTabRestoring", () => {
                         browser[name]();
                       }, { once: true });
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -3593,19 +3593,17 @@ var SessionStoreInternal = {
     } else {
       tabbrowser.showTab(tab);
     }
 
     if (!!tabData.muted != browser.audioMuted) {
       tab.toggleMuteAudio(tabData.muteReason);
     }
 
-    if (tabData.mediaBlocked) {
-      browser.blockMedia();
-    } else {
+    if (!tabData.mediaBlocked) {
       browser.resumeMedia();
     }
 
     if (tabData.lastAccessed) {
       tab.updateLastAccessed(tabData.lastAccessed);
     }
 
     if ("attributes" in tabData) {
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -1001,19 +1001,16 @@ var AudioPlaybackListener = {
         utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
         break;
       case "mediaControlPaused":
         utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
         break;
       case "mediaControlStopped":
         utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
         break;
-      case "blockInactivePageMedia":
-        utils.mediaSuspend = suspendTypes.SUSPENDED_BLOCK;
-        break;
       case "resumeMedia":
         utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
         break;
       default:
         dump("Error : wrong media control msg!\n");
         break;
     }
   },
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -28,16 +28,18 @@ tags = audiochannel
 tags = audiochannel
 [browser_autoscroll_disabled.js]
 [browser_block_autoplay_media.js]
 tags = audiochannel
 [browser_block_autoplay_media_pausedAfterPlay.js]
  tags = audiochannel
 [browser_block_autoplay_playAfterTabVisible.js]
 tags = audiochannel
+[browser_block_multipleMedia.js]
+tags = audiochannel
 [browser_block_notInTreeAudio.js]
 tags = audiochannel
 [browser_block_playMediaInMuteTab.js]
 tags = audiochannel
 [browser_block_plugIn.js]
 tags = audiochannel
 [browser_block_silentAudioTrack_media.js]
 tags = audiochannel
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_block_multipleMedia.js
@@ -0,0 +1,120 @@
+const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_multipleAudio.html";
+
+var SuspendedType = {
+  NONE_SUSPENDED: 0,
+  SUSPENDED_PAUSE: 1,
+  SUSPENDED_BLOCK: 2,
+  SUSPENDED_PAUSE_DISPOSABLE: 3
+};
+
+function check_all_audio_suspended(suspendedType) {
+  let autoPlay = content.document.getElementById("autoplay");
+  let nonAutoPlay = content.document.getElementById("nonautoplay");
+  if (!autoPlay || !nonAutoPlay) {
+    ok(false, "Can't get the audio element!");
+  }
+
+  is(autoPlay.computedSuspended, suspendedType,
+     "The suspeded state of autoplay audio is correct.");
+  is(nonAutoPlay.computedSuspended, suspendedType,
+     "The suspeded state of non-autoplay audio is correct.");
+}
+
+function check_autoplay_audio_suspended(suspendedType) {
+  let 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.");
+}
+
+function check_autoplay_audio_onplay() {
+  let autoPlay = content.document.getElementById("autoplay");
+  if (!autoPlay) {
+    ok(false, "Can't get the audio element!");
+  }
+
+  return new Promise((resolve, reject) => {
+    autoPlay.onplay = () => {
+      ok(false, "Should not receive play event!");
+      this.onplay = null;
+      reject();
+    };
+
+    autoPlay.pause();
+    autoPlay.play();
+
+    setTimeout(() => {
+      ok(true, "Doesn't receive play event when media was blocked.");
+      autoPlay.onplay = null;
+      resolve();
+    }, 1000)
+  });
+}
+
+function check_nonautoplay_audio_suspended(suspendedType) {
+  let nonAutoPlay = content.document.getElementById("nonautoplay");
+  if (!nonAutoPlay) {
+    ok(false, "Can't get the audio element!");
+  }
+
+  is(nonAutoPlay.computedSuspended, suspendedType,
+     "The suspeded state of non-autoplay audio is correct.");
+}
+
+function play_nonautoplay_audio_should_be_blocked() {
+  let nonAutoPlay = content.document.getElementById("nonautoplay");
+  if (!nonAutoPlay) {
+    ok(false, "Can't get the audio element!");
+  }
+
+  nonAutoPlay.play();
+  ok(nonAutoPlay.paused, "The blocked audio can't be playback.");
+}
+
+add_task(async function setup_test_preference() {
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["media.useAudioChannelService.testing", true],
+    ["media.block-autoplay-until-in-foreground", true]
+  ]});
+});
+
+add_task(async function block_multiple_media() {
+  info("- open new background tab -");
+  let tab = window.gBrowser.addTab("about:blank");
+  let browser = tab.linkedBrowser;
+  browser.loadURI(PAGE);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  info("- tab should be blocked -");
+  await waitForTabBlockEvent(tab, true);
+
+  info("- autoplay media should be blocked -");
+  await ContentTask.spawn(browser, SuspendedType.SUSPENDED_BLOCK,
+                                   check_autoplay_audio_suspended);
+  await ContentTask.spawn(browser, null,
+                                   check_autoplay_audio_onplay);
+
+  info("- non-autoplay media won't be blocked, because it doesn't start playing -");
+  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
+                                   check_nonautoplay_audio_suspended);
+
+  info("- non-autoplay can't start playback when the tab is blocked -");
+  await ContentTask.spawn(browser, null,
+                                   play_nonautoplay_audio_should_be_blocked);
+  await ContentTask.spawn(browser, SuspendedType.SUSPENDED_BLOCK,
+                                   check_nonautoplay_audio_suspended);
+
+  info("- select tab as foreground tab -");
+  await BrowserTestUtils.switchTab(window.gBrowser, tab);
+
+  info("- tab should be resumed -");
+  await waitForTabPlayingEvent(tab, true);
+  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
+                                   check_all_audio_suspended);
+
+  info("- remove tab -");
+  await BrowserTestUtils.removeTab(tab);
+});
--- a/toolkit/content/tests/browser/browser_mediaPlayback_suspended.js
+++ b/toolkit/content/tests/browser/browser_mediaPlayback_suspended.js
@@ -9,41 +9,16 @@ var SuspendedType = {
 
 function wait_for_event(browser, event) {
   return BrowserTestUtils.waitForEvent(browser, event, false, (event) => {
     is(event.originalTarget, browser, "Event must be dispatched to correct browser.");
     return true;
   });
 }
 
-function check_audio_onplay() {
-  var list = content.document.getElementsByTagName("audio");
-  if (list.length != 1) {
-    ok(false, "There should be only one audio element in page!")
-  }
-
-  var audio = list[0];
-  return new Promise((resolve, reject) => {
-    audio.onplay = () => {
-      ok(false, "Should not receive play event!");
-      this.onplay = null;
-      reject();
-    };
-
-    audio.pause();
-    audio.play();
-
-    setTimeout(() => {
-      ok(true, "Doesn't receive play event when media was blocked.");
-      audio.onplay = null;
-      resolve();
-    }, 1000)
-  });
-}
-
 function check_audio_suspended(suspendedType) {
   var list = content.document.getElementsByTagName("audio");
   if (list.length != 1) {
     ok(false, "There should be only one audio element in page!")
   }
 
   var audio = list[0];
   is(audio.computedSuspended, suspendedType,
@@ -129,40 +104,19 @@ async function suspended_stop_disposable
 
   info("- stop playing audio -");
   browser.stopMedia();
   await wait_for_event(browser, "DOMAudioPlaybackStopped");
   await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
                                    check_audio_suspended);
 }
 
-async function suspended_block(url, browser) {
-  info("### Start test for suspended-block ###");
-  browser.loadURI(url);
-
-  info("- page should have playing audio -");
-  await wait_for_event(browser, "DOMAudioPlaybackStarted");
-
-  info("- block playing audio -");
-  browser.blockMedia();
-  await ContentTask.spawn(browser, SuspendedType.SUSPENDED_BLOCK,
-                                   check_audio_suspended);
-  await ContentTask.spawn(browser, null,
-                                   check_audio_onplay);
-
-  info("- resume blocked audio -");
-  browser.resumeMedia();
-  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
-                                   check_audio_suspended);
-}
-
 add_task(async function setup_test_preference() {
   await SpecialPowers.pushPrefEnv({"set": [
-    ["media.useAudioChannelService.testing", true],
-    ["media.block-autoplay-until-in-foreground", true]
+    ["media.useAudioChannelService.testing", true]
   ]});
 });
 
 add_task(async function test_suspended_pause() {
   await BrowserTestUtils.withNewTab({
       gBrowser,
       url: "about:blank"
     }, suspended_pause.bind(this, PAGE));
@@ -176,15 +130,8 @@ add_task(async function test_suspended_p
 });
 
 add_task(async function test_suspended_stop_disposable() {
   await BrowserTestUtils.withNewTab({
       gBrowser,
       url: "about:blank"
     }, suspended_stop_disposable.bind(this, PAGE));
 });
-
-add_task(async function test_suspended_block() {
-  await BrowserTestUtils.withNewTab({
-      gBrowser,
-      url: "about:blank"
-    }, suspended_block.bind(this, PAGE));
-});
--- a/toolkit/content/tests/browser/browser_mediaPlayback_suspended_multipleAudio.js
+++ b/toolkit/content/tests/browser/browser_mediaPlayback_suspended_multipleAudio.js
@@ -131,26 +131,16 @@ function no_audio_resumed() {
   var nonAutoPlay = content.document.getElementById("nonautoplay");
   if (!autoPlay || !nonAutoPlay) {
     ok(false, "Can't get the audio element!");
   }
 
   is(autoPlay.paused && nonAutoPlay.paused, true, "No audio was resumed.");
 }
 
-function play_nonautoplay_audio_should_be_blocked(suspendedType) {
-  var nonAutoPlay = content.document.getElementById("nonautoplay");
-  if (!nonAutoPlay) {
-    ok(false, "Can't get the audio element!");
-  }
-
-  nonAutoPlay.play();
-  ok(nonAutoPlay.paused, "The blocked audio can't be playback.");
-}
-
 async function suspended_pause(url, browser) {
   info("### Start test for suspended-pause ###");
   browser.loadURI(url);
 
   info("- page should have playing audio -");
   await wait_for_event(browser, "DOMAudioPlaybackStarted");
 
   info("- the default suspended state of all audio should be non-suspened-");
@@ -241,48 +231,19 @@ async function suspended_stop_disposable
 
   info("- no any audio can be resumed by page -");
   browser.resumeMedia();
   await ContentTask.spawn(browser, null, no_audio_resumed);
   await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
                                    check_all_audio_suspended);
 }
 
-async function suspended_block(url, browser) {
-  info("### Start test for suspended-block ###");
-  browser.loadURI(url);
-
-  info("- page should have playing audio -");
-  await wait_for_event(browser, "DOMAudioPlaybackStarted");
-
-  info("- the default suspended state of all audio should be non-suspened-");
-  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
-                                   check_all_audio_suspended);
-
-  info("- block autoplay audio -");
-  browser.blockMedia();
-  await ContentTask.spawn(browser, SuspendedType.SUSPENDED_BLOCK,
-                                   check_autoplay_audio_suspended);
-  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
-                                   check_nonautoplay_audio_suspended);
-
-  info("- no audio can be playback during suspended-block -");
-  await ContentTask.spawn(browser, SuspendedType.SUSPENDED_BLOCK,
-                                   play_nonautoplay_audio_should_be_blocked);
-
-  info("- both audio should be resumed at the same time -");
-  browser.resumeMedia();
-  await ContentTask.spawn(browser, SuspendedType.NONE_SUSPENDED,
-                                   check_all_audio_suspended);
-}
-
 add_task(async function setup_test_preference() {
   await SpecialPowers.pushPrefEnv({"set": [
-    ["media.useAudioChannelService.testing", true],
-    ["media.block-autoplay-until-in-foreground", true]
+    ["media.useAudioChannelService.testing", true]
   ]});
 });
 
 add_task(async function test_suspended_pause() {
   await BrowserTestUtils.withNewTab({
       gBrowser,
       url: "about:blank"
     }, suspended_pause.bind(this, PAGE));
@@ -296,15 +257,8 @@ add_task(async function test_suspended_p
 });
 
 add_task(async function test_suspended_stop_disposable() {
   await BrowserTestUtils.withNewTab({
       gBrowser,
       url: "about:blank"
     }, suspended_stop_disposable.bind(this, PAGE));
 });
-
-add_task(async function test_suspended_block() {
-  await BrowserTestUtils.withNewTab({
-      gBrowser,
-      url: "about:blank"
-    }, suspended_block.bind(this, PAGE));
-});
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -829,29 +829,16 @@
         <body>
           <![CDATA[
             this.messageManager.sendAsyncMessage("AudioPlayback",
                                                  {type: "mediaControlStopped"});
           ]]>
         </body>
       </method>
 
-      <method name="blockMedia">
-        <body>
-          <![CDATA[
-            if (!this.mPrefs.getBoolPref("media.block-autoplay-until-in-foreground", true)) {
-              return;
-            }
-            this._mediaBlocked = true;
-            this.messageManager.sendAsyncMessage("AudioPlayback",
-                                                 {type: "blockInactivePageMedia"});
-          ]]>
-        </body>
-      </method>
-
       <method name="resumeMedia">
         <body>
           <![CDATA[
             this._mediaBlocked = false;
             this.messageManager.sendAsyncMessage("AudioPlayback",
                                                  {type: "resumeMedia"});
             if (this._hasAnyPlayingMediaBeenBlocked) {
               this._hasAnyPlayingMediaBeenBlocked = false;