2010-08-09 16:59:26 -07:00
|
|
|
Cu.import("resource://services-sync/engines/bookmarks.js");
|
2010-12-06 15:51:33 -08:00
|
|
|
Cu.import("resource://services-sync/type_records/bookmark.js");
|
2010-08-09 16:59:26 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
|
|
|
|
2010-12-06 15:51:33 -08:00
|
|
|
let store = new BookmarksEngine()._store;
|
|
|
|
let fxuri = Utils.makeURI("http://getfirefox.com/");
|
|
|
|
let tburi = Utils.makeURI("http://getthunderbird.com/");
|
2010-08-09 16:59:26 -07:00
|
|
|
|
2010-12-06 15:51:33 -08:00
|
|
|
function test_bookmark_create() {
|
2010-08-09 16:59:26 -07:00
|
|
|
try {
|
|
|
|
_("Ensure the record isn't present yet.");
|
|
|
|
let ids = Svc.Bookmark.getBookmarkIdsForURI(fxuri, {});
|
|
|
|
do_check_eq(ids.length, 0);
|
|
|
|
|
|
|
|
_("Let's create a new record.");
|
2010-12-06 15:51:38 -08:00
|
|
|
let fxrecord = new Bookmark("bookmarks", "get-firefox1");
|
2010-12-06 15:51:33 -08:00
|
|
|
fxrecord.bmkUri = fxuri.spec;
|
|
|
|
fxrecord.description = "Firefox is awesome.";
|
|
|
|
fxrecord.title = "Get Firefox!";
|
|
|
|
fxrecord.tags = ["firefox", "awesome", "browser"];
|
|
|
|
fxrecord.keyword = "awesome";
|
|
|
|
fxrecord.loadInSidebar = false;
|
|
|
|
fxrecord.parentName = "Bookmarks Toolbar";
|
|
|
|
fxrecord.parentid = "toolbar";
|
2010-08-09 16:59:26 -07:00
|
|
|
store.applyIncoming(fxrecord);
|
|
|
|
|
|
|
|
_("Verify it has been created correctly.");
|
2010-12-06 15:51:38 -08:00
|
|
|
let id = store.idForGUID(fxrecord.id);
|
|
|
|
do_check_eq(store.GUIDForId(id), fxrecord.id);
|
2010-08-09 16:59:26 -07:00
|
|
|
do_check_eq(Svc.Bookmark.getItemType(id), Svc.Bookmark.TYPE_BOOKMARK);
|
|
|
|
do_check_eq(Svc.Bookmark.getItemTitle(id), fxrecord.title);
|
|
|
|
do_check_eq(Svc.Bookmark.getFolderIdForItem(id),
|
|
|
|
Svc.Bookmark.toolbarFolder);
|
|
|
|
do_check_eq(Svc.Bookmark.getKeywordForBookmark(id), fxrecord.keyword);
|
|
|
|
|
|
|
|
_("Have the store create a new record object. Verify that it has the same data.");
|
2010-11-29 16:41:17 -08:00
|
|
|
let newrecord = store.createRecord(fxrecord.id);
|
2010-12-06 15:51:33 -08:00
|
|
|
do_check_true(newrecord instanceof Bookmark);
|
|
|
|
for each (let property in ["type", "bmkUri", "description", "title",
|
|
|
|
"keyword", "parentName", "parentid"])
|
|
|
|
do_check_eq(newrecord[property], fxrecord[property]);
|
|
|
|
do_check_true(Utils.deepEquals(newrecord.tags.sort(),
|
|
|
|
fxrecord.tags.sort()));
|
2010-08-09 16:59:26 -07:00
|
|
|
|
|
|
|
_("The calculated sort index is based on frecency data.");
|
|
|
|
do_check_true(newrecord.sortindex >= 150);
|
2010-12-06 15:51:33 -08:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_folder_create() {
|
|
|
|
try {
|
|
|
|
_("Create a folder.");
|
2010-12-06 15:51:38 -08:00
|
|
|
let folder = new BookmarkFolder("bookmarks", "testfolder-1");
|
2010-12-06 15:51:33 -08:00
|
|
|
folder.parentName = "Bookmarks Toolbar";
|
|
|
|
folder.parentid = "toolbar";
|
|
|
|
folder.title = "Test Folder";
|
|
|
|
store.applyIncoming(folder);
|
|
|
|
|
|
|
|
_("Verify it has been created correctly.");
|
2010-12-06 15:51:38 -08:00
|
|
|
let id = store.idForGUID(folder.id);
|
2010-12-06 15:51:33 -08:00
|
|
|
do_check_eq(Svc.Bookmark.getItemType(id), Svc.Bookmark.TYPE_FOLDER);
|
|
|
|
do_check_eq(Svc.Bookmark.getItemTitle(id), folder.title);
|
|
|
|
do_check_eq(Svc.Bookmark.getFolderIdForItem(id),
|
|
|
|
Svc.Bookmark.toolbarFolder);
|
|
|
|
|
|
|
|
_("Have the store create a new record object. Verify that it has the same data.");
|
|
|
|
let newrecord = store.createRecord(folder.id);
|
|
|
|
do_check_true(newrecord instanceof BookmarkFolder);
|
|
|
|
for each (let property in ["title","title", "parentName", "parentid"])
|
|
|
|
do_check_eq(newrecord[property], folder[property]);
|
2010-11-09 13:53:50 -08:00
|
|
|
|
|
|
|
_("Folders have high sort index to ensure they're synced first.");
|
2010-12-06 15:51:33 -08:00
|
|
|
do_check_eq(newrecord.sortindex, 1000000);
|
2010-08-09 16:59:26 -07:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
function test_move_folder() {
|
|
|
|
try {
|
|
|
|
_("Create two folders and a bookmark in one of them.");
|
|
|
|
let folder1_id = Svc.Bookmark.createFolder(
|
|
|
|
Svc.Bookmark.toolbarFolder, "Folder1", 0);
|
2010-12-06 15:51:38 -08:00
|
|
|
let folder1_guid = store.GUIDForId(folder1_id);
|
2010-12-06 15:51:33 -08:00
|
|
|
let folder2_id = Svc.Bookmark.createFolder(
|
|
|
|
Svc.Bookmark.toolbarFolder, "Folder2", 0);
|
2010-12-06 15:51:38 -08:00
|
|
|
let folder2_guid = store.GUIDForId(folder2_id);
|
2010-12-06 15:51:33 -08:00
|
|
|
let bmk_id = Svc.Bookmark.insertBookmark(
|
|
|
|
folder1_id, fxuri, Svc.Bookmark.DEFAULT_INDEX, "Get Firefox!");
|
2010-12-06 15:51:38 -08:00
|
|
|
let bmk_guid = store.GUIDForId(bmk_id);
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
_("Get a record, reparent it and apply it to the store.");
|
|
|
|
let record = store.createRecord(bmk_guid);
|
|
|
|
do_check_eq(record.parentid, folder1_guid);
|
|
|
|
record.parentid = folder2_guid;
|
|
|
|
record.description = ""; //TODO for some reason we need this
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Verify the new parent.");
|
|
|
|
let new_folder_id = Svc.Bookmark.getFolderIdForItem(bmk_id);
|
2010-12-06 15:51:38 -08:00
|
|
|
do_check_eq(store.GUIDForId(new_folder_id), folder2_guid);
|
2010-12-06 15:51:33 -08:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_move_order() {
|
|
|
|
try {
|
|
|
|
_("Create two bookmarks");
|
|
|
|
let bmk1_id = Svc.Bookmark.insertBookmark(
|
|
|
|
Svc.Bookmark.toolbarFolder, fxuri, Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Firefox!");
|
2010-12-06 15:51:38 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
2010-12-06 15:51:33 -08:00
|
|
|
let bmk2_id = Svc.Bookmark.insertBookmark(
|
|
|
|
Svc.Bookmark.toolbarFolder, tburi, Svc.Bookmark.DEFAULT_INDEX,
|
|
|
|
"Get Thunderbird!");
|
2010-12-06 15:51:38 -08:00
|
|
|
let bmk2_guid = store.GUIDForId(bmk2_id);
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
_("Verify order.");
|
|
|
|
do_check_eq(Svc.Bookmark.getItemIndex(bmk1_id), 0);
|
|
|
|
do_check_eq(Svc.Bookmark.getItemIndex(bmk2_id), 1);
|
|
|
|
let rec1 = store.createRecord(bmk1_guid);
|
|
|
|
let rec2 = store.createRecord(bmk2_guid);
|
|
|
|
do_check_eq(rec1.predecessorid, undefined);
|
|
|
|
do_check_eq(rec2.predecessorid, rec1.id);
|
|
|
|
|
|
|
|
_("Move bookmarks around.");
|
|
|
|
rec2.predecessorid = null;
|
|
|
|
rec1.predecessorid = rec2.id;
|
|
|
|
rec2.description = rec1.description = ""; //TODO for some reason we need this
|
|
|
|
store.applyIncoming(rec2);
|
|
|
|
store.applyIncoming(rec1);
|
|
|
|
|
|
|
|
_("Verify new order.");
|
|
|
|
do_check_eq(Svc.Bookmark.getItemIndex(bmk2_id), 0);
|
|
|
|
do_check_eq(Svc.Bookmark.getItemIndex(bmk1_id), 1);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
test_bookmark_create();
|
|
|
|
test_folder_create();
|
|
|
|
test_move_folder();
|
|
|
|
test_move_order();
|
|
|
|
}
|