gecko/services/sync/tests/unit/test_bookmark_tracker.js
Philipp von Weitershausen 8b467f2644 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.
2010-08-06 23:25:59 +02:00

52 lines
1.7 KiB
JavaScript

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 = 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"),
Svc.Bookmark.DEFAULT_INDEX,
"Get Firefox!");
}
try {
_("Create bookmark. Won't show because we haven't started tracking yet");
createBmk();
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
_("Tell the tracker to start tracking changes.");
Svc.Obs.notify("weave:engine:start-tracking");
createBmk();
do_check_eq([id for (id in tracker.changedIDs)].length, 1);
_("Notifying twice won't do any harm.");
Svc.Obs.notify("weave:engine:start-tracking");
createBmk();
do_check_eq([id for (id in tracker.changedIDs)].length, 2);
_("Let's stop tracking again.");
tracker.clearChangedIDs();
Svc.Obs.notify("weave:engine:stop-tracking");
createBmk();
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.");
engine._store.wipe();
}
}