mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1412139 - Prepare existing bookmark engine tests for new buffered engine. r=kitcambridge
MozReview-Commit-ID: 2HIkdPOuWOy --HG-- extra : rebase_source : 6c8108f707f59e8d795dfd489453c614f00fd096
This commit is contained in:
parent
a562b72999
commit
3b78d2f449
@ -12,19 +12,20 @@ Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
Cu.import("resource://services-sync/bookmark_validator.js");
|
||||
|
||||
const bms = PlacesUtils.bookmarks;
|
||||
let engine;
|
||||
let store;
|
||||
|
||||
add_task(async function setup() {
|
||||
initTestLogging("Trace");
|
||||
await Service.engineManager.register(BookmarksEngine);
|
||||
engine = Service.engineManager.get("bookmarks");
|
||||
store = engine._store;
|
||||
store._log.level = Log.Level.Trace;
|
||||
engine._log.level = Log.Level.Trace;
|
||||
await Service.engineManager.unregister("bookmarks");
|
||||
});
|
||||
|
||||
async function sharedSetup() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
await engine.initialize();
|
||||
let store = engine._store;
|
||||
|
||||
store._log.level = Log.Level.Trace;
|
||||
engine._log.level = Log.Level.Trace;
|
||||
|
||||
let server = await serverForFoo(engine);
|
||||
await SyncTestingInfrastructure(server);
|
||||
|
||||
@ -32,16 +33,18 @@ async function sharedSetup() {
|
||||
|
||||
Svc.Obs.notify("weave:engine:start-tracking"); // We skip usual startup...
|
||||
|
||||
return { server, collection };
|
||||
return { engine, store, server, collection };
|
||||
}
|
||||
|
||||
async function cleanup(server) {
|
||||
async function cleanup(engine, server) {
|
||||
Svc.Obs.notify("weave:engine:stop-tracking");
|
||||
let promiseStartOver = promiseOneObserver("weave:service:start-over:finish");
|
||||
await Service.startOver();
|
||||
await promiseStartOver;
|
||||
await promiseStopServer(server);
|
||||
await bms.eraseEverything();
|
||||
await engine.resetClient();
|
||||
await engine.finalize();
|
||||
}
|
||||
|
||||
async function syncIdToId(syncId) {
|
||||
@ -122,7 +125,7 @@ async function validate(collection, expectedFailures = []) {
|
||||
add_task(async function test_dupe_bookmark() {
|
||||
_("Ensure that a bookmark we consider a dupe is handled correctly.");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -186,14 +189,14 @@ add_task(async function test_dupe_bookmark() {
|
||||
await validate(collection);
|
||||
PlacesUtils.bookmarks.removeObserver(obs);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_dupe_reparented_bookmark() {
|
||||
_("Ensure that a bookmark we consider a dupe from a different parent is handled correctly");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -252,14 +255,14 @@ add_task(async function test_dupe_reparented_bookmark() {
|
||||
// and a final sanity check - use the validator
|
||||
await validate(collection);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_dupe_reparented_locally_changed_bookmark() {
|
||||
_("Ensure that a bookmark with local changes we consider a dupe from a different parent is handled correctly");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -333,7 +336,7 @@ add_task(async function test_dupe_reparented_locally_changed_bookmark() {
|
||||
// and a final sanity check - use the validator
|
||||
await validate(collection);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
@ -341,7 +344,7 @@ add_task(async function test_dupe_reparented_to_earlier_appearing_parent_bookmar
|
||||
_("Ensure that a bookmark we consider a dupe from a different parent that " +
|
||||
"appears in the same sync before the dupe item");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, store, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -410,7 +413,7 @@ add_task(async function test_dupe_reparented_to_earlier_appearing_parent_bookmar
|
||||
// Make sure the validator thinks everything is hunky-dory.
|
||||
await validate(collection);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
@ -418,7 +421,7 @@ add_task(async function test_dupe_reparented_to_later_appearing_parent_bookmark(
|
||||
_("Ensure that a bookmark we consider a dupe from a different parent that " +
|
||||
"doesn't exist locally as we process the child, but does appear in the same sync");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, store, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -487,7 +490,7 @@ add_task(async function test_dupe_reparented_to_later_appearing_parent_bookmark(
|
||||
// Make sure the validator thinks everything is hunky-dory.
|
||||
await validate(collection);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
@ -495,7 +498,7 @@ add_task(async function test_dupe_reparented_to_future_arriving_parent_bookmark(
|
||||
_("Ensure that a bookmark we consider a dupe from a different parent that " +
|
||||
"doesn't exist locally and doesn't appear in this Sync is handled correctly");
|
||||
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, store, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The parent folder and one bookmark in it.
|
||||
@ -611,7 +614,7 @@ add_task(async function test_dupe_reparented_to_future_arriving_parent_bookmark(
|
||||
await validate(collection, expected);
|
||||
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
|
||||
@ -619,7 +622,7 @@ add_task(async function test_dupe_empty_folder() {
|
||||
_("Ensure that an empty folder we consider a dupe is handled correctly.");
|
||||
// Empty folders aren't particularly interesting in practice (as that seems
|
||||
// an edge-case) but duping folders with items is broken - bug 1293163.
|
||||
let { server, collection } = await this.sharedSetup();
|
||||
let { engine, server, collection } = await this.sharedSetup();
|
||||
|
||||
try {
|
||||
// The folder we will end up duping away.
|
||||
@ -653,7 +656,7 @@ add_task(async function test_dupe_empty_folder() {
|
||||
ok(getServerRecord(collection, folder1_guid).deleted);
|
||||
await promiseNoLocalItem(folder1_guid);
|
||||
} finally {
|
||||
await cleanup(server);
|
||||
await cleanup(engine, server);
|
||||
}
|
||||
});
|
||||
// XXX - TODO - folders with children. Bug 1293163
|
||||
|
@ -42,6 +42,13 @@ add_task(async function setup() {
|
||||
await generateNewKeys(Service.collectionKeys);
|
||||
});
|
||||
|
||||
add_task(async function setup() {
|
||||
await Service.engineManager.unregister("bookmarks");
|
||||
|
||||
initTestLogging("Trace");
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
});
|
||||
|
||||
add_task(async function test_delete_invalid_roots_from_server() {
|
||||
_("Ensure that we delete the Places and Reading List roots from the server.");
|
||||
|
||||
@ -194,6 +201,7 @@ add_task(async function test_processIncoming_error_orderChildren() {
|
||||
|
||||
} finally {
|
||||
await store.wipe();
|
||||
await engine.resetClient();
|
||||
Svc.Prefs.resetBranch("");
|
||||
Service.recordManager.clearCache();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
@ -379,6 +387,7 @@ async function test_restoreOrImport(aReplace) {
|
||||
|
||||
} finally {
|
||||
await store.wipe();
|
||||
await engine.resetClient();
|
||||
Svc.Prefs.resetBranch("");
|
||||
Service.recordManager.clearCache();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
@ -477,6 +486,7 @@ add_task(async function test_mismatched_types() {
|
||||
|
||||
} finally {
|
||||
await store.wipe();
|
||||
await engine.resetClient();
|
||||
Svc.Prefs.resetBranch("");
|
||||
Service.recordManager.clearCache();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
@ -637,6 +647,7 @@ add_task(async function test_misreconciled_root() {
|
||||
do_check_eq(parentIDBefore, parentIDAfter);
|
||||
|
||||
await store.wipe();
|
||||
await engine.resetClient();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
await promiseStopServer(server);
|
||||
});
|
||||
@ -785,6 +796,7 @@ add_task(async function test_sync_dateAdded() {
|
||||
|
||||
} finally {
|
||||
await store.wipe();
|
||||
await engine.resetClient();
|
||||
Svc.Prefs.resetBranch("");
|
||||
Service.recordManager.clearCache();
|
||||
await PlacesSyncUtils.bookmarks.reset();
|
||||
|
@ -10,8 +10,7 @@ let tracker;
|
||||
|
||||
add_task(async function setup() {
|
||||
initTestLogging("Trace");
|
||||
await Service.engineManager.register(BookmarksEngine);
|
||||
engine = Service.engineManager.get("bookmarks");
|
||||
engine = new BookmarksEngine(Service);
|
||||
store = engine._store;
|
||||
tracker = engine._tracker;
|
||||
});
|
||||
|
@ -10,9 +10,6 @@ Cu.import("resource://services-sync/service.js");
|
||||
|
||||
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
||||
|
||||
let engine;
|
||||
let store;
|
||||
|
||||
// Record borrowed from Bug 631361.
|
||||
const record631361 = {
|
||||
id: "M5bwUKK8hPyF",
|
||||
@ -66,12 +63,13 @@ add_task(async function setup() {
|
||||
initTestLogging("Trace");
|
||||
Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace;
|
||||
Log.repository.getLogger("Sync.Store.Bookmarks").level = Log.Level.Trace;
|
||||
|
||||
engine = Service.engineManager.get("bookmarks");
|
||||
store = engine._store;
|
||||
});
|
||||
|
||||
add_task(async function test_livemark_descriptions() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
await engine.initialize();
|
||||
let store = engine._store;
|
||||
|
||||
let record = record631361.payload;
|
||||
|
||||
async function doRecord(r) {
|
||||
@ -91,9 +89,15 @@ add_task(async function test_livemark_descriptions() {
|
||||
let id = await store.idForGUID(record.id);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, DESCRIPTION_ANNO, "", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
|
||||
await engine.finalize();
|
||||
});
|
||||
|
||||
add_task(async function test_livemark_invalid() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
await engine.initialize();
|
||||
let store = engine._store;
|
||||
|
||||
_("Livemarks considered invalid by nsLivemarkService are skipped.");
|
||||
|
||||
_("Parent is unknown. Will be set to unfiled.");
|
||||
@ -121,4 +125,6 @@ add_task(async function test_livemark_invalid() {
|
||||
await store.create(lmParentRec);
|
||||
// No exception, but no creation occurs.
|
||||
do_check_eq(-1, (await store.idForGUID(lmParentRec.id, true)));
|
||||
|
||||
await engine.finalize();
|
||||
});
|
||||
|
@ -148,8 +148,13 @@ async function resolveConflict(engine, collection, timestamp, buildTree,
|
||||
expectedTree, message);
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await Service.engineManager.unregister("bookmarks");
|
||||
});
|
||||
|
||||
add_task(async function test_local_order_newer() {
|
||||
let engine = Service.engineManager.get("bookmarks");
|
||||
let engine = new BookmarksEngine(Service);
|
||||
await engine.initialize();
|
||||
|
||||
let server = await serverForFoo(engine);
|
||||
await SyncTestingInfrastructure(server);
|
||||
@ -190,11 +195,13 @@ add_task(async function test_local_order_newer() {
|
||||
await engine.wipeClient();
|
||||
await Service.startOver();
|
||||
await promiseStopServer(server);
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_remote_order_newer() {
|
||||
let engine = Service.engineManager.get("bookmarks");
|
||||
let engine = new BookmarksEngine(Service);
|
||||
await engine.initialize();
|
||||
|
||||
let server = await serverForFoo(engine);
|
||||
await SyncTestingInfrastructure(server);
|
||||
@ -235,6 +242,7 @@ add_task(async function test_remote_order_newer() {
|
||||
await engine.wipeClient();
|
||||
await Service.startOver();
|
||||
await promiseStopServer(server);
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -13,11 +13,6 @@ Cu.import("resource://services-sync/engines/clients.js");
|
||||
Cu.import("resource://services-sync/engines/bookmarks.js");
|
||||
Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
initTestLogging("Trace");
|
||||
Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace;
|
||||
Log.repository.getLogger("Sync.Engine.Clients").level = Log.Level.Trace;
|
||||
Log.repository.getLogger("Sqlite").level = Log.Level.Info; // less noisy
|
||||
|
||||
const LAST_BOOKMARK_SYNC_PREFS = [
|
||||
"bookmarks.lastSync",
|
||||
"bookmarks.lastSyncLocal",
|
||||
@ -46,6 +41,11 @@ add_task(async function setup() {
|
||||
Service.recordTelemetryEvent = (object, method, value, extra = undefined) => {
|
||||
recordedEvents.push({ object, method, value, extra });
|
||||
};
|
||||
|
||||
initTestLogging("Trace");
|
||||
Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace;
|
||||
Log.repository.getLogger("Sync.Engine.Clients").level = Log.Level.Trace;
|
||||
Log.repository.getLogger("Sqlite").level = Log.Level.Info; // less noisy
|
||||
});
|
||||
|
||||
function checkRecordedEvents(expected, message) {
|
||||
|
@ -13,12 +13,18 @@ const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
||||
const IOService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
|
||||
function newSmartBookmark(parent, uri, position, title, queryID) {
|
||||
let id = PlacesUtils.bookmarks.insertBookmark(parent, uri, position, title);
|
||||
async function newSmartBookmark(parentGuid, url, position, title, queryID) {
|
||||
let info = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid,
|
||||
url,
|
||||
position,
|
||||
title,
|
||||
});
|
||||
let id = await PlacesUtils.promiseItemId(info.guid);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, SMART_BOOKMARKS_ANNO,
|
||||
queryID, 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
return id;
|
||||
return info;
|
||||
}
|
||||
|
||||
function smartBookmarkCount() {
|
||||
@ -70,14 +76,14 @@ add_task(async function test_annotation_uploaded() {
|
||||
}
|
||||
|
||||
_("Create a smart bookmark in the toolbar.");
|
||||
let parent = PlacesUtils.toolbarFolderId;
|
||||
let uri =
|
||||
CommonUtils.makeURI("place:sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=10");
|
||||
let url = "place:sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=10";
|
||||
let title = "Most Visited";
|
||||
|
||||
let mostVisitedID = newSmartBookmark(parent, uri, -1, title, "MostVisited");
|
||||
let mostVisitedInfo = await newSmartBookmark(
|
||||
PlacesUtils.bookmarks.toolbarGuid, url, -1, title, "MostVisited");
|
||||
let mostVisitedID = await PlacesUtils.promiseItemId(mostVisitedInfo.guid);
|
||||
|
||||
_("New item ID: " + mostVisitedID);
|
||||
do_check_true(!!mostVisitedID);
|
||||
@ -96,7 +102,7 @@ add_task(async function test_annotation_uploaded() {
|
||||
do_check_true(record instanceof Bookmark);
|
||||
do_check_true(record instanceof BookmarkQuery);
|
||||
|
||||
do_check_eq(record.bmkUri, uri.spec);
|
||||
do_check_eq(record.bmkUri, url);
|
||||
|
||||
_("Make sure the new record carries with it the annotation.");
|
||||
do_check_eq("MostVisited", record.queryId);
|
||||
@ -150,17 +156,18 @@ add_task(async function test_annotation_uploaded() {
|
||||
let newAnnoValue = PlacesUtils.annotations.getItemAnnotation(
|
||||
newID, SMART_BOOKMARKS_ANNO);
|
||||
do_check_eq(newAnnoValue, "MostVisited");
|
||||
do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(newID).spec, uri.spec);
|
||||
do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(newID).spec, url);
|
||||
|
||||
_("Test updating.");
|
||||
let newRecord = await store.createRecord(serverGUID);
|
||||
do_check_eq(newRecord.queryId, newAnnoValue);
|
||||
newRecord.queryId = "LeastVisited";
|
||||
await store.update(newRecord);
|
||||
collection.insert(serverGUID, encryptPayload(newRecord.cleartext));
|
||||
engine.lastModified = collection.timestamp + 1;
|
||||
await sync_engine_and_validate_telem(engine, false);
|
||||
do_check_eq("LeastVisited", PlacesUtils.annotations.getItemAnnotation(
|
||||
newID, SMART_BOOKMARKS_ANNO));
|
||||
|
||||
|
||||
} finally {
|
||||
// Clean up.
|
||||
await store.wipe();
|
||||
@ -173,44 +180,116 @@ add_task(async function test_annotation_uploaded() {
|
||||
add_task(async function test_smart_bookmarks_duped() {
|
||||
let server = await serverForFoo(engine);
|
||||
await SyncTestingInfrastructure(server);
|
||||
let collection = server.user("foo").collection("bookmarks");
|
||||
|
||||
let parent = PlacesUtils.toolbarFolderId;
|
||||
let uri =
|
||||
CommonUtils.makeURI("place:sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=10");
|
||||
let url = "place:sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=10";
|
||||
let title = "Most Visited";
|
||||
let mostVisitedID = newSmartBookmark(parent, uri, -1, title, "MostVisited");
|
||||
let mostVisitedGUID = await store.GUIDForId(mostVisitedID);
|
||||
|
||||
let record = await store.createRecord(mostVisitedGUID);
|
||||
|
||||
_("Prepare sync.");
|
||||
try {
|
||||
await engine._syncStartup();
|
||||
|
||||
_("Verify that mapDupe uses the anno, discovering a dupe regardless of URI.");
|
||||
do_check_eq(mostVisitedGUID, (await engine._mapDupe(record)));
|
||||
_("Verify that queries with the same anno and URL dupe");
|
||||
{
|
||||
let info = await newSmartBookmark(PlacesUtils.bookmarks.toolbarGuid, url,
|
||||
-1, title, "MostVisited");
|
||||
let idForOldGUID = await PlacesUtils.promiseItemId(info.guid);
|
||||
|
||||
record.bmkUri = "http://foo/";
|
||||
do_check_eq(mostVisitedGUID, (await engine._mapDupe(record)));
|
||||
do_check_neq(PlacesUtils.bookmarks.getBookmarkURI(mostVisitedID).spec,
|
||||
record.bmkUri);
|
||||
let record = await store.createRecord(info.guid);
|
||||
record.id = Utils.makeGUID();
|
||||
collection.insert(record.id, encryptPayload(record.cleartext));
|
||||
|
||||
collection.insert("toolbar", encryptPayload({
|
||||
id: "toolbar",
|
||||
parentid: "places",
|
||||
type: "folder",
|
||||
title: "Bookmarks Toolbar",
|
||||
children: [record.id],
|
||||
}));
|
||||
|
||||
await sync_engine_and_validate_telem(engine, false);
|
||||
|
||||
let idForNewGUID = await PlacesUtils.promiseItemId(record.id);
|
||||
equal(idForOldGUID, idForNewGUID);
|
||||
}
|
||||
|
||||
_("Verify that queries with the same anno and different URL dupe");
|
||||
{
|
||||
let info = await newSmartBookmark(PlacesUtils.bookmarks.menuGuid,
|
||||
"place:bar", -1, title,
|
||||
"MostVisited");
|
||||
let idForOldGUID = await PlacesUtils.promiseItemId(info.guid);
|
||||
|
||||
let record = await store.createRecord(info.guid);
|
||||
record.id = Utils.makeGUID();
|
||||
collection.insert(record.id, encryptPayload(record.cleartext), engine.lastSync + 1);
|
||||
|
||||
collection.insert("menu", encryptPayload({
|
||||
id: "menu",
|
||||
parentid: "places",
|
||||
type: "folder",
|
||||
title: "Bookmarks Menu",
|
||||
children: [record.id],
|
||||
}), engine.lastSync + 1);
|
||||
|
||||
engine.lastModified = collection.timestamp;
|
||||
await sync_engine_and_validate_telem(engine, false);
|
||||
|
||||
let idForNewGUID = await PlacesUtils.promiseItemId(record.id);
|
||||
equal(idForOldGUID, idForNewGUID);
|
||||
}
|
||||
|
||||
_("Verify that different annos don't dupe.");
|
||||
let other = new BookmarkQuery("bookmarks", "abcdefabcdef");
|
||||
other.queryId = "LeastVisited";
|
||||
other.parentName = "Bookmarks Toolbar";
|
||||
other.bmkUri = "place:foo";
|
||||
other.title = "";
|
||||
do_check_eq(undefined, (await engine._findDupe(other)));
|
||||
{
|
||||
let info = await newSmartBookmark(PlacesUtils.bookmarks.unfiledGuid,
|
||||
"place:foo", -1, title, "LeastVisited");
|
||||
let idForOldGUID = await PlacesUtils.promiseItemId(info.guid);
|
||||
|
||||
let other = await store.createRecord(info.guid);
|
||||
other.id = "abcdefabcdef";
|
||||
other.queryId = "MostVisited";
|
||||
collection.insert(other.id, encryptPayload(other.cleartext), engine.lastSync + 1);
|
||||
|
||||
collection.insert("unfiled", encryptPayload({
|
||||
id: "unfiled",
|
||||
parentid: "places",
|
||||
type: "folder",
|
||||
title: "Other Bookmarks",
|
||||
children: [other.id],
|
||||
}), engine.lastSync + 1);
|
||||
|
||||
engine.lastModified = collection.timestamp;
|
||||
await sync_engine_and_validate_telem(engine, false);
|
||||
|
||||
let idForNewGUID = await PlacesUtils.promiseItemId(other.id);
|
||||
notEqual(idForOldGUID, idForNewGUID);
|
||||
}
|
||||
|
||||
_("Handle records without a queryId entry.");
|
||||
record.bmkUri = uri;
|
||||
delete record.queryId;
|
||||
do_check_eq(mostVisitedGUID, (await engine._mapDupe(record)));
|
||||
{
|
||||
let info = await newSmartBookmark(PlacesUtils.bookmarks.mobileGuid, url,
|
||||
-1, title, "MostVisited");
|
||||
let idForOldGUID = await PlacesUtils.promiseItemId(info.guid);
|
||||
|
||||
await engine._syncFinish();
|
||||
let record = await store.createRecord(info.guid);
|
||||
record.id = Utils.makeGUID();
|
||||
delete record.queryId;
|
||||
collection.insert(record.id, encryptPayload(record.cleartext), engine.lastSync + 1);
|
||||
|
||||
collection.insert("mobile", encryptPayload({
|
||||
id: "mobile",
|
||||
parentid: "places",
|
||||
type: "folder",
|
||||
title: "Mobile Bookmarks",
|
||||
children: [record.id],
|
||||
}), engine.lastSync + 1);
|
||||
|
||||
engine.lastModified = collection.timestamp;
|
||||
await sync_engine_and_validate_telem(engine, false);
|
||||
|
||||
let idForNewGUID = await PlacesUtils.promiseItemId(record.id);
|
||||
equal(idForOldGUID, idForNewGUID);
|
||||
}
|
||||
|
||||
} finally {
|
||||
// Clean up.
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
Cu.import("resource://gre/modules/PlacesSyncUtils.jsm");
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
Cu.import("resource://services-sync/engines.js");
|
||||
Cu.import("resource://services-sync/engines/bookmarks.js");
|
||||
@ -9,37 +10,27 @@ Cu.import("resource://services-sync/util.js");
|
||||
|
||||
const PARENT_ANNO = "sync/parent";
|
||||
|
||||
let engine;
|
||||
let store;
|
||||
let tracker;
|
||||
|
||||
const fxuri = CommonUtils.makeURI("http://getfirefox.com/");
|
||||
const tburi = CommonUtils.makeURI("http://getthunderbird.com/");
|
||||
|
||||
add_task(async function setup() {
|
||||
await Service.engineManager.register(BookmarksEngine);
|
||||
|
||||
engine = Service.engineManager.get("bookmarks");
|
||||
store = engine._store;
|
||||
tracker = engine._tracker;
|
||||
|
||||
// Don't write some persistence files asynchronously.
|
||||
tracker.persistChangedIDs = false;
|
||||
});
|
||||
|
||||
add_task(async function test_ignore_specials() {
|
||||
_("Ensure that we can't delete bookmark roots.");
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
// Belt...
|
||||
let record = new BookmarkFolder("bookmarks", "toolbar", "folder");
|
||||
record.deleted = true;
|
||||
do_check_neq(null, (await store.idForGUID("toolbar")));
|
||||
do_check_neq(null, (await PlacesUtils.promiseItemId(
|
||||
PlacesSyncUtils.bookmarks.syncIdToGuid("toolbar"))));
|
||||
|
||||
await store.applyIncoming(record);
|
||||
await store.deletePending();
|
||||
|
||||
// Ensure that the toolbar exists.
|
||||
do_check_neq(null, (await store.idForGUID("toolbar")));
|
||||
do_check_neq(null, (await PlacesUtils.promiseItemId(
|
||||
PlacesSyncUtils.bookmarks.syncIdToGuid("toolbar"))));
|
||||
|
||||
// This will fail painfully in getItemType if the deletion worked.
|
||||
await engine._buildGUIDMap();
|
||||
@ -47,13 +38,19 @@ add_task(async function test_ignore_specials() {
|
||||
// Braces...
|
||||
await store.remove(record);
|
||||
await store.deletePending();
|
||||
do_check_neq(null, (await store.idForGUID("toolbar")));
|
||||
do_check_neq(null, (await PlacesUtils.promiseItemId(
|
||||
PlacesSyncUtils.bookmarks.syncIdToGuid("toolbar"))));
|
||||
await engine._buildGUIDMap();
|
||||
|
||||
await store.wipe();
|
||||
|
||||
await engine.finalize();
|
||||
});
|
||||
|
||||
add_task(async function test_bookmark_create() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Ensure the record isn't present yet.");
|
||||
let ids = PlacesUtils.bookmarks.getBookmarkIdsForURI(fxuri, {});
|
||||
@ -72,8 +69,8 @@ add_task(async function test_bookmark_create() {
|
||||
await store.applyIncoming(fxrecord);
|
||||
|
||||
_("Verify it has been created correctly.");
|
||||
let id = await store.idForGUID(fxrecord.id);
|
||||
do_check_eq((await store.GUIDForId(id)), fxrecord.id);
|
||||
let id = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(fxrecord.id));
|
||||
do_check_eq((await PlacesUtils.promiseItemGuid(id)), fxrecord.id);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
||||
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
do_check_true(PlacesUtils.bookmarks.getBookmarkURI(id).equals(fxuri));
|
||||
@ -105,8 +102,8 @@ add_task(async function test_bookmark_create() {
|
||||
await store.applyIncoming(tbrecord);
|
||||
|
||||
_("Verify it has been created correctly.");
|
||||
id = await store.idForGUID(tbrecord.id);
|
||||
do_check_eq((await store.GUIDForId(id)), tbrecord.id);
|
||||
id = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(tbrecord.id));
|
||||
do_check_eq((await PlacesUtils.promiseItemGuid(id)), tbrecord.id);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
||||
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
do_check_true(PlacesUtils.bookmarks.getBookmarkURI(id).equals(tburi));
|
||||
@ -124,10 +121,14 @@ add_task(async function test_bookmark_create() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_bookmark_update() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create a bookmark whose values we'll change.");
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
@ -138,7 +139,7 @@ add_task(async function test_bookmark_update() {
|
||||
bmk1_id, "bookmarkProperties/description", "Firefox is awesome.", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
PlacesUtils.bookmarks.setKeywordForBookmark(bmk1_id, "firefox");
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
|
||||
_("Update the record with some null values.");
|
||||
let record = await store.createRecord(bmk1_guid);
|
||||
@ -158,16 +159,20 @@ add_task(async function test_bookmark_update() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_bookmark_createRecord() {
|
||||
let engine = Service.engineManager.get("bookmarks");
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create a bookmark without a description or title.");
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, null);
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
|
||||
_("Verify that the record is created accordingly.");
|
||||
let record = await store.createRecord(bmk1_guid);
|
||||
@ -182,6 +187,9 @@ add_task(async function test_bookmark_createRecord() {
|
||||
});
|
||||
|
||||
add_task(async function test_folder_create() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create a folder.");
|
||||
let folder = new BookmarkFolder("bookmarks", "testfolder-1");
|
||||
@ -191,7 +199,7 @@ add_task(async function test_folder_create() {
|
||||
await store.applyIncoming(folder);
|
||||
|
||||
_("Verify it has been created correctly.");
|
||||
let id = await store.idForGUID(folder.id);
|
||||
let id = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(folder.id));
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
||||
PlacesUtils.bookmarks.TYPE_FOLDER);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), folder.title);
|
||||
@ -209,15 +217,19 @@ add_task(async function test_folder_create() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_folder_createRecord() {
|
||||
let engine = Service.engineManager.get("bookmarks");
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create a folder.");
|
||||
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
||||
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
||||
let folder1_guid = await store.GUIDForId(folder1_id);
|
||||
let folder1_guid = await PlacesUtils.promiseItemGuid(folder1_id);
|
||||
|
||||
_("Create two bookmarks in that folder without assigning them GUIDs.");
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
@ -233,8 +245,8 @@ add_task(async function test_folder_createRecord() {
|
||||
do_check_eq(record.parentName, "Bookmarks Toolbar");
|
||||
|
||||
_("Verify the folder's children. Ensures that the bookmarks were given GUIDs.");
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk2_guid = await store.GUIDForId(bmk2_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
let bmk2_guid = await PlacesUtils.promiseItemGuid(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);
|
||||
@ -246,12 +258,15 @@ add_task(async function test_folder_createRecord() {
|
||||
});
|
||||
|
||||
add_task(async function test_deleted() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create a bookmark that will be deleted.");
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
|
||||
_("Delete the bookmark through the store.");
|
||||
let record = new PlacesItem("bookmarks", bmk1_guid);
|
||||
@ -273,21 +288,25 @@ add_task(async function test_deleted() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_move_folder() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
_("Create two folders and a bookmark in one of them.");
|
||||
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
||||
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
||||
let folder1_guid = await store.GUIDForId(folder1_id);
|
||||
let folder1_guid = await PlacesUtils.promiseItemGuid(folder1_id);
|
||||
let folder2_id = PlacesUtils.bookmarks.createFolder(
|
||||
PlacesUtils.bookmarks.toolbarFolder, "Folder2", 0);
|
||||
let folder2_guid = await store.GUIDForId(folder2_id);
|
||||
let folder2_guid = await PlacesUtils.promiseItemGuid(folder2_id);
|
||||
let bmk_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
folder1_id, fxuri, PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
||||
let bmk_guid = await store.GUIDForId(bmk_id);
|
||||
let bmk_guid = await PlacesUtils.promiseItemGuid(bmk_id);
|
||||
|
||||
_("Get a record, reparent it and apply it to the store.");
|
||||
let record = await store.createRecord(bmk_guid);
|
||||
@ -297,14 +316,19 @@ add_task(async function test_move_folder() {
|
||||
|
||||
_("Verify the new parent.");
|
||||
let new_folder_id = PlacesUtils.bookmarks.getFolderIdForItem(bmk_id);
|
||||
do_check_eq((await store.GUIDForId(new_folder_id)), folder2_guid);
|
||||
do_check_eq((await PlacesUtils.promiseItemGuid(new_folder_id)), folder2_guid);
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_move_order() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
let tracker = engine._tracker;
|
||||
|
||||
// Make sure the tracker is turned on.
|
||||
Svc.Obs.notify("weave:engine:start-tracking");
|
||||
try {
|
||||
@ -312,11 +336,11 @@ add_task(async function test_move_order() {
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
let bmk2_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.bookmarks.toolbarFolder, tburi,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Thunderbird!");
|
||||
let bmk2_guid = await store.GUIDForId(bmk2_id);
|
||||
let bmk2_guid = await PlacesUtils.promiseItemGuid(bmk2_id);
|
||||
|
||||
_("Verify order.");
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 0);
|
||||
@ -344,17 +368,21 @@ add_task(async function test_move_order() {
|
||||
Svc.Obs.notify("weave:engine:stop-tracking");
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_orphan() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
|
||||
_("Add a new bookmark locally.");
|
||||
let bmk1_id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.bookmarks.toolbarFolder, fxuri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
|
||||
let bmk1_guid = await store.GUIDForId(bmk1_id);
|
||||
let bmk1_guid = await PlacesUtils.promiseItemGuid(bmk1_id);
|
||||
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
|
||||
PlacesUtils.bookmarks.toolbarFolder);
|
||||
let error;
|
||||
@ -379,14 +407,18 @@ add_task(async function test_orphan() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_reparentOrphans() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
try {
|
||||
let folder1_id = PlacesUtils.bookmarks.createFolder(
|
||||
PlacesUtils.bookmarks.toolbarFolder, "Folder1", 0);
|
||||
let folder1_guid = await store.GUIDForId(folder1_id);
|
||||
let folder1_guid = await PlacesUtils.promiseItemGuid(folder1_id);
|
||||
|
||||
_("Create a bogus orphan record and write the record back to the store to trigger _reparentOrphans.");
|
||||
PlacesUtils.annotations.setItemAnnotation(
|
||||
@ -404,12 +436,16 @@ add_task(async function test_reparentOrphans() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
// Tests Bug 806460, in which query records arrive with empty folder
|
||||
// names and missing bookmark URIs.
|
||||
add_task(async function test_empty_query_doesnt_die() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
let record = new BookmarkQuery("bookmarks", "8xoDGqKrXf1P");
|
||||
record.folderName = "";
|
||||
record.queryId = "";
|
||||
@ -422,6 +458,7 @@ add_task(async function test_empty_query_doesnt_die() {
|
||||
delete record.folderName;
|
||||
await store.applyIncoming(record);
|
||||
|
||||
await engine.finalize();
|
||||
});
|
||||
|
||||
function assertDeleted(id) {
|
||||
@ -435,6 +472,9 @@ function assertDeleted(id) {
|
||||
}
|
||||
|
||||
add_task(async function test_delete_buffering() {
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
await store.wipe();
|
||||
await PlacesTestUtils.markBookmarksAsSynced();
|
||||
|
||||
@ -462,9 +502,9 @@ add_task(async function test_delete_buffering() {
|
||||
await store.applyIncoming(fxRecord);
|
||||
await store.applyIncoming(tbRecord);
|
||||
|
||||
let folderId = await store.idForGUID(folder.id);
|
||||
let fxRecordId = await store.idForGUID(fxRecord.id);
|
||||
let tbRecordId = await store.idForGUID(tbRecord.id);
|
||||
let folderId = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(folder.id));
|
||||
let fxRecordId = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(fxRecord.id));
|
||||
let tbRecordId = await PlacesUtils.promiseItemId(PlacesSyncUtils.bookmarks.syncIdToGuid(tbRecord.id));
|
||||
|
||||
_("Check everything was created correctly.");
|
||||
|
||||
@ -522,6 +562,7 @@ add_task(async function test_delete_buffering() {
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
await store.wipe();
|
||||
await engine.finalize();
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user