Bug 1415835 - Convert xpcshell-tests in toolkit/components/places/tests/bookmarks to Bookmarks.jsm API. r?mak draft
authorMark Banner <standard8@mozilla.com>
Mon, 06 Nov 2017 18:34:13 +0000
changeset 695574 c8c928f70615517db90392de4d195e23a99741a1
parent 695523 d16b52f5d1955192c42c7b5c5da4e05a7dffef27
child 739644 7f0755f24b44e22977d9f6fcac4ee8e3dabf8275
push id88471
push userbmo:standard8@mozilla.com
push dateThu, 09 Nov 2017 13:39:24 +0000
reviewersmak
bugs1415835
milestone58.0a1
Bug 1415835 - Convert xpcshell-tests in toolkit/components/places/tests/bookmarks to Bookmarks.jsm API. r?mak MozReview-Commit-ID: 3HB47rMkpuy
toolkit/components/places/tests/bookmarks/test_395593.js
toolkit/components/places/tests/bookmarks/test_448584.js
toolkit/components/places/tests/bookmarks/test_458683.js
toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js
toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js
toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js
toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js
toolkit/components/places/tests/bookmarks/test_savedsearches.js
--- a/toolkit/components/places/tests/bookmarks/test_395593.js
+++ b/toolkit/components/places/tests/bookmarks/test_395593.js
@@ -1,69 +1,76 @@
 /* -*- 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/. */
 
 
-var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-         getService(Ci.nsINavBookmarksService);
-var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
-         getService(Ci.nsINavHistoryService);
-
-function check_queries_results(aQueries, aOptions, aExpectedItemIds) {
-  var result = hs.executeQueries(aQueries, aQueries.length, aOptions);
+function check_queries_results(aQueries, aOptions, aExpectedBookmarks) {
+  var result = PlacesUtils.history.executeQueries(aQueries, aQueries.length, aOptions);
   var root = result.root;
   root.containerOpen = true;
 
   // Dump found nodes.
   for (let i = 0; i < root.childCount; i++) {
     dump("nodes[" + i + "]: " + root.getChild(0).title + "\n");
   }
 
-  do_check_eq(root.childCount, aExpectedItemIds.length);
+  do_check_eq(root.childCount, aExpectedBookmarks.length);
   for (let i = 0; i < root.childCount; i++) {
-    do_check_eq(root.getChild(i).itemId, aExpectedItemIds[i]);
+    do_check_eq(root.getChild(i).bookmarkGuid, aExpectedBookmarks[i].guid);
   }
 
   root.containerOpen = false;
 }
 
 // main
-function run_test() {
-  var id1 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
-                              bs.DEFAULT_INDEX, "123 0");
-  var id2 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
-                              bs.DEFAULT_INDEX, "456");
-  var id3 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
-                              bs.DEFAULT_INDEX, "123 456");
-  var id4 = bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://foo.tld"),
-                              bs.DEFAULT_INDEX, "789 456");
+add_task(async function run_test() {
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "123 0",
+      url: "http://foo.tld",
+    }, {
+      title: "456",
+      url: "http://foo.tld",
+    }, {
+      title: "123 456",
+      url: "http://foo.tld",
+    }, {
+      title: "789 456",
+      url: "http://foo.tld",
+    }]
+  });
 
   /**
    * All of the query objects are ORed together. Within a query, all the terms
    * are ANDed together. See nsINavHistory.idl.
    */
   var queries = [];
-  queries.push(hs.getNewQuery());
-  queries.push(hs.getNewQuery());
-  var options = hs.getNewQueryOptions();
+  queries.push(PlacesUtils.history.getNewQuery());
+  queries.push(PlacesUtils.history.getNewQuery());
+  var options = PlacesUtils.history.getNewQueryOptions();
   options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
 
   // Test 1
   dump("Test searching for 123 OR 789\n");
   queries[0].searchTerms = "123";
   queries[1].searchTerms = "789";
-  check_queries_results(queries, options, [id1, id3, id4]);
+  check_queries_results(queries, options, [
+    bookmarks[0],
+    bookmarks[2],
+    bookmarks[3]
+  ]);
 
   // Test 2
   dump("Test searching for 123 OR 456\n");
   queries[0].searchTerms = "123";
   queries[1].searchTerms = "456";
-  check_queries_results(queries, options, [id1, id2, id3, id4]);
+  check_queries_results(queries, options, bookmarks);
 
   // Test 3
   dump("Test searching for 00 OR 789\n");
   queries[0].searchTerms = "00";
   queries[1].searchTerms = "789";
-  check_queries_results(queries, options, [id4]);
-}
+  check_queries_results(queries, options, [bookmarks[3]]);
+});
--- a/toolkit/components/places/tests/bookmarks/test_448584.js
+++ b/toolkit/components/places/tests/bookmarks/test_448584.js
@@ -1,108 +1,89 @@
 /* -*- 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/. */
 
-var tests = [];
-
 // Get database connection
 try {
   var mDBConn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
                                    .DBConnection;
 } catch (ex) {
   do_throw("Could not get database connection\n");
 }
 
 /*
   This test is:
     - don't try to add invalid uri nodes to a JSON backup
 */
 
-var invalidURITest = {
-  _itemTitle: "invalid uri",
-  _itemUrl: "http://test.mozilla.org/",
-  _itemId: null,
+const ITEM_TITLE = "invalid uri";
+const ITEM_URL = "http://test.mozilla.org";
 
-  populate() {
-    // add a valid bookmark
-    PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
-                                         PlacesUtils._uri(this._itemUrl),
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                         this._itemTitle);
-    // this bookmark will go corrupt
-    this._itemId =
-      PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
-                                           PlacesUtils._uri(this._itemUrl),
-                                           PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                           this._itemTitle);
-  },
+function validateResults(expectedValidItemsCount) {
+  var query = PlacesUtils.history.getNewQuery();
+  query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
+  var options = PlacesUtils.history.getNewQueryOptions();
+  var result = PlacesUtils.history.executeQuery(query, options);
 
-  clean() {
-    PlacesUtils.bookmarks.removeItem(this._itemId);
-  },
+  var toolbar = result.root;
+  toolbar.containerOpen = true;
 
-  validate(aExpectValidItemsCount) {
-    var query = PlacesUtils.history.getNewQuery();
-    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
-    var options = PlacesUtils.history.getNewQueryOptions();
-    var result = PlacesUtils.history.executeQuery(query, options);
-
-    var toolbar = result.root;
-    toolbar.containerOpen = true;
+  // test for our bookmark
+  do_check_eq(toolbar.childCount, expectedValidItemsCount);
+  for (var i = 0; i < toolbar.childCount; i++) {
+    var folderNode = toolbar.getChild(0);
+    do_check_eq(folderNode.type, folderNode.RESULT_TYPE_URI);
+    do_check_eq(folderNode.title, ITEM_TITLE);
+  }
 
-    // test for our bookmark
-    do_check_eq(toolbar.childCount, aExpectValidItemsCount);
-    for (var i = 0; i < toolbar.childCount; i++) {
-      var folderNode = toolbar.getChild(0);
-      do_check_eq(folderNode.type, folderNode.RESULT_TYPE_URI);
-      do_check_eq(folderNode.title, this._itemTitle);
-    }
-
-    // clean up
-    toolbar.containerOpen = false;
-  }
-};
-tests.push(invalidURITest);
+  // clean up
+  toolbar.containerOpen = false;
+}
 
 add_task(async function() {
   // make json file
   let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json");
 
   // populate db
-  tests.forEach(function(aTest) {
-    aTest.populate();
-    // sanity
-    aTest.validate(2);
-    // Something in the code went wrong and we finish up losing the place, so
-    // the bookmark uri becomes null.
-    var sql = "UPDATE moz_bookmarks SET fk = 1337 WHERE id = ?1";
-    var stmt = mDBConn.createStatement(sql);
-    stmt.bindByIndex(0, aTest._itemId);
-    try {
-      stmt.execute();
-    } finally {
-      stmt.finalize();
-    }
+  // add a valid bookmark
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: ITEM_TITLE,
+    url: ITEM_URL,
+  });
+
+  let badBookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: ITEM_TITLE,
+    url: ITEM_URL,
   });
+  // sanity
+  validateResults(2);
+  // Something in the code went wrong and we finish up losing the place, so
+  // the bookmark uri becomes null.
+  var sql = "UPDATE moz_bookmarks SET fk = 1337 WHERE guid = ?1";
+  var stmt = mDBConn.createStatement(sql);
+  stmt.bindByIndex(0, badBookmark.guid);
+  try {
+    stmt.execute();
+  } finally {
+    stmt.finalize();
+  }
 
   await BookmarkJSONUtils.exportToFile(jsonFile);
 
   // clean
-  tests.forEach(function(aTest) {
-    aTest.clean();
-  });
+  await PlacesUtils.bookmarks.remove(badBookmark);
 
   // restore json file
   try {
     await BookmarkJSONUtils.importFromFile(jsonFile, true);
   } catch (ex) { do_throw("couldn't import the exported file: " + ex); }
 
   // validate
-  tests.forEach(function(aTest) {
-    aTest.validate(1);
-  });
+  validateResults(1);
 
   // clean up
   await OS.File.remove(jsonFile);
 });
--- a/toolkit/components/places/tests/bookmarks/test_458683.js
+++ b/toolkit/components/places/tests/bookmarks/test_458683.js
@@ -1,118 +1,98 @@
 /* -*- 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/. */
 
-var tests = [];
-
 /*
   This test is:
     - don't block while doing backup and restore if tag containers contain
       bogus items (separators, folders)
 */
 
-var invalidTagChildTest = {
-  _itemTitle: "invalid uri",
-  _itemUrl: "http://test.mozilla.org/",
-  _itemId: -1,
-  _tag: "testTag",
-  _tagItemId: -1,
-
-  populate() {
-    // add a valid bookmark
-    this._itemId = PlacesUtils.bookmarks
-                              .insertBookmark(PlacesUtils.toolbarFolderId,
-                                              PlacesUtils._uri(this._itemUrl),
-                                              PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                              this._itemTitle);
+const ITEM_TITLE = "invalid uri";
+const ITEM_URL = "http://test.mozilla.org/";
+const TAG_NAME = "testTag";
 
-    // create a tag
-    PlacesUtils.tagging.tagURI(PlacesUtils._uri(this._itemUrl), [this._tag]);
-    // get tag folder id
-    var options = PlacesUtils.history.getNewQueryOptions();
-    var query = PlacesUtils.history.getNewQuery();
-    query.setFolders([PlacesUtils.bookmarks.tagsFolder], 1);
-    var result = PlacesUtils.history.executeQuery(query, options);
-    var tagRoot = result.root;
-    tagRoot.containerOpen = true;
-    do_check_eq(tagRoot.childCount, 1);
-    var tagNode = tagRoot.getChild(0)
-                          .QueryInterface(Ci.nsINavHistoryContainerResultNode);
-    this._tagItemId = tagNode.itemId;
-    tagRoot.containerOpen = false;
+function validateResults() {
+  var query = PlacesUtils.history.getNewQuery();
+  query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
+  var options = PlacesUtils.history.getNewQueryOptions();
+  var result = PlacesUtils.history.executeQuery(query, options);
 
-    // add a separator and a folder inside tag folder
-    PlacesUtils.bookmarks.insertSeparator(this._tagItemId,
-                                         PlacesUtils.bookmarks.DEFAULT_INDEX);
-    PlacesUtils.bookmarks.createFolder(this._tagItemId,
-                                       "test folder",
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX);
+  var toolbar = result.root;
+  toolbar.containerOpen = true;
 
-    // add a separator and a folder inside tag root
-    PlacesUtils.bookmarks.insertSeparator(PlacesUtils.bookmarks.tagsFolder,
-                                          PlacesUtils.bookmarks.DEFAULT_INDEX);
-    PlacesUtils.bookmarks.createFolder(PlacesUtils.bookmarks.tagsFolder,
-                                       "test tags root folder",
-                                       PlacesUtils.bookmarks.DEFAULT_INDEX);
-  },
-
-  clean() {
-    PlacesUtils.tagging.untagURI(PlacesUtils._uri(this._itemUrl), [this._tag]);
-    PlacesUtils.bookmarks.removeItem(this._itemId);
-  },
-
-  validate() {
-    var query = PlacesUtils.history.getNewQuery();
-    query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
-    var options = PlacesUtils.history.getNewQueryOptions();
-    var result = PlacesUtils.history.executeQuery(query, options);
+  // test for our bookmark
+  do_check_eq(toolbar.childCount, 1);
+  for (var i = 0; i < toolbar.childCount; i++) {
+    var folderNode = toolbar.getChild(0);
+    do_check_eq(folderNode.type, folderNode.RESULT_TYPE_URI);
+    do_check_eq(folderNode.title, ITEM_TITLE);
+  }
+  toolbar.containerOpen = false;
 
-    var toolbar = result.root;
-    toolbar.containerOpen = true;
-
-    // test for our bookmark
-    do_check_eq(toolbar.childCount, 1);
-    for (var i = 0; i < toolbar.childCount; i++) {
-      var folderNode = toolbar.getChild(0);
-      do_check_eq(folderNode.type, folderNode.RESULT_TYPE_URI);
-      do_check_eq(folderNode.title, this._itemTitle);
-    }
-    toolbar.containerOpen = false;
-
-    // test for our tag
-    var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(this._itemUrl));
-    do_check_eq(tags.length, 1);
-    do_check_eq(tags[0], this._tag);
-  }
-};
-tests.push(invalidTagChildTest);
+  // test for our tag
+  var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(ITEM_URL));
+  do_check_eq(tags.length, 1);
+  do_check_eq(tags[0], TAG_NAME);
+}
 
 add_task(async function() {
   let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json");
 
-  // populate db
-  tests.forEach(function(aTest) {
-    aTest.populate();
-    // sanity
-    aTest.validate();
+  // add a valid bookmark
+  let item = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: ITEM_TITLE,
+    url: ITEM_URL,
   });
 
+  // create a tag
+  PlacesUtils.tagging.tagURI(PlacesUtils._uri(ITEM_URL), [TAG_NAME]);
+  // get tag folder id
+  var options = PlacesUtils.history.getNewQueryOptions();
+  var query = PlacesUtils.history.getNewQuery();
+  query.setFolders([PlacesUtils.bookmarks.tagsFolder], 1);
+  var result = PlacesUtils.history.executeQuery(query, options);
+  var tagRoot = result.root;
+  tagRoot.containerOpen = true;
+  do_check_eq(tagRoot.childCount, 1);
+  var tagNode = tagRoot.getChild(0)
+                        .QueryInterface(Ci.nsINavHistoryContainerResultNode);
+  let tagItemId = tagNode.itemId;
+  tagRoot.containerOpen = false;
+
+  // Currently these use the old API as the new API doesn't support inserting
+  // invalid items into the tag folder.
+
+  // add a separator and a folder inside tag folder
+  PlacesUtils.bookmarks.insertSeparator(tagItemId,
+                                       PlacesUtils.bookmarks.DEFAULT_INDEX);
+  PlacesUtils.bookmarks.createFolder(tagItemId,
+                                     "test folder",
+                                     PlacesUtils.bookmarks.DEFAULT_INDEX);
+
+  // add a separator and a folder inside tag root
+  PlacesUtils.bookmarks.insertSeparator(PlacesUtils.bookmarks.tagsFolder,
+                                        PlacesUtils.bookmarks.DEFAULT_INDEX);
+  PlacesUtils.bookmarks.createFolder(PlacesUtils.bookmarks.tagsFolder,
+                                     "test tags root folder",
+                                     PlacesUtils.bookmarks.DEFAULT_INDEX);
+  // sanity
+  validateResults();
+
   await BookmarkJSONUtils.exportToFile(jsonFile);
 
   // clean
-  tests.forEach(function(aTest) {
-    aTest.clean();
-  });
+  PlacesUtils.tagging.untagURI(PlacesUtils._uri(ITEM_URL), [TAG_NAME]);
+  await PlacesUtils.bookmarks.remove(item);
 
   // restore json file
   await BookmarkJSONUtils.importFromFile(jsonFile, true);
 
-  // validate
-  tests.forEach(function(aTest) {
-    aTest.validate();
-  });
+  validateResults();
 
   // clean up
   await OS.File.remove(jsonFile);
 });
--- a/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js
+++ b/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js
@@ -29,27 +29,29 @@ add_task(async function() {
   do_check_eq(backupFiles.length, 1);
 
   let matches = OS.Path.basename(backupFiles[0]).match(PlacesBackups.filenamesRegex);
   do_check_eq(matches[1], PlacesBackups.toISODateString(new Date()));
   do_check_eq(matches[2], count);
   do_check_eq(matches[3], hash);
 
   // Add a bookmark and create another backup.
-  let bookmarkId = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder,
-                                                        uri("http://foo.com"),
-                                                        PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                        "foo");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: "foo",
+    url: "http://foo.com",
+  });
+
   // We must enforce a backup since one for today already exists.  The forced
   // backup will replace the existing one.
   await PlacesBackups.create(undefined, true);
   do_check_eq(backupFiles.length, 1);
   let recentBackup = await PlacesBackups.getMostRecentBackup();
   do_check_neq(recentBackup, OS.Path.join(backupFolder, oldBackupName));
   matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex);
   do_check_eq(matches[1], PlacesBackups.toISODateString(new Date()));
   do_check_eq(matches[2], count + 1);
   do_check_neq(matches[3], hash);
 
   // Clean up
-  PlacesUtils.bookmarks.removeItem(bookmarkId);
+  await PlacesUtils.bookmarks.remove(bookmark);
   await PlacesBackups.create(0);
 });
--- a/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js
+++ b/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js
@@ -25,29 +25,30 @@ add_task(async function compress_bookmar
 
   // Check that, if the user created a custom backup out of the default
   // backups folder, it gets copied (compressed) into it.
   let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json");
   await PlacesBackups.saveBookmarksToJSONFile(jsonFile);
   do_check_eq((await PlacesBackups.getBackupFiles()).length, 1);
 
   // Check if import works from lz4 compressed json
-  let uri = NetUtil.newURI("http://www.mozilla.org/en-US/");
-  let bm  = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                                 uri,
-                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                 "bookmark");
+  let url = "http://www.mozilla.org/en-US/"
+  let bm = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    title: "bookmark",
+    url,
+  });
 
   // Force create a compressed backup, Remove the bookmark, the restore the backup
   await PlacesBackups.create(undefined, true);
   let recentBackup = await PlacesBackups.getMostRecentBackup();
-  PlacesUtils.bookmarks.removeItem(bm);
+  await PlacesUtils.bookmarks.remove(bm);
   await BookmarkJSONUtils.importFromFile(recentBackup, true);
   let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
   let node = root.getChild(0);
-  do_check_eq(node.uri, uri.spec);
+  do_check_eq(node.uri, url);
 
   root.containerOpen = false;
   PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
 
   // Cleanup.
   await OS.File.remove(jsonFile);
 });
--- a/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js
+++ b/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js
@@ -3,21 +3,21 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * To confirm that metadata i.e. bookmark count is set and retrieved for
  * automatic backups.
  */
 add_task(async function test_saveBookmarksToJSONFile_and_create() {
   // Add a bookmark
-  let uri = NetUtil.newURI("http://getfirefox.com/");
-  let bookmarkId =
-    PlacesUtils.bookmarks.insertBookmark(
-      PlacesUtils.unfiledBookmarksFolderId, uri,
-      PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    title: "Get Firefox!",
+    url: "http://getfirefox.com/"
+  });
 
   // Test saveBookmarksToJSONFile()
   let backupFile = FileUtils.getFile("TmpD", ["bookmarks.json"]);
   backupFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0600", 8));
 
   let nodeCount = await PlacesBackups.saveBookmarksToJSONFile(backupFile, true);
   do_check_true(nodeCount > 0);
   do_check_true(backupFile.exists());
@@ -42,10 +42,10 @@ add_task(async function test_saveBookmar
   do_check_neq(mostRecentBackupFile, null);
   matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex);
   do_check_eq(matches[2], nodeCount);
   do_check_eq(matches[3].length, 24);
 
   // Cleanup
   backupFile.remove(false);
   await PlacesBackups.create(0);
-  PlacesUtils.bookmarks.removeItem(bookmarkId);
+  await PlacesUtils.bookmarks.remove(bookmark);
 });
--- a/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
+++ b/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
@@ -3,42 +3,54 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * Checks that backups properly include all of the bookmarks if the hierarchy
  * in the database is unordered so that a hierarchy is defined before its
  * ancestor in the bookmarks table.
  */
 add_task(async function() {
-  let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                                NetUtil.newURI("http://mozilla.org/"),
-                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                "bookmark");
-  let f2 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f2",
-                                              PlacesUtils.bookmarks.DEFAULT_INDEX);
-  PlacesUtils.bookmarks.moveItem(bm, f2, PlacesUtils.bookmarks.DEFAULT_INDEX);
-  let f1 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f1",
-                                              PlacesUtils.bookmarks.DEFAULT_INDEX);
-  PlacesUtils.bookmarks.moveItem(f2, f1, PlacesUtils.bookmarks.DEFAULT_INDEX);
+  let bms = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.unfiledGuid,
+    children: [{
+      title: "bookmark",
+      url: "http://mozilla.org",
+    }, {
+      title: "f2",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    }, {
+      title: "f1",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    }]
+  });
+
+  let bookmark = bms[0];
+  let folder2 = bms[1];
+  let folder1 = bms[2];
+  bookmark.parentGuid = folder2.guid;
+  await PlacesUtils.bookmarks.update(bookmark);
+
+  folder2.parentGuid = folder1.guid;
+  await PlacesUtils.bookmarks.update(folder2);
 
   // Create a backup.
   await PlacesBackups.create();
 
   // Remove the bookmarks, then restore the backup.
-  PlacesUtils.bookmarks.removeItem(f1);
+  await PlacesUtils.bookmarks.remove(folder1);
   await BookmarkJSONUtils.importFromFile((await PlacesBackups.getMostRecentBackup()), true);
 
   do_print("Checking first level");
   let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
   let level1 = root.getChild(0);
   do_check_eq(level1.title, "f1");
   do_print("Checking second level");
   PlacesUtils.asContainer(level1).containerOpen = true;
   let level2 = level1.getChild(0);
   do_check_eq(level2.title, "f2");
   do_print("Checking bookmark");
   PlacesUtils.asContainer(level2).containerOpen = true;
-  let bookmark = level2.getChild(0);
+  bookmark = level2.getChild(0);
   do_check_eq(bookmark.title, "bookmark");
   level2.containerOpen = false;
   level1.containerOpen = false;
   root.containerOpen = false;
 });
--- a/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js
+++ b/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js
@@ -1,32 +1,33 @@
 /* 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/. */
 
 /**
  * Checks that we don't encodeURI twice when creating bookmarks.html.
  */
 add_task(async function() {
-  let uri = NetUtil.newURI("http://bt.ktxp.com/search.php?keyword=%E5%A6%84%E6%83%B3%E5%AD%A6%E7%94%9F%E4%BC%9A");
-  let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                                uri,
-                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                "bookmark");
+  let url = "http://bt.ktxp.com/search.php?keyword=%E5%A6%84%E6%83%B3%E5%AD%A6%E7%94%9F%E4%BC%9A";
+  let bm = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    title: "bookmark",
+    url,
+  });
 
-  let file =  OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.exported.997030.html");
+  let file = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.exported.997030.html");
   if ((await OS.File.exists(file))) {
     await OS.File.remove(file);
   }
   await BookmarkHTMLUtils.exportToFile(file);
 
   // Remove the bookmarks, then restore the backup.
-  PlacesUtils.bookmarks.removeItem(bm);
+  await PlacesUtils.bookmarks.remove(bm);
   await BookmarkHTMLUtils.importFromFile(file, true);
 
   do_print("Checking first level");
   let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
   let node = root.getChild(0);
-  do_check_eq(node.uri, uri.spec);
+  do_check_eq(node.uri, url);
 
   root.containerOpen = false;
-  PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
+  await PlacesUtils.bookmarks.eraseEverything();
 });
--- a/toolkit/components/places/tests/bookmarks/test_savedsearches.js
+++ b/toolkit/components/places/tests/bookmarks/test_savedsearches.js
@@ -1,51 +1,54 @@
 /* -*- 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/. */
 
-// get bookmarks root id
-var root = PlacesUtils.bookmarksMenuFolderId;
-
 // a search term that matches a default bookmark
 const searchTerm = "about";
 
 var testRoot;
+var testRootId;
 
-// main
-function run_test() {
+add_task(async function setup() {
   // create a folder to hold all the tests
   // this makes the tests more tolerant of changes to the default bookmarks set
   // also, name it using the search term, for testing that containers that match don't show up in query results
-  testRoot = PlacesUtils.bookmarks.createFolder(
-    root, searchTerm, PlacesUtils.bookmarks.DEFAULT_INDEX);
-
-  run_next_test();
-}
+  testRoot = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: searchTerm,
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+  });
+  testRootId = await PlacesUtils.promiseItemId(testRoot.guid);
+});
 
-add_test(function test_savedsearches_bookmarks() {
+add_task(async function test_savedsearches_bookmarks() {
   // add a bookmark that matches the search term
-  var bookmarkId = PlacesUtils.bookmarks.insertBookmark(
-    root, uri("http://foo.com"), PlacesUtils.bookmarks.DEFAULT_INDEX,
-    searchTerm);
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: searchTerm,
+    url: "http://foo.com",
+  });
 
   // create a saved-search that matches a default bookmark
-  var searchId = PlacesUtils.bookmarks.insertBookmark(
-    testRoot, uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
+  let search = await PlacesUtils.bookmarks.insert({
+    parentGuid: testRoot.guid,
+    title: searchTerm,
+    url: "place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1",
+  });
 
   // query for the test root, expandQueries=0
   // the query should show up as a regular bookmark
   try {
     let options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 0;
     let query = PlacesUtils.history.getNewQuery();
-    query.setFolders([testRoot], 1);
+    query.setFolders([testRootId], 1);
     let result = PlacesUtils.history.executeQuery(query, options);
     let rootNode = result.root;
     rootNode.containerOpen = true;
     let cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (let i = 0; i < cc; i++) {
       let node = rootNode.getChild(i);
       // test that queries have valid itemId
@@ -61,17 +64,17 @@ add_test(function test_savedsearches_boo
 
   // bookmark saved search
   // query for the test root, expandQueries=1
   // the query should show up as a query container, with 1 child
   try {
     let options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 1;
     let query = PlacesUtils.history.getNewQuery();
-    query.setFolders([testRoot], 1);
+    query.setFolders([testRootId], 1);
     let result = PlacesUtils.history.executeQuery(query, options);
     let rootNode = result.root;
     rootNode.containerOpen = true;
     let cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (let i = 0; i < cc; i++) {
       let node = rootNode.getChild(i);
       // test that query node type is container when expandQueries=1
@@ -83,77 +86,82 @@ add_test(function test_savedsearches_boo
 
       // test that queries have children when excludeItems=1
       // test that query nodes don't show containers (shouldn't have our folder that matches)
       // test that queries don't show themselves in query results (shouldn't have our saved search)
       do_check_eq(node.childCount, 1);
 
       // test that bookmark shows in query results
       var item = node.getChild(0);
-      do_check_eq(item.itemId, bookmarkId);
+      do_check_eq(item.bookmarkGuid, bookmark.guid);
 
       // XXX - FAILING - test live-update of query results - add a bookmark that matches the query
       // var tmpBmId = PlacesUtils.bookmarks.insertBookmark(
       //  root, uri("http://" + searchTerm + ".com"),
       //  PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah");
       // do_check_eq(query.childCount, 2);
 
       // XXX - test live-update of query results - delete a bookmark that matches the query
       // PlacesUtils.bookmarks.removeItem(tmpBMId);
       // do_check_eq(query.childCount, 1);
 
       // test live-update of query results - add a folder that matches the query
-      PlacesUtils.bookmarks.createFolder(
-        root, searchTerm + "zaa", PlacesUtils.bookmarks.DEFAULT_INDEX);
+      await PlacesUtils.bookmarks.insert({
+        parentGuid: PlacesUtils.bookmarks.menuGuid,
+        title: searchTerm + "zaa",
+        type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      });
       do_check_eq(node.childCount, 1);
       // test live-update of query results - add a query that matches the query
-      PlacesUtils.bookmarks.insertBookmark(
-        root, uri("place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1"),
-        PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah");
+      await PlacesUtils.bookmarks.insert({
+        parentGuid: PlacesUtils.bookmarks.menuGuid,
+        title: searchTerm + "blah",
+        url: "place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1",
+      });
       do_check_eq(node.childCount, 1);
     }
     rootNode.containerOpen = false;
   } catch (ex) {
     do_throw("expandQueries=1 bookmarks query: " + ex);
   }
 
   // delete the bookmark search
-  PlacesUtils.bookmarks.removeItem(searchId);
-
-  run_next_test();
+  await PlacesUtils.bookmarks.remove(search);
 });
 
 add_task(async function test_savedsearches_history() {
   // add a visit that matches the search term
   var testURI = uri("http://" + searchTerm + ".com");
   await PlacesTestUtils.addVisits({ uri: testURI, title: searchTerm });
 
   // create a saved-search that matches the visit we added
-  var searchId = PlacesUtils.bookmarks.insertBookmark(testRoot,
-    uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"),
-    PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
+  var searchItem = await PlacesUtils.bookmarks.insert({
+    parentGuid: testRoot.guid,
+    title: searchTerm,
+    url: "place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0",
+  });
 
   // query for the test root, expandQueries=1
   // the query should show up as a query container, with 1 child
   try {
     var options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 1;
     var query = PlacesUtils.history.getNewQuery();
-    query.setFolders([testRoot], 1);
+    query.setFolders([testRootId], 1);
     var result = PlacesUtils.history.executeQuery(query, options);
     var rootNode = result.root;
     rootNode.containerOpen = true;
     var cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (var i = 0; i < cc; i++) {
       var node = rootNode.getChild(i);
       // test that query node type is container when expandQueries=1
       do_check_eq(node.type, node.RESULT_TYPE_QUERY);
       // test that queries (as containers) have valid itemId
-      do_check_eq(node.itemId, searchId);
+      do_check_eq(node.bookmarkGuid, searchItem.guid);
       node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
       node.containerOpen = true;
 
       // test that queries have children when excludeItems=1
       // test that query nodes don't show containers (shouldn't have our folder that matches)
       // test that queries don't show themselves in query results (shouldn't have our saved search)
       do_check_eq(node.childCount, 1);
 
@@ -172,35 +180,38 @@ add_task(async function test_savedsearch
 
       // test live-update of query results - delete a history visit that matches the query
       await PlacesUtils.history.remove("http://foo.com");
       do_check_eq(node.childCount, 1);
       node.containerOpen = false;
     }
 
     // test live-update of moved queries
-    var tmpFolderId = PlacesUtils.bookmarks.createFolder(
-      testRoot, "foo", PlacesUtils.bookmarks.DEFAULT_INDEX);
-    PlacesUtils.bookmarks.moveItem(
-      searchId, tmpFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX);
+    let tmpFolder = await PlacesUtils.bookmarks.insert({
+      parentGuid: testRoot.guid,
+      title: "foo",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    });
+
+    searchItem.parentGuid = tmpFolder.guid;
+    await PlacesUtils.bookmarks.update(searchItem);
     var tmpFolderNode = rootNode.getChild(0);
-    do_check_eq(tmpFolderNode.itemId, tmpFolderId);
+    do_check_eq(tmpFolderNode.bookmarkGuid, tmpFolder.guid);
     tmpFolderNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
     tmpFolderNode.containerOpen = true;
     do_check_eq(tmpFolderNode.childCount, 1);
 
     // test live-update of renamed queries
-    PlacesUtils.bookmarks.setItemTitle(searchId, "foo");
+    searchItem.title = "foo";
+    await PlacesUtils.bookmarks.update(searchItem);
     do_check_eq(tmpFolderNode.title, "foo");
 
     // test live-update of deleted queries
-    PlacesUtils.bookmarks.removeItem(searchId);
-    try {
-      tmpFolderNode = root.getChild(1);
-      do_throw("query was not removed");
-    } catch (ex) {}
+    await PlacesUtils.bookmarks.remove(searchItem);
+    Assert.throws(() => tmpFolderNode = rootNode.getChild(1), /NS_ERROR_ILLEGAL_VALUE/,
+      "getting a deleted child should throw");
 
     tmpFolderNode.containerOpen = false;
     rootNode.containerOpen = false;
   } catch (ex) {
     do_throw("expandQueries=1 bookmarks query: " + ex);
   }
 });