Bug 1094853 - Convert chrome tests in browser/components/places to Bookmarks.jsm API r=mak
authorTim Taubert <ttaubert@mozilla.com>
Wed, 28 Jan 2015 17:36:46 +0100
changeset 227664 3fb22d2c7fd7c27907e70bb1a90efd436cc393a9
parent 227663 5dcd284d63af6cf02a0ecb7a5bf7a73afef03b64
child 227665 dab32e003884dcf1b75cc7aa271f8a219ba12398
push id28236
push userryanvm@gmail.com
push dateThu, 05 Feb 2015 22:15:34 +0000
treeherdermozilla-central@71972672e292 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1094853
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1094853 - Convert chrome tests in browser/components/places to Bookmarks.jsm API r=mak
browser/components/places/tests/chrome/test_0_multiple_left_pane.xul
browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul
browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul
browser/components/places/tests/chrome/test_bug549192.xul
browser/components/places/tests/chrome/test_bug549491.xul
browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul
browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul
browser/components/places/tests/chrome/test_selectItems_on_nested_tree.xul
browser/components/places/tests/chrome/test_treeview_date.xul
--- a/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul
+++ b/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul
@@ -29,54 +29,57 @@
     <div id="content" style="display: none"></div>
     <pre id="test"></pre>
   </body>
 
   <script type="application/javascript">
   <![CDATA[
 
     function runTest() {
-      // Sanity checks.
-      ok(PlacesUtils, "PlacesUtils is running in chrome context");
-      ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
-      ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
-         "Left pane version in chrome context, " +
-           "current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION );
+      SimpleTest.waitForExplicitFinish();
+
+      Task.spawn(function* () {
+        // Sanity checks.
+        ok(PlacesUtils, "PlacesUtils is running in chrome context");
+        ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
+        ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
+           "Left pane version in chrome context, " +
+             "current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION );
 
-      var fakeLeftPanes = [];
-      var as = PlacesUtils.annotations;
-      var bs = PlacesUtils.bookmarks;
+        let fakeLeftPanes = [];
+        // We need 2 left pane folders to simulate a corrupt profile.
+        do {
+          let leftPaneItems = PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
+
+          // Create a fake left pane folder.
+          let folder = yield PlacesUtils.bookmarks.insert({
+            parentGuid: PlacesUtils.bookmarks.rootGuid,
+            index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+            type: PlacesUtils.bookmarks.TYPE_FOLDER
+          });
 
-      // We need 2 left pane folders to simulate a corrupt profile.
-      do {
-        let leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
-        // Create a fake left pane folder.
-        let fakeLeftPaneRoot = bs.createFolder(PlacesUtils.placesRootId, "",
-                                               bs.DEFAULT_INDEX);
-        as.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
-                             PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
-                             as.EXPIRE_NEVER);
-        fakeLeftPanes.push(fakeLeftPaneRoot);
-      } while (fakeLeftPanes.length < 2);
+          let fakeLeftPaneRoot = yield PlacesUtils.promiseItemId(folder.guid);
+          PlacesUtils.annotations.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
+                               PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
+                               PlacesUtils.annotations.EXPIRE_NEVER);
+          fakeLeftPanes.push(folder.guid);
+        } while (fakeLeftPanes.length < 2);
 
-      // Initialize the left pane queries.
-      PlacesUIUtils.leftPaneFolderId;
+        // Initialize the left pane queries.
+        PlacesUIUtils.leftPaneFolderId;
 
-      // Check left pane.
-      ok(PlacesUIUtils.leftPaneFolderId > 0,
-         "Left pane folder correctly created");
-      var leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
-      is(leftPaneItems.length, 1,
-         "We correctly have only 1 left pane folder");
+        // Check left pane.
+        ok(PlacesUIUtils.leftPaneFolderId > 0,
+           "Left pane folder correctly created");
+        let leftPaneItems = PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
+        is(leftPaneItems.length, 1,
+           "We correctly have only 1 left pane folder");
 
-      // Check that all old left pane items have been removed.
-      fakeLeftPanes.forEach(function(aItemId) {
-        try {
-          bs.getItemTitle(aItemId);
-          throw("This folder should have been removed");
-        } catch (ex) {}
-      });
-
+        // Check that all old left pane items have been removed.
+        for (let guid of fakeLeftPanes) {
+          ok(!(yield PlacesUtils.bookmarks.fetch({guid})), "This folder should have been removed");
+        }
+      }).then(() => SimpleTest.finish());
     }
   ]]>
   </script>
 
 </window>
--- a/browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul
+++ b/browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul
@@ -37,50 +37,55 @@
   <![CDATA[
 
      /**
       * Bug 427633 - Disable creating a New Folder in the bookmarks dialogs if
       * insertionPoint is invalid.
       */
 
     function runTest() {
-      var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-               getService(Ci.nsINavBookmarksService);
-      var ios = Cc["@mozilla.org/network/io-service;1"].
-                getService(Ci.nsIIOService);
-      function uri(spec) {
-        return ios.newURI(spec, null, null);
-      }
+      SimpleTest.waitForExplicitFinish();
 
-      // Add a bookmark.
-      var itemId = bs.insertBookmark(PlacesUtils.toolbarFolderId,
-                                     uri("http://www.example.com/"),
-                                     bs.DEFAULT_INDEX,
-                                     "mozilla");
+      Task.spawn(function* () {
+        // Add a bookmark.
+        let bm = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+          url: "http://www.example.com/",
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          title: "mozilla"
+        });
+
+        // Init panel.
+        ok(gEditItemOverlay, "gEditItemOverlay is in context");
+        let itemId = yield PlacesUtils.promiseItemId(bm.guid);
+        gEditItemOverlay.initPanel(itemId);
+        ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
+
+        let tree = gEditItemOverlay._element("folderTree");
+        yield openFolderTree(tree);
 
-      // Init panel.
-      ok(gEditItemOverlay, "gEditItemOverlay is in context");
-      gEditItemOverlay.initPanel(itemId);
-      ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
-      // We must be sure tree is initialized, so we wait for place to be set.
-      SimpleTest.waitForExplicitFinish();
-      var tree = gEditItemOverlay._element("folderTree");
-      tree.addEventListener("DOMAttrModified", function(event) {
-          if (event.attrName != "place")
-            return;
-          tree.removeEventListener("DOMAttrModified", arguments.callee, false);
-          SimpleTest.executeSoon(function() {
-            tree.view.selection.clearSelection();
-            ok(document.getElementById("editBMPanel_newFolderButton").disabled,
-               "New folder button is disabled if there's no selection");
+        tree.view.selection.clearSelection();
+        ok(document.getElementById("editBMPanel_newFolderButton").disabled,
+           "New folder button is disabled if there's no selection");
+
+        // Cleanup.
+        yield PlacesUtils.bookmarks.remove(bm.guid);
+      }).then(() => SimpleTest.finish());
+    }
 
-            // Cleanup.
-            bs.removeItem(itemId);
-            SimpleTest.finish();
-            });
-        }, false);
-      // Open the folder tree.
-      document.getElementById("editBMPanel_foldersExpander").doCommand();
+    function openFolderTree(tree) {
+      return new Promise(resolve => {
+        tree.addEventListener("DOMAttrModified", function onAttrModified(event) {
+          if (event.attrName == "place") {
+            tree.removeEventListener("DOMAttrModified", onAttrModified);
+            resolve();
+          }
+        });
+
+        // Open the folder tree.
+        document.getElementById("editBMPanel_foldersExpander").doCommand();
+      });
     }
   ]]>
   </script>
 
 </window>
--- a/browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul
+++ b/browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul
@@ -32,54 +32,52 @@
   <body xmlns="http://www.w3.org/1999/xhtml" />
 
   <vbox id="editBookmarkPanelContent"/>
 
   <script type="application/javascript">
   <![CDATA[
 
     function runTest() {
-      var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-               getService(Ci.nsINavBookmarksService);
-      var ts = Cc["@mozilla.org/browser/tagging-service;1"].
-               getService(Ci.nsITaggingService);
-      var ios = Cc["@mozilla.org/network/io-service;1"].
-                getService(Ci.nsIIOService);
-      function uri(spec) {
-        return ios.newURI(spec, null, null);
-      }
+      SimpleTest.waitForExplicitFinish();
+
+      Task.spawn(function* () {
+        let testTag = "foo";
+        let testTagUpper = "Foo";
+        let testURI = Services.io.newURI("http://www.example.com/", null, null);
 
-      var testURI = uri("http://www.example.com/");
-      var testTag = "foo";
-      var testTagUpper = "Foo";
-
-      // Add a bookmark
-      var itemId = bs.insertBookmark(bs.toolbarFolder,
-                                     testURI,
-                                     bs.DEFAULT_INDEX,
-                                     "mozilla");
+        // Add a bookmark.
+        let bm = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          title: "mozilla",
+          url: testURI
+        });
 
-      // Init panel
-      ok(gEditItemOverlay, "gEditItemOverlay is in context");
-      gEditItemOverlay.initPanel(itemId);
+        // Init panel
+        ok(gEditItemOverlay, "gEditItemOverlay is in context");
+        let itemId = yield PlacesUtils.promiseItemId(bm.guid);
+        gEditItemOverlay.initPanel(itemId);
 
-      // add a tag
-      document.getElementById("editBMPanel_tagsField").value = testTag;
-      gEditItemOverlay.onTagsFieldBlur();
+        // add a tag
+        document.getElementById("editBMPanel_tagsField").value = testTag;
+        gEditItemOverlay.onTagsFieldBlur();
 
-      // test that the tag has been added in the backend
-      is(ts.getTagsForURI(testURI)[0], testTag, "tags match");
+        // test that the tag has been added in the backend
+        is(PlacesUtils.tagging.getTagsForURI(testURI)[0], testTag, "tags match");
 
-      // change the tag
-      document.getElementById("editBMPanel_tagsField").value = testTagUpper;
-      gEditItemOverlay.onTagsFieldBlur();
+        // change the tag
+        document.getElementById("editBMPanel_tagsField").value = testTagUpper;
+        gEditItemOverlay.onTagsFieldBlur();
 
-      // test that the tag has been added in the backend
-      is(ts.getTagsForURI(testURI)[0], testTagUpper, "tags match");
+        // test that the tag has been added in the backend
+        is(PlacesUtils.tagging.getTagsForURI(testURI)[0], testTagUpper, "tags match");
 
-      // Cleanup.
-      ts.untagURI(testURI, [testTag]);
-      bs.removeItem(itemId);
+        // Cleanup.
+        PlacesUtils.tagging.untagURI(testURI, [testTag]);
+        yield PlacesUtils.bookmarks.remove(bm.guid);
+      }).then(() => SimpleTest.finish());
     }
   ]]>
   </script>
 
 </window>
--- a/browser/components/places/tests/chrome/test_bug549192.xul
+++ b/browser/components/places/tests/chrome/test_bug549192.xul
@@ -36,36 +36,35 @@
   <script type="application/javascript"><![CDATA[
     /**
      * Bug 874407
      * Ensures that history views are updated properly after visits.
      * Bug 549192
      * Ensures that history views are updated after deleting entries.
      */
 
-    SimpleTest.waitForExplicitFinish();
+    function runTest() {
+      SimpleTest.waitForExplicitFinish();
 
-    function runTest() {
-      // The mochitest page is added to history.
-      PlacesTestUtils.clearHistory().then(continue_test);
-    }
+      Task.spawn(function* () {
+        yield PlacesTestUtils.clearHistory();
 
-    function continue_test() {
-      // Add some visits.
-      let vtime = Date.now() * 1000;
-      const ttype = PlacesUtils.history.TRANSITION_TYPED;
-      let places =
-        [{ uri: Services.io.newURI("http://example.tld/", null, null),
-           visitDate: ++vtime, transition: ttype },
-         { uri: Services.io.newURI("http://example2.tld/", null, null),
-           visitDate: ++vtime, transition: ttype },
-         { uri: Services.io.newURI("http://example3.tld/", null, null),
-           visitDate: ++vtime, transition: ttype }];
+        // Add some visits.
+        let vtime = Date.now() * 1000;
+        const ttype = PlacesUtils.history.TRANSITION_TYPED;
+        let places =
+          [{ uri: Services.io.newURI("http://example.tld/", null, null),
+             visitDate: ++vtime, transition: ttype },
+           { uri: Services.io.newURI("http://example2.tld/", null, null),
+             visitDate: ++vtime, transition: ttype },
+           { uri: Services.io.newURI("http://example3.tld/", null, null),
+             visitDate: ++vtime, transition: ttype }];
 
-      addVisits(places, function() {
+        yield new Promise(resolve => addVisits(places, resolve));
+
         // Make a history query.
         let query = PlacesUtils.history.getNewQuery();
         let opts = PlacesUtils.history.getNewQueryOptions();
         opts.sortingMode = opts.SORT_BY_DATE_DESCENDING;
         let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
 
         // Setup the places tree contents.
         var tree = document.getElementById("tree");
@@ -82,34 +81,33 @@
           is(node.uri, places[rc - i - 1].uri.spec,
              "Found expected node at position " + i + ".");
         }
 
         is(rc, 3, "Found expected number of rows.");
 
         // First check live-update of the view when adding visits.
         places.forEach(place => place.visitDate = ++vtime);
-        addVisits(places, function() {
-          for (let i = 0; i < rc; i++) {
-            selection.select(i);
-            let node = tree.selectedNode;
-            is(node.uri, places[rc - i - 1].uri.spec,
-               "Found expected node at position " + i + ".");
-          }
+        yield new Promise(resolve => addVisits(places, resolve));
+
+        for (let i = 0; i < rc; i++) {
+          selection.select(i);
+          let node = tree.selectedNode;
+          is(node.uri, places[rc - i - 1].uri.spec,
+             "Found expected node at position " + i + ".");
+        }
 
-          // Now remove the pages and verify live-update again.
-          for (let i = 0; i < rc; i++) {
-            selection.select(0);
-            let node = tree.selectedNode;
-            tree.controller.remove("Removing page");
-            ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
-              node.uri + " removed.");
-            ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
-          }
+        // Now remove the pages and verify live-update again.
+        for (let i = 0; i < rc; i++) {
+          selection.select(0);
+          let node = tree.selectedNode;
+          tree.controller.remove("Removing page");
+          ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
+            node.uri + " removed.");
+          ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
+        }
 
-          // Cleanup.
-          PlacesTestUtils.clearHistory().then(SimpleTest.finish);
-        });
-      });
+        // Cleanup.
+        yield PlacesTestUtils.clearHistory();
+      }).then(() => SimpleTest.finish());
     }
-
   ]]></script>
 </window>
--- a/browser/components/places/tests/chrome/test_bug549491.xul
+++ b/browser/components/places/tests/chrome/test_bug549491.xul
@@ -39,42 +39,41 @@
     /**
      * Bug 549491
      * https://bugzilla.mozilla.org/show_bug.cgi?id=549491
      *
      * Ensures that changing the details of places tree's root-node doesn't
      * throw.
      */
 
-    SimpleTest.waitForExplicitFinish();
+    function runTest() {
+      SimpleTest.waitForExplicitFinish();
+
+      Task.spawn(function* () {
+        yield PlacesTestUtils.clearHistory();
 
-    function runTest() {
-      // The mochitest page is added to history.
-      PlacesTestUtils.clearHistory().then(continue_test);
-    }
+        let visits = {
+          uri: Services.io.newURI("http://example.tld/", null, null),
+          transition: PlacesUtils.history.TRANSITION_TYPED
+        };
+        yield new Promise(resolve => addVisits(visits, resolve));
 
-    function continue_test() {
-      addVisits(
-        {uri: Services.io.newURI("http://example.tld/", null, null),
-          transition: PlacesUtils.history.TRANSITION_TYPED},
-        function() {
-          // Make a history query.
-          let query = PlacesUtils.history.getNewQuery();
-          let opts = PlacesUtils.history.getNewQueryOptions();
-          let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
+        // Make a history query.
+        let query = PlacesUtils.history.getNewQuery();
+        let opts = PlacesUtils.history.getNewQueryOptions();
+        let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
+
+        // Setup the places tree contents.
+        let tree = document.getElementById("tree");
+        tree.place = queryURI;
 
-          // Setup the places tree contents.
-          let tree = document.getElementById("tree");
-          tree.place = queryURI;
+        let rootNode = tree.result.root;
+        let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
+        obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
+        obs.nodeTitleChanged(rootNode, rootNode.title);
+        ok(true, "No exceptions thrown");
 
-          let rootNode = tree.result.root;
-          let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
-          obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
-          obs.nodeTitleChanged(rootNode, rootNode.title);
-          ok(true, "No exceptions thrown");
-
-          // Cleanup.
-          PlacesTestUtils.clearHistory().then(SimpleTest.finish);
-        });
+        // Cleanup.
+        yield PlacesTestUtils.clearHistory();
+      }).then(SimpleTest.finish);
     }
-
   ]]></script>
 </window>
--- a/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul
+++ b/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul
@@ -38,122 +38,133 @@
      /**
       * This test checks that editing tags doesn't scroll the tags selector
       * listbox to wrong positions.
       */
 
     function runTest() {
       SimpleTest.waitForExplicitFinish();
 
-      Components.utils.import("resource://gre/modules/NetUtil.jsm");
+      Task.spawn(function* () {
+        let bs = PlacesUtils.bookmarks;
 
-      let tags = ["a", "b", "c", "d", "e", "f", "g",
-                  "h", "i", "l", "m", "n", "o", "p"];
+        let tags = ["a", "b", "c", "d", "e", "f", "g",
+                    "h", "i", "l", "m", "n", "o", "p"];
 
-      // Add a bookmark and tag it.
-      let uri1 = NetUtil.newURI("http://www1.mozilla.org/");
-      let id1 = PlacesUtils.bookmarks.insertBookmark(
-        PlacesUtils.toolbarFolderId, uri1,
-        PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla"
-      );
-      PlacesUtils.tagging.tagURI(uri1, tags);
-
-      // Add a second bookmark so that tags won't disappear when unchecked.
-      let uri2 = NetUtil.newURI("http://www2.mozilla.org/");
-      let id2 = PlacesUtils.bookmarks.insertBookmark(
-        PlacesUtils.toolbarFolderId, uri2,
-        PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla"
-      );
-      PlacesUtils.tagging.tagURI(uri2, tags);
+        // Add a bookmark and tag it.
+        let uri1 = Services.io.newURI("http://www1.mozilla.org/", null, null);
+        let bm1 = yield bs.insert({
+          parentGuid: bs.toolbarGuid,
+          index: bs.DEFAULT_INDEX,
+          type: bs.TYPE_BOOKMARK,
+          title: "mozilla",
+          url: uri1.spec
+        });
+        PlacesUtils.tagging.tagURI(uri1, tags);
 
-      // Init panel.
-      ok(gEditItemOverlay, "gEditItemOverlay is in context");
-      gEditItemOverlay.initPanel(id1);
-      ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
+        // Add a second bookmark so that tags won't disappear when unchecked.
+        let uri2 = Services.io.newURI("http://www2.mozilla.org/", null, null);
+        let bm2 = yield bs.insert({
+          parentGuid: bs.toolbarGuid,
+          index: bs.DEFAULT_INDEX,
+          type: bs.TYPE_BOOKMARK,
+          title: "mozilla",
+          url: uri2.spec
+        });
+        PlacesUtils.tagging.tagURI(uri2, tags);
 
-      // Wait for the tags selector to be open.
-      let tagsSelectorRow = document.getElementById("editBMPanel_tagsSelectorRow");
-      tagsSelectorRow.addEventListener("DOMAttrModified", function (event) {
-        tagsSelectorRow.removeEventListener("DOMAttrModified", arguments.callee, false);
-        SimpleTest.executeSoon(function () {
-          let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
+        // Init panel.
+        ok(gEditItemOverlay, "gEditItemOverlay is in context");
+        let id1 = yield PlacesUtils.promiseItemId(bm1.guid);
+        gEditItemOverlay.initPanel(id1);
+        ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
 
-          // Go by two so there is some untouched tag in the middle.
-          for (let i = 8; i < tags.length; i += 2) {
-            tagsSelector.selectedIndex = i;
-            let listItem = tagsSelector.selectedItem;
-            SimpleTest.isnot(listItem, null, "Valid listItem found");
+        yield openTagSelector();
+        let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
 
-            tagsSelector.ensureElementIsVisible(listItem);
-            let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
+        // Go by two so there is some untouched tag in the middle.
+        for (let i = 8; i < tags.length; i += 2) {
+          tagsSelector.selectedIndex = i;
+          let listItem = tagsSelector.selectedItem;
+          isnot(listItem, null, "Valid listItem found");
 
-            SimpleTest.ok(listItem.checked, "Item is checked " + i);
-            let selectedTag = listItem.label;
+          tagsSelector.ensureElementIsVisible(listItem);
+          let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
 
-            // Uncheck the tag.
-            listItem.checked = false;
-            SimpleTest.is(visibleIndex,
-                          tagsSelector.getIndexOfFirstVisibleRow(),
-                          "Scroll position did not change");
+          ok(listItem.checked, "Item is checked " + i);
+          let selectedTag = listItem.label;
+
+          // Uncheck the tag.
+          listItem.checked = false;
+          is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(),
+             "Scroll position did not change");
 
-            // The listbox is rebuilt, so we have to get the new element.
-            let newItem = tagsSelector.selectedItem;
-            SimpleTest.isnot(newItem, null, "Valid new listItem found");
-            SimpleTest.ok(!newItem.checked, "New listItem is unchecked " + i);
-            SimpleTest.is(newItem.label, selectedTag,
-                          "Correct tag is still selected");
+          // The listbox is rebuilt, so we have to get the new element.
+          let newItem = tagsSelector.selectedItem;
+          isnot(newItem, null, "Valid new listItem found");
+          ok(!newItem.checked, "New listItem is unchecked " + i);
+          is(newItem.label, selectedTag, "Correct tag is still selected");
+
+          // Check the tag.
+          newItem.checked = true;
+          is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(),
+             "Scroll position did not change");
+        }
+
+        // Remove the second bookmark, then nuke some of the tags.
+        yield bs.remove(bm2.guid);
 
-            // Check the tag.
-            newItem.checked = true;
-            SimpleTest.is(visibleIndex,
-                          tagsSelector.getIndexOfFirstVisibleRow(),
-                          "Scroll position did not change");
-          }
+        // Doing this backwords tests more interesting paths.
+        for (let i = tags.length - 1; i >= 0 ; i -= 2) {
+          tagsSelector.selectedIndex = i;
+          let listItem = tagsSelector.selectedItem;
+          isnot(listItem, null, "Valid listItem found");
 
-          // Remove the second bookmark, then nuke some of the tags.
-          PlacesUtils.bookmarks.removeItem(id2);
+          tagsSelector.ensureElementIsVisible(listItem);
+          let firstVisibleTag = tags[tagsSelector.getIndexOfFirstVisibleRow()];
 
-          // Doing this backwords tests more interesting paths.
-          for (let i = tags.length - 1; i >= 0 ; i -= 2) {
-            tagsSelector.selectedIndex = i;
-            let listItem = tagsSelector.selectedItem;
-            SimpleTest.isnot(listItem, null, "Valid listItem found");
+          ok(listItem.checked, "Item is checked " + i);
+          let selectedTag = listItem.label;
 
-            tagsSelector.ensureElementIsVisible(listItem);
-            let firstVisibleTag = tags[tagsSelector.getIndexOfFirstVisibleRow()];
+          // Uncheck the tag.
+          listItem.checked = false;
 
-            SimpleTest.ok(listItem.checked, "Item is checked " + i);
-            let selectedTag = listItem.label;
-
-            // Uncheck the tag.
-            listItem.checked = false;
-
-            // Ensure the first visible tag is still visible in the list.
-            let firstVisibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
-            let lastVisibleIndex = firstVisibleIndex + tagsSelector.getNumberOfVisibleRows() -1;
-            let expectedTagIndex = tags.indexOf(firstVisibleTag);
-            SimpleTest.ok(expectedTagIndex >= firstVisibleIndex &&
-                          expectedTagIndex <= lastVisibleIndex,
-                          "Scroll position is correct");
+          // Ensure the first visible tag is still visible in the list.
+          let firstVisibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
+          let lastVisibleIndex = firstVisibleIndex + tagsSelector.getNumberOfVisibleRows() -1;
+          let expectedTagIndex = tags.indexOf(firstVisibleTag);
+          ok(expectedTagIndex >= firstVisibleIndex &&
+             expectedTagIndex <= lastVisibleIndex,
+             "Scroll position is correct");
 
-            // The listbox is rebuilt, so we have to get the new element.
-            let newItem = tagsSelector.selectedItem;
-            SimpleTest.isnot(newItem, null, "Valid new listItem found");
-            SimpleTest.ok(newItem.checked, "New listItem is checked " + i);
-            SimpleTest.is(tagsSelector.selectedItem.label,
-                          tags[Math.min(i + 1, tags.length - 2)],
-                          "The next tag is now selected");
-          }
+          // The listbox is rebuilt, so we have to get the new element.
+          let newItem = tagsSelector.selectedItem;
+          isnot(newItem, null, "Valid new listItem found");
+          ok(newItem.checked, "New listItem is checked " + i);
+          is(tagsSelector.selectedItem.label,
+             tags[Math.min(i + 1, tags.length - 2)],
+             "The next tag is now selected");
+        }
 
-          // Cleanup.
-          PlacesUtils.bookmarks.removeItem(id1);
+        // Cleanup.
+        yield bs.remove(bm1.guid);
+      }).then(SimpleTest.finish).catch(alert);
+    }
 
-          SimpleTest.finish();
+    function openTagSelector() {
+      // Wait for the tags selector to be open.
+      let promise = new Promise(resolve => {
+        let row = document.getElementById("editBMPanel_tagsSelectorRow");
+        row.addEventListener("DOMAttrModified", function onAttrModified() {
+          row.removeEventListener("DOMAttrModified", onAttrModified);
+          resolve();
         });
-      }, false);
+      });
 
       // Open the tags selector.
       document.getElementById("editBMPanel_tagsSelectorExpander").doCommand();
+
+      return promise;
     }
   ]]>
   </script>
 
 </window>
--- a/browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul
+++ b/browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul
@@ -29,170 +29,177 @@
           src="chrome://browser/content/places/editBookmarkOverlay.js"/>
 
   <body xmlns="http://www.w3.org/1999/xhtml" />
 
   <vbox id="editBookmarkPanelContent"/>
 
   <script type="application/javascript">
   <![CDATA[
-    function runTest()
-    {
-      Components.utils.import("resource://gre/modules/NetUtil.jsm");
+    function checkTagsSelector(aAvailableTags, aCheckedTags) {
+      is(PlacesUtils.tagging.allTags.length, aAvailableTags.length,
+         "tagging service is in sync.");
+      let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
+      let children = tagsSelector.childNodes;
+      is(children.length, aAvailableTags.length,
+          "Found expected number of tags in the tags selector");
 
-      const TEST_URI = NetUtil.newURI("http://www.test.me/");
-      const TEST_URI2 = NetUtil.newURI("http://www.test.again.me/");
-      const TEST_TAG = "test-tag";
-
-      ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context");
-
-      // Open the tags selector.
-      document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false;
+      Array.forEach(children, function (aChild) {
+        let tag = aChild.getAttribute("label");
+        ok(true, "Found tag '" + tag + "' in the selector");
+        ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag");
+        let checked = aChild.getAttribute("checked") == "true";
+        is(checked, aCheckedTags.indexOf(tag) != -1,
+           "Tag is correctly marked");
+      });
+    }
 
-      function checkTagsSelector(aAvailableTags, aCheckedTags)
-      {
-        is(PlacesUtils.tagging.allTags.length, aAvailableTags.length,
-           "tagging service is in sync.");
-        let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
-        let children = tagsSelector.childNodes;
-        is(children.length, aAvailableTags.length,
-            "Found expected number of tags in the tags selector");
-        Array.forEach(children, function (aChild) {
-          let tag = aChild.getAttribute("label");
-          ok(true, "Found tag '" + tag + "' in the selector");
-          ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag");
-          let checked = aChild.getAttribute("checked") == "true";
-          is(checked, aCheckedTags.indexOf(tag) != -1,
-             "Tag is correctly marked");
+    function runTest() {
+      SimpleTest.waitForExplicitFinish();
+
+      Task.spawn(function* () {
+        const TEST_URI = Services.io.newURI("http://www.test.me/", null, null);
+        const TEST_URI2 = Services.io.newURI("http://www.test.again.me/", null, null);
+        const TEST_TAG = "test-tag";
+
+        ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context");
+
+        // Open the tags selector.
+        document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false;
+
+        // Add a bookmark.
+        let bm = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          url: TEST_URI.spec,
+          title: "test.me"
         });
-      }
 
-      // Add a bookmark.
-      let itemId = PlacesUtils.bookmarks.insertBookmark(
-        PlacesUtils.unfiledBookmarksFolderId, TEST_URI,
-        PlacesUtils.bookmarks.DEFAULT_INDEX, "test.me"
-      );
+        // Init panel.
+        itemId = yield PlacesUtils.promiseItemId(bm.guid);
+        gEditItemOverlay.initPanel(itemId);
+
+        // Add a tag.
+        PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
 
-      // Init panel.
-      gEditItemOverlay.initPanel(itemId);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
+           "Correctly added tag to a single bookmark");
+        is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
+           "Editing a single bookmark shows the added tag");
+        checkTagsSelector([TEST_TAG], [TEST_TAG]);
 
-      // Add a tag.
-      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
+        // Remove tag.
+        PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
+           "The tag has been removed");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing a single bookmark should not show any tag");
+        checkTagsSelector([], []);
 
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
-         "Correctly added tag to a single bookmark");
-      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
-         "Editing a single bookmark shows the added tag");
-      checkTagsSelector([TEST_TAG], [TEST_TAG]);
+        // Add a second bookmark.
+        let bm2 = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          title: "test.again.me",
+          url: TEST_URI2.spec
+        });
 
-      // Remove tag.
-      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
-         "The tag has been removed");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing a single bookmark should not show any tag");
-      checkTagsSelector([], []);
+        // Init panel with multiple bookmarks.
+        itemId2 = yield PlacesUtils.promiseItemId(bm2.guid);
+        gEditItemOverlay.initPanel([itemId, itemId2]);
 
-      // Add a second bookmark.
-      let itemId2 = PlacesUtils.bookmarks.insertBookmark(
-        PlacesUtils.unfiledBookmarksFolderId, TEST_URI2,
-        PlacesUtils.bookmarks.DEFAULT_INDEX, "test.again.me"
-      );
-
-      // Init panel with multiple bookmarks.
-      gEditItemOverlay.initPanel([itemId, itemId2]);
+        // Add a tag to the first bookmark.
+        PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
+           "Correctly added a tag to the first bookmark.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple bookmarks without matching tags should not show any tag.");
+        checkTagsSelector([TEST_TAG], []);
 
-      // Add a tag to the first bookmark.
-      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
-         "Correctly added a tag to the first bookmark.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple bookmarks without matching tags should not show any tag.");
-      checkTagsSelector([TEST_TAG], []);
-      
-      // Add a tag to the second bookmark.
-      PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
-         "Correctly added a tag to the second bookmark.");
-      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
-         "Editing multiple bookmarks should show matching tags.");
-      checkTagsSelector([TEST_TAG], [TEST_TAG]);
+        // Add a tag to the second bookmark.
+        PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
+           "Correctly added a tag to the second bookmark.");
+        is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
+           "Editing multiple bookmarks should show matching tags.");
+        checkTagsSelector([TEST_TAG], [TEST_TAG]);
+
+        // Remove tag from the first bookmark.
+        PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
+           "Correctly removed tag from the first bookmark.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple bookmarks without matching tags should not show any tag.");
+        checkTagsSelector([TEST_TAG], []);
 
-      // Remove tag from the first bookmark.
-      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
-         "Correctly removed tag from the first bookmark.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple bookmarks without matching tags should not show any tag.");
-      checkTagsSelector([TEST_TAG], []);
+        // Remove tag from the second bookmark.
+        PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
+           "Correctly removed tag from the second bookmark.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple bookmarks without matching tags should not show any tag.");
+        checkTagsSelector([], []);
 
-      // Remove tag from the second bookmark.
-      PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
-         "Correctly removed tag from the second bookmark.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple bookmarks without matching tags should not show any tag.");
-      checkTagsSelector([], []);
+        // Init panel with a nsIURI entry.
+        gEditItemOverlay.initPanel(TEST_URI);
 
-      // Init panel with a nsIURI entry.
-      gEditItemOverlay.initPanel(TEST_URI);
-
-      // Add a tag.
-      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
-         "Correctly added tag to the first entry.");
-      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
-         "Editing a single nsIURI entry shows the added tag");
-      checkTagsSelector([TEST_TAG], [TEST_TAG]);
+        // Add a tag.
+        PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
+           "Correctly added tag to the first entry.");
+        is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
+           "Editing a single nsIURI entry shows the added tag");
+        checkTagsSelector([TEST_TAG], [TEST_TAG]);
 
-      // Remove tag.
-      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
-         "Correctly removed tag from the nsIURI entry.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing a single nsIURI entry should not show any tag");
-      checkTagsSelector([], []);
+        // Remove tag.
+        PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
+           "Correctly removed tag from the nsIURI entry.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing a single nsIURI entry should not show any tag");
+        checkTagsSelector([], []);
 
-      // Init panel with multiple nsIURI entries.
-      gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]);
+        // Init panel with multiple nsIURI entries.
+        gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]);
 
-      // Add a tag to the first entry.
-      PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
-         "Tag correctly added.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple nsIURIs without matching tags should not show any tag.");
-      checkTagsSelector([TEST_TAG], []);
+        // Add a tag to the first entry.
+        PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
+           "Tag correctly added.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple nsIURIs without matching tags should not show any tag.");
+        checkTagsSelector([TEST_TAG], []);
 
-      // Add a tag to the second entry.
-      PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
-         "Tag correctly added.");
-      is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
-         "Editing multiple nsIURIs should show matching tags");
-      checkTagsSelector([TEST_TAG], [TEST_TAG]);
+        // Add a tag to the second entry.
+        PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
+           "Tag correctly added.");
+        is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
+           "Editing multiple nsIURIs should show matching tags");
+        checkTagsSelector([TEST_TAG], [TEST_TAG]);
 
-      // Remove tag from the first entry.
-      PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
-         "Correctly removed tag from the first entry.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple nsIURIs without matching tags should not show any tag.");
-      checkTagsSelector([TEST_TAG], []);
+        // Remove tag from the first entry.
+        PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
+           "Correctly removed tag from the first entry.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple nsIURIs without matching tags should not show any tag.");
+        checkTagsSelector([TEST_TAG], []);
 
-      // Remove tag from the second entry.
-      PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
-      is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
-         "Correctly removed tag from the second entry.");
-      is(document.getElementById("editBMPanel_tagsField").value, "",
-         "Editing multiple nsIURIs without matching tags should not show any tag.");
-      checkTagsSelector([], []);
+        // Remove tag from the second entry.
+        PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
+        is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
+           "Correctly removed tag from the second entry.");
+        is(document.getElementById("editBMPanel_tagsField").value, "",
+           "Editing multiple nsIURIs without matching tags should not show any tag.");
+        checkTagsSelector([], []);
 
-      // Cleanup.
-      PlacesUtils.bookmarks.removeFolderChildren(
-        PlacesUtils.unfiledBookmarksFolderId
-      );
-
+        // Cleanup.
+        yield PlacesUtils.bookmarks.remove(bm.guid);
+        yield PlacesUtils.bookmarks.remove(bm2.guid);
+      }).then(SimpleTest.finish);
     }
   ]]>
   </script>
 
 </window>
--- a/browser/components/places/tests/chrome/test_selectItems_on_nested_tree.xul
+++ b/browser/components/places/tests/chrome/test_selectItems_on_nested_tree.xul
@@ -33,34 +33,54 @@
   </tree>
 
   <script type="application/javascript"><![CDATA[
     /**
      * Ensure that selectItems doesn't recurse infinitely in nested trees.
      */
 
     function runTest() {
-      PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                           NetUtil.newURI("place:folder=UNFILED_BOOKMARKS"),
-                                           PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                           "shortcut");
-      PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                           NetUtil.newURI("place:folder=UNFILED_BOOKMARKS&maxResults=10"),
-                                           PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                           "query");
-      let folderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
-                                                        "folder",
-                                                        PlacesUtils.bookmarks.DEFAULT_INDEX);
-      let itemId = PlacesUtils.bookmarks.insertBookmark(folderId,
-                                                        NetUtil.newURI("http://www.mozilla.org/"),
-                                                        PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                                        "bookmark");
-      // Setup the places tree contents.
-      var tree = document.getElementById("tree");
-      tree.place = "place:folder=UNFILED_BOOKMARKS";
+      SimpleTest.waitForExplicitFinish();
+
+      Task.spawn(function* () {
+        yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          url: "place:folder=UNFILED_BOOKMARKS",
+          title: "shortcut"
+        });
+
+        yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          url: "place:folder=UNFILED_BOOKMARKS&maxResults=10",
+          title: "query"
+        });
 
-      // Select the last bookmark.
-      tree.selectItems([itemId]);
-      is (tree.selectedNode.itemId, itemId, "The right node was selected");
+        let folder = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_FOLDER,
+          title: "folder"
+        });
+
+        let bm = yield PlacesUtils.bookmarks.insert({
+          parentGuid: folder.guid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+          url: "http://www.mozilla.org/",
+          title: "bookmark"
+        });
+
+        // Setup the places tree contents.
+        let tree = document.getElementById("tree");
+        tree.place = "place:folder=UNFILED_BOOKMARKS";
+
+        // Select the last bookmark.
+        let itemId = yield PlacesUtils.promiseItemId(bm.guid);
+        tree.selectItems([itemId]);
+        is (tree.selectedNode.itemId, itemId, "The right node was selected");
+      }).then(SimpleTest.finish);
     }
-
   ]]></script>
 </window>
--- a/browser/components/places/tests/chrome/test_treeview_date.xul
+++ b/browser/components/places/tests/chrome/test_treeview_date.xul
@@ -45,127 +45,120 @@
 
     /**
      * Bug 435322
      * https://bugzilla.mozilla.org/show_bug.cgi?id=435322
      *
      * Ensures that date in places treeviews is correctly formatted.
      */
 
-    SimpleTest.waitForExplicitFinish();
-
     function runTest() {
-      // The mochitest page is added to history.
-      PlacesTestUtils.clearHistory().then(continue_test);
-    }
+      SimpleTest.waitForExplicitFinish();
 
-    function continue_test() {
-      var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
-               getService(Ci.nsINavHistoryService);
-      var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
-      var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-               getService(Ci.nsINavBookmarksService);
-      var ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
+      let ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
                getService(Ci.nsIScriptableDateFormat);
 
-      var iosvc = Cc["@mozilla.org/network/io-service;1"].
-                  getService(Ci.nsIIOService);
       function uri(spec) {
-        return iosvc.newURI(spec, null, null);
+        return Services.io.newURI(spec, null, null);
       }
 
-      var midnight = new Date();
-      midnight.setHours(0);
-      midnight.setMinutes(0);
-      midnight.setSeconds(0);
-      midnight.setMilliseconds(0);
+      Task.spawn(function* () {
+        yield PlacesTestUtils.clearHistory();
+
+        let midnight = new Date();
+        midnight.setHours(0);
+        midnight.setMinutes(0);
+        midnight.setSeconds(0);
+        midnight.setMilliseconds(0);
 
-      function addVisitsCallback() {
+        // Add a visit 1ms before midnight, a visit at midnight, and
+        // a visit 1ms after midnight.
+        yield new Promise(resolve => addVisits(
+          [{uri: uri("http://before.midnight.com/"),
+             visitDate: (midnight.getTime() - 1) * 1000,
+             transition: PlacesUtils.history.TRANSITION_TYPED},
+           {uri: uri("http://at.midnight.com/"),
+             visitDate: (midnight.getTime()) * 1000,
+             transition: PlacesUtils.history.TRANSITION_TYPED},
+           {uri: uri("http://after.midnight.com/"),
+             visitDate: (midnight.getTime() + 1) * 1000,
+             transition: PlacesUtils.history.TRANSITION_TYPED}],
+          resolve));
+
         // add a bookmark to the midnight visit
-        var itemId = bs.insertBookmark(bs.toolbarFolder,
-                                       uri("http://at.midnight.com/"),
-                                       bs.DEFAULT_INDEX,
-                                       "A bookmark at midnight");
+        let bm = yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+          index: PlacesUtils.bookmarks.DEFAULT_INDEX,
+          url: "http://at.midnight.com/",
+          title: "A bookmark at midnight",
+          type: PlacesUtils.bookmarks.TYPE_BOOKMARK
+        });
 
         // Make a history query.
-        var query = hs.getNewQuery();
-        var opts = hs.getNewQueryOptions();
-        var queryURI = hs.queriesToQueryString([query], 1, opts);
+        let query = PlacesUtils.history.getNewQuery();
+        let opts = PlacesUtils.history.getNewQueryOptions();
+        let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
 
         // Setup the places tree contents.
-        var tree = document.getElementById("tree");
+        let tree = document.getElementById("tree");
         tree.place = queryURI;
 
         // loop through the rows and check formatting
-        var treeView = tree.view;
-        var rc = treeView.rowCount;
+        let treeView = tree.view;
+        let rc = treeView.rowCount;
         ok(rc >= 3, "Rows found");
-        var columns = tree.columns;
+        let columns = tree.columns;
         ok(columns.count > 0, "Columns found");
-        for (var r = 0; r < rc; r++) {
-          var node = treeView.nodeForTreeIndex(r);
+        for (let r = 0; r < rc; r++) {
+          let node = treeView.nodeForTreeIndex(r);
           ok(node, "Places node found");
-          for (var ci = 0; ci < columns.count; ci++) {
-            var c = columns.getColumnAt(ci);
-            var text = treeView.getCellText(r, c);
+          for (let ci = 0; ci < columns.count; ci++) {
+            let c = columns.getColumnAt(ci);
+            let text = treeView.getCellText(r, c);
             switch (c.element.getAttribute("anonid")) {
               case "title":
                 // The title can differ, we did not set any title so we would
                 // expect null, but in such a case the view will generate a title
                 // through PlacesUIUtils.getBestTitle.
                 if (node.title)
                   is(text, node.title, "Title is correct");
                 break;
               case "url":
                 is(text, node.uri, "Uri is correct");
                 break;
               case "date":
-                var timeObj = new Date(node.time / 1000);
+                let timeObj = new Date(node.time / 1000);
                 // Default is short date format.
-                var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
+                let dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
                 // For today's visits we don't show date portion.
                 if (node.uri == "http://at.midnight.com/" ||
                     node.uri == "http://after.midnight.com/")
                   dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone;
                 else if (node.uri == "http://before.midnight.com/")
                   dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
                 else {
                   // Avoid to test spurious uris, due to how the test works
                   // a redirecting uri could be put in the tree while we test.
                   break;
                 }
-                var timeStr = ds.FormatDateTime("", dateFormat,
+                let timeStr = ds.FormatDateTime("", dateFormat,
                       Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
                       timeObj.getFullYear(), timeObj.getMonth() + 1,
                       timeObj.getDate(), timeObj.getHours(),
                       timeObj.getMinutes(), timeObj.getSeconds())
 
                 is(text, timeStr, "Date format is correct");
                 break;
               case "visitCount":
                 is(text, 1, "Visit count is correct");
                 break;
             }
           }
         }
+
         // Cleanup.
-        bs.removeItem(itemId);
-        PlacesTestUtils.clearHistory().then(SimpleTest.finish);
-      }
-
-      // Add a visit 1ms before midnight, a visit at midnight, and
-      // a visit 1ms after midnight.
-      addVisits(
-        [{uri: uri("http://before.midnight.com/"),
-           visitDate: (midnight.getTime() - 1) * 1000,
-           transition: hs.TRANSITION_TYPED},
-         {uri: uri("http://at.midnight.com/"),
-           visitDate: (midnight.getTime()) * 1000,
-           transition: hs.TRANSITION_TYPED},
-         {uri: uri("http://after.midnight.com/"),
-           visitDate: (midnight.getTime() + 1) * 1000,
-           transition: hs.TRANSITION_TYPED}],
-        addVisitsCallback);
+        yield PlacesUtils.bookmarks.remove(bm.guid);
+        yield PlacesTestUtils.clearHistory();
+      }).then(SimpleTest.finish);
     }
-
   ]]>
   </script>
 </window>