Bug 1341062 - part1 : wait for audioplayback event to ensure the media element has been resumed. r=baku
authorAlastor Wu <alwu@mozilla.com>
Thu, 02 Mar 2017 17:38:53 +0800
changeset 394557 5304ef02b51f89a520075d42b5bcc0ae3f1dbc75
parent 394556 4c467c55430d94e1036d90bc3160dcd01448ad24
child 394558 19350704484da94b554dfa4722587eae5072dfea
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [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 - part1 : wait for audioplayback event to ensure the media element has been resumed. r=baku Block-stop should be dispatched before audio-playback, so we can check block event first. Also add "loop" attribute for video to avoid getting the wrong pause state. MozReview-Commit-ID: 3WHuJGsZCPn
toolkit/content/tests/browser/browser_block_autoplay_media_pausedAfterPlay.js
toolkit/content/tests/browser/file_blockMedia_shouldPlay.html
toolkit/content/tests/browser/head.js
--- a/toolkit/content/tests/browser/browser_block_autoplay_media_pausedAfterPlay.js
+++ b/toolkit/content/tests/browser/browser_block_autoplay_media_pausedAfterPlay.js
@@ -59,24 +59,25 @@ add_task(function* block_autoplay_media(
   info("- select tab1 as foreground tab, and tab1's media should be paused -");
   yield BrowserTestUtils.switchTab(window.gBrowser, tab1);
   yield ContentTask.spawn(tab1.linkedBrowser, true,
                           check_audio_pause_state);
 
   info("- the tab1 should not be blocked -");
   yield waitForTabBlockEvent(tab1, false);
 
-  info("- select tab2 as foreground tab, and tab2's media should be playing -");
+  info("- select tab2 as foreground tab, and the tab2 should not be blocked -");
   yield BrowserTestUtils.switchTab(window.gBrowser, tab2);
+  yield waitForTabBlockEvent(tab2, false);
+
+  info("- tab2's media should be playing -");
+  yield waitForTabPlayingEvent(tab2, true);
   yield ContentTask.spawn(tab2.linkedBrowser, false,
                           check_audio_pause_state);
 
-  info("- the tab2 should not be blocked -");
-  yield waitForTabBlockEvent(tab2, false);
-
   info("- check tab2's media suspend type -");
   yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- remove tabs -");
   yield BrowserTestUtils.removeTab(tab1);
   yield BrowserTestUtils.removeTab(tab2);
 });
--- a/toolkit/content/tests/browser/file_blockMedia_shouldPlay.html
+++ b/toolkit/content/tests/browser/file_blockMedia_shouldPlay.html
@@ -1,15 +1,15 @@
 <!DOCTYPE html>
 <head>
   <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
   <meta content="utf-8" http-equiv="encoding">
 </head>
 <body>
-<audio id="testAudio" src="audio.ogg"></audio>
+<audio id="testAudio" src="audio.ogg" loop></audio>
 <script type="text/javascript">
 
 var audio = document.getElementById("testAudio");
 audio.play();
 audio.pause();
 audio.play();
 
 </script>
--- a/toolkit/content/tests/browser/head.js
+++ b/toolkit/content/tests/browser/head.js
@@ -44,8 +44,26 @@ function* waitForTabBlockEvent(tab, expe
       if (event.detail.changed.indexOf("blocked") >= 0) {
         is(tab.soundBlocked, expectBlocked, "The tab should " + (expectBlocked ? "" : "not ") + "be blocked");
         return true;
       }
       return false;
     });
   }
 }
+
+/**
+ * Used to check whether the tab has soundplaying attribute.
+ */
+function* waitForTabPlayingEvent(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;
+    });
+  }
+}