Bug 725549. (Av1) Port |Bug 663763 - Provide helper function for opening the library in tests| to SeaMonkey. r=Callek.
authorSerge Gautherie <sgautherie.bz@free.fr>
Mon, 13 Feb 2012 01:35:44 +0100
changeset 10807 da8b3f35d37fd7df1747f508f69d1f3e062b0ccd
parent 10806 0bba3a536d6ead85c8e8cd2fc998a918d6a8b0c6
child 10808 eda26cb3231e9a983157b107d641d9250505286a
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCallek
bugs725549, 663763
Bug 725549. (Av1) Port |Bug 663763 - Provide helper function for opening the library in tests| to SeaMonkey. r=Callek.
suite/common/places/tests/browser/browser_0_library_left_pane_migration.js
suite/common/places/tests/browser/browser_library_infoBox.js
suite/common/places/tests/browser/browser_library_left_pane_commands.js
suite/common/places/tests/browser/browser_library_left_pane_fixnames.js
suite/common/places/tests/browser/browser_library_open_leak.js
suite/common/places/tests/browser/browser_library_views_liveupdate.js
suite/common/places/tests/browser/browser_sort_in_library.js
suite/common/places/tests/browser/head.js
--- a/suite/common/places/tests/browser/browser_0_library_left_pane_migration.js
+++ b/suite/common/places/tests/browser/browser_0_library_left_pane_migration.js
@@ -39,27 +39,17 @@
 /**
  *  Test we correctly migrate Library left pane to the latest version.
  *  Note: this test MUST be the first between browser chrome tests, or results
  *        of next tests could be unexpected due to PlacesUIUtils getters.
  */
 
 const TEST_URI = "http://www.mozilla.org/";
 
-var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-         getService(Ci.nsIWindowWatcher);
-
-function windowObserver(aSubject, aTopic, aData) {
-  if (aTopic != "domwindowopened")
-    return;
-  ww.unregisterNotification(windowObserver);
-  var organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  organizer.addEventListener("load", function onLoad(event) {
-    organizer.removeEventListener("load", onLoad, false);
-    executeSoon(function () {
+function onLibraryReady(organizer) {
       // Check left pane.
       ok(PlacesUIUtils.leftPaneFolderId > 0,
          "Left pane folder correctly created");
       var leftPaneItems =
         PlacesUtils.annotations
                    .getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
       is(leftPaneItems.length, 1,
          "We correctly have only 1 left pane folder");
@@ -78,18 +68,16 @@ function windowObserver(aSubject, aTopic
       is(organizer.PlacesOrganizer._places.selectedNode.itemId,
          PlacesUIUtils.leftPaneQueries["AllBookmarks"],
          "Library left pane is populated and working");
 
       // Close Library window.
       organizer.close();
       // No need to cleanup anything, we have a correct left pane now.
       finish();
-    });
-  }, false);
 }
 
 function test() {
   waitForExplicitFinish();
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils is running in chrome context");
   ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
   ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
@@ -128,15 +116,10 @@ function test() {
   is(leftPaneItems[0], fakeLeftPaneRoot, "left pane root itemId is correct");
 
   // Check version.
   var version = PlacesUtils.annotations.getItemAnnotation(fakeLeftPaneRoot,
                                                           PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
   is(version, PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION - 1, "Left pane version correctly set");
 
   // Open Library, this will upgrade our left pane version.
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(onLibraryReady);
 }
--- a/suite/common/places/tests/browser/browser_library_infoBox.js
+++ b/suite/common/places/tests/browser/browser_library_infoBox.js
@@ -181,40 +181,21 @@ function nextTest() {
   else {
     // Close Library window.
     gLibrary.close();
     // No need to cleanup anything, we have a correct left pane now.
     finish();
   }
 }
 
-var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-         getService(Ci.nsIWindowWatcher);
-
-function windowObserver(aSubject, aTopic, aData) {
-  if (aTopic != "domwindowopened")
-    return;
-  ww.unregisterNotification(windowObserver);
-  gLibrary = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  gLibrary.addEventListener("load", function onLoad(event) {
-    gLibrary.removeEventListener("load", onLoad, false);
-    executeSoon(function() {
-      gLibrary.PlacesOrganizer._places.focus();
-      waitForFocus(nextTest, gLibrary);
-    });
-  }, false);
-}
-
 function test() {
-  dump("Starting test browser_library_infoBox.js\n");
   waitForExplicitFinish();
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils is running in chrome context");
   ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
 
   // Open Library.
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(function (library) {
+    gLibrary = library;
+    gLibrary.PlacesOrganizer._places.focus();
+    nextTest(gLibrary);
+  });
 }
--- a/suite/common/places/tests/browser/browser_library_left_pane_commands.js
+++ b/suite/common/places/tests/browser/browser_library_left_pane_commands.js
@@ -113,36 +113,20 @@ function nextTest() {
   else {
     // Close Library window.
     gLibrary.close();
     // No need to cleanup anything, we have a correct left pane now.
     finish();
   }
 }
 
-var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-         getService(Ci.nsIWindowWatcher);
-
-function windowObserver(aSubject, aTopic, aData) {
-  if (aTopic != "domwindowopened")
-    return;
-  ww.unregisterNotification(windowObserver);
-  gLibrary = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  gLibrary.addEventListener("load", function onLoad(event) {
-    gLibrary.removeEventListener("load", onLoad, false);
-    executeSoon(nextTest);
-  }, false);
-}
-
 function test() {
   waitForExplicitFinish();
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils is running in chrome context");
   ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
 
   // Open Library.
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(function (library) {
+    gLibrary = library;
+    nextTest();
+  });
 }
--- a/suite/common/places/tests/browser/browser_library_left_pane_fixnames.js
+++ b/suite/common/places/tests/browser/browser_library_left_pane_fixnames.js
@@ -35,50 +35,38 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /**
  *  Test we correctly fix broken Library left pane queries names.
  */
 
-var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-         getService(Ci.nsIWindowWatcher);
-
 // Array of left pane queries objects, each one has the following properties:
 // name: query's identifier got from annotations,
 // itemId: query's itemId,
 // correctTitle: original and correct query's title.
 var leftPaneQueries = [];
 
-function windowObserver(aSubject, aTopic, aData) {
-  if (aTopic != "domwindowopened")
-    return;
-  ww.unregisterNotification(windowObserver);
-  var organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  organizer.addEventListener("load", function onLoad(event) {
-    organizer.removeEventListener("load", onLoad, false);
-    executeSoon(function () {
+function onLibraryReady(organizer) {
       // Check titles have been fixed.
       for (var i = 0; i < leftPaneQueries.length; i++) {
         var query = leftPaneQueries[i];
         is(PlacesUtils.bookmarks.getItemTitle(query.itemId),
            query.correctTitle, "Title is correct for query " + query.name);
         if ("concreteId" in query) {
           is(PlacesUtils.bookmarks.getItemTitle(query.concreteId),
            query.concreteTitle, "Concrete title is correct for query " + query.name);
         }
       }
 
       // Close Library window.
       organizer.close();
       // No need to cleanup anything, we have a correct left pane now.
       finish();
-    });
-  }, false);
 }
 
 function test() {
   waitForExplicitFinish();
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils is running in chrome context");
   ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
   ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
@@ -129,15 +117,10 @@ function test() {
     PlacesUtils.bookmarks.setItemTitle(query.itemId, "badName");
     if ("concreteId" in query)
       PlacesUtils.bookmarks.setItemTitle(query.concreteId, "badName");
   }
 
   PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter);
 
   // Open Library, this will kick-off left pane code.
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(onLibraryReady);
 }
--- a/suite/common/places/tests/browser/browser_library_open_leak.js
+++ b/suite/common/places/tests/browser/browser_library_open_leak.js
@@ -40,35 +40,16 @@
  * Bug 474831
  * https://bugzilla.mozilla.org/show_bug.cgi?id=474831
  *
  * Tests for leaks caused by simply opening and closing the Places Library
  * window.  Opens the Places Library window, waits for it to load, closes it,
  * and finishes.
  */
 
-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 win = aSubject.QueryInterface(Ci.nsIDOMWindow);
-  win.addEventListener("load", function onLoad(event) {
-    win.removeEventListener("load", onLoad, false);
-    executeSoon(function () {
-      ok(true, "Library has been correctly opened");
-      win.close();
-      finish();
-    });
-  }, false);
-}
-
 function test() {
   waitForExplicitFinish();
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(function (win) {
+    ok(true, "Library has been correctly opened");
+    win.close();
+    finish();
+  });
 }
--- a/suite/common/places/tests/browser/browser_library_views_liveupdate.js
+++ b/suite/common/places/tests/browser/browser_library_views_liveupdate.js
@@ -51,34 +51,20 @@ function test() {
   // See Bug 525610.
   requestLongerTimeout(2);
 
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils in context");
   ok(PlacesUIUtils, "PlacesUIUtils in context");
 
   // Open Library, we will check the left pane.
-  var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
-  function windowObserver(aSubject, aTopic, aData) {
-    if (aTopic != "domwindowopened")
-      return;
-    ww.unregisterNotification(windowObserver);
-    gLibrary = aSubject.QueryInterface(Ci.nsIDOMWindow);
-    gLibrary.addEventListener("load", function onLoad(event) {
-      gLibrary.removeEventListener("load", onLoad, false);
-      executeSoon(startTest);
-    }, false);
-  }
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  openLibrary(function (library) {
+    gLibrary = library;
+    startTest();
+  });
 }
 
 /**
  * Adds bookmarks observer, and executes a bunch of bookmarks operations.
  */
 function startTest() {
   var bs = PlacesUtils.bookmarks;
   // Add observers.
--- a/suite/common/places/tests/browser/browser_sort_in_library.js
+++ b/suite/common/places/tests/browser/browser_sort_in_library.js
@@ -263,43 +263,24 @@ function testSortByDir(aOrganizerWin, aP
   });
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 function test() {
   waitForExplicitFinish();
 
-  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 win = aSubject.QueryInterface(Ci.nsIDOMWindow);
-    win.addEventListener("load", function onLoad(event) {
-      win.removeEventListener("load", onLoad, false);
-      executeSoon(function () {
+  openLibrary(function (win) {
         let tree = win.document.getElementById("placeContent");
         isnot(tree, null, "sanity check: placeContent tree should exist");
         // Run the tests.
         testSortByColAndDir(win, tree, true);
         testSortByColAndDir(win, tree, false);
         testSortByDir(win, tree, true);
         testSortByDir(win, tree, false);
         testInvalid(win, tree);
         // Reset the sort to SORT_BY_NONE.
         setSort(win, tree, false, false);
         // Close the window and finish.
         win.close();
         finish();
-      });
-    }, false);
-  }
-
-  ww.registerNotification(windowObserver);
-  ww.openWindow(null,
-                "chrome://communicator/content/bookmarks/bookmarksManager.xul",
-                "",
-                "chrome,toolbar=yes,dialog=no,resizable",
-                null);
+  });
 }
--- a/suite/common/places/tests/browser/head.js
+++ b/suite/common/places/tests/browser/head.js
@@ -9,16 +9,25 @@ let (getter = PlacesUIUtils.__lookupGett
 registerCleanupFunction(function(){
   let (getter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId")) {
     if (cachedLeftPaneFolderIdGetter && typeof(getter) != "function")
       PlacesUIUtils.__defineGetter__("leftPaneFolderId",
                                      cachedLeftPaneFolderIdGetter);
   }
 });
 
+function openLibrary(callback) {
+  var library = window.openDialog(
+    "chrome://communicator/content/bookmarks/bookmarksManager.xul",
+    "", "chrome,toolbar=yes,dialog=no,resizable");
+  waitForFocus(function () {
+    callback(library);
+  }, library);
+}
+
 /**
  * Waits for completion of a clear history operation, before
  * proceeding with aCallback.
  *
  * @param aCallback
  *        Function to be called when done.
  */
 function waitForClearHistory(aCallback) {