2011-04-07 16:35:48 -07:00
|
|
|
Cu.import("resource://services-sync/engines/bookmarks.js");
|
2010-12-06 15:51:38 -08:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
2010-08-06 08:31:21 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
2011-04-07 16:35:48 -07:00
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
2011-02-07 11:25:47 -08:00
|
|
|
|
|
|
|
Engines.register(BookmarksEngine);
|
|
|
|
let engine = Engines.get("bookmarks");
|
|
|
|
let store = engine._store;
|
|
|
|
store.wipe();
|
|
|
|
|
|
|
|
function test_tracking() {
|
2010-08-06 08:31:21 -07:00
|
|
|
_("Verify we've got an empty tracker to work with.");
|
2010-08-06 14:25:59 -07:00
|
|
|
let tracker = engine._tracker;
|
2010-08-06 08:31:21 -07:00
|
|
|
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() {
|
2011-02-07 11:25:47 -08:00
|
|
|
return Svc.Bookmark.insertBookmark(folder,
|
|
|
|
Utils.makeURI("http://getfirefox.com"),
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Firefox!");
|
2010-08-06 08:31:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2010-12-06 15:51:56 -08:00
|
|
|
// We expect two changed items because the containing folder
|
|
|
|
// changed as well (new child).
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 2);
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("Notifying twice won't do any harm.");
|
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
|
|
|
createBmk();
|
2010-12-06 15:51:56 -08:00
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 3);
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("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);
|
2011-02-07 11:25:47 -08:00
|
|
|
|
2010-08-06 08:31:21 -07:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
2011-02-07 11:25:47 -08:00
|
|
|
store.wipe();
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
2010-08-06 08:31:21 -07:00
|
|
|
}
|
|
|
|
}
|
2011-02-07 11:25:47 -08:00
|
|
|
|
2011-04-07 16:32:20 -07:00
|
|
|
function test_onItemChanged() {
|
|
|
|
// Anno that's in ANNOS_TO_TRACK.
|
2011-04-26 05:25:27 -07:00
|
|
|
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
2011-04-07 16:32:20 -07:00
|
|
|
|
|
|
|
_("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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
let folder = Svc.Bookmark.createFolder(Svc.Bookmark.bookmarksMenuFolder,
|
|
|
|
"Parent",
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX);
|
|
|
|
_("Track changes to annos.");
|
|
|
|
let b = Svc.Bookmark.insertBookmark(folder,
|
|
|
|
Utils.makeURI("http://getfirefox.com"),
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Firefox!");
|
|
|
|
let bGUID = engine._store.GUIDForId(b);
|
|
|
|
_("New item is " + b);
|
|
|
|
_("GUID: " + bGUID);
|
|
|
|
|
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
2011-04-26 05:25:27 -07:00
|
|
|
Svc.Annos.setItemAnnotation(b, DESCRIPTION_ANNO, "A test description", 0,
|
2011-04-07 16:32:20 -07:00
|
|
|
Svc.Annos.EXPIRE_NEVER);
|
|
|
|
do_check_true(tracker.changedIDs[bGUID] > 0);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:27:39 -07:00
|
|
|
function test_onItemMoved() {
|
|
|
|
_("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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
let fx_id = Svc.Bookmark.insertBookmark(
|
|
|
|
Svc.Bookmark.bookmarksMenuFolder,
|
|
|
|
Utils.makeURI("http://getfirefox.com"),
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Firefox!");
|
|
|
|
let fx_guid = engine._store.GUIDForId(fx_id);
|
|
|
|
let tb_id = Svc.Bookmark.insertBookmark(
|
|
|
|
Svc.Bookmark.bookmarksMenuFolder,
|
|
|
|
Utils.makeURI("http://getthunderbird.com"),
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Thunderbird!");
|
|
|
|
let tb_guid = engine._store.GUIDForId(tb_id);
|
|
|
|
|
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
|
|
|
|
|
|
|
// Moving within the folder will just track the folder.
|
|
|
|
Svc.Bookmark.moveItem(tb_id, Svc.Bookmark.bookmarksMenuFolder, 0);
|
|
|
|
do_check_true(tracker.changedIDs['menu'] > 0);
|
|
|
|
do_check_eq(tracker.changedIDs['toolbar'], undefined);
|
|
|
|
do_check_eq(tracker.changedIDs[fx_guid], undefined);
|
|
|
|
do_check_eq(tracker.changedIDs[tb_guid], undefined);
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
|
|
|
|
// Moving a bookmark to a different folder will track the old
|
|
|
|
// folder, the new folder and the bookmark.
|
|
|
|
Svc.Bookmark.moveItem(tb_id, Svc.Bookmark.toolbarFolder,
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX);
|
|
|
|
do_check_true(tracker.changedIDs['menu'] > 0);
|
|
|
|
do_check_true(tracker.changedIDs['toolbar'] > 0);
|
|
|
|
do_check_eq(tracker.changedIDs[fx_guid], undefined);
|
|
|
|
do_check_true(tracker.changedIDs[tb_guid] > 0);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-07 11:25:47 -08:00
|
|
|
function run_test() {
|
|
|
|
initTestLogging("Trace");
|
|
|
|
|
|
|
|
Log4Moz.repository.getLogger("Engine.Bookmarks").level = Log4Moz.Level.Trace;
|
|
|
|
Log4Moz.repository.getLogger("Store.Bookmarks").level = Log4Moz.Level.Trace;
|
|
|
|
Log4Moz.repository.getLogger("Tracker.Bookmarks").level = Log4Moz.Level.Trace;
|
|
|
|
|
|
|
|
test_tracking();
|
2011-05-18 14:27:39 -07:00
|
|
|
test_onItemChanged();
|
|
|
|
test_onItemMoved();
|
2011-02-07 11:25:47 -08:00
|
|
|
}
|
|
|
|
|