Bug 1412139 - Prepare existing bookmark engine tests for new buffered engine. r=kitcambridge draft
authorKit Cambridge <kit@yakshaving.ninja>
Mon, 11 Sep 2017 14:17:24 -0700
changeset 687216 ddcee8f3df56a29973dfdbde5bc664a337fef91a
parent 687040 7290c8fce8a1f5c4bce930d951eaf1d6326bd788
child 737589 e5e9f519af5bcddda4b59633a6f441e13d987e99
push id86429
push userbmo:kit@mozilla.com
push dateThu, 26 Oct 2017 23:17:16 +0000
reviewerskitcambridge
bugs1412139
milestone58.0a1
Bug 1412139 - Prepare existing bookmark engine tests for new buffered engine. r=kitcambridge MozReview-Commit-ID: 2HIkdPOuWOy
services/sync/tests/unit/test_bookmark_duping.js
services/sync/tests/unit/test_bookmark_engine.js
services/sync/tests/unit/test_bookmark_invalid.js
services/sync/tests/unit/test_bookmark_livemarks.js
services/sync/tests/unit/test_bookmark_order.js
services/sync/tests/unit/test_bookmark_repair.js
services/sync/tests/unit/test_bookmark_smart_bookmarks.js
services/sync/tests/unit/test_bookmark_store.js
--- a/services/sync/tests/unit/test_bookmark_duping.js
+++ b/services/sync/tests/unit/test_bookmark_duping.js
@@ -7,46 +7,49 @@ Cu.import("resource://gre/modules/Log.js
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/bookmarks.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 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);
 
   let collection = server.user("foo").collection("bookmarks");
 
   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) {
   let guid = PlacesSyncUtils.bookmarks.syncIdToGuid(syncId);
   return PlacesUtils.promiseItemId(guid);
 }
 
 async function getFolderChildrenIDs(folderId) {
@@ -117,17 +120,17 @@ async function validate(collection, expe
     do_print("Local bookmark tree:\n" + JSON.stringify(tree, undefined, 2));
     ok(false);
   }
 }
 
 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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {id: localId, guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
 
     await engine.sync();
 
@@ -181,24 +184,24 @@ add_task(async function test_dupe_bookma
     ok(serverRecord.children.includes(newGUID));
 
     ok(onItemChangedObserved);
 
     // and a final sanity check - use the validator
     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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
     // Another parent folder *with the same name*
     let {id: folder2_id, guid: folder2_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
 
@@ -247,24 +250,24 @@ add_task(async function test_dupe_repare
     // The record for folder2 on the server should only reference the new new GUID.
     let serverRecord2 = getServerRecord(collection, folder2_guid);
     ok(!serverRecord2.children.includes(bmk1_guid));
     ok(serverRecord2.children.includes(newGUID));
 
     // 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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
     // Another parent folder *with the same name*
     let {id: folder2_id, guid: folder2_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
 
@@ -328,25 +331,25 @@ add_task(async function test_dupe_repare
     // The record for folder2 on the server should reference nothing.
     let serverRecord2 = getServerRecord(collection, folder2_guid);
     ok(!serverRecord2.children.includes(bmk1_guid));
     ok(!serverRecord2.children.includes(newGUID));
 
     // 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_to_earlier_appearing_parent_bookmark() {
   _("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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
     // One more folder we'll use later.
     let {guid: folder2_guid} = await createFolder(bms.toolbarFolder, "A second folder");
 
@@ -405,25 +408,25 @@ add_task(async function test_dupe_repare
     equal((await getFolderChildrenIDs(folder1_id)).length, 0);
     let newParentID = await store.idForGUID(newParentGUID);
     let newID = await store.idForGUID(newGUID);
     deepEqual(await getFolderChildrenIDs(newParentID), [newID]);
 
     // Make sure the validator thinks everything is hunky-dory.
     await validate(collection);
   } finally {
-    await cleanup(server);
+    await cleanup(engine, server);
   }
 });
 
 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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
     // One more folder we'll use later.
     let {guid: folder2_guid} = await createFolder(bms.toolbarFolder, "A second folder");
 
@@ -482,25 +485,25 @@ add_task(async function test_dupe_repare
     equal((await getFolderChildrenIDs(folder1_id)).length, 0);
     let newParentID = await store.idForGUID(newParentGUID);
     let newID = await store.idForGUID(newGUID);
     deepEqual(await getFolderChildrenIDs(newParentID), [newID]);
 
     // Make sure the validator thinks everything is hunky-dory.
     await validate(collection);
   } finally {
-    await cleanup(server);
+    await cleanup(engine, server);
   }
 });
 
 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.
     let {id: folder1_id, guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
     let {guid: bmk1_guid} = await createBookmark(folder1_id, "http://getfirefox.com/", "Get Firefox!");
     // One more folder we'll use later.
     let {guid: folder2_guid} = await createFolder(bms.toolbarFolder, "A second folder");
 
@@ -606,25 +609,25 @@ add_task(async function test_dupe_repare
       //   to correctly reparent - but that reparenting process does not change
       //   the server record.
       // Hence, newGUID is a child of both those server records :(
       { name: "multipleParents", count: 1 },
     ];
     await validate(collection, expected);
 
   } finally {
-    await cleanup(server);
+    await cleanup(engine, server);
   }
 });
 
 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.
     let {guid: folder1_guid } = await createFolder(bms.toolbarFolder, "Folder 1");
 
     await engine.sync();
 
     // We've added 1 folder, "menu", "toolbar", "unfiled", and "mobile".
@@ -648,12 +651,12 @@ add_task(async function test_dupe_empty_
     await validate(collection);
 
     // Collection now has one additional record - the logically deleted dupe.
     equal(collection.count(), 6);
     // original folder should be logically deleted.
     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
--- a/services/sync/tests/unit/test_bookmark_engine.js
+++ b/services/sync/tests/unit/test_bookmark_engine.js
@@ -37,16 +37,23 @@ async function fetchAllSyncIds() {
   }
   return syncIds;
 }
 add_task(async function setup() {
   initTestLogging("Trace");
   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.");
 
   let engine  = new BookmarksEngine(Service);
   await engine.initialize();
   let store   = engine._store;
   let server = await serverForFoo(engine);
   await SyncTestingInfrastructure(server);
@@ -189,16 +196,17 @@ add_task(async function test_processInco
     do_check_eq(new_children[0], folder1_payload.children[0]);
     do_check_eq(new_children[1], folder1_payload.children[1]);
 
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 1);
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 0);
 
   } finally {
     await store.wipe();
+    await engine.resetClient();
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
     await PlacesSyncUtils.bookmarks.reset();
     await promiseStopServer(server);
   }
 });
 
 add_task(async function test_restorePromptsReupload() {
@@ -374,16 +382,17 @@ async function test_restoreOrImport(aRep
     } else {
       expectedFolders = [expectedFolder1, expectedFolder1];
     }
 
     doCheckWBOs(folderWBOs, expectedFolders);
 
   } finally {
     await store.wipe();
+    await engine.resetClient();
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
     await PlacesSyncUtils.bookmarks.reset();
     await promiseStopServer(server);
   }
 }
 
 function doCheckWBOs(WBOs, expected) {
@@ -472,16 +481,17 @@ add_task(async function test_mismatched_
 
     _("Applied new. It's a livemark.");
     do_check_eq(bms.getItemType(newID), bms.TYPE_FOLDER);
     do_check_true(PlacesUtils.annotations
                              .itemHasAnnotation(newID, PlacesUtils.LMANNO_FEEDURI));
 
   } finally {
     await store.wipe();
+    await engine.resetClient();
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
     await PlacesSyncUtils.bookmarks.reset();
     await promiseStopServer(server);
   }
 });
 
 add_task(async function test_bookmark_guidMap_fail() {
@@ -632,16 +642,17 @@ add_task(async function test_misreconcil
   let toolbarAfter = await store.createRecord("toolbar", "bookmarks");
   let parentGUIDAfter = toolbarAfter.parentid;
   let parentIDAfter = await store.idForGUID(parentGUIDAfter);
   do_check_eq((await store.GUIDForId(toolbarIDBefore)), "toolbar");
   do_check_eq(parentGUIDBefore, parentGUIDAfter);
   do_check_eq(parentIDBefore, parentIDAfter);
 
   await store.wipe();
+  await engine.resetClient();
   await PlacesSyncUtils.bookmarks.reset();
   await promiseStopServer(server);
 });
 
 add_task(async function test_sync_dateAdded() {
   await Service.recordManager.clearCache();
   await PlacesSyncUtils.bookmarks.reset();
   let engine = new BookmarksEngine(Service);
@@ -780,16 +791,17 @@ add_task(async function test_sync_dateAd
     let newerRecord2 = await store.createRecord(item2GUID);
     equal(newerRecord2.dateAdded, newRecord2.dateAdded,
       "dateAdded update should be ignored for later date if we know an earlier one ");
 
 
 
   } finally {
     await store.wipe();
+    await engine.resetClient();
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
     await PlacesSyncUtils.bookmarks.reset();
     await promiseStopServer(server);
   }
 });
 
 // Bug 890217.
--- a/services/sync/tests/unit/test_bookmark_invalid.js
+++ b/services/sync/tests/unit/test_bookmark_invalid.js
@@ -5,18 +5,17 @@ Cu.import("resource://services-sync/serv
 Cu.import("resource://services-sync/util.js");
 
 let engine;
 let store;
 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;
 });
 
 add_task(async function test_ignore_invalid_uri() {
   _("Ensure that we don't die with invalid bookmarks.");
 
   // First create a valid bookmark.
--- a/services/sync/tests/unit/test_bookmark_livemarks.js
+++ b/services/sync/tests/unit/test_bookmark_livemarks.js
@@ -5,19 +5,16 @@ Cu.import("resource://gre/modules/Log.js
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/bookmarks.js");
 Cu.import("resource://services-sync/util.js");
 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",
   index: 150,
   modified: 1296768176.49,
   payload:
   {"id": "M5bwUKK8hPyF",
    "type": "livemark",
@@ -61,22 +58,23 @@ function makeLivemark(p, mintGUID) {
 
   return b;
 }
 
 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) {
     store._childrenToOrder = {};
     await store.applyIncoming(r);
     await store._orderChildren();
     delete store._childrenToOrder;
   }
@@ -86,19 +84,25 @@ add_task(async function test_livemark_de
   await doRecord(makeLivemark(record));
   record.description = "";
   await doRecord(makeLivemark(record));
 
   // Attempt to provoke an error by adding a bad description anno.
   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.");
   let lateParentRec = makeLivemark(record631361.payload, true);
   let parentGUID = Utils.makeGUID();
   lateParentRec.parentid = parentGUID;
   do_check_eq(-1, (await store.idForGUID(parentGUID)));
 
@@ -116,9 +120,11 @@ add_task(async function test_livemark_in
   do_check_eq(-1, (await store.idForGUID(noFeedURIRec.id, true)));
 
   _("Parent is a Livemark. Will be skipped.");
   let lmParentRec = makeLivemark(record631361.payload, true);
   lmParentRec.parentid = await store.GUIDForId(recID);
   await store.create(lmParentRec);
   // No exception, but no creation occurs.
   do_check_eq(-1, (await store.idForGUID(lmParentRec.id, true)));
+
+  await engine.finalize();
 });
--- a/services/sync/tests/unit/test_bookmark_order.js
+++ b/services/sync/tests/unit/test_bookmark_order.js
@@ -143,18 +143,23 @@ async function resolveConflict(engine, c
   engine.lastModified = collection.timestamp;
   await sync_engine_and_validate_telem(engine, false);
 
   let expectedTree = buildTree(guids);
   await assertBookmarksTreeMatches(PlacesUtils.bookmarks.menuGuid,
     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);
 
   try {
     let collection = server.user("foo").collection("bookmarks");
     let serverModified = Date.now() / 1000 - 120;
     await resolveConflict(engine, collection, serverModified, guids => [{
@@ -185,21 +190,23 @@ add_task(async function test_local_order
     }, {
       guid: guids.tb,
       index: 2,
     }], "Should use local order as base if remote is older");
   } finally {
     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);
 
   try {
     let collection = server.user("foo").collection("bookmarks");
     let serverModified = Date.now() / 1000 + 120;
     await resolveConflict(engine, collection, serverModified, guids => [{
@@ -230,16 +237,17 @@ add_task(async function test_remote_orde
     }, {
       guid: guids.fx,
       index: 2,
     }], "Should use remote order as base if local is older");
   } finally {
     await engine.wipeClient();
     await Service.startOver();
     await promiseStopServer(server);
+    await engine.finalize();
   }
 });
 
 add_task(async function test_bookmark_order() {
   let engine = new BookmarksEngine(Service);
   let store = engine._store;
 
   _("Starting with a clean slate of no bookmarks");
--- a/services/sync/tests/unit/test_bookmark_repair.js
+++ b/services/sync/tests/unit/test_bookmark_repair.js
@@ -8,21 +8,16 @@ Cu.import("resource://gre/modules/osfile
 Cu.import("resource://services-sync/bookmark_repair.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/doctor.js");
 Cu.import("resource://services-sync/service.js");
 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",
 ];
 
 const BOOKMARK_REPAIR_STATE_PREFS = [
   "client.GUID",
   "doctor.lastRepairAdvance",
@@ -41,16 +36,21 @@ add_task(async function setup() {
   clientsEngine.ignoreLastModifiedOnProcessCommands = true;
   bookmarksEngine = Service.engineManager.get("bookmarks");
 
   await generateNewKeys(Service.collectionKeys);
 
   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) {
   deepEqual(recordedEvents, expected, message);
   // and clear the list so future checks are easier to write.
   recordedEvents = [];
 }
 
--- a/services/sync/tests/unit/test_bookmark_smart_bookmarks.js
+++ b/services/sync/tests/unit/test_bookmark_smart_bookmarks.js
@@ -8,22 +8,28 @@ Cu.import("resource://services-sync/engi
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
 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() {
   // We do it this way because PlacesUtils.annotations.getItemsWithAnnotation
   // doesn't work the same (or at all?) between 3.6 and 4.0.
   let out = {};
   PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO, out);
   return out.value;
@@ -65,24 +71,24 @@ add_task(async function test_annotation_
 
   if (startCount > 0) {
     // This can happen in XULRunner.
     clearBookmarks();
     _("Start count is now " + startCount);
   }
 
   _("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);
 
   let annoValue = PlacesUtils.annotations.getItemAnnotation(mostVisitedID,
                                               SMART_BOOKMARKS_ANNO);
   _("Anno: " + annoValue);
   do_check_eq("MostVisited", annoValue);
@@ -91,17 +97,17 @@ add_task(async function test_annotation_
   _("GUID: " + guid);
   do_check_true(!!guid);
 
   _("Create record object and verify that it's sane.");
   let record = await store.createRecord(guid);
   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);
 
   _("Our count has increased since we started.");
   do_check_eq(smartBookmarkCount(), startCount + 1);
 
   _("Sync record to the server.");
@@ -145,77 +151,150 @@ add_task(async function test_annotation_
     _("Our count has increased again.");
     do_check_eq(smartBookmarkCount(), startCount + 1);
 
     _("Find by GUID and verify that it's annotated.");
     let newID = await store.idForGUID(serverGUID);
     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();
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
     await promiseStopServer(server);
   }
 });
 
 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);
+
+  try {
+
+    _("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);
 
-  let record = await store.createRecord(mostVisitedGUID);
+      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);
 
-  _("Prepare sync.");
-  try {
-    await engine._syncStartup();
+      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);
 
-    _("Verify that mapDupe uses the anno, discovering a dupe regardless of URI.");
-    do_check_eq(mostVisitedGUID, (await engine._mapDupe(record)));
+      collection.insert("menu", encryptPayload({
+        id: "menu",
+        parentid: "places",
+        type: "folder",
+        title: "Bookmarks Menu",
+        children: [record.id],
+      }), engine.lastSync + 1);
 
-    record.bmkUri = "http://foo/";
-    do_check_eq(mostVisitedGUID, (await engine._mapDupe(record)));
-    do_check_neq(PlacesUtils.bookmarks.getBookmarkURI(mostVisitedID).spec,
-                 record.bmkUri);
+      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);
+
+      let record = await store.createRecord(info.guid);
+      record.id = Utils.makeGUID();
+      delete record.queryId;
+      collection.insert(record.id, encryptPayload(record.cleartext), engine.lastSync + 1);
 
-    await engine._syncFinish();
+      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.
     await store.wipe();
     await promiseStopServer(server);
     Svc.Prefs.resetBranch("");
     Service.recordManager.clearCache();
   }
--- a/services/sync/tests/unit/test_bookmark_store.js
+++ b/services/sync/tests/unit/test_bookmark_store.js
@@ -1,64 +1,61 @@
 /* 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");
 Cu.import("resource://services-sync/service.js");
 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();
 
   // 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, {});
     do_check_eq(ids.length, 0);
 
     _("Let's create a new record.");
     let fxrecord = new Bookmark("bookmarks", "get-firefox1");
     fxrecord.bmkUri        = fxuri.spec;
@@ -67,18 +64,18 @@ add_task(async function test_bookmark_cr
     fxrecord.tags          = ["firefox", "awesome", "browser"];
     fxrecord.keyword       = "awesome";
     fxrecord.loadInSidebar = false;
     fxrecord.parentName    = "Bookmarks Toolbar";
     fxrecord.parentid      = "toolbar";
     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));
     do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), fxrecord.title);
     do_check_eq(PlacesUtils.annotations.getItemAnnotation(id, "bookmarkProperties/description"),
                 fxrecord.description);
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
                 PlacesUtils.bookmarks.toolbarFolder);
@@ -100,18 +97,18 @@ add_task(async function test_bookmark_cr
     _("Create a record with some values missing.");
     let tbrecord = new Bookmark("bookmarks", "thunderbird1");
     tbrecord.bmkUri        = tburi.spec;
     tbrecord.parentName    = "Bookmarks Toolbar";
     tbrecord.parentid      = "toolbar";
     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));
     do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), "");
     let error;
     try {
       PlacesUtils.annotations.getItemAnnotation(id, "bookmarkProperties/description");
     } catch (ex) {
@@ -119,31 +116,35 @@ add_task(async function test_bookmark_cr
     }
     do_check_eq(error.result, Cr.NS_ERROR_NOT_AVAILABLE);
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
                 PlacesUtils.bookmarks.toolbarFolder);
     do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null);
   } 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(
       PlacesUtils.bookmarks.toolbarFolder, fxuri,
       PlacesUtils.bookmarks.DEFAULT_INDEX,
       "Get Firefox!");
     PlacesUtils.annotations.setItemAnnotation(
       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);
     record.title = null;
     record.description = null;
     record.keyword = null;
     record.tags = null;
     await store.applyIncoming(record);
@@ -153,50 +154,57 @@ add_task(async function test_bookmark_up
       PlacesUtils.annotations.getItemAnnotation(
         bmk1_id, "bookmarkProperties/description");
     }, Cr.NS_ERROR_NOT_AVAILABLE);
     do_check_eq(PlacesUtils.bookmarks.getItemTitle(bmk1_id), "");
     do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(bmk1_id), null);
   } 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);
     do_check_eq(record.title, "");
     do_check_eq(record.description, null);
     do_check_eq(record.keyword, null);
 
   } finally {
     _("Clean up.");
     await store.wipe();
   }
 });
 
 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");
     folder.parentName = "Bookmarks Toolbar";
     folder.parentid   = "toolbar";
     folder.title      = "Test Folder";
     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);
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
                 PlacesUtils.bookmarks.toolbarFolder);
 
     _("Have the store create a new record object. Verify that it has the same data.");
     let newrecord = await store.createRecord(folder.id);
@@ -204,59 +212,66 @@ add_task(async function test_folder_crea
     for (let property of ["title", "parentName", "parentid"])
       do_check_eq(newrecord[property], folder[property]);
 
     _("Folders have high sort index to ensure they're synced first.");
     do_check_eq(newrecord.sortindex, 1000000);
   } 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(
       folder1_id, fxuri, PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
     let bmk2_id = PlacesUtils.bookmarks.insertBookmark(
       folder1_id, tburi, PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Thunderbird!");
 
     _("Create a record for the folder and verify basic properties.");
     let record = await 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 = 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);
 
   } finally {
     _("Clean up.");
     await store.wipe();
   }
 });
 
 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);
     record.deleted = true;
     await store.applyIncoming(record);
     await store.deletePending();
     _("Ensure it has been deleted.");
     let error;
@@ -268,60 +283,69 @@ add_task(async function test_deleted() {
     do_check_eq(error.result, Cr.NS_ERROR_ILLEGAL_VALUE);
 
     let newrec = await store.createRecord(bmk1_guid);
     do_check_eq(newrec.deleted, true);
 
   } 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);
     do_check_eq(record.parentid, folder1_guid);
     record.parentid = folder2_guid;
     await store.applyIncoming(record);
 
     _("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 {
     _("Create two bookmarks");
     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);
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 1);
     let toolbar = await 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);
@@ -339,27 +363,31 @@ add_task(async function test_move_order(
     _("Verify new order.");
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk2_id), 0);
     do_check_eq(PlacesUtils.bookmarks.getItemIndex(bmk1_id), 1);
 
   } finally {
     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;
     try {
       PlacesUtils.annotations.getItemAnnotation(bmk1_id, PARENT_ANNO);
     } catch (ex) {
       error = ex;
     }
@@ -374,24 +402,28 @@ add_task(async function test_orphan() {
     do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(bmk1_id),
                 PlacesUtils.bookmarks.toolbarFolder);
     do_check_eq(PlacesUtils.annotations.getItemAnnotation(bmk1_id, PARENT_ANNO),
                 "non-existent");
 
   } 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(
       folder1_id, PARENT_ANNO, folder1_guid, 0,
       PlacesUtils.annotations.EXPIRE_NEVER);
     let record = await store.createRecord(folder1_guid);
     record.title = "New title for Folder 1";
     store._childrenToOrder = {};
@@ -399,47 +431,55 @@ add_task(async function test_reparentOrp
 
     _("Verify that is has been marked as an orphan even though it couldn't be moved into itself.");
     do_check_eq(PlacesUtils.annotations.getItemAnnotation(folder1_id, PARENT_ANNO),
                 folder1_guid);
 
   } 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       = "";
   record.parentName    = "Toolbar";
   record.parentid      = "toolbar";
 
   // These should not throw.
   await store.applyIncoming(record);
 
   delete record.folderName;
   await store.applyIncoming(record);
 
+  await engine.finalize();
 });
 
 function assertDeleted(id) {
   let error;
   try {
     PlacesUtils.bookmarks.getItemType(id);
   } catch (e) {
     error = e;
   }
   equal(error.result, Cr.NS_ERROR_ILLEGAL_VALUE);
 }
 
 add_task(async function test_delete_buffering() {
+  let engine = new BookmarksEngine(Service);
+  let store = engine._store;
+
   await store.wipe();
   await PlacesTestUtils.markBookmarksAsSynced();
 
   try {
     _("Create a folder with two bookmarks.");
     let folder = new BookmarkFolder("bookmarks", "testfolder-1");
     folder.parentName = "Bookmarks Toolbar";
     folder.parentid = "toolbar";
@@ -457,19 +497,19 @@ add_task(async function test_delete_buff
     tbRecord.bmkUri        = tburi.spec;
     tbRecord.title         = "Get Thunderbird!";
     tbRecord.parentName    = "Test Folder";
     tbRecord.parentid      = "testfolder-1";
 
     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.");
 
     equal(PlacesUtils.bookmarks.getItemType(fxRecordId),
           PlacesUtils.bookmarks.TYPE_BOOKMARK);
     equal(PlacesUtils.bookmarks.getItemType(tbRecordId),
           PlacesUtils.bookmarks.TYPE_BOOKMARK);
     equal(PlacesUtils.bookmarks.getItemType(folderId),
@@ -517,16 +557,17 @@ add_task(async function test_delete_buff
     ok(!store._itemsToDelete.has(fxRecord.id));
 
     equal(PlacesUtils.bookmarks.getFolderIdForItem(tbRecordId),
           PlacesUtils.bookmarks.toolbarFolder);
 
   } finally {
     _("Clean up.");
     await store.wipe();
+    await engine.finalize();
   }
 });
 
 
 function run_test() {
   initTestLogging("Trace");
   run_next_test();
 }