Bug 1376234 - Convert some xpcshell-tests in toolkit/components/places/tests/unit to async Bookmarks.jsm API. r?mak draft
authorMark Banner <standard8@mozilla.com>
Sun, 25 Jun 2017 12:13:21 +0100
changeset 600967 40959cc46f0e1d5fecd4c101aa43a94e111120f2
parent 600616 f4e52135d9bdc6ce98bb37b450021445aed894ce
child 600968 1b01250b07522ccd0231b46a28379241eb2b31ff
push id65927
push userbmo:standard8@mozilla.com
push dateTue, 27 Jun 2017 22:40:46 +0000
reviewersmak
bugs1376234
milestone56.0a1
Bug 1376234 - Convert some xpcshell-tests in toolkit/components/places/tests/unit to async Bookmarks.jsm API. r?mak MozReview-Commit-ID: 8c5NZDfrh4e
toolkit/components/places/tests/unit/test_PlacesUtils_lazyobservers.js
toolkit/components/places/tests/unit/test_bookmarks_html.js
toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js
toolkit/components/places/tests/unit/test_bookmarks_json.js
toolkit/components/places/tests/unit/test_broken_folderShortcut_result.js
toolkit/components/places/tests/unit/test_browserhistory.js
toolkit/components/places/tests/unit/test_childlessTags.js
toolkit/components/places/tests/unit/test_frecency_observers.js
toolkit/components/places/tests/unit/test_frecency_zero_updated.js
toolkit/components/places/tests/unit/test_getChildIndex.js
toolkit/components/places/tests/unit/test_history_autocomplete_tags.js
toolkit/components/places/tests/unit/test_history_catobs.js
toolkit/components/places/tests/unit/test_history_clear.js
toolkit/components/places/tests/unit/test_hosts_triggers.js
toolkit/components/places/tests/unit/test_isvisited.js
toolkit/components/places/tests/unit/test_markpageas.js
toolkit/components/places/tests/unit/test_multi_queries.js
toolkit/components/places/tests/unit/test_multi_word_tags.js
toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
toolkit/components/places/tests/unit/test_onItemChanged_tags.js
toolkit/components/places/tests/unit/test_pageGuid_bookmarkGuid.js
toolkit/components/places/tests/unit/test_placeURIs.js
toolkit/components/places/tests/unit/test_resolveNullBookmarkTitles.js
toolkit/components/places/tests/unit/test_result_sort.js
--- a/toolkit/components/places/tests/unit/test_PlacesUtils_lazyobservers.js
+++ b/toolkit/components/places/tests/unit/test_PlacesUtils_lazyobservers.js
@@ -1,26 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function run_test() {
-  do_test_pending();
+add_task(async function test_lazyBookmarksObservers() {
+  const TEST_URI = Services.io.newURI("http://moz.org/");
 
-  const TEST_URI = NetUtil.newURI("http://moz.org/")
+  let promise = PromiseUtils.defer();
+
   let observer = {
     QueryInterface: XPCOMUtils.generateQI([
       Ci.nsINavBookmarkObserver,
     ]),
 
     onBeginUpdateBatch() {},
     onEndUpdateBatch() {},
     onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI) {
       do_check_true(aURI.equals(TEST_URI));
       PlacesUtils.removeLazyBookmarkObserver(this);
-      do_test_finished();
+      promise.resolve();
     },
     onItemRemoved() {},
     onItemChanged() {},
     onItemVisited() {},
     onItemMoved() {},
   };
 
   // Check registration and removal with uninitialized bookmarks service.
@@ -35,13 +36,16 @@ function run_test() {
   PlacesUtils.bookmarks;
   PlacesUtils.addLazyBookmarkObserver(observer);
   PlacesUtils.removeLazyBookmarkObserver(observer);
   try {
     PlacesUtils.bookmarks.removeObserver(observer);
     do_throw("Trying to remove a nonexisting observer should throw!");
   } catch (ex) {}
 
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       TEST_URI,
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                       "Bookmark title");
-}
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URI,
+    title: "Bookmark title"
+  });
+
+  await promise;
+});
--- a/toolkit/components/places/tests/unit/test_bookmarks_html.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js
@@ -68,20 +68,16 @@ var test_bookmarks = {
   ]
 };
 
 // Pre-Places bookmarks.html file pointer.
 var gBookmarksFileOld;
 // Places bookmarks.html file pointer.
 var gBookmarksFileNew;
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function setup() {
   // Avoid creating smart bookmarks during the test.
   Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
 
   // File pointer to legacy bookmarks file.
   gBookmarksFileOld = do_get_file("bookmarks.preplaces.html");
 
   // File pointer to a new Places-exported bookmarks file.
--- a/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
@@ -4,20 +4,16 @@
  */
 
 const DESCRIPTION_ANNO = "bookmarkProperties/description";
 const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
 
 const TEST_FAVICON_PAGE_URL = "http://en-US.www.mozilla.com/en-US/firefox/central/";
 const TEST_FAVICON_DATA_SIZE = 580;
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_corrupt_file() {
   // avoid creating the places smart folder during tests
   Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
 
   // Import bookmarks from the corrupt file.
   let corruptHtml = OS.Path.join(do_get_cwd().path, "bookmarks.corrupt.html");
   await BookmarkHTMLUtils.importFromFile(corruptHtml, true);
 
@@ -58,18 +54,22 @@ add_task(async function test_corrupt_dat
 var database_check = async function() {
   // BOOKMARKS MENU
   let root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root;
   Assert.equal(root.childCount, 2);
 
   let folderNode = root.getChild(1);
   Assert.equal(folderNode.type, folderNode.RESULT_TYPE_FOLDER);
   Assert.equal(folderNode.title, "test");
-  Assert.equal(PlacesUtils.bookmarks.getItemDateAdded(folderNode.itemId), 1177541020000000);
-  Assert.equal(PlacesUtils.bookmarks.getItemLastModified(folderNode.itemId), 1177541050000000);
+
+  let bookmark = await PlacesUtils.bookmarks.fetch({
+    guid: folderNode.bookmarkGuid
+  });
+  Assert.equal(PlacesUtils.toPRTime(bookmark.dateAdded), 1177541020000000);
+  Assert.equal(PlacesUtils.toPRTime(bookmark.lastModified), 1177541050000000);
   Assert.equal("folder test comment",
                PlacesUtils.annotations.getItemAnnotation(folderNode.itemId,
                                                          DESCRIPTION_ANNO));
   // open test folder, and test the children
   PlacesUtils.asQuery(folderNode);
   Assert.equal(folderNode.hasChildren, true);
   folderNode.containerOpen = true;
   Assert.equal(folderNode.childCount, 1);
--- a/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js
@@ -4,20 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Test for bug #801450
 
 // Get Services
 Cu.import("resource://gre/modules/BookmarkHTMLUtils.jsm");
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_bookmarks_html_singleframe() {
   let bookmarksFile = OS.Path.join(do_get_cwd().path, "bookmarks_html_singleframe.html");
   await BookmarkHTMLUtils.importFromFile(bookmarksFile, true);
 
   let root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root;
   do_check_eq(root.childCount, 1);
   let folder = root.getChild(0);
   PlacesUtils.asContainer(folder).containerOpen = true;
--- a/toolkit/components/places/tests/unit/test_bookmarks_json.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_json.js
@@ -1,18 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
 
-function run_test() {
-  run_next_test();
-}
-
 const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
 const DESCRIPTION_ANNO = "bookmarkProperties/description";
 
 // An object representing the contents of bookmarks.json.
 var test_bookmarks = {
   menu: [
     { guid: "OCyeUO5uu9FF",
       title: "Mozilla Firefox",
@@ -156,93 +152,91 @@ async function testImportedBookmarks() {
     for (let key in items) {
       await checkItem(items[key], root.getChild(key));
     }
 
     root.containerOpen = false;
   }
 }
 
-function checkItem(aExpected, aNode) {
+async function checkItem(aExpected, aNode) {
   let id = aNode.itemId;
+  let bookmark = await PlacesUtils.bookmarks.fetch(aNode.bookmarkGuid);
 
-  return (async function() {
-    for (let prop in aExpected) {
-      switch (prop) {
-        case "type":
-          do_check_eq(aNode.type, aExpected.type);
-          break;
-        case "title":
-          do_check_eq(aNode.title, aExpected.title);
-          break;
-        case "description":
-          do_check_eq(PlacesUtils.annotations.getItemAnnotation(
-                      id, DESCRIPTION_ANNO), aExpected.description);
-          break;
-        case "dateAdded":
-          do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(id),
-                      aExpected.dateAdded);
-          break;
-        case "lastModified":
-          do_check_eq(PlacesUtils.bookmarks.getItemLastModified(id),
-                      aExpected.lastModified);
-          break;
-        case "url":
-          if (!("feedUrl" in aExpected))
-            do_check_eq(aNode.uri, aExpected.url);
-          break;
-        case "icon":
-          let deferred = Promise.defer();
-          PlacesUtils.favicons.getFaviconDataForPage(
-            NetUtil.newURI(aExpected.url),
-            function(aURI, aDataLen, aData, aMimeType) {
-              deferred.resolve(aData);
-            });
-          let data = await deferred.promise;
-          let base64Icon = "data:image/png;base64," +
-                           base64EncodeString(String.fromCharCode.apply(String, data));
-          do_check_eq(base64Icon, aExpected.icon);
-          break;
-        case "keyword": {
-          let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
-          Assert.equal(entry.keyword, aExpected.keyword);
-          break;
+  for (let prop in aExpected) {
+    switch (prop) {
+      case "type":
+        do_check_eq(aNode.type, aExpected.type);
+        break;
+      case "title":
+        do_check_eq(aNode.title, aExpected.title);
+        break;
+      case "description":
+        do_check_eq(PlacesUtils.annotations.getItemAnnotation(
+                    id, DESCRIPTION_ANNO), aExpected.description);
+        break;
+      case "dateAdded":
+        do_check_eq(PlacesUtils.toPRTime(bookmark.dateAdded),
+                    aExpected.dateAdded);
+        break;
+      case "lastModified":
+        do_check_eq(PlacesUtils.toPRTime(bookmark.lastModified),
+                    aExpected.lastModified);
+        break;
+      case "url":
+        if (!("feedUrl" in aExpected))
+          do_check_eq(aNode.uri, aExpected.url);
+        break;
+      case "icon":
+        let deferred = Promise.defer();
+        PlacesUtils.favicons.getFaviconDataForPage(
+          NetUtil.newURI(aExpected.url),
+          function(aURI, aDataLen, aData, aMimeType) {
+            deferred.resolve(aData);
+          });
+        let data = await deferred.promise;
+        let base64Icon = "data:image/png;base64," +
+                         base64EncodeString(String.fromCharCode.apply(String, data));
+        do_check_eq(base64Icon, aExpected.icon);
+        break;
+      case "keyword": {
+        let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
+        Assert.equal(entry.keyword, aExpected.keyword);
+        break;
+      }
+      case "guid":
+        do_check_eq(bookmark.guid, aExpected.guid);
+        break;
+      case "sidebar":
+        do_check_eq(PlacesUtils.annotations.itemHasAnnotation(
+                    id, LOAD_IN_SIDEBAR_ANNO), aExpected.sidebar);
+        break;
+      case "postData": {
+        let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
+        Assert.equal(entry.postData, aExpected.postData);
+        break;
+      }
+      case "charset":
+        let testURI = NetUtil.newURI(aNode.uri);
+        do_check_eq((await PlacesUtils.getCharsetForURI(testURI)), aExpected.charset);
+        break;
+      case "feedUrl":
+        let livemark = await PlacesUtils.livemarks.getLivemark({ id });
+        do_check_eq(livemark.siteURI.spec, aExpected.url);
+        do_check_eq(livemark.feedURI.spec, aExpected.feedUrl);
+        break;
+      case "children":
+        let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
+        do_check_eq(folder.hasChildren, aExpected.children.length > 0);
+        folder.containerOpen = true;
+        do_check_eq(folder.childCount, aExpected.children.length);
+
+        for (let index = 0; index < aExpected.children.length; index++) {
+          await checkItem(aExpected.children[index], folder.getChild(index));
         }
-        case "guid":
-          let guid = await PlacesUtils.promiseItemGuid(id);
-          do_check_eq(guid, aExpected.guid);
-          break;
-        case "sidebar":
-          do_check_eq(PlacesUtils.annotations.itemHasAnnotation(
-                      id, LOAD_IN_SIDEBAR_ANNO), aExpected.sidebar);
-          break;
-        case "postData": {
-          let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
-          Assert.equal(entry.postData, aExpected.postData);
-          break;
-        }
-        case "charset":
-          let testURI = NetUtil.newURI(aNode.uri);
-          do_check_eq((await PlacesUtils.getCharsetForURI(testURI)), aExpected.charset);
-          break;
-        case "feedUrl":
-          let livemark = await PlacesUtils.livemarks.getLivemark({ id });
-          do_check_eq(livemark.siteURI.spec, aExpected.url);
-          do_check_eq(livemark.feedURI.spec, aExpected.feedUrl);
-          break;
-        case "children":
-          let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
-          do_check_eq(folder.hasChildren, aExpected.children.length > 0);
-          folder.containerOpen = true;
-          do_check_eq(folder.childCount, aExpected.children.length);
 
-          for (let index = 0; index < aExpected.children.length; index++) {
-            await checkItem(aExpected.children[index], folder.getChild(index));
-          }
-
-          folder.containerOpen = false;
-          break;
-        default:
-          throw new Error("Unknown property");
-      }
+        folder.containerOpen = false;
+        break;
+      default:
+        throw new Error("Unknown property");
     }
-  })();
+  }
 }
--- a/toolkit/components/places/tests/unit/test_broken_folderShortcut_result.js
+++ b/toolkit/components/places/tests/unit/test_broken_folderShortcut_result.js
@@ -1,32 +1,28 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function run_test() {
-  run_next_test();
-}
-
-add_task(async function test_execute() {
-  PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("http://1.moz.org/"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, "Bookmark 1"
-  );
-  let id1 = PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("place:folder=1234"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, "Shortcut 1"
-  );
-  let id2 = PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("place:folder=-1"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, "Shortcut 2"
-  );
-  PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("http://2.moz.org/"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, "Bookmark 2"
-  );
+add_task(async function test_brokenFolderShortcut() {
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.unfiledGuid,
+    children: [{
+      url: "http://1.moz.org/",
+      title: "Bookmark 1",
+    }, {
+      url: "place:folder=1234",
+      title: "Shortcut 1",
+    }, {
+      url: "place:folder=-1",
+      title: "Shortcut 2",
+    }, {
+      url: "http://2.moz.org/",
+      title: "Bookmark 2",
+    }]
+  });
 
   // Add also a simple visit.
   await PlacesTestUtils.addVisits(uri(("http://3.moz.org/")));
 
   // Query containing a broken folder shortcuts among results.
   let query = PlacesUtils.history.getNewQuery();
   query.setFolders([PlacesUtils.unfiledBookmarksFolderId], 1);
   let options = PlacesUtils.history.getNewQueryOptions();
@@ -37,27 +33,27 @@ add_task(async function test_execute() {
 
   let shortcut = root.getChild(1);
   do_check_eq(shortcut.uri, "place:folder=1234");
   PlacesUtils.asContainer(shortcut);
   shortcut.containerOpen = true;
   do_check_eq(shortcut.childCount, 0);
   shortcut.containerOpen = false;
   // Remove the broken shortcut while the containing result is open.
-  PlacesUtils.bookmarks.removeItem(id1);
+  await PlacesUtils.bookmarks.remove(bookmarks[1]);
   do_check_eq(root.childCount, 3);
 
   shortcut = root.getChild(1);
   do_check_eq(shortcut.uri, "place:folder=-1");
   PlacesUtils.asContainer(shortcut);
   shortcut.containerOpen = true;
   do_check_eq(shortcut.childCount, 0);
   shortcut.containerOpen = false;
   // Remove the broken shortcut while the containing result is open.
-  PlacesUtils.bookmarks.removeItem(id2);
+  await PlacesUtils.bookmarks.remove(bookmarks[2]);
   do_check_eq(root.childCount, 2);
 
   root.containerOpen = false;
 
   // Broken folder shortcut as root node.
   query = PlacesUtils.history.getNewQuery();
   query.setFolders([1234], 1);
   options = PlacesUtils.history.getNewQueryOptions();
--- a/toolkit/components/places/tests/unit/test_browserhistory.js
+++ b/toolkit/components/places/tests/unit/test_browserhistory.js
@@ -27,40 +27,42 @@ add_task(async function test_removePages
   // Bookmarked item should not be removed from moz_places.
   const ANNO_INDEX = 1;
   const ANNO_NAME = "testAnno";
   const ANNO_VALUE = "foo";
   const BOOKMARK_INDEX = 2;
   PlacesUtils.annotations.setPageAnnotation(pages[ANNO_INDEX],
                                             ANNO_NAME, ANNO_VALUE, 0,
                                             Ci.nsIAnnotationService.EXPIRE_NEVER);
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       pages[BOOKMARK_INDEX],
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                       "test bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: pages[BOOKMARK_INDEX],
+    title: "test bookmark"
+  });
   PlacesUtils.annotations.setPageAnnotation(pages[BOOKMARK_INDEX],
                                             ANNO_NAME, ANNO_VALUE, 0,
                                             Ci.nsIAnnotationService.EXPIRE_NEVER);
 
   await PlacesUtils.history.remove(pages);
   do_check_eq(0, PlacesUtils.history.hasHistoryEntries);
 
   // Check that the bookmark and its annotation still exist.
-  do_check_true(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0) > 0);
+  let folder = await PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId);
+  do_check_eq(folder.root.childCount, 1);
   do_check_eq(PlacesUtils.annotations.getPageAnnotation(pages[BOOKMARK_INDEX], ANNO_NAME),
               ANNO_VALUE);
 
   // Check the annotation on the non-bookmarked page does not exist anymore.
   try {
     PlacesUtils.annotations.getPageAnnotation(pages[ANNO_INDEX], ANNO_NAME);
     do_throw("did not expire expire_never anno on a not bookmarked item");
   } catch (ex) {}
 
   // Cleanup.
-  PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
+  await PlacesUtils.bookmarks.eraseEverything();
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function test_removePagesByTimeframe() {
   let visits = [];
   let startDate = (Date.now() - 10000) * 1000;
   for (let i = 0; i < 10; i++) {
     visits.push({
@@ -118,12 +120,8 @@ add_task(async function test_getObserver
         // Just invoking getObservers should be enough to invalidate the cache.
         PlacesUtils.history.getObservers();
         do_check_eq(0, PlacesUtils.history.hasHistoryEntries);
         resolve();
       }
     });
   });
 });
-
-function run_test() {
-  run_next_test();
-}
--- a/toolkit/components/places/tests/unit/test_childlessTags.js
+++ b/toolkit/components/places/tests/unit/test_childlessTags.js
@@ -4,79 +4,66 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * Ensures that removal of a bookmark untags the bookmark if it's no longer
  * contained in any regular, non-tag folders.  See bug 444849.
  */
 
-// Add your tests here.  Each is an object with a summary string |desc| and a
-// method run() that's called to run the test.
-var tests = [
-  {
-    desc: "Removing a tagged bookmark should cause the tag to be removed.",
-    run() {
-      print("  Make a bookmark.");
-      var bmId = bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder,
-                                      BOOKMARK_URI,
-                                      bmsvc.DEFAULT_INDEX,
-                                      "test bookmark");
-      do_check_true(bmId > 0);
+ var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+               getService(Ci.nsINavHistoryService);
+
+ var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
+               getService(Ci.nsITaggingService);
+
+ const BOOKMARK_URI = uri("http://example.com/");
 
-      print("  Tag it up.");
-      var tags = ["foo", "bar"];
-      tagssvc.tagURI(BOOKMARK_URI, tags);
-      ensureTagsExist(tags);
+add_task(async function test_removing_tagged_bookmark_removes_tag() {
+  print("  Make a bookmark.");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: BOOKMARK_URI,
+    title: "test bookmark",
+  });
 
-      print("  Remove the bookmark.  The tags should no longer exist.");
-      bmsvc.removeItem(bmId);
-      ensureTagsExist([]);
-    }
-  },
+  print("  Tag it up.");
+  let tags = ["foo", "bar"];
+  tagssvc.tagURI(BOOKMARK_URI, tags);
+  ensureTagsExist(tags);
 
-  {
-    desc: "Removing a folder containing a tagged bookmark should cause the " +
-          "tag to be removed.",
-    run() {
-      print("  Make a folder.");
-      var folderId = bmsvc.createFolder(bmsvc.unfiledBookmarksFolder,
-                                        "test folder",
-                                        bmsvc.DEFAULT_INDEX);
-      do_check_true(folderId > 0);
+  print("  Remove the bookmark.  The tags should no longer exist.");
+  await PlacesUtils.bookmarks.remove(bookmark.guid);
+  ensureTagsExist([]);
+});
 
-      print("  Stick a bookmark in the folder.");
-      var bmId = bmsvc.insertBookmark(folderId,
-                                      BOOKMARK_URI,
-                                      bmsvc.DEFAULT_INDEX,
-                                      "test bookmark");
-      do_check_true(bmId > 0);
+add_task(async function test_removing_folder_containing_tagged_bookmark_removes_tag() {
+  print("  Make a folder.");
+  let folder = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    title: "test folder",
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+  });
 
-      print("  Tag the bookmark.");
-      var tags = ["foo", "bar"];
-      tagssvc.tagURI(BOOKMARK_URI, tags);
-      ensureTagsExist(tags);
+  print("  Stick a bookmark in the folder.");
+  var bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: folder.guid,
+    url: BOOKMARK_URI,
+    title: "test bookmark",
+  });
 
-      print("  Remove the folder.  The tags should no longer exist.");
-      bmsvc.removeItem(folderId);
-      ensureTagsExist([]);
-    }
-  }
-];
+  print("  Tag the bookmark.");
+  var tags = ["foo", "bar"];
+  tagssvc.tagURI(BOOKMARK_URI, tags);
+  ensureTagsExist(tags);
 
-var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-            getService(Ci.nsINavBookmarksService);
-
-var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
-              getService(Ci.nsINavHistoryService);
-
-var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
-              getService(Ci.nsITaggingService);
-
-const BOOKMARK_URI = uri("http://example.com/");
+  print("  Remove the folder.  The tags should no longer exist.");
+  await PlacesUtils.bookmarks.remove(bookmark.guid);
+  ensureTagsExist([]);
+});
 
 /**
  * Runs a tag query and ensures that the tags returned are those and only those
  * in aTags.  aTags may be empty, in which case this function ensures that no
  * tags exist.
  *
  * @param aTags
  *        An array of tags (strings)
@@ -102,15 +89,8 @@ function ensureTagsExist(aTags) {
     var tag = resultRoot.getChild(i).title;
     var indexOfTag = tags.indexOf(tag);
     do_check_true(indexOfTag >= 0);
     tags.splice(indexOfTag, 1);
   }
 
   resultRoot.containerOpen = false;
 }
-
-function run_test() {
-  tests.forEach(function(test) {
-    print("Running test: " + test.desc);
-    test.run();
-  });
-}
--- a/toolkit/components/places/tests/unit/test_frecency_observers.js
+++ b/toolkit/components/places/tests/unit/test_frecency_observers.js
@@ -1,50 +1,51 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function run_test() {
-  run_next_test();
-}
-
 // Each of these tests a path that triggers a frecency update.  Together they
 // hit all sites that update a frecency.
 
 // InsertVisitedURIs::UpdateFrecency and History::InsertPlace
 add_task(async function test_InsertVisitedURIs_UpdateFrecency_and_History_InsertPlace() {
   // InsertPlace is at the end of a path that UpdateFrecency is also on, so kill
   // two birds with one stone and expect two notifications.  Trigger the path by
   // adding a download.
-  let uri = NetUtil.newURI("http://example.com/a");
+  let url = Services.io.newURI("http://example.com/a");
   Cc["@mozilla.org/browser/download-history;1"].
     getService(Ci.nsIDownloadHistory).
-    addDownload(uri);
-  await Promise.all([onFrecencyChanged(uri), onFrecencyChanged(uri)]);
+    addDownload(url);
+  await Promise.all([onFrecencyChanged(url), onFrecencyChanged(url)]);
 });
 
 // nsNavHistory::UpdateFrecency
 add_task(async function test_nsNavHistory_UpdateFrecency() {
-  let bm = PlacesUtils.bookmarks;
-  let uri = NetUtil.newURI("http://example.com/b");
-  bm.insertBookmark(bm.unfiledBookmarksFolder, uri,
-                    Ci.nsINavBookmarksService.DEFAULT_INDEX, "test");
-  await onFrecencyChanged(uri);
+  let url = Services.io.newURI("http://example.com/b");
+  let promise = onFrecencyChanged(url);
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url,
+    title: "test"
+  });
+  await promise;
 });
 
 // nsNavHistory::invalidateFrecencies for particular pages
 add_task(async function test_nsNavHistory_invalidateFrecencies_somePages() {
-  let uri = NetUtil.newURI("http://test-nsNavHistory-invalidateFrecencies-somePages.com/");
+  let url = Services.io.newURI("http://test-nsNavHistory-invalidateFrecencies-somePages.com/");
   // Bookmarking the URI is enough to add it to moz_places, and importantly, it
   // means that removePagesFromHost doesn't remove it from moz_places, so its
   // frecency is able to be changed.
-  let bm = PlacesUtils.bookmarks;
-  bm.insertBookmark(bm.unfiledBookmarksFolder, uri,
-                    Ci.nsINavBookmarksService.DEFAULT_INDEX, "test");
-  PlacesUtils.history.removePagesFromHost(uri.host, false);
-  await onFrecencyChanged(uri);
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url,
+    title: "test"
+  });
+  PlacesUtils.history.removePagesFromHost(url.host, false);
+  await onFrecencyChanged(url);
 });
 
 // nsNavHistory::invalidateFrecencies for all pages
 add_task(async function test_nsNavHistory_invalidateFrecencies_allPages() {
   await Promise.all([onManyFrecenciesChanged(), PlacesTestUtils.clearHistory()]);
 });
 
 // nsNavHistory::DecayFrecency and nsNavHistory::FixInvalidFrecencies
--- a/toolkit/components/places/tests/unit/test_frecency_zero_updated.js
+++ b/toolkit/components/places/tests/unit/test_frecency_zero_updated.js
@@ -1,28 +1,25 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Tests a zero frecency is correctly updated when inserting new valid visits.
 
-function run_test() {
-  run_next_test()
-}
-
 add_task(async function() {
   const TEST_URI = NetUtil.newURI("http://example.com/");
-  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                                TEST_URI,
-                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                "A title");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URI,
+    title: "A title"
+  });
   await PlacesTestUtils.promiseAsyncUpdates();
   do_check_true(frecencyForUrl(TEST_URI) > 0);
 
   // Removing the bookmark should leave an orphan page with zero frecency.
   // Note this would usually be expired later by expiration.
-  PlacesUtils.bookmarks.removeItem(id);
+  await PlacesUtils.bookmarks.remove(bookmark.guid);
   await PlacesTestUtils.promiseAsyncUpdates();
   do_check_eq(frecencyForUrl(TEST_URI), 0);
 
   // Now add a valid visit to the page, frecency should increase.
   await PlacesTestUtils.addVisits({ uri: TEST_URI });
   do_check_true(frecencyForUrl(TEST_URI) > 0);
 });
--- a/toolkit/components/places/tests/unit/test_getChildIndex.js
+++ b/toolkit/components/places/tests/unit/test_getChildIndex.js
@@ -3,28 +3,30 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Tests nsNavHistoryContainerResultNode::GetChildIndex(aNode) functionality.
  */
 
-function run_test() {
+add_task(async function test_get_child_index() {
   // Add a bookmark to the menu.
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
-                                       uri("http://test.mozilla.org/bookmark/"),
-                                       Ci.nsINavBookmarksService.DEFAULT_INDEX,
-                                       "Test bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: "http://test.mozilla.org/bookmark/",
+    title: "Test bookmark"
+  });
 
   // Add a bookmark to unfiled folder.
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       uri("http://test.mozilla.org/unfiled/"),
-                                       Ci.nsINavBookmarksService.DEFAULT_INDEX,
-                                       "Unfiled bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: "http://test.mozilla.org/unfiled/",
+    title: "Unfiled bookmark"
+  });
 
   // Get the unfiled bookmark node.
   let unfiledNode = getNodeAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   if (!unfiledNode)
     do_throw("Unable to find bookmark in hierarchy!");
   do_check_eq(unfiledNode.title, "Unfiled bookmark");
 
   let hs = PlacesUtils.history;
@@ -46,17 +48,17 @@ function run_test() {
   try {
     root.getChildIndex(unfiledNode);
     do_throw("Searching for an invalid node should have thrown.");
   } catch (ex) {
     print("We correctly got an exception.");
   }
 
   root.containerOpen = false;
-}
+});
 
 function getNodeAt(aFolderId, aIndex) {
   let hs = PlacesUtils.history;
   let query = hs.getNewQuery();
   query.setFolders([aFolderId], 1);
   let options = hs.getNewQueryOptions();
   options.queryType = options.QUERY_TYPE_BOOKMARKS;
   let root = hs.executeQuery(query, options).root;
--- a/toolkit/components/places/tests/unit/test_history_autocomplete_tags.js
+++ b/toolkit/components/places/tests/unit/test_history_autocomplete_tags.js
@@ -34,33 +34,21 @@ AutoCompleteInput.prototype = {
 
   popupOpen: false,
 
   popup: {
     setSelectedIndex(aIndex) {},
     invalidate() {},
 
     // nsISupports implementation
-    QueryInterface(iid) {
-      if (iid.equals(Ci.nsISupports) ||
-          iid.equals(Ci.nsIAutoCompletePopup))
-        return this;
-
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-    }
+    QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup])
   },
 
   // nsISupports implementation
-  QueryInterface(iid) {
-    if (iid.equals(Ci.nsISupports) ||
-        iid.equals(Ci.nsIAutoCompleteInput))
-      return this;
-
-    throw Components.results.NS_ERROR_NO_INTERFACE;
-  }
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput])
 }
 
 // Get tagging service
 try {
   var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
                 getService(Ci.nsITaggingService);
 } catch (ex) {
   do_throw("Could not get tagging service\n");
@@ -95,35 +83,35 @@ function ensure_tag_results(uris, search
     do_check_eq(controller.matchCount, uris.length);
     let vals = [];
     for (let i = 0; i < controller.matchCount; i++) {
       // Keep the URL for later because order of tag results is undefined
       vals.push(controller.getValueAt(i));
       do_check_eq(controller.getStyleAt(i), "bookmark-tag");
     }
     // Sort the results then check if we have the right items
-    vals.sort().forEach((val, i) => do_check_eq(val, uris[i].spec))
+    vals.sort().forEach((val, i) => do_check_eq(val, uris[i]))
 
     if (current_test < (tests.length - 1)) {
       current_test++;
       tests[current_test]();
     }
 
     do_test_finished();
   };
 
   controller.startSearch(searchTerm);
 }
 
-var uri1 = uri("http://site.tld/1/aaa");
-var uri2 = uri("http://site.tld/2/bbb");
-var uri3 = uri("http://site.tld/3/aaa");
-var uri4 = uri("http://site.tld/4/bbb");
-var uri5 = uri("http://site.tld/5/aaa");
-var uri6 = uri("http://site.tld/6/bbb");
+var uri1 = "http://site.tld/1/aaa";
+var uri2 = "http://site.tld/2/bbb";
+var uri3 = "http://site.tld/3/aaa";
+var uri4 = "http://site.tld/4/bbb";
+var uri5 = "http://site.tld/5/aaa";
+var uri6 = "http://site.tld/6/bbb";
 
 var tests = [
   () => ensure_tag_results([uri1, uri4, uri6], "foo"),
   () => ensure_tag_results([uri1], "foo aaa"),
   () => ensure_tag_results([uri4, uri6], "foo bbb"),
   () => ensure_tag_results([uri2, uri4, uri5, uri6], "bar"),
   () => ensure_tag_results([uri5], "bar aaa"),
   () => ensure_tag_results([uri2, uri4, uri6], "bar bbb"),
@@ -145,40 +133,41 @@ var tests = [
   () => ensure_tag_results([uri6], "cheese bar foo"),
   () => ensure_tag_results([], "foo bar cheese aaa"),
   () => ensure_tag_results([uri6], "foo bar cheese bbb"),
 ];
 
 /**
  * Properly tags a uri adding it to bookmarks.
  *
- * @param aURI
+ * @param url
  *        The nsIURI to tag.
- * @param aTags
+ * @param tags
  *        The tags to add.
  */
-function tagURI(aURI, aTags) {
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       aURI,
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                       "A title");
-  tagssvc.tagURI(aURI, aTags);
+async function tagURI(url, tags) {
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url,
+    title: "A title",
+  });
+  tagssvc.tagURI(uri(url), tags);
 }
 
 /**
  * Test history autocomplete
  */
-function run_test() {
+add_task(async function test_history_autocomplete_tags() {
   // always search in history + bookmarks, no matter what the default is
   var prefs = Cc["@mozilla.org/preferences-service;1"].
               getService(Ci.nsIPrefBranch);
   prefs.setIntPref("browser.urlbar.search.sources", 3);
   prefs.setIntPref("browser.urlbar.default.behavior", 0);
 
-  tagURI(uri1, ["foo"]);
-  tagURI(uri2, ["bar"]);
-  tagURI(uri3, ["cheese"]);
-  tagURI(uri4, ["foo bar"]);
-  tagURI(uri5, ["bar cheese"]);
-  tagURI(uri6, ["foo bar cheese"]);
+  await tagURI(uri1, ["foo"]);
+  await tagURI(uri2, ["bar"]);
+  await tagURI(uri3, ["cheese"]);
+  await tagURI(uri4, ["foo bar"]);
+  await tagURI(uri5, ["bar cheese"]);
+  await tagURI(uri6, ["foo bar cheese"]);
 
   tests[0]();
-}
+});
--- a/toolkit/components/places/tests/unit/test_history_catobs.js
+++ b/toolkit/components/places/tests/unit/test_history_catobs.js
@@ -1,16 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function() {
   do_load_manifest("nsDummyObserver.manifest");
 
   let dummyCreated = false;
   let dummyReceivedOnVisit = false;
 
   Services.obs.addObserver(function created() {
     Services.obs.removeObserver(created, "dummy-observer-created");
--- a/toolkit/components/places/tests/unit/test_history_clear.js
+++ b/toolkit/components/places/tests/unit/test_history_clear.js
@@ -60,34 +60,36 @@ add_task(async function test_history_cle
       transition: TRANSITION_REDIRECT_TEMPORARY,
       referrer: "http://link.mozilla.org/"},
     { uri: uri("http://redir_perm.mozilla.org/"),
       transition: TRANSITION_REDIRECT_PERMANENT,
       referrer: "http://link.mozilla.org/"},
   ]);
 
   // add a place: bookmark
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       uri("place:folder=4"),
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                       "shortcut");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: "place:folder=4",
+    title: "shortcut"
+  });
 
   // Add an expire never annotation
   // Actually expire never annotations are removed as soon as a page is removed
   // from the database, so this should act as a normal visit.
   PlacesUtils.annotations.setPageAnnotation(uri("http://download.mozilla.org/"),
                                             "never", "never", 0,
                                             PlacesUtils.annotations.EXPIRE_NEVER);
 
   // Add a bookmark
   // Bookmarked page should have history cleared and frecency = -1
-  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                       uri("http://typed.mozilla.org/"),
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                       "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: "http://typed.mozilla.org/",
+    title: "bookmark"
+  });
 
   await PlacesTestUtils.addVisits([
     { uri: uri("http://typed.mozilla.org/"),
       transition: TRANSITION_BOOKMARK },
     { uri: uri("http://frecency.mozilla.org/"),
       transition: TRANSITION_LINK },
   ]);
   await PlacesTestUtils.promiseAsyncUpdates();
--- a/toolkit/components/places/tests/unit/test_hosts_triggers.js
+++ b/toolkit/components/places/tests/unit/test_hosts_triggers.js
@@ -102,42 +102,49 @@ add_task(async function test_remove_plac
   for (let idx in urls) {
     checkHostNotInMozHosts(urls[idx].uri, urls[idx].typed, urls[idx].prefix);
   }
 });
 
 add_task(async function test_bookmark_changes() {
   let testUri = NetUtil.newURI("http://test.mozilla.org");
 
-  let itemId = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                                     testUri,
-                                                     PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                     "bookmark title");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: testUri,
+    title: "bookmark title",
+  });
 
   do_check_true(isHostInMozPlaces(testUri));
 
   // Change the hostname
-  PlacesUtils.bookmarks.changeBookmarkURI(itemId, NetUtil.newURI(NEW_URL));
+  await PlacesUtils.bookmarks.update({
+    guid: bookmark.guid,
+    url: NEW_URL,
+  });
 
   await PlacesTestUtils.clearHistory();
 
   let newUri = NetUtil.newURI(NEW_URL);
   do_check_true(isHostInMozPlaces(newUri));
   checkHostInMozHosts(newUri, false, null);
   checkHostNotInMozHosts(NetUtil.newURI("http://test.mozilla.org"), false, null);
 });
 
 add_task(async function test_bookmark_removal() {
-  let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId,
-                                                    PlacesUtils.bookmarks.DEFAULT_INDEX);
-  let newUri = NetUtil.newURI(NEW_URL);
-  PlacesUtils.bookmarks.removeItem(itemId);
+  // Get the last bookmark.
+  let unfiledBookmarksRoot =
+    await PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
+  let itemGuid =
+    unfiledBookmarksRoot.getChild(unfiledBookmarksRoot.childCount - 1).bookmarkGuid;
+
+  await PlacesUtils.bookmarks.remove(itemGuid);
   await PlacesTestUtils.clearHistory();
 
-  checkHostNotInMozHosts(newUri, false, null);
+  checkHostNotInMozHosts(Services.io.newURI(NEW_URL), false, null);
 });
 
 add_task(async function test_moz_hosts_typed_update() {
   const TEST_URI = NetUtil.newURI("http://typed.mozilla.com");
   let places = [{ uri: TEST_URI,
                   title: "test for " + TEST_URI.spec
                 },
                 { uri: TEST_URI,
--- a/toolkit/components/places/tests/unit/test_isvisited.js
+++ b/toolkit/components/places/tests/unit/test_isvisited.js
@@ -1,18 +1,14 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_execute() {
   var referrer = uri("about:blank");
 
   // add a http:// uri
   var uri1 = uri("http://mozilla.com");
   await PlacesTestUtils.addVisits({uri: uri1, referrer});
   do_check_guid_for_uri(uri1);
   do_check_true(await promiseIsURIVisited(uri1));
@@ -64,9 +60,8 @@ add_task(async function test_execute() {
         do_throw("Should not have added history for invalid URI.");
       }, error => {
         do_check_true(error.message.includes("No items were added to history"));
       });
       do_check_false(await promiseIsURIVisited(cantAddUri));
     }
   }
 });
-
--- a/toolkit/components/places/tests/unit/test_markpageas.js
+++ b/toolkit/components/places/tests/unit/test_markpageas.js
@@ -6,20 +6,16 @@
 
 var gVisits = [{url: "http://www.mozilla.com/",
                 transition: TRANSITION_TYPED},
                {url: "http://www.google.com/",
                 transition: TRANSITION_BOOKMARK},
                {url: "http://www.espn.com/",
                 transition: TRANSITION_LINK}];
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_execute() {
   let observer;
   let completionPromise = new Promise(resolveCompletionPromise => {
     observer = {
       __proto__: NavHistoryObserver.prototype,
       _visitCount: 0,
       onVisit(aURI, aVisitID, aTime, aSessionID, aReferringID,
                         aTransitionType, aAdded) {
@@ -50,9 +46,8 @@ add_task(async function test_execute() {
       transition: visit.transition
     });
   }
 
   await completionPromise;
 
   PlacesUtils.history.removeObserver(observer);
 });
-
--- a/toolkit/components/places/tests/unit/test_multi_queries.js
+++ b/toolkit/components/places/tests/unit/test_multi_queries.js
@@ -15,20 +15,16 @@
 async function add_visit(aURI, aDayOffset, aTransition) {
   await PlacesTestUtils.addVisits({
     uri: aURI,
     transition: aTransition,
     visitDate: (Date.now() + aDayOffset * 86400000) * 1000
   });
 }
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_execute() {
   await add_visit(uri("http://mirror1.mozilla.com/a"), -1, TRANSITION_LINK);
   await add_visit(uri("http://mirror2.mozilla.com/b"), -2, TRANSITION_LINK);
   await add_visit(uri("http://mirror3.mozilla.com/c"), -4, TRANSITION_FRAMED_LINK);
   await add_visit(uri("http://mirror1.google.com/b"), -1, TRANSITION_EMBED);
   await add_visit(uri("http://mirror2.google.com/a"), -2, TRANSITION_LINK);
   await add_visit(uri("http://mirror1.apache.org/b"), -3, TRANSITION_LINK);
   await add_visit(uri("http://mirror2.apache.org/a"), -4, TRANSITION_FRAMED_LINK);
--- a/toolkit/components/places/tests/unit/test_multi_word_tags.js
+++ b/toolkit/components/places/tests/unit/test_multi_word_tags.js
@@ -7,47 +7,39 @@
 // Get history service
 try {
   var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
                 getService(Ci.nsINavHistoryService);
 } catch (ex) {
   do_throw("Could not get history service\n");
 }
 
-// Get bookmark service
-try {
-  var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-              getService(Ci.nsINavBookmarksService);
-} catch (ex) {
-  do_throw("Could not get the nav-bookmarks-service\n");
-}
-
 // Get tagging service
 try {
   var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
                 getService(Ci.nsITaggingService);
 } catch (ex) {
   do_throw("Could not get tagging service\n");
 }
 
-// main
-function run_test() {
+add_task(async function run_test() {
   var uri1 = uri("http://site.tld/1");
   var uri2 = uri("http://site.tld/2");
   var uri3 = uri("http://site.tld/3");
   var uri4 = uri("http://site.tld/4");
   var uri5 = uri("http://site.tld/5");
   var uri6 = uri("http://site.tld/6");
 
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri1, bmsvc.DEFAULT_INDEX, null);
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri2, bmsvc.DEFAULT_INDEX, null);
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri3, bmsvc.DEFAULT_INDEX, null);
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri4, bmsvc.DEFAULT_INDEX, null);
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri5, bmsvc.DEFAULT_INDEX, null);
-  bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri6, bmsvc.DEFAULT_INDEX, null);
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [
+      { url: uri1 }, { url: uri2 }, { url: uri3 },
+      { url: uri4 }, { url: uri5 }, { url: uri6 },
+    ]
+  });
 
   tagssvc.tagURI(uri1, ["foo"]);
   tagssvc.tagURI(uri2, ["bar"]);
   tagssvc.tagURI(uri3, ["cheese"]);
   tagssvc.tagURI(uri4, ["foo bar"]);
   tagssvc.tagURI(uri5, ["bar cheese"]);
   tagssvc.tagURI(uri6, ["foo bar cheese"]);
 
@@ -141,9 +133,9 @@ function run_test() {
 
   query.searchTerms = "cheese bar foo";
   result = histsvc.executeQuery(query, options);
   root = result.root;
   root.containerOpen = true;
   do_check_eq(root.childCount, 1);
   do_check_eq(root.getChild(0).uri, "http://site.tld/6");
   root.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
+++ b/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
@@ -72,20 +72,16 @@ var resultObserver = {
     this.closedContainer = null;
     this.invalidatedContainer = null;
     this.sortingMode = null;
   }
 };
 
 var testURI = uri("http://mozilla.com");
 
-function run_test() {
-  run_next_test();
-}
-
 add_test(function check_history_query() {
   var options = PlacesUtils.history.getNewQueryOptions();
   options.sortingMode = options.SORT_BY_DATE_DESCENDING;
   options.resultType = options.RESULTS_AS_VISIT;
   var query = PlacesUtils.history.getNewQuery();
   var result = PlacesUtils.history.executeQuery(query, options);
   result.addObserver(resultObserver);
   var root = result.root;
@@ -148,57 +144,66 @@ add_test(function check_history_query() 
           resultObserver.reset();
           PlacesTestUtils.promiseAsyncUpdates().then(run_next_test);
         });
       });
     });
   });
 });
 
-add_test(function check_bookmarks_query() {
+add_task(async function check_bookmarks_query() {
   var options = PlacesUtils.history.getNewQueryOptions();
   var query = PlacesUtils.history.getNewQuery();
   query.setFolders([PlacesUtils.bookmarks.bookmarksMenuFolder], 1);
   var result = PlacesUtils.history.executeQuery(query, options);
   result.addObserver(resultObserver);
   var root = result.root;
   root.containerOpen = true;
 
   do_check_neq(resultObserver.openedContainer, null);
 
   // nsINavHistoryResultObserver.nodeInserted
   // add a bookmark
   var testBookmark =
-    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder,
-                                         testURI,
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                         "foo");
+    await PlacesUtils.bookmarks.insert({
+      parentGuid: PlacesUtils.bookmarks.menuGuid,
+      url: testURI,
+      title: "foo"
+  });
   do_check_eq("foo", resultObserver.insertedNode.title);
   do_check_eq(testURI.spec, resultObserver.insertedNode.uri);
 
   // nsINavHistoryResultObserver.nodeHistoryDetailsChanged
   // adding a visit causes nodeHistoryDetailsChanged for the folder
   do_check_eq(root.uri, resultObserver.nodeChangedByHistoryDetails.uri);
 
   // nsINavHistoryResultObserver.nodeTitleChanged for a leaf node
-  PlacesUtils.bookmarks.setItemTitle(testBookmark, "baz");
+  await PlacesUtils.bookmarks.update({
+    guid: testBookmark.guid,
+    title: "baz",
+  });
   do_check_eq(resultObserver.nodeChangedByTitle.title, "baz");
   do_check_eq(resultObserver.newTitle, "baz");
 
-  var testBookmark2 =
-    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder,
-                                         uri("http://google.com"),
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                         "foo");
-  PlacesUtils.bookmarks.moveItem(testBookmark2, PlacesUtils.bookmarks.bookmarksMenuFolder, 0);
-  do_check_eq(resultObserver.movedNode.itemId, testBookmark2);
+  var testBookmark2 = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: "http://google.com",
+    title: "foo"
+  });
+
+  await PlacesUtils.bookmarks.update({
+    guid: testBookmark2.guid,
+    index: 0,
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+  });
+  do_check_eq(resultObserver.movedNode.bookmarkGuid, testBookmark2.guid);
 
   // nsINavHistoryResultObserver.nodeRemoved
-  PlacesUtils.bookmarks.removeItem(testBookmark2);
-  do_check_eq(testBookmark2, resultObserver.removedNode.itemId);
+  await PlacesUtils.bookmarks.remove(testBookmark2.guid);
+  do_check_eq(testBookmark2.guid, resultObserver.removedNode.bookmarkGuid);
 
   // XXX nsINavHistoryResultObserver.invalidateContainer
 
   // nsINavHistoryResultObserver.sortingChanged
   resultObserver.invalidatedContainer = null;
   result.sortingMode = options.SORT_BY_TITLE_ASCENDING;
   do_check_eq(resultObserver.sortingMode, options.SORT_BY_TITLE_ASCENDING);
   do_check_eq(resultObserver.invalidatedContainer, result.root);
--- a/toolkit/components/places/tests/unit/test_onItemChanged_tags.js
+++ b/toolkit/components/places/tests/unit/test_onItemChanged_tags.js
@@ -1,52 +1,56 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // This test checks that changing a tag for a bookmark with multiple tags
 // notifies OnItemChanged("tags") only once, and not once per tag.
 
-function run_test() {
-  do_test_pending();
-
+add_task(async function run_test() {
   let tags = ["a", "b", "c"];
-  let uri = NetUtil.newURI("http://1.moz.org/");
+  let uri = Services.io.newURI("http://1.moz.org/");
 
-  let id = PlacesUtils.bookmarks.insertBookmark(
-    PlacesUtils.unfiledBookmarksFolderId, uri,
-    PlacesUtils.bookmarks.DEFAULT_INDEX, "Bookmark 1"
-  );
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: uri,
+    title: "Bookmark 1"
+  });
   PlacesUtils.tagging.tagURI(uri, tags);
 
+  let promise = PromiseUtils.defer();
+
   let bookmarksObserver = {
     QueryInterface: XPCOMUtils.generateQI([
       Ci.nsINavBookmarkObserver
     ]),
 
     _changedCount: 0,
     onItemChanged(aItemId, aProperty, aIsAnnotationProperty, aValue,
-                            aLastModified, aItemType) {
+                            aLastModified, aItemType, aParentId, aGuid) {
       if (aProperty == "tags") {
-        do_check_eq(aItemId, id);
+        do_check_eq(aGuid, bookmark.guid);
         this._changedCount++;
       }
     },
 
-    onItemRemoved(aItemId, aParentId, aIndex, aItemType) {
-      if (aItemId == id) {
+    onItemRemoved(aItemId, aParentId, aIndex, aItemType, aURI, aGuid) {
+      if (aGuid == bookmark.guid) {
         PlacesUtils.bookmarks.removeObserver(this);
         do_check_eq(this._changedCount, 2);
-        do_test_finished();
+        promise.resolve();
       }
     },
 
     onItemAdded() {},
     onBeginUpdateBatch() {},
     onEndUpdateBatch() {},
     onItemVisited() {},
     onItemMoved() {},
   };
   PlacesUtils.bookmarks.addObserver(bookmarksObserver);
 
   PlacesUtils.tagging.tagURI(uri, ["d"]);
   PlacesUtils.tagging.tagURI(uri, ["e"]);
-  PlacesUtils.bookmarks.removeItem(id);
-}
+
+  await promise;
+
+  await PlacesUtils.bookmarks.remove(bookmark.guid);
+});
--- a/toolkit/components/places/tests/unit/test_pageGuid_bookmarkGuid.js
+++ b/toolkit/components/places/tests/unit/test_pageGuid_bookmarkGuid.js
@@ -1,33 +1,43 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const bmsvc = PlacesUtils.bookmarks;
 const histsvc = PlacesUtils.history;
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test_addBookmarksAndCheckGuids() {
-  let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX);
-  bmsvc.insertBookmark(folder, uri("http://test1.com/"),
-                       bmsvc.DEFAULT_INDEX, "1 title");
-  bmsvc.insertBookmark(folder, uri("http://test2.com/"),
-                       bmsvc.DEFAULT_INDEX, "2 title");
-  bmsvc.insertBookmark(folder, uri("http://test3.com/"),
-                       bmsvc.DEFAULT_INDEX, "3 title");
-  bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX);
-  bmsvc.createFolder(folder, "test folder 2", bmsvc.DEFAULT_INDEX);
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "test folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        url: "http://test1.com/",
+        title: "1 title",
+      }, {
+        url: "http://test2.com/",
+        title: "2 title",
+      }, {
+        url: "http://test3.com/",
+        title: "3 title",
+      }, {
+        type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
+      }, {
+        title: "test folder 2",
+        type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      }]
+    }]
+  });
 
-  let root = PlacesUtils.getFolderContents(folder).root;
+  let folderId = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+
+  let root = PlacesUtils.getFolderContents(folderId).root;
   do_check_eq(root.childCount, 5);
 
   // check bookmark guids
   let bookmarkGuidZero = root.getChild(0).bookmarkGuid;
   do_check_eq(bookmarkGuidZero.length, 12);
   // bookmarks have bookmark guids
   do_check_eq(root.getChild(1).bookmarkGuid.length, 12);
   do_check_eq(root.getChild(2).bookmarkGuid.length, 12);
@@ -55,49 +65,68 @@ add_task(async function test_addBookmark
   do_check_neq(root.getChild(1).pageGuid, root.getChild(2).pageGuid);
 
   root.containerOpen = false;
 
   await PlacesUtils.bookmarks.eraseEverything();
 });
 
 add_task(async function test_updateBookmarksAndCheckGuids() {
-  let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX);
-  let b1 = bmsvc.insertBookmark(folder, uri("http://test1.com/"),
-                                bmsvc.DEFAULT_INDEX, "1 title");
-  let f1 = bmsvc.createFolder(folder, "test folder 2", bmsvc.DEFAULT_INDEX);
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "test folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        url: "http://test1.com/",
+        title: "1 title",
+      }, {
+        title: "test folder 2",
+        type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      }]
+    }]
+  });
 
-  let root = PlacesUtils.getFolderContents(folder).root;
+  let folderId = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+
+  let root = PlacesUtils.getFolderContents(folderId).root;
   do_check_eq(root.childCount, 2);
 
   // ensure the bookmark and page guids remain the same after modifing other property.
   let bookmarkGuidZero = root.getChild(0).bookmarkGuid;
   let pageGuidZero = root.getChild(0).pageGuid;
-  bmsvc.setItemTitle(b1, "1 title mod");
+  await PlacesUtils.bookmarks.update({
+    guid: bookmarks[1].guid,
+    title: "1 title mod",
+  });
   do_check_eq(root.getChild(0).title, "1 title mod");
   do_check_eq(root.getChild(0).bookmarkGuid, bookmarkGuidZero);
   do_check_eq(root.getChild(0).pageGuid, pageGuidZero);
 
   let bookmarkGuidOne = root.getChild(1).bookmarkGuid;
   let pageGuidOne = root.getChild(1).pageGuid;
-  bmsvc.setItemTitle(f1, "test foolder 234");
+
+  await PlacesUtils.bookmarks.update({
+    guid: bookmarks[2].guid,
+    title: "test foolder 234",
+  });
   do_check_eq(root.getChild(1).title, "test foolder 234");
   do_check_eq(root.getChild(1).bookmarkGuid, bookmarkGuidOne);
   do_check_eq(root.getChild(1).pageGuid, pageGuidOne);
 
   root.containerOpen = false;
 
   await PlacesUtils.bookmarks.eraseEverything();
 });
 
 add_task(async function test_addVisitAndCheckGuid() {
   // add a visit and test page guid and non-existing bookmark guids.
   let sourceURI = uri("http://test4.com/");
   await PlacesTestUtils.addVisits({ uri: sourceURI });
-  do_check_eq(bmsvc.getBookmarkedURIFor(sourceURI), null);
+  do_check_eq(await PlacesUtils.bookmarks.fetch({ url: sourceURI }, null));
 
   let options = histsvc.getNewQueryOptions();
   let query = histsvc.getNewQuery();
   query.uri = sourceURI;
   let root = histsvc.executeQuery(query, options).root;
   root.containerOpen = true;
   do_check_eq(root.childCount, 1);
 
@@ -106,70 +135,111 @@ add_task(async function test_addVisitAnd
   root.containerOpen = false;
 
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function test_addItemsWithInvalidGUIDsFails() {
   const INVALID_GUID = "XYZ";
   try {
-    bmsvc.createFolder(bmsvc.placesRoot, "XYZ folder",
-                       bmsvc.DEFAULT_INDEX, INVALID_GUID);
+    await PlacesUtils.bookmarks.insert({
+      parentGuid: PlacesUtils.bookmarks.menuGuid,
+      guid: INVALID_GUID,
+      title: "XYZ folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    });
     do_throw("Adding a folder with an invalid guid should fail");
   } catch (ex) { }
 
-  let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder",
-                                  bmsvc.DEFAULT_INDEX);
+  let folder = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: "test folder",
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+  });
   try {
-    bmsvc.insertBookmark(folder, uri("http://test.tld"), bmsvc.DEFAULT_INDEX,
-                         "title", INVALID_GUID);
+    PlacesUtils.bookmarks.insert({
+      parentGuid: folder.guid,
+      guid: INVALID_GUID,
+      title: "title",
+      url: "http://test.tld",
+    });
     do_throw("Adding a bookmark with an invalid guid should fail");
   } catch (ex) { }
 
   try {
-    bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX, INVALID_GUID);
+    PlacesUtils.bookmarks.insert({
+      parentGuid: folder.guid,
+      guid: INVALID_GUID,
+      type: PlacesUtils.bookmarks.TYPE_SEPARATOR
+    });
     do_throw("Adding a separator with an invalid guid should fail");
   } catch (ex) { }
 
   await PlacesUtils.bookmarks.eraseEverything();
 });
 
 add_task(async function test_addItemsWithGUIDs() {
   const FOLDER_GUID     = "FOLDER--GUID";
   const BOOKMARK_GUID   = "BM------GUID";
   const SEPARATOR_GUID  = "SEP-----GUID";
 
-  let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder",
-                                  bmsvc.DEFAULT_INDEX, FOLDER_GUID);
-  bmsvc.insertBookmark(folder, uri("http://test1.com/"), bmsvc.DEFAULT_INDEX,
-                       "1 title", BOOKMARK_GUID);
-  bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX, SEPARATOR_GUID);
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "test folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      guid: FOLDER_GUID,
+      children: [{
+        url: "http://test1.com",
+        title: "1 title",
+        guid: BOOKMARK_GUID,
+      }, {
+        type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
+        guid: SEPARATOR_GUID,
+      }]
+    }]
+  });
 
-  let root = PlacesUtils.getFolderContents(folder).root;
+  let folderId = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+
+  let root = PlacesUtils.getFolderContents(folderId).root;
   do_check_eq(root.childCount, 2);
   do_check_eq(root.bookmarkGuid, FOLDER_GUID);
   do_check_eq(root.getChild(0).bookmarkGuid, BOOKMARK_GUID);
   do_check_eq(root.getChild(1).bookmarkGuid, SEPARATOR_GUID);
 
   root.containerOpen = false;
   await PlacesUtils.bookmarks.eraseEverything();
 });
 
-add_task(async function test_emptyGUIDIgnored() {
-  let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder",
-                                  bmsvc.DEFAULT_INDEX, "");
-  do_check_valid_places_guid(PlacesUtils.getFolderContents(folder)
-                                        .root.bookmarkGuid);
-  await PlacesUtils.bookmarks.eraseEverything();
+add_task(async function test_emptyGUIDFails() {
+  try {
+    await PlacesUtils.bookmarks.insert({
+      parentGuid: PlacesUtils.bookmarks.menuGuid,
+      guid: "",
+      title: "test folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER
+    });
+    do_throw("Adding a folder with an empty guid should fail")
+  } catch (ex) {
+  }
 });
 
 add_task(async function test_usingSameGUIDFails() {
   const GUID = "XYZXYZXYZXYZ";
-  bmsvc.createFolder(bmsvc.placesRoot, "test folder",
-                     bmsvc.DEFAULT_INDEX, GUID);
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    guid: GUID,
+    title: "test folder",
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+  });
   try {
-    bmsvc.createFolder(bmsvc.placesRoot, "test folder 2",
-                       bmsvc.DEFAULT_INDEX, GUID);
+    await PlacesUtils.bookmarks.insert({
+      parentGuid: PlacesUtils.bookmarks.menuGuid,
+      guid: GUID,
+      title: "test folder 2",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    });
     do_throw("Using the same guid twice should fail");
   } catch (ex) { }
 
   await PlacesUtils.bookmarks.eraseEverything();
 });
--- a/toolkit/components/places/tests/unit/test_placeURIs.js
+++ b/toolkit/components/places/tests/unit/test_placeURIs.js
@@ -12,22 +12,20 @@ try {
   do_throw("Could not get history service\n");
 }
 
 // main
 function run_test() {
   // XXX Full testing coverage for QueriesToQueryString and
   // QueryStringToQueries
 
-  var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-           getService(Ci.nsINavBookmarksService);
   const NHQO = Ci.nsINavHistoryQueryOptions;
   // Bug 376798
   var query = histsvc.getNewQuery();
-  query.setFolders([bs.placesRoot], 1);
+  query.setFolders([PlacesUtils.bookmarks.placesRoot], 1);
   do_check_eq(histsvc.queriesToQueryString([query], 1, histsvc.getNewQueryOptions()),
               "place:folder=PLACES_ROOT");
 
   // Bug 378828
   var options = histsvc.getNewQueryOptions();
   options.sortingAnnotation = "test anno";
   options.sortingMode = NHQO.SORT_BY_ANNOTATION_DESCENDING;
   var placeURI =
--- a/toolkit/components/places/tests/unit/test_resolveNullBookmarkTitles.js
+++ b/toolkit/components/places/tests/unit/test_resolveNullBookmarkTitles.js
@@ -1,49 +1,44 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function run_test() {
-  run_next_test();
-}
-
-add_test(function test_resolveNullBookmarkTitles() {
+add_task(async function test_resolveNullBookmarkTitles() {
   let uri1 = uri("http://foo.tld/");
   let uri2 = uri("https://bar.tld/");
 
-  PlacesTestUtils.addVisits([
+  await PlacesTestUtils.addVisits([
     { uri: uri1, title: "foo title" },
     { uri: uri2, title: "bar title" }
-  ]).then(function() {
-    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
-                                         uri1,
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                         null);
-    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
-                                         uri2,
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                         null);
+  ]);
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: uri1,
+    title: null,
+  });
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: uri2,
+    title: null
+  });
 
-    PlacesUtils.tagging.tagURI(uri1, ["tag 1"]);
-    PlacesUtils.tagging.tagURI(uri2, ["tag 2"]);
+  PlacesUtils.tagging.tagURI(uri1, ["tag 1"]);
+  PlacesUtils.tagging.tagURI(uri2, ["tag 2"]);
 
-    let options = PlacesUtils.history.getNewQueryOptions();
-    options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
-    options.resultType = options.RESULTS_AS_TAG_CONTENTS;
+  let options = PlacesUtils.history.getNewQueryOptions();
+  options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
+  options.resultType = options.RESULTS_AS_TAG_CONTENTS;
 
-    let query = PlacesUtils.history.getNewQuery();
-    // if we don't set a tag folder, RESULTS_AS_TAG_CONTENTS will return all
-    // tagged URIs
-    let root = PlacesUtils.history.executeQuery(query, options).root;
-    root.containerOpen = true;
-    do_check_eq(root.childCount, 2);
-    // actually RESULTS_AS_TAG_CONTENTS return results ordered by place_id DESC
-    // so they are reversed
-    do_check_eq(root.getChild(0).title, "bar title");
-    do_check_eq(root.getChild(1).title, "foo title");
-    root.containerOpen = false;
-
-    run_next_test();
-  });
+  let query = PlacesUtils.history.getNewQuery();
+  // if we don't set a tag folder, RESULTS_AS_TAG_CONTENTS will return all
+  // tagged URIs
+  let root = PlacesUtils.history.executeQuery(query, options).root;
+  root.containerOpen = true;
+  do_check_eq(root.childCount, 2);
+  // actually RESULTS_AS_TAG_CONTENTS return results ordered by place_id DESC
+  // so they are reversed
+  do_check_eq(root.getChild(0).title, "bar title");
+  do_check_eq(root.getChild(1).title, "foo title");
+  root.containerOpen = false;
 });
--- a/toolkit/components/places/tests/unit/test_result_sort.js
+++ b/toolkit/components/places/tests/unit/test_result_sort.js
@@ -18,122 +18,137 @@ function promiseOnItemVisited() {
         // Enqueue to be sure that all onItemVisited notifications ran.
         do_execute_soon(resolve);
       }
     };
     PlacesUtils.bookmarks.addObserver(bookmarksObserver);
   });
 }
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function test() {
-  let testFolder = PlacesUtils.bookmarks.createFolder(
-    PlacesUtils.bookmarks.placesRoot,
-    "Result-sort functionality tests root",
-    PlacesUtils.bookmarks.DEFAULT_INDEX);
+  const uri1 = "http://foo.tld/a";
+  const uri2 = "http://foo.tld/b";
 
-  let uri1 = NetUtil.newURI("http://foo.tld/a");
-  let uri2 = NetUtil.newURI("http://foo.tld/b");
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "Result-sort functionality tests root",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        title: "b",
+        url: uri1,
+      }, {
+        title: "a",
+        url: uri2,
+      }, {
+        // url of the first child, title of second
+        title: "a",
+        url: uri1,
+      }, ]
+    }]
+  });
 
-  let id1 = PlacesUtils.bookmarks.insertBookmark(
-    testFolder, uri1, PlacesUtils.bookmarks.DEFAULT_INDEX, "b");
-  let id2 = PlacesUtils.bookmarks.insertBookmark(
-    testFolder, uri2, PlacesUtils.bookmarks.DEFAULT_INDEX, "a");
-  // url of id1, title of id2
-  let id3 = PlacesUtils.bookmarks.insertBookmark(
-    testFolder, uri1, PlacesUtils.bookmarks.DEFAULT_INDEX, "a");
+  let testFolderId = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+
+  let guid1 = bookmarks[1].guid;
+  let guid2 = bookmarks[2].guid;
+  let guid3 = bookmarks[3].guid;
 
   // query with natural order
-  let result = PlacesUtils.getFolderContents(testFolder);
+  let result = PlacesUtils.getFolderContents(testFolderId);
   let root = result.root;
 
   do_check_eq(root.childCount, 3);
 
   function checkOrder(a, b, c) {
-    do_check_eq(root.getChild(0).itemId, a);
-    do_check_eq(root.getChild(1).itemId, b);
-    do_check_eq(root.getChild(2).itemId, c);
+    do_check_eq(root.getChild(0).bookmarkGuid, a);
+    do_check_eq(root.getChild(1).bookmarkGuid, b);
+    do_check_eq(root.getChild(2).bookmarkGuid, c);
   }
 
   // natural order
   do_print("Natural order");
-  checkOrder(id1, id2, id3);
+  checkOrder(guid1, guid2, guid3);
 
-  // title: id3 should precede id2 since we fall-back to URI-based sorting
+  // title: guid3 should precede guid2 since we fall-back to URI-based sorting
   do_print("Sort by title asc");
   result.sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
-  checkOrder(id3, id2, id1);
+  checkOrder(guid3, guid2, guid1);
 
   // In reverse
   do_print("Sort by title desc");
   result.sortingMode = NHQO.SORT_BY_TITLE_DESCENDING;
-  checkOrder(id1, id2, id3);
+  checkOrder(guid1, guid2, guid3);
 
-  // uri sort: id1 should precede id3 since we fall-back to natural order
+  // uri sort: guid1 should precede guid3 since we fall-back to natural order
   do_print("Sort by uri asc");
   result.sortingMode = NHQO.SORT_BY_URI_ASCENDING;
-  checkOrder(id1, id3, id2);
+  checkOrder(guid1, guid3, guid2);
 
   // test live update
   do_print("Change bookmark uri liveupdate");
-  PlacesUtils.bookmarks.changeBookmarkURI(id1, uri2);
-  checkOrder(id3, id1, id2);
-  PlacesUtils.bookmarks.changeBookmarkURI(id1, uri1);
-  checkOrder(id1, id3, id2);
+  await PlacesUtils.bookmarks.update({
+    guid: guid1,
+    url: uri2,
+  });
+  checkOrder(guid3, guid1, guid2);
+  await PlacesUtils.bookmarks.update({
+    guid: guid1,
+    url: uri1,
+  });
+  checkOrder(guid1, guid3, guid2);
 
   // keyword sort
   do_print("Sort by keyword asc");
   result.sortingMode = NHQO.SORT_BY_KEYWORD_ASCENDING;
-  checkOrder(id3, id2, id1);  // no keywords set - falling back to title sort
-  await PlacesUtils.keywords.insert({ url: uri1.spec, keyword: "a" });
-  await PlacesUtils.keywords.insert({ url: uri2.spec, keyword: "z" });
-  checkOrder(id3, id1, id2);
+  checkOrder(guid3, guid2, guid1);  // no keywords set - falling back to title sort
+  await PlacesUtils.keywords.insert({ url: uri1, keyword: "a" });
+  await PlacesUtils.keywords.insert({ url: uri2, keyword: "z" });
+  checkOrder(guid3, guid1, guid2);
 
   // XXXtodo: test history sortings (visit count, visit date)
   // XXXtodo: test different item types once folderId and bookmarkId are merged.
   // XXXtodo: test sortingAnnotation functionality with non-bookmark nodes
 
   do_print("Sort by annotation desc");
-  PlacesUtils.annotations.setItemAnnotation(id1, "testAnno", "a", 0, 0);
-  PlacesUtils.annotations.setItemAnnotation(id3, "testAnno", "b", 0, 0);
+  let ids = await PlacesUtils.promiseManyItemIds([guid1, guid3]);
+  PlacesUtils.annotations.setItemAnnotation(ids.get(guid1), "testAnno", "a", 0, 0);
+  PlacesUtils.annotations.setItemAnnotation(ids.get(guid3), "testAnno", "b", 0, 0);
   result.sortingAnnotation = "testAnno";
   result.sortingMode = NHQO.SORT_BY_ANNOTATION_DESCENDING;
 
-  // id1 precedes id2 per title-descending fallback
-  checkOrder(id3, id1, id2);
+  // guid1 precedes guid2 per title-descending fallback
+  checkOrder(guid3, guid1, guid2);
 
   // XXXtodo:  test dateAdded sort
   // XXXtodo:  test lastModified sort
 
   // test live update
   do_print("Annotation liveupdate");
-  PlacesUtils.annotations.setItemAnnotation(id1, "testAnno", "c", 0, 0);
-  checkOrder(id1, id3, id2);
+  PlacesUtils.annotations.setItemAnnotation(ids.get(guid1), "testAnno", "c", 0, 0);
+  checkOrder(guid1, guid3, guid2);
 
   // Add a visit, then check frecency ordering.
 
   // When the bookmarks service gets onVisit, it asynchronously fetches all
   // items for that visit, and then notifies onItemVisited.  Thus we must
   // explicitly wait for that.
   let waitForVisited = promiseOnItemVisited();
   await PlacesTestUtils.addVisits({ uri: uri2, transition: TRANSITION_TYPED });
   await waitForVisited;
 
   do_print("Sort by frecency desc");
   result.sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING;
   for (let i = 0; i < root.childCount; ++i) {
     print(root.getChild(i).uri + " " + root.getChild(i).title);
   }
-  // For id1 and id3, since they have same frecency and no visits, fallback
+  // For guid1 and guid3, since they have same frecency and no visits, fallback
   // to sort by the newest bookmark.
-  checkOrder(id2, id3, id1);
+  checkOrder(guid2, guid3, guid1);
   do_print("Sort by frecency asc");
   result.sortingMode = NHQO.SORT_BY_FRECENCY_ASCENDING;
   for (let i = 0; i < root.childCount; ++i) {
     print(root.getChild(i).uri + " " + root.getChild(i).title);
   }
-  checkOrder(id1, id3, id2);
+  checkOrder(guid1, guid3, guid2);
 
   root.containerOpen = false;
 });