Bug 1293853 - Part 1: Add numeric typeCode to PlacesUtils.promiseBookmarksTree, r?mak draft
authorBob Silverberg <bsilverberg@mozilla.com>
Tue, 29 Aug 2017 10:27:38 -0400
changeset 657526 b50f63d76667c8c139cd40351d458581b75640e9
parent 657343 a3585c77e2b1bc5f5fea907e97762f7b47a12033
child 657527 ea907a4e38848ec7bb15c2ab39046c660eb07ad9
push id77550
push userbmo:bob.silverberg@gmail.com
push dateFri, 01 Sep 2017 16:04:30 +0000
reviewersmak
bugs1293853
milestone57.0a1
Bug 1293853 - Part 1: Add numeric typeCode to PlacesUtils.promiseBookmarksTree, r?mak This allows promiseBookmarksTree to return nodes that describe their type in both string (i.e., PlacesUtils.TYPE_X_*) format and numeric (i.e., PlacesUtils.bookmarks.TYPE_*) formats. ext-bookmarks.js would prefer to be able to use the numeric format as that is what is used throughout the rest of the file. MozReview-Commit-ID: 7DpqAb3zVio
toolkit/components/places/PlacesUtils.jsm
toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -1690,16 +1690,18 @@ this.PlacesUtils = {
    *
    * @return {Promise}
    * @resolves to a JS object that represents either a single item or a
    * bookmarks tree.  Each node in the tree has the following properties set:
    *  - guid (string): the item's GUID (same as aItemGuid for the top item).
    *  - [deprecated] id (number): the item's id. This is only if
    *    aOptions.includeItemIds is set.
    *  - type (string):  the item's type.  @see PlacesUtils.TYPE_X_*
+   *  - typeCode (number):  the item's type in numeric format.
+   *    @see PlacesUtils.bookmarks.TYPE_*
    *  - title (string): the item's title. If it has no title, this property
    *    isn't set.
    *  - dateAdded (number, microseconds from the epoch): the date-added value of
    *    the item.
    *  - lastModified (number, microseconds from the epoch): the last-modified
    *    value of the item.
    *  - annos (see getAnnotationsForItem): the item's annotations.  This is not
    *    set if there are no annotations set for the item).
@@ -1748,16 +1750,17 @@ this.PlacesUtils = {
       let itemId = aRow.getResultByName("id");
       if (aOptions.includeItemIds)
         item.id = itemId;
 
       // Cache it for promiseItemId consumers regardless.
       GuidHelper.updateCache(itemId, item.guid);
 
       let type = aRow.getResultByName("type");
+      item.typeCode = type;
       if (type == Ci.nsINavBookmarksService.TYPE_BOOKMARK)
         copyProps("charset", "tags", "iconuri");
 
       // Add annotations.
       if (aRow.getResultByName("has_annos")) {
         try {
           item.annos = PlacesUtils.getAnnotationsForItem(itemId);
         } catch (e) {
--- a/toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
+++ b/toolkit/components/places/tests/unit/test_promiseBookmarksTree.js
@@ -52,16 +52,17 @@ async function compareToNode(aItem, aNod
   const BOOKMARK_ONLY_PROPS = ["uri", "iconuri", "tags", "charset", "keyword"];
   const FOLDER_ONLY_PROPS = ["children", "root"];
 
   let nodesCount = 1;
 
   switch (aNode.type) {
     case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER:
       Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER);
+      Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_FOLDER);
       compare_prop("title", "title", true);
       check_unset(...BOOKMARK_ONLY_PROPS);
 
       let expectedChildrenNodes = [];
 
       PlacesUtils.asContainer(aNode);
       if (!aNode.containerOpen)
         aNode.containerOpen = true;
@@ -90,20 +91,22 @@ async function compareToNode(aItem, aNod
       let rootName = mapItemIdToInternalRootName(aItem.id);
       if (rootName)
         Assert.equal(aItem.root, rootName);
       else
         check_unset("root");
       break;
     case Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR:
       Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR);
+      Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_SEPARATOR);
       check_unset(...BOOKMARK_ONLY_PROPS, ...FOLDER_ONLY_PROPS);
       break;
     default:
       Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE);
+      Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_BOOKMARK);
       compare_prop("uri");
       // node.tags's format is "a, b" whilst promiseBoookmarksTree is "a,b"
       if (aNode.tags === null)
         check_unset("tags");
       else
         Assert.equal(aItem.tags, aNode.tags.replace(/, /g, ","));
 
       if (aNode.icon) {