2012-08-29 14:43:41 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
2010-08-09 16:59:26 -07:00
|
|
|
Cu.import("resource://services-sync/engines/bookmarks.js");
|
2012-08-29 14:43:41 -07:00
|
|
|
Cu.import("resource://services-sync/service.js");
|
2010-08-09 16:59:26 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
|
|
|
|
2011-01-14 13:41:09 -08:00
|
|
|
const PARENT_ANNO = "sync/parent";
|
|
|
|
|
2012-08-29 14:43:41 -07:00
|
|
|
Service.engineManager.register(BookmarksEngine);
|
|
|
|
let engine = Service.engineManager.get("bookmarks");
|
2010-12-06 15:51:56 -08:00
|
|
|
let store = engine._store;
|
2010-12-06 15:51:33 -08:00
|
|
|
let fxuri = Utils.makeURI("http://getfirefox.com/");
|
|
|
|
let tburi = Utils.makeURI("http://getthunderbird.com/");
|
2010-08-09 16:59:26 -07:00
|
|
|
|
2011-01-14 13:41:09 -08: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.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let ids = PlacesUtils.bookmarks.getBookmarkIdsForURI(fxuri, {});
|
2010-08-09 16:59:26 -07:00
|
|
|
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);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
|
|
|
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
|
|
|
do_check_true(PlacesUtils.bookmarks.getBookmarkURI(id).equals(fxuri));
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), fxrecord.title);
|
|
|
|
do_check_eq(PlacesUtils.annotations.getItemAnnotation(id, "bookmarkProperties/description"),
|
2011-01-14 13:41:09 -08:00
|
|
|
fxrecord.description);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), fxrecord.keyword);
|
2010-08-09 16:59:26 -07:00
|
|
|
|
|
|
|
_("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",
|
2011-01-14 13:41:09 -08:00
|
|
|
"keyword", "parentName", "parentid"]) {
|
2010-12-06 15:51:33 -08:00
|
|
|
do_check_eq(newrecord[property], fxrecord[property]);
|
2011-01-14 13:41:09 -08:00
|
|
|
}
|
2010-12-06 15:51:33 -08:00
|
|
|
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);
|
2011-01-14 13:41:09 -08:00
|
|
|
|
|
|
|
_("Create a record with some values missing.");
|
|
|
|
let tbrecord = new Bookmark("bookmarks", "thunderbird1");
|
|
|
|
tbrecord.bmkUri = tburi.spec;
|
|
|
|
tbrecord.parentName = "Bookmarks Toolbar";
|
|
|
|
tbrecord.parentid = "toolbar";
|
|
|
|
store.applyIncoming(tbrecord);
|
|
|
|
|
|
|
|
_("Verify it has been created correctly.");
|
|
|
|
id = store.idForGUID(tbrecord.id);
|
|
|
|
do_check_eq(store.GUIDForId(id), tbrecord.id);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
|
|
|
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
|
|
|
do_check_true(PlacesUtils.bookmarks.getBookmarkURI(id).equals(tburi));
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), null);
|
2011-01-14 13:41:09 -08:00
|
|
|
let error;
|
|
|
|
try {
|
2011-05-19 18:08:22 -07:00
|
|
|
PlacesUtils.annotations.getItemAnnotation(id, "bookmarkProperties/description");
|
2011-01-14 13:41:09 -08:00
|
|
|
} catch(ex) {
|
|
|
|
error = ex;
|
|
|
|
}
|
|
|
|
do_check_eq(error.result, Cr.NS_ERROR_NOT_AVAILABLE);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null);
|
2011-01-14 13:41:09 -08:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_bookmark_update() {
|
|
|
|
try {
|
|
|
|
_("Create a bookmark whose values we'll change.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
2011-01-14 13:41:09 -08:00
|
|
|
"Get Firefox!");
|
2011-05-19 18:08:22 -07:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
bmk1_id, "bookmarkProperties/description", "Firefox is awesome.", 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
|
|
|
PlacesUtils.bookmarks.setKeywordForBookmark(bmk1_id, "firefox");
|
2011-01-14 13:41:09 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
|
|
|
|
|
|
|
_("Update the record with some null values.");
|
|
|
|
let record = store.createRecord(bmk1_guid);
|
|
|
|
record.title = null;
|
|
|
|
record.description = null;
|
|
|
|
record.keyword = null;
|
|
|
|
record.tags = null;
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Verify that the values have been cleared.");
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_throws(function () {
|
|
|
|
PlacesUtils.annotations.getItemAnnotation(
|
|
|
|
bmk1_id, "bookmarkProperties/description");
|
|
|
|
}, Cr.NS_ERROR_NOT_AVAILABLE);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemTitle(bmk1_id), null);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(bmk1_id), null);
|
2011-01-14 13:41:09 -08:00
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_bookmark_createRecord() {
|
|
|
|
try {
|
|
|
|
_("Create a bookmark without a description or title.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX, null);
|
2011-01-14 13:41:09 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
|
|
|
|
|
|
|
_("Verify that the record is created accordingly.");
|
|
|
|
let record = store.createRecord(bmk1_guid);
|
|
|
|
do_check_eq(record.title, null);
|
|
|
|
do_check_eq(record.description, null);
|
|
|
|
do_check_eq(record.keyword, null);
|
|
|
|
|
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);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
|
|
|
PlacesUtils.bookmarks.TYPE_FOLDER);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), folder.title);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder);
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
_("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);
|
2011-01-13 14:03:11 -08:00
|
|
|
for each (let property in ["title", "parentName", "parentid"])
|
2012-08-29 14:43:41 -07:00
|
|
|
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
|
|
|
|
2011-01-13 14:03:11 -08:00
|
|
|
function test_folder_createRecord() {
|
|
|
|
try {
|
|
|
|
_("Create a folder.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
2011-01-13 14:03:11 -08:00
|
|
|
let folder1_guid = store.GUIDForId(folder1_id);
|
|
|
|
|
|
|
|
_("Create two bookmarks in that folder without assigning them GUIDs.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
folder1_id, fxuri, PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
|
|
|
let bmk2_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
folder1_id, tburi, PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Thunderbird!");
|
2011-01-13 14:03:11 -08:00
|
|
|
|
|
|
|
_("Create a record for the folder and verify basic properties.");
|
|
|
|
let record = store.createRecord(folder1_guid);
|
|
|
|
do_check_true(record instanceof BookmarkFolder);
|
|
|
|
do_check_eq(record.title, "Folder1");
|
|
|
|
do_check_eq(record.parentid, "toolbar");
|
|
|
|
do_check_eq(record.parentName, "Bookmarks Toolbar");
|
|
|
|
|
|
|
|
_("Verify the folder's children. Ensures that the bookmarks were given GUIDs.");
|
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
|
|
|
let bmk2_guid = store.GUIDForId(bmk2_id);
|
|
|
|
do_check_eq(record.children.length, 2);
|
|
|
|
do_check_eq(record.children[0], bmk1_guid);
|
|
|
|
do_check_eq(record.children[1], bmk2_guid);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 13:41:09 -08:00
|
|
|
function test_deleted() {
|
|
|
|
try {
|
|
|
|
_("Create a bookmark that will be deleted.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
2011-01-14 13:41:09 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
|
|
|
|
|
|
|
_("Delete the bookmark through the store.");
|
|
|
|
let record = new PlacesItem("bookmarks", bmk1_guid);
|
|
|
|
record.deleted = true;
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Ensure it has been deleted.");
|
|
|
|
let error;
|
|
|
|
try {
|
2011-05-19 18:08:22 -07:00
|
|
|
PlacesUtils.bookmarks.getBookmarkURI(bmk1_id);
|
2011-01-14 13:41:09 -08:00
|
|
|
} catch(ex) {
|
|
|
|
error = ex;
|
|
|
|
}
|
|
|
|
do_check_eq(error.result, Cr.NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
|
|
|
let newrec = store.createRecord(bmk1_guid);
|
|
|
|
do_check_eq(newrec.deleted, true);
|
|
|
|
|
|
|
|
} 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.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
2010-12-06 15:51:38 -08:00
|
|
|
let folder1_guid = store.GUIDForId(folder1_id);
|
2011-05-19 18:08:22 -07:00
|
|
|
let folder2_id = PlacesUtils.bookmarks.createFolder(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, "Folder2", 0);
|
2010-12-06 15:51:38 -08:00
|
|
|
let folder2_guid = store.GUIDForId(folder2_id);
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
folder1_id, fxuri, PlacesUtils.bookmarks.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;
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Verify the new parent.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let new_folder_id = PlacesUtils.bookmarks.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() {
|
2010-12-06 15:51:56 -08:00
|
|
|
// Make sure the tracker is turned on.
|
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
2010-12-06 15:51:33 -08:00
|
|
|
try {
|
|
|
|
_("Create two bookmarks");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
2010-12-06 15:51:38 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk2_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, tburi,
|
|
|
|
PlacesUtils.bookmarks.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.");
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 0);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 1);
|
2010-12-06 15:51:56 -08:00
|
|
|
let toolbar = store.createRecord("toolbar");
|
|
|
|
do_check_eq(toolbar.children.length, 2);
|
|
|
|
do_check_eq(toolbar.children[0], bmk1_guid);
|
|
|
|
do_check_eq(toolbar.children[1], bmk2_guid);
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
_("Move bookmarks around.");
|
2010-12-06 15:51:56 -08:00
|
|
|
store._childrenToOrder = {};
|
|
|
|
toolbar.children = [bmk2_guid, bmk1_guid];
|
|
|
|
store.applyIncoming(toolbar);
|
|
|
|
// Bookmarks engine does this at the end of _processIncoming
|
|
|
|
engine._tracker.ignoreAll = true;
|
|
|
|
store._orderChildren();
|
|
|
|
engine._tracker.ignoreAll = false;
|
|
|
|
delete store._childrenToOrder;
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
_("Verify new order.");
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 0);
|
|
|
|
do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 1);
|
2010-12-06 15:51:33 -08:00
|
|
|
|
|
|
|
} finally {
|
2010-12-06 15:51:56 -08:00
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
2010-12-06 15:51:33 -08:00
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 13:41:09 -08:00
|
|
|
function test_orphan() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
_("Add a new bookmark locally.");
|
2011-05-19 18:08:22 -07:00
|
|
|
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
2011-01-14 13:41:09 -08:00
|
|
|
let bmk1_guid = store.GUIDForId(bmk1_id);
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder);
|
2011-01-14 13:41:09 -08:00
|
|
|
let error;
|
|
|
|
try {
|
2011-05-19 18:08:22 -07:00
|
|
|
PlacesUtils.annotations.getItemAnnotation(bmk1_id, PARENT_ANNO);
|
2011-01-14 13:41:09 -08:00
|
|
|
} catch(ex) {
|
|
|
|
error = ex;
|
|
|
|
}
|
|
|
|
do_check_eq(error.result, Cr.NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
_("Apply a server record that is the same but refers to non-existent folder.");
|
|
|
|
let record = store.createRecord(bmk1_guid);
|
|
|
|
record.parentid = "non-existent";
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Verify that bookmark has been flagged as orphan, has not moved.");
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder);
|
|
|
|
do_check_eq(PlacesUtils.annotations.getItemAnnotation(bmk1_id, PARENT_ANNO),
|
|
|
|
"non-existent");
|
2011-01-14 13:41:09 -08:00
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_reparentOrphans() {
|
|
|
|
try {
|
2011-05-19 18:08:22 -07:00
|
|
|
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
|
|
|
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
2011-01-14 13:41:09 -08:00
|
|
|
let folder1_guid = store.GUIDForId(folder1_id);
|
|
|
|
|
|
|
|
_("Create a bogus orphan record and write the record back to the store to trigger _reparentOrphans.");
|
2011-05-19 18:08:22 -07:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
folder1_id, PARENT_ANNO, folder1_guid, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-01-14 13:41:09 -08:00
|
|
|
let record = store.createRecord(folder1_guid);
|
|
|
|
record.title = "New title for Folder 1";
|
|
|
|
store._childrenToOrder = {};
|
|
|
|
store.applyIncoming(record);
|
|
|
|
|
|
|
|
_("Verify that is has been marked as an orphan even though it couldn't be moved into itself.");
|
2011-05-19 18:08:22 -07:00
|
|
|
do_check_eq(PlacesUtils.annotations.getItemAnnotation(folder1_id, PARENT_ANNO),
|
2011-03-02 15:27:16 -08:00
|
|
|
folder1_guid);
|
2011-01-14 13:41:09 -08:00
|
|
|
|
|
|
|
} finally {
|
|
|
|
_("Clean up.");
|
|
|
|
store.wipe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 15:51:33 -08:00
|
|
|
function run_test() {
|
2011-01-25 12:37:23 -08:00
|
|
|
initTestLogging('Trace');
|
2010-12-06 15:51:33 -08:00
|
|
|
test_bookmark_create();
|
2011-01-14 13:41:09 -08:00
|
|
|
test_bookmark_createRecord();
|
|
|
|
test_bookmark_update();
|
2010-12-06 15:51:33 -08:00
|
|
|
test_folder_create();
|
2011-01-13 14:03:11 -08:00
|
|
|
test_folder_createRecord();
|
2011-01-14 13:41:09 -08:00
|
|
|
test_deleted();
|
2010-12-06 15:51:33 -08:00
|
|
|
test_move_folder();
|
|
|
|
test_move_order();
|
2011-01-14 13:41:09 -08:00
|
|
|
test_orphan();
|
|
|
|
test_reparentOrphans();
|
2012-07-12 16:28:53 -07:00
|
|
|
if (engine._tracker._lazySave) {
|
|
|
|
engine._tracker._lazySave.clear();
|
|
|
|
}
|
2010-12-06 15:51:33 -08:00
|
|
|
}
|