Bug 1088163 - Fix intermittent browser_offlineQuotaNotification.js timeouts by properly waiting for a notification to show. r=markh, a=test-only
💩💩 backed out by 196c6575593d 💩 💩
authorTim Taubert <ttaubert@mozilla.com>
Fri, 20 Mar 2015 12:48:51 +0100
changeset 252086 72912a71fb98
parent 252085 8358c6c2c417
child 252087 62a72d33d16b
push id698
push userjlund@mozilla.com
push date2015-03-23 22:08 +0000
treeherdermozilla-release@b0c0ae7b02a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, test-only
bugs1088163
milestone37.0
Bug 1088163 - Fix intermittent browser_offlineQuotaNotification.js timeouts by properly waiting for a notification to show. r=markh, a=test-only
browser/base/content/test/general/browser_offlineQuotaNotification.js
--- a/browser/base/content/test/general/browser_offlineQuotaNotification.js
+++ b/browser/base/content/test/general/browser_offlineQuotaNotification.js
@@ -46,18 +46,30 @@ function checkInContentPreferences(win) 
   is(tab, "networkTab", "Network tab is selected");
   // all good, we are done.
   win.close();
   finish();
 }
 
 function test() {
   waitForExplicitFinish();
-  gBrowser.selectedBrowser.addEventListener("load", function onload() {
-    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
+
+  Services.prefs.setBoolPref("offline-apps.allow_by_default", false);
+
+  // Open a new tab.
+  gBrowser.selectedTab = gBrowser.addTab(URL);
+  registerCleanupFunction(() => gBrowser.removeCurrentTab());
+
+
+  Promise.all([
+    // Wait for a notification that asks whether to allow offline storage.
+    promiseNotification(),
+    // Wait for the tab to load.
+    BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser)
+  ]).then(() => {
     gBrowser.selectedBrowser.contentWindow.applicationCache.oncached = function() {
       executeSoon(function() {
         // We got cached - now we should have provoked the quota warning.
         let notification = PopupNotifications.getNotification('offline-app-usage');
         ok(notification, "have offline-app-usage notification");
         // select the default action - this should cause the preferences
         // window to open - which we track either via a window watcher (for
         // the window-based prefs) or via an "Initialized" event (for
@@ -82,13 +94,19 @@ function test() {
         }
       });
     };
     Services.prefs.setIntPref("offline-apps.quota.warn", 1);
 
     // Click the notification panel's "Allow" button.  This should kick
     // off updates which will call our oncached handler above.
     PopupNotifications.panel.firstElementChild.button.click();
-  }, true);
+  });
+}
 
-  Services.prefs.setBoolPref("offline-apps.allow_by_default", false);
-  gBrowser.contentWindow.location = URL;
+function promiseNotification() {
+  return new Promise(resolve => {
+    PopupNotifications.panel.addEventListener("popupshown", function onShown() {
+      PopupNotifications.panel.removeEventListener("popupshown", onShown);
+      resolve();
+    });
+  });
 }