Bug 585190 - Fix tracker tests on m-c [r=mconnor]
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Fri, 06 Aug 2010 23:25:59 +0200
changeset 49604 ab817970c2274e146e8e335dee384acd3736efcd
parent 49603 1228b03b822ccc2301b83202d3656359c7a6a783
child 49605 74bcf68d60892820cfaf780a224a55e2350422c7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconnor
bugs585190
Bug 585190 - Fix tracker tests on m-c [r=mconnor] Ensure that the bookmark tracker test starts out with a clean slate. Svc.History.removeAllPages(), as called by the history tracker test during clean up, needs the "UHist" alias registered, which isn't available by default in xpcshell.
services/sync/tests/unit/test_bookmark_tracker.js
services/sync/tests/unit/test_history_tracker.js
--- a/services/sync/tests/unit/test_bookmark_tracker.js
+++ b/services/sync/tests/unit/test_bookmark_tracker.js
@@ -1,14 +1,17 @@
 Cu.import("resource://services-sync/engines/bookmarks.js");
 Cu.import("resource://services-sync/util.js");
 
 function run_test() {
+  let engine = new BookmarksEngine();
+  engine._store.wipe();
+
   _("Verify we've got an empty tracker to work with.");
-  let tracker = new BookmarksEngine()._tracker;
+  let tracker = engine._tracker;
   do_check_eq([id for (id in tracker.changedIDs)].length, 0);
 
   let folder = Svc.Bookmark.createFolder(Svc.Bookmark.bookmarksMenuFolder,
                                          "Test Folder",
                                          Svc.Bookmark.DEFAULT_INDEX);
   function createBmk() {
     Svc.Bookmark.insertBookmark(folder,
                                 Utils.makeURI("http://getfirefox.com"),
@@ -38,11 +41,11 @@ function run_test() {
     do_check_eq([id for (id in tracker.changedIDs)].length, 0);
 
     _("Notifying twice won't do any harm.");
     Svc.Obs.notify("weave:engine:stop-tracking");
     createBmk();
     do_check_eq([id for (id in tracker.changedIDs)].length, 0);
   } finally {
     _("Clean up.");
-    Svc.Bookmark.removeItem(folder);
+    engine._store.wipe();
   }
 }
--- a/services/sync/tests/unit/test_history_tracker.js
+++ b/services/sync/tests/unit/test_history_tracker.js
@@ -1,11 +1,34 @@
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://services-sync/engines/history.js");
 Cu.import("resource://services-sync/util.js");
 
+
+// See toolkit/components/places/tests/head_common.js
+const NS_APP_HISTORY_50_FILE = "UHist";
+const dirsvc = Cc["@mozilla.org/file/directory_service;1"].
+               getService(Ci.nsIDirectoryService);
+
+// Add our own dirprovider for old history.dat.
+let provider = {
+  getFile: function(prop, persistent) {
+    persistent.value = true;
+    if (prop == NS_APP_HISTORY_50_FILE) {
+      let histFile = dirsvc.get("ProfD", Ci.nsIFile);
+      histFile.append("history.dat");
+      return histFile;
+    }
+    throw Cr.NS_ERROR_FAILURE;
+  },
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider])
+};
+dirsvc.registerProvider(provider);
+
+
 function run_test() {
   _("Verify we've got an empty tracker to work with.");
   let tracker = new HistoryEngine()._tracker;
   do_check_eq([id for (id in tracker.changedIDs)].length, 0);
 
   let _counter = 0;
   function addVisit() {
     Svc.History.addVisit(Utils.makeURI("http://getfirefox.com/" + _counter),