Bug 1376234 - Convert more xpcshell-tests in toolkit/components/places/tests/unit to async Bookmarks.jsm API. r?mak draft
authorMark Banner <standard8@mozilla.com>
Mon, 26 Jun 2017 12:52:29 -0700
changeset 600968 1b01250b07522ccd0231b46a28379241eb2b31ff
parent 600967 40959cc46f0e1d5fecd4c101aa43a94e111120f2
child 635142 a546ef61f634c7c295221da7119cb2d1940e9ec7
push id65927
push userbmo:standard8@mozilla.com
push dateTue, 27 Jun 2017 22:40:46 +0000
reviewersmak
bugs1376234
milestone56.0a1
Bug 1376234 - Convert more xpcshell-tests in toolkit/components/places/tests/unit to async Bookmarks.jsm API. r?mak MozReview-Commit-ID: FF7URaUt5fM
toolkit/components/places/tests/unit/test_resultsAsVisit_details.js
toolkit/components/places/tests/unit/test_telemetry.js
toolkit/components/places/tests/unit/test_update_frecency_after_delete.js
toolkit/components/places/tests/unit/test_utils_backups_create.js
toolkit/components/places/tests/unit/test_utils_getURLsForContainerNode.js
toolkit/components/places/tests/unit/test_utils_setAnnotationsFor.js
--- a/toolkit/components/places/tests/unit/test_resultsAsVisit_details.js
+++ b/toolkit/components/places/tests/unit/test_resultsAsVisit_details.js
@@ -1,12 +1,12 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 
-const {bookmarks, history} = PlacesUtils
+const {history} = PlacesUtils;
 
 add_task(async function test_addVisitCheckFields() {
   let uri = NetUtil.newURI("http://test4.com/");
   await PlacesTestUtils.addVisits([
     { uri },
     { uri, referrer: uri },
     { uri, transition: history.TRANSITION_TYPED },
   ]);
@@ -58,28 +58,38 @@ add_task(async function test_addVisitChe
   equal(child.fromVisitId, -1, "Referrer visit id should be -1");
 
   root.containerOpen = false;
 
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function test_bookmarkFields() {
-  let folder = bookmarks.createFolder(bookmarks.placesRoot, "test folder", bookmarks.DEFAULT_INDEX);
-  bookmarks.insertBookmark(folder, uri("http://test4.com/"),
-                           bookmarks.DEFAULT_INDEX, "test4 title");
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.unfiledGuid,
+    children: [{
+      title: "test folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        title: "test title",
+        url: "http://test4.com",
+      }]
+    }],
+  });
 
-  let root = PlacesUtils.getFolderContents(folder).root;
+  let folderId = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+
+  let root = PlacesUtils.getFolderContents(folderId).root;
   equal(root.childCount, 1);
 
   equal(root.visitType, 0, "Visit type should be 0");
   equal(root.visitId, -1, "Visit ID should be -1");
   equal(root.fromVisitId, -1, "Referrer visit id should be -1");
 
   let child = root.getChild(0);
   equal(child.visitType, 0, "Visit type should be 0");
   equal(child.visitId, -1, "Visit ID should be -1");
   equal(child.fromVisitId, -1, "Referrer visit id should be -1");
 
   root.containerOpen = false;
 
-  await bookmarks.eraseEverything();
+  await PlacesUtils.bookmarks.eraseEverything();
 });
--- a/toolkit/components/places/tests/unit/test_telemetry.js
+++ b/toolkit/components/places/tests/unit/test_telemetry.js
@@ -60,33 +60,41 @@ function getExpirablePRTime(daysAgo = 7)
   dateObj.setSeconds(0);
   dateObj.setMilliseconds(0);
   dateObj = new Date(dateObj.getTime() - (daysAgo + 1) * 86400000);
   return dateObj.getTime() * 1000;
 }
 
 add_task(async function test_execute() {
   // Put some trash in the database.
-  let uri = NetUtil.newURI("http://moz.org/");
+  let uri = Services.io.newURI("http://moz.org/");
 
-  let folderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
-                                                    "moz test",
-                                                    PlacesUtils.bookmarks.DEFAULT_INDEX);
-  let itemId = PlacesUtils.bookmarks.insertBookmark(folderId,
-                                                    uri,
-                                                    PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                    "moz test");
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.unfiledGuid,
+    children: [{
+      title: "moz test",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        title: "moz test",
+        url: uri,
+      }]
+    }],
+  });
+
   PlacesUtils.tagging.tagURI(uri, ["tag"]);
   await PlacesUtils.keywords.insert({ url: uri.spec, keyword: "keyword"});
 
   // Set a large annotation.
   let content = "";
   while (content.length < 1024) {
     content += "0";
   }
+
+  let itemId = await PlacesUtils.promiseItemId(bookmarks[1].guid);
+
   PlacesUtils.annotations.setItemAnnotation(itemId, "test-anno", content, 0,
                                             PlacesUtils.annotations.EXPIRE_NEVER);
   PlacesUtils.annotations.setPageAnnotation(uri, "test-anno", content, 0,
                                             PlacesUtils.annotations.EXPIRE_NEVER);
 
   // Request to gather telemetry data.
   Cc["@mozilla.org/places/categoriesStarter;1"]
     .getService(Ci.nsIObserver)
--- a/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js
+++ b/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js
@@ -10,17 +10,17 @@
  *
  * Ensures that the frecency of a bookmark's URI is what it should be after the
  * bookmark is deleted.
  */
 
 add_task(async function removed_bookmark() {
   do_print("After removing bookmark, frecency of bookmark's URI should be " +
            "zero if URI is unvisited and no longer bookmarked.");
-  const TEST_URI = NetUtil.newURI("http://example.com/1");
+  const TEST_URI = Services.io.newURI("http://example.com/1");
   let bm = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmark title",
     url: TEST_URI
   });
 
   await PlacesTestUtils.promiseAsyncUpdates();
   do_print("Bookmarked => frecency of URI should be != 0");
@@ -34,17 +34,17 @@ add_task(async function removed_bookmark
 
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function removed_but_visited_bookmark() {
   do_print("After removing bookmark, frecency of bookmark's URI should " +
            "not be zero if URI is visited.");
-  const TEST_URI = NetUtil.newURI("http://example.com/1");
+  const TEST_URI = Services.io.newURI("http://example.com/1");
   let bm = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmark title",
     url: TEST_URI
   });
 
   await PlacesTestUtils.promiseAsyncUpdates();
   do_print("Bookmarked => frecency of URI should be != 0");
@@ -59,17 +59,17 @@ add_task(async function removed_but_visi
 
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function remove_bookmark_still_bookmarked() {
   do_print("After removing bookmark, frecency of bookmark's URI should " +
            "not be zero if URI is still bookmarked.");
-  const TEST_URI = NetUtil.newURI("http://example.com/1");
+  const TEST_URI = Services.io.newURI("http://example.com/1");
   let bm1 = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmark 1 title",
     url: TEST_URI
   });
   await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmark 2 title",
@@ -88,17 +88,17 @@ add_task(async function remove_bookmark_
 
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function cleared_parent_of_visited_bookmark() {
   do_print("After removing all children from bookmark's parent, frecency " +
            "of bookmark's URI should not be zero if URI is visited.");
-  const TEST_URI = NetUtil.newURI("http://example.com/1");
+  const TEST_URI = Services.io.newURI("http://example.com/1");
   await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
     title: "bookmark title",
     url: TEST_URI
   });
 
   await PlacesTestUtils.promiseAsyncUpdates();
   do_print("Bookmarked => frecency of URI should be != 0");
@@ -114,17 +114,17 @@ add_task(async function cleared_parent_o
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesTestUtils.clearHistory();
 });
 
 add_task(async function cleared_parent_of_bookmark_still_bookmarked() {
   do_print("After removing all children from bookmark's parent, frecency " +
            "of bookmark's URI should not be zero if URI is still " +
            "bookmarked.");
-  const TEST_URI = NetUtil.newURI("http://example.com/1");
+  const TEST_URI = Services.io.newURI("http://example.com/1");
   await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     title: "bookmark 1 title",
     url: TEST_URI
   });
 
   let folder = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
--- a/toolkit/components/places/tests/unit/test_utils_backups_create.js
+++ b/toolkit/components/places/tests/unit/test_utils_backups_create.js
@@ -5,20 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
  /**
   * Check for correct functionality of bookmarks backups
   */
 
 const NUMBER_OF_BACKUPS = 10;
 
-function run_test() {
-  run_next_test();
-}
-
 add_task(async function() {
   // Generate random dates.
   let dateObj = new Date();
   let dates = [];
   while (dates.length < NUMBER_OF_BACKUPS) {
     // Use last year to ensure today's backup is the newest.
     let randomDate = new Date(dateObj.getFullYear() - 1,
                               Math.floor(12 * Math.random()),
--- a/toolkit/components/places/tests/unit/test_utils_getURLsForContainerNode.js
+++ b/toolkit/components/places/tests/unit/test_utils_getURLsForContainerNode.js
@@ -6,151 +6,224 @@
 
  /**
   * Check for correct functionality of PlacesUtils.getURLsForContainerNode and
   * PlacesUtils.hasChildURIs (those helpers share almost all of their code)
   */
 
 var PU = PlacesUtils;
 var hs = PU.history;
-var bs = PU.bookmarks;
 
-var tests = [
 
-function() {
-  dump("\n\n*** TEST: folder\n");
-  // This is the folder we will check for children.
-  var folderId = bs.createFolder(bs.toolbarFolder, "folder", bs.DEFAULT_INDEX);
-
-  // Create a folder and a query node inside it, these should not be considered
-  // uri nodes.
-  bs.createFolder(folderId, "inside folder", bs.DEFAULT_INDEX);
-  bs.insertBookmark(folderId, uri("place:sort=1"),
-                    bs.DEFAULT_INDEX, "inside query");
+add_task(async function test_getURLsForContainerNode_folder() {
+  do_print("*** TEST: folder");
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.toolbarGuid,
+    children: [{
+      // This is the folder we will check for children.
+      title: "folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      // Create a folder and a query node inside it, these should not be considered
+      // uri nodes.
+      children: [{
+        title: "inside folder",
+        type: PlacesUtils.bookmarks.TYPE_FOLDER,
+        children: [{
+          url: "place:sort=1",
+          title: "inside query",
+        }]
+      }]
+    }],
+  });
 
   var query = hs.getNewQuery();
-  query.setFolders([bs.toolbarFolder], 1);
+  query.setFolders([PlacesUtils.toolbarFolderId], 1);
   var options = hs.getNewQueryOptions();
 
-  dump("Check folder without uri nodes\n");
+  do_print("Check folder without uri nodes");
   check_uri_nodes(query, options, 0);
 
-  dump("Check folder with uri nodes\n");
+  do_print("Check folder with uri nodes");
   // Add an uri node, this should be considered.
-  bs.insertBookmark(folderId, uri("http://www.mozilla.org/"),
-                    bs.DEFAULT_INDEX, "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: bookmarks[0].guid,
+    url: "http://www.mozilla.org/",
+    title: "bookmark"
+  });
   check_uri_nodes(query, options, 1);
-},
+
+  await PlacesUtils.bookmarks.eraseEverything();
+});
 
-function() {
-  dump("\n\n*** TEST: folder in an excludeItems root\n");
-  // This is the folder we will check for children.
-  var folderId = bs.createFolder(bs.toolbarFolder, "folder", bs.DEFAULT_INDEX);
-
-  // Create a folder and a query node inside it, these should not be considered
-  // uri nodes.
-  bs.createFolder(folderId, "inside folder", bs.DEFAULT_INDEX);
-  bs.insertBookmark(folderId, uri("place:sort=1"), bs.DEFAULT_INDEX, "inside query");
+add_task(async function test_getURLsForContainerNode_folder_excludeItems() {
+  do_print("*** TEST: folder in an excludeItems root");
+  let bookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.toolbarGuid,
+    children: [{
+      // This is the folder we will check for children.
+      title: "folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      // Create a folder and a query node inside it, these should not be considered
+      // uri nodes.
+      children: [{
+        title: "inside folder",
+        type: PlacesUtils.bookmarks.TYPE_FOLDER,
+        children: [{
+          url: "place:sort=1",
+          title: "inside query",
+        }]
+      }]
+    }],
+  });
 
   var query = hs.getNewQuery();
-  query.setFolders([bs.toolbarFolder], 1);
+  query.setFolders([PlacesUtils.toolbarFolderId], 1);
   var options = hs.getNewQueryOptions();
   options.excludeItems = true;
 
-  dump("Check folder without uri nodes\n");
+  do_print("Check folder without uri nodes");
   check_uri_nodes(query, options, 0);
 
-  dump("Check folder with uri nodes\n");
+  do_print("Check folder with uri nodes");
   // Add an uri node, this should be considered.
-  bs.insertBookmark(folderId, uri("http://www.mozilla.org/"),
-                    bs.DEFAULT_INDEX, "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: bookmarks[0].guid,
+    url: "http://www.mozilla.org/",
+    title: "bookmark"
+  });
   check_uri_nodes(query, options, 1);
-},
+
+  await PlacesUtils.bookmarks.eraseEverything();
+});
 
-function() {
-  dump("\n\n*** TEST: query\n");
+add_task(async function test_getURLsForContainerNode_query() {
+  do_print("*** TEST: query");
   // This is the query we will check for children.
-  bs.insertBookmark(bs.toolbarFolder, uri("place:folder=BOOKMARKS_MENU&sort=1"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: "inside query",
+    url: "place:folder=BOOKMARKS_MENU&sort=1",
+  });
 
   // Create a folder and a query node inside it, these should not be considered
   // uri nodes.
-  bs.createFolder(bs.bookmarksMenuFolder, "inside folder", bs.DEFAULT_INDEX);
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("place:sort=1"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "inside folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        url: "place:sort=1",
+        title: "inside query",
+      }]
+    }],
+  });
 
   var query = hs.getNewQuery();
-  query.setFolders([bs.toolbarFolder], 1);
+  query.setFolders([PlacesUtils.toolbarFolderId], 1);
   var options = hs.getNewQueryOptions();
 
-  dump("Check query without uri nodes\n");
+  do_print("Check query without uri nodes");
   check_uri_nodes(query, options, 0);
 
-  dump("Check query with uri nodes\n");
+  do_print("Check query with uri nodes");
   // Add an uri node, this should be considered.
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://www.mozilla.org/"),
-                    bs.DEFAULT_INDEX, "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: "http://www.mozilla.org/",
+    title: "bookmark"
+  });
   check_uri_nodes(query, options, 1);
-},
+
+  await PlacesUtils.bookmarks.eraseEverything();
+});
 
-function() {
-  dump("\n\n*** TEST: excludeItems Query\n");
+add_task(async function test_getURLsForContainerNode_query_excludeItems() {
+  do_print("*** TEST: excludeItems Query");
   // This is the query we will check for children.
-  bs.insertBookmark(bs.toolbarFolder, uri("place:folder=BOOKMARKS_MENU&sort=8"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: "inside query",
+    url: "place:folder=BOOKMARKS_MENU&sort=1",
+  });
 
   // Create a folder and a query node inside it, these should not be considered
   // uri nodes.
-  bs.createFolder(bs.bookmarksMenuFolder, "inside folder", bs.DEFAULT_INDEX);
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("place:sort=1"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "inside folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        url: "place:sort=1",
+        title: "inside query",
+      }]
+    }],
+  });
 
   var query = hs.getNewQuery();
-  query.setFolders([bs.toolbarFolder], 1);
+  query.setFolders([PlacesUtils.toolbarFolderId], 1);
   var options = hs.getNewQueryOptions();
   options.excludeItems = true;
 
-  dump("Check folder without uri nodes\n");
+  do_print("Check folder without uri nodes");
   check_uri_nodes(query, options, 0);
 
-  dump("Check folder with uri nodes\n");
+  do_print("Check folder with uri nodes");
   // Add an uri node, this should be considered.
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://www.mozilla.org/"),
-                    bs.DEFAULT_INDEX, "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: "http://www.mozilla.org/",
+    title: "bookmark"
+  });
   check_uri_nodes(query, options, 1);
-},
+
+  await PlacesUtils.bookmarks.eraseEverything();
+});
 
-function() {
-  dump("\n\n*** TEST: !expandQueries Query\n");
+add_task(async function test_getURLsForContainerNode_query_excludeQueries() {
+  do_print("*** TEST: !expandQueries Query");
   // This is the query we will check for children.
-  bs.insertBookmark(bs.toolbarFolder, uri("place:folder=BOOKMARKS_MENU&sort=8"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    title: "inside query",
+    url: "place:folder=BOOKMARKS_MENU&sort=1",
+  });
 
   // Create a folder and a query node inside it, these should not be considered
   // uri nodes.
-  bs.createFolder(bs.bookmarksMenuFolder, "inside folder", bs.DEFAULT_INDEX);
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("place:sort=1"),
-                    bs.DEFAULT_INDEX, "inside query");
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: [{
+      title: "inside folder",
+      type: PlacesUtils.bookmarks.TYPE_FOLDER,
+      children: [{
+        url: "place:sort=1",
+        title: "inside query",
+      }]
+    }],
+  });
 
   var query = hs.getNewQuery();
-  query.setFolders([bs.toolbarFolder], 1);
+  query.setFolders([PlacesUtils.toolbarFolderId], 1);
   var options = hs.getNewQueryOptions();
   options.expandQueries = false;
 
-  dump("Check folder without uri nodes\n");
+  do_print("Check folder without uri nodes");
   check_uri_nodes(query, options, 0);
 
-  dump("Check folder with uri nodes\n");
+  do_print("Check folder with uri nodes");
   // Add an uri node, this should be considered.
-  bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://www.mozilla.org/"),
-                    bs.DEFAULT_INDEX, "bookmark");
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    url: "http://www.mozilla.org/",
+    title: "bookmark"
+  });
   check_uri_nodes(query, options, 1);
-}
-
-];
+});
 
 /**
  * Executes a query and checks number of uri nodes in the first container in
  * query's results.  To correctly test a container ensure that the query will
  * return only your container in the first level.
  *
  * @param  aQuery
  *         nsINavHistoryQuery object defining the query
@@ -163,18 +236,8 @@ function check_uri_nodes(aQuery, aOption
   var result = hs.executeQuery(aQuery, aOptions);
   var root = result.root;
   root.containerOpen = true;
   var node = root.getChild(0);
   do_check_eq(PU.hasChildURIs(node), aExpectedURINodes > 0);
   do_check_eq(PU.getURLsForContainerNode(node).length, aExpectedURINodes);
   root.containerOpen = false;
 }
-
-add_task(async function() {
-  for (let test of tests) {
-    await PlacesUtils.bookmarks.eraseEverything();
-    test();
-  }
-
-  // Cleanup.
-  await PlacesUtils.bookmarks.eraseEverything();
-});
--- a/toolkit/components/places/tests/unit/test_utils_setAnnotationsFor.js
+++ b/toolkit/components/places/tests/unit/test_utils_setAnnotationsFor.js
@@ -3,26 +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/. */
 
  /**
   * Check for correct functionality of PlacesUtils.setAnnotationsForItem/URI
   */
 
-var bs = PlacesUtils.bookmarks;
 var as = PlacesUtils.annotations;
 
 const TEST_URL = "http://test.mozilla.org/";
 
-function run_test() {
-  var testURI = uri(TEST_URL);
+add_task(async function test_setAnnotationsFor() {
+  let testURI = uri(TEST_URL);
   // add a bookmark
-  var itemId = bs.insertBookmark(bs.unfiledBookmarksFolder, testURI,
-                                 bs.DEFAULT_INDEX, "test");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    title: "test",
+    url: testURI,
+  });
+
+  let itemId = await PlacesUtils.promiseItemId(bookmark.guid);
 
   // create annotations array
   var testAnnos = [{ name: "testAnno/test0",
                      flags: 0,
                      value: "test0",
                      expires: Ci.nsIAnnotationService.EXPIRE_NEVER },
                    { name: "testAnno/test1",
                      flags: 0,
@@ -70,9 +74,9 @@ function run_test() {
   });
 
   // Unset all page annotations
   PlacesUtils.setAnnotationsForURI(testURI, testAnnos);
   // Check for correct removal
   testAnnos.forEach(function(anno) {
     do_check_false(as.pageHasAnnotation(testURI, anno.name));
   });
-}
+});