Bug 556721 - Remove flaky timeout from browser_library_panel_leak.js.
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 26 May 2011 23:37:00 +0200
changeset 71230 04753538e3b651e18970866f3ab332e81a14c4f0
parent 71229 a2f4b2f633933742178260809605b856dc516a93
child 71231 8b9ce2b1e438d66b8c20a8972a8aa779942898e2
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs556721
milestone7.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 556721 - Remove flaky timeout from browser_library_panel_leak.js. rs=places-team
browser/components/places/tests/browser/browser_library_panel_leak.js
--- a/browser/components/places/tests/browser/browser_library_panel_leak.js
+++ b/browser/components/places/tests/browser/browser_library_panel_leak.js
@@ -53,46 +53,38 @@ const TEST_URI = "http://www.mozilla.org
 let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
          getService(Ci.nsIWindowWatcher);
 
 function windowObserver(aSubject, aTopic, aData) {
   if (aTopic != "domwindowopened")
     return;
   ww.unregisterNotification(windowObserver);
   let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  organizer.addEventListener("load", function onLoad(event) {
-    organizer.removeEventListener("load", onLoad, false);
-    executeSoon(function () {
-      let contentTree = organizer.document.getElementById("placeContent");
-      isnot(contentTree, null, "Sanity check: placeContent tree should exist");
-      isnot(organizer.PlacesOrganizer, null, "Sanity check: PlacesOrganizer should exist");
-      isnot(organizer.gEditItemOverlay, null, "Sanity check: gEditItemOverlay should exist");
+  waitForFocus(function () {
+    let contentTree = organizer.document.getElementById("placeContent");
+    isnot(contentTree, null, "Sanity check: placeContent tree should exist");
+    isnot(organizer.PlacesOrganizer, null, "Sanity check: PlacesOrganizer should exist");
+    isnot(organizer.gEditItemOverlay, null, "Sanity check: gEditItemOverlay should exist");
 
-      if (!organizer.gEditItemOverlay._initialized){
-        // The overlay is initialized on focus, we wait for it to be fully operational.
-        setTimeout(arguments.callee, 10);
-        return;
-      }
+    ok(organizer.gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
+    isnot(organizer.gEditItemOverlay.itemId, -1, "Editing a bookmark");
 
-      isnot(organizer.gEditItemOverlay.itemId, -1, "Editing a bookmark");
-      // Select History in the left pane.
-      organizer.PlacesOrganizer.selectLeftPaneQuery('History');
-      // Select the first history entry.
-      let selection = contentTree.view.selection;
-      selection.clearSelection();
-      selection.rangedSelect(0, 0, true);
-      // Check the panel is editing the history entry.
-      is(organizer.gEditItemOverlay.itemId, -1, "Editing an history entry");
-      // Close Library window.
-      organizer.close();
-      // Clean up history.
-      PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
-      finish();
-    });
-  }, false);
+    // Select History in the left pane.
+    organizer.PlacesOrganizer.selectLeftPaneQuery('History');
+    // Select the first history entry.
+    let selection = contentTree.view.selection;
+    selection.clearSelection();
+    selection.rangedSelect(0, 0, true);
+    // Check the panel is editing the history entry.
+    is(organizer.gEditItemOverlay.itemId, -1, "Editing an history entry");
+    // Close Library window.
+    organizer.close();
+    // Clean up history.
+    waitForClearHistory(finish);
+  }, organizer);
 }
 
 function test() {
   waitForExplicitFinish();
   // Add an history entry.
   ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
   PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
                                null, PlacesUtils.history.TRANSITION_TYPED,
@@ -100,8 +92,19 @@ function test() {
 
   ww.registerNotification(windowObserver);
   ww.openWindow(null,
                 "chrome://browser/content/places/places.xul",
                 "",
                 "chrome,toolbar=yes,dialog=no,resizable",
                 null);
 }
+
+function waitForClearHistory(aCallback) {
+  let observer = {
+    observe: function(aSubject, aTopic, aData) {
+      Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
+      aCallback(aSubject, aTopic, aData);
+    }
+  };
+  Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
+  PlacesUtils.bhistory.removeAllPages();
+}