Bug 1312031 - Fix failing TPS test_sync.js test. r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Tue, 01 Nov 2016 13:16:38 -0400
changeset 432331 b7f617936b7b3c0c32d5f26b870e7e654bdcc323
parent 432301 4cde141bbedfd7355bdf3e9ac41740fb8fa2f06d
child 535606 beb6f1fd109e822ad90c2a767402335968ab5c11
push id34264
push userbmo:tchiovoloni@mozilla.com
push dateTue, 01 Nov 2016 17:19:48 +0000
reviewersmarkh
bugs1312031
milestone52.0a1
Bug 1312031 - Fix failing TPS test_sync.js test. r?markh This required: 1. Using the same method of updating keywords used by PlacesSyncUtils. Calling into PlacesSyncUtils directly is not possible here, since it would pass SOURCE_SYNC as the source, which would ensure that we ignore the changes). 2. Ensuring that we update the keyword *after* the URI in TPS. Note that neither one of these changes on their own was sufficient. MozReview-Commit-ID: Ls4kEVBHdNc
services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
--- a/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
@@ -8,16 +8,17 @@
   */
 
 var EXPORTED_SYMBOLS = ["PlacesItem", "Bookmark", "Separator", "Livemark",
                         "BookmarkFolder", "DumpBookmarks"];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/PlacesBackups.jsm");
+Cu.import("resource://gre/modules/PlacesSyncUtils.jsm");
 Cu.import("resource://gre/modules/PlacesUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://services-common/async.js");
 Cu.import("resource://tps/logger.jsm");
 
 var DumpBookmarks = function TPS_Bookmarks__DumpBookmarks() {
   let cb = Async.makeSpinningCallback();
   PlacesBackups.getBookmarksTree().then(result => {
@@ -104,16 +105,21 @@ PlacesItem.prototype = {
             ret.push(props[i] + ": " + that.props[props[i]])
           }
         }
         return ret;
       })().join(", ") + ")";
     return string;
   },
 
+  GetSyncId() {
+    let guid = Async.promiseSpinningly(PlacesUtils.promiseItemGuid(this.props.item_id));
+    return PlacesSyncUtils.bookmarks.guidToSyncId(guid);
+  },
+
   /**
    * GetPlacesNodeId
    *
    * Finds the id of the an item with the specified properties in the places
    * database.
    *
    * @param folder The id of the folder to search
    * @param type The type of the item to find, or null to match any item;
@@ -427,18 +433,29 @@ Bookmark.prototype = {
    *
    * Update this bookmark's keyword.
    *
    * @param keyword The keyword to set for this bookmark; if null, no
    *        changes are made
    * @return nothing
    */
   SetKeyword: function(keyword) {
-    if (keyword != null)
-      PlacesUtils.bookmarks.setKeywordForBookmark(this.props.item_id, keyword);
+    if (keyword != null) {
+      // Mirror logic from PlacesSyncUtils's updateBookmarkMetadata
+      let entry = Async.promiseSpinningly(PlacesUtils.keywords.fetch({
+        url: this.props.uri,
+      }));
+      if (entry) {
+        Async.promiseSpinningly(PlacesUtils.keywords.remove(entry));
+      }
+      Async.promiseSpinningly(PlacesUtils.keywords.insert({
+        keyword: keyword,
+        url: this.props.uri
+      }));
+    }
   },
 
   /**
    * SetLoadInSidebar
    *
    * Updates this bookmark's loadInSidebar property.
    *
    * @param loadInSidebar if true, the loadInSidebar property will be set,
@@ -537,21 +554,21 @@ Bookmark.prototype = {
    * Updates this bookmark's properties according the properties on this
    * object's 'updateProps' property.
    *
    * @return nothing
    */
   Update: function() {
     Logger.AssertTrue(this.props.item_id != -1 && this.props.item_id != null,
       "Invalid item_id during Remove");
-    this.SetKeyword(this.updateProps.keyword);
     this.SetDescription(this.updateProps.description);
     this.SetLoadInSidebar(this.updateProps.loadInSidebar);
     this.SetTitle(this.updateProps.title);
     this.SetUri(this.updateProps.uri);
+    this.SetKeyword(this.updateProps.keyword);
     this.SetTags(this.updateProps.tags);
     this.SetLocation(this.updateProps.location);
     this.SetPosition(this.updateProps.position);
   },
 
   /**
    * Find
    *
@@ -573,17 +590,18 @@ Bookmark.prototype = {
 
     if (this.props.item_id == -1) {
       Logger.logPotentialError(this.toString() + " not found");
       return -1;
     }
     if (!this.CheckDescription(this.props.description))
       return -1;
     if (this.props.keyword != null) {
-      let keyword = PlacesUtils.bookmarks.getKeywordForBookmark(this.props.item_id);
+      let { keyword } = Async.promiseSpinningly(
+        PlacesSyncUtils.bookmarks.fetch(this.GetSyncId()));
       if (keyword != this.props.keyword) {
         Logger.logPotentialError("Incorrect keyword - expected: " +
           this.props.keyword + ", actual: " + keyword +
           " for " + this.toString());
         return -1;
       }
     }
     let loadInSidebar = PlacesUtils.annotations.itemHasAnnotation(