Bug 1552818 - part1 : prevent to leak audio-playback notification. r=padenot, a=RyanVM
authoralwu <alwu@mozilla.com>
Tue, 02 Jul 2019 12:05:38 +0000
changeset 522828 0ddbde0b74fba2226258f381c94437782179068e
parent 522827 582e8db79ecc8b63f26dba6f59eb723f97ac79da
child 522829 16410020f7e1a7b8dd7922def256eae4e08d23be
push id52
push userryanvm@gmail.com
push dateMon, 08 Jul 2019 20:14:04 +0000
treeherdermozilla-esr68@16410020f7e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, RyanVM
bugs1552818
milestone68.1.0
Bug 1552818 - part1 : prevent to leak audio-playback notification. r=padenot, a=RyanVM This test will leak one `audio-playback` notification to next test, because when we close this test, we would close iframe and send the `inaudible-pause` notification. It would somehow affect the following test if the next one is also listening to the `audio-playback` notification. Differential Revision: https://phabricator.services.mozilla.com/D36534
dom/base/test/test_audioNotificationNavigationWebAudio.html
--- a/dom/base/test/test_audioNotificationNavigationWebAudio.html
+++ b/dom/base/test/test_audioNotificationNavigationWebAudio.html
@@ -9,26 +9,25 @@
 <pre id="test">
 </pre>
 <iframe></iframe>
 
 <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
-// playback starts, stops when the page is reloaded, and starts again.
-var expectedNotification = ["active", "inactive-pause", "active"];
+var expectedNotification = null;
 var iframe = null;
 
 var observer = {
   observe: function(subject, topic, data) {
     is(topic, "audio-playback", "audio-playback received");
     var expected = expectedNotification.shift();
-    is(data, expected, "This is the right notification");
-    if (expected != "inactive-pause") {
+    is(data, expected, `"${data}" is the right notification`);
+    if (expectedNotification.length == 0) {
       runTest();
     }
   }
 };
 
 var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
                                    .getService(SpecialPowers.Ci.nsIObserverService);
 
@@ -36,27 +35,32 @@ var tests = [
   function() {
     iframe = document.querySelector("iframe");
     observerService.addObserver(observer, "audio-playback");
     ok(true, "Observer set");
     runTest();
   },
 
   function() {
+    info("Load iframe");
+    expectedNotification = ["active"];
     iframe.src = "file_webAudioAudible.html";
   },
 
   function() {
-    // Reload
+    info("Reload iframe");
+    // As reloading frame would stop previous audio playing in frame, we would
+    // receive "inactive-pause" first.
+    expectedNotification = ["inactive-pause", "active"];
     iframe.src = "file_webAudioAudible.html";
   },
   function() {
-    // Wait for the "active" notification, that is expected after the previous
-    // load of "file_webAudioAudible.html".
-    runTest();
+    info("Cleaning up iframe");
+    expectedNotification = ["inactive-pause"];
+    iframe.src = null;
   }
 ];
 
 function runTest() {
   if (!tests.length) {
     observerService.removeObserver(observer, "audio-playback");
     ok(true, "Observer removed");
     SimpleTest.finish();