2009-08-20 05:15:12 +04:00
|
|
|
_("Making sure after processing incoming bookmarks, they show up in the right order");
|
2010-06-17 01:30:08 +04:00
|
|
|
Cu.import("resource://services-sync/engines/bookmarks.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
2009-08-20 05:15:12 +04:00
|
|
|
|
|
|
|
function getBookmarks(folderId) {
|
|
|
|
let bookmarks = [];
|
|
|
|
|
|
|
|
let pos = 0;
|
|
|
|
while (true) {
|
|
|
|
let itemId = Svc.Bookmark.getIdForItemAt(folderId, pos);
|
|
|
|
_("Got itemId", itemId, "under", folderId, "at", pos);
|
|
|
|
if (itemId == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (Svc.Bookmark.getItemType(itemId)) {
|
|
|
|
case Svc.Bookmark.TYPE_BOOKMARK:
|
|
|
|
bookmarks.push(Svc.Bookmark.getItemTitle(itemId));
|
|
|
|
break;
|
|
|
|
case Svc.Bookmark.TYPE_FOLDER:
|
|
|
|
bookmarks.push(getBookmarks(itemId));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_("Unsupported item type..");
|
|
|
|
}
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bookmarks;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check(expected) {
|
|
|
|
let bookmarks = getBookmarks(Svc.Bookmark.unfiledBookmarksFolder);
|
|
|
|
|
|
|
|
_("Checking if the bookmark structure is", JSON.stringify(expected));
|
|
|
|
_("Got bookmarks:", JSON.stringify(bookmarks));
|
|
|
|
do_check_true(Utils.deepEquals(bookmarks, expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
2010-12-07 02:51:56 +03:00
|
|
|
let store = new BookmarksEngine()._store;
|
|
|
|
initTestLogging("Trace");
|
|
|
|
|
2009-08-20 05:15:12 +04:00
|
|
|
_("Starting with a clean slate of no bookmarks");
|
|
|
|
store.wipe();
|
|
|
|
check([]);
|
|
|
|
|
2010-12-07 02:51:56 +03:00
|
|
|
function bookmark(name, parent) {
|
2010-08-13 00:19:41 +04:00
|
|
|
let bookmark = new Bookmark("http://weave.server/my-bookmark");
|
2009-08-20 05:15:12 +04:00
|
|
|
bookmark.id = name;
|
|
|
|
bookmark.title = name;
|
|
|
|
bookmark.bmkUri = "http://uri/";
|
|
|
|
bookmark.parentid = parent || "unfiled";
|
|
|
|
bookmark.tags = [];
|
2010-12-07 02:51:56 +03:00
|
|
|
return bookmark;
|
2009-08-20 05:15:12 +04:00
|
|
|
}
|
|
|
|
|
2010-12-07 02:51:56 +03:00
|
|
|
function folder(name, parent, children) {
|
2010-08-13 00:19:41 +04:00
|
|
|
let folder = new BookmarkFolder("http://weave.server/my-bookmark-folder");
|
2009-08-20 05:15:12 +04:00
|
|
|
folder.id = name;
|
|
|
|
folder.title = name;
|
|
|
|
folder.parentid = parent || "unfiled";
|
2010-12-07 02:51:56 +03:00
|
|
|
folder.children = children;
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
function apply(record) {
|
|
|
|
store._childrenToOrder = {};
|
|
|
|
store.applyIncoming(record);
|
|
|
|
store._orderChildren();
|
|
|
|
delete store._childrenToOrder;
|
2009-08-20 05:15:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
_("basic add first bookmark");
|
2010-12-07 02:51:56 +03:00
|
|
|
apply(bookmark("10", ""));
|
2009-08-20 05:15:12 +04:00
|
|
|
check(["10"]);
|
|
|
|
|
|
|
|
_("basic append behind 10");
|
2010-12-07 02:51:56 +03:00
|
|
|
apply(bookmark("20", ""));
|
2009-08-20 05:15:12 +04:00
|
|
|
check(["10", "20"]);
|
|
|
|
|
|
|
|
_("basic create in folder");
|
2010-12-07 02:51:56 +03:00
|
|
|
apply(bookmark("31", "f30"));
|
|
|
|
let f30 = folder("f30", "", ["31"]);
|
|
|
|
apply(f30);
|
2009-08-20 05:15:12 +04:00
|
|
|
check(["10", "20", ["31"]]);
|
|
|
|
|
2010-12-07 02:51:56 +03:00
|
|
|
_("insert missing parent -> append to unfiled");
|
|
|
|
apply(bookmark("41", "f40"));
|
|
|
|
check(["10", "20", ["31"], "41"]);
|
2009-08-20 05:15:12 +04:00
|
|
|
|
|
|
|
_("insert another missing parent -> append");
|
2010-12-07 02:51:56 +03:00
|
|
|
apply(bookmark("42", "f40"));
|
|
|
|
check(["10", "20", ["31"], "41", "42"]);
|
2009-08-20 05:15:12 +04:00
|
|
|
|
|
|
|
_("insert folder -> move children and followers");
|
2010-12-07 02:51:56 +03:00
|
|
|
let f40 = folder("f40", "", ["41", "42"]);
|
|
|
|
apply(f40);
|
|
|
|
check(["10", "20", ["31"], ["41", "42"]]);
|
2009-08-20 05:15:12 +04:00
|
|
|
|
2010-12-07 02:51:56 +03:00
|
|
|
_("Moving 41 behind 42 -> update f40");
|
|
|
|
f40.children = ["42", "41"];
|
|
|
|
apply(f40);
|
|
|
|
check(["10", "20", ["31"], ["42", "41"]]);
|
2009-08-20 05:15:12 +04:00
|
|
|
|
|
|
|
_("Moving 10 back to front -> update 10, 20");
|
2010-12-07 02:51:56 +03:00
|
|
|
f40.children = ["41", "42"];
|
|
|
|
apply(f40);
|
|
|
|
check(["10", "20", ["31"], ["41", "42"]]);
|
|
|
|
|
|
|
|
_("Moving 20 behind 42 in f40 -> update 50");
|
|
|
|
apply(bookmark("20", "f40"));
|
|
|
|
check(["10", ["31"], ["41", "42", "20"]]);
|
|
|
|
|
|
|
|
_("Moving 10 in front of 31 in f30 -> update 10, f30");
|
|
|
|
apply(bookmark("10", "f30"));
|
|
|
|
f30.children = ["10", "31"];
|
|
|
|
apply(f30);
|
|
|
|
check([["10", "31"], ["41", "42", "20"]]);
|
|
|
|
|
|
|
|
_("Moving 20 from f40 to f30 -> update 20, f30");
|
|
|
|
apply(bookmark("20", "f30"));
|
|
|
|
f30.children = ["10", "20", "31"];
|
|
|
|
apply(f30);
|
|
|
|
check([["10", "20", "31"], ["41", "42"]]);
|
|
|
|
|
|
|
|
_("Move 20 back to front -> update 20, f30");
|
|
|
|
apply(bookmark("20", ""));
|
|
|
|
f30.children = ["10", "31"];
|
|
|
|
apply(f30);
|
|
|
|
check([["10", "31"], ["41", "42"], "20"]);
|
|
|
|
|
2009-08-20 05:15:12 +04:00
|
|
|
}
|