Bug 1049545 - use a mutation observer instead of a timeout to wait for the notification, r=mak, a=test-only
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 07 Aug 2014 10:55:19 +0100
changeset 217415 7123465251a7053de4c349a6e6edba20d0258e8a
parent 217414 67b46a59bcc0845409a78d8d47a704989fc02217
child 217416 cf771b63d6d78d648de5e220bc3751f48ef54c5b
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, test-only
bugs1049545
milestone33.0a2
Bug 1049545 - use a mutation observer instead of a timeout to wait for the notification, r=mak, a=test-only
browser/base/content/test/general/browser_urlbarSearchSingleWordNotification.js
--- a/browser/base/content/test/general/browser_urlbarSearchSingleWordNotification.js
+++ b/browser/base/content/test/general/browser_urlbarSearchSingleWordNotification.js
@@ -1,23 +1,37 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+let notificationObserver;
 registerCleanupFunction(function() {
   Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost");
+  if (notificationObserver) {
+    notificationObserver.disconnect();
+  }
 });
 
 function promiseNotificationForTab(value, expected, tab=gBrowser.selectedTab) {
   let deferred = Promise.defer();
   let notificationBox = gBrowser.getNotificationBox(tab.linkedBrowser);
   if (expected) {
-    waitForCondition(() => notificationBox.getNotificationWithValue(value) !== null,
-                     deferred.resolve, "Were expecting to get a notification");
+    let checkForNotification = function() {
+      if (notificationBox.getNotificationWithValue(value)) {
+        notificationObserver.disconnect();
+        notificationObserver = null;
+        deferred.resolve();
+      }
+    }
+    if (notificationObserver) {
+      notificationObserver.disconnect();
+    }
+    notificationObserver = new MutationObserver(checkForNotification);
+    notificationObserver.observe(notificationBox, {childList: true});
   } else {
     setTimeout(() => {
       is(notificationBox.getNotificationWithValue(value), null, "We are expecting to not get a notification");
       deferred.resolve();
     }, 1000);
   }
   return deferred.promise;
 }