Bug 610375 - Make bookmark folders not sync last [r=mconnor]
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Tue, 09 Nov 2010 13:53:50 -0800
changeset 57541 03632b58255d53a4edd0d5778480c7ac9666ecdb
parent 57540 3594e3cc6077ad326e67634a1538df7120d42bc7
child 57542 0bd3f5510fbaea3758ce89f200ed236423fccddd
push idunknown
push userunknown
push dateunknown
reviewersmconnor
bugs610375
Bug 610375 - Make bookmark folders not sync last [r=mconnor]
services/sync/modules/engines/bookmarks.js
services/sync/tests/unit/test_bookmark_store.js
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -40,16 +40,17 @@ const EXPORTED_SYMBOLS = ['BookmarksEngi
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const PARENT_ANNO = "weave/parent";
 const PREDECESSOR_ANNO = "weave/predecessor";
 const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
+const FOLDER_SORTINDEX = 1000000;
 
 try {
   Cu.import("resource://gre/modules/PlacesUtils.jsm");
 }
 catch(ex) {
   Cu.import("resource://gre/modules/utils.js");
 }
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -857,16 +858,20 @@ BookmarksStore.prototype = {
         "FROM moz_places " +
         "WHERE url = :url " +
         "LIMIT 1");
     }
     return this.__frecencyStm;
   },
 
   _calculateIndex: function _calculateIndex(record) {
+    // Ensure folders have a very high sort index so they're not synced last.
+    if (record.type == "folder")
+      return FOLDER_SORTINDEX;
+
     // For anything directly under the toolbar, give it a boost of more than an
     // unvisited bookmark
     let index = 0;
     if (record.parentid == "toolbar")
       index += 150;
 
     // Add in the bookmark's frecency if we have something
     if (record.bmkUri != null) {
--- a/services/sync/tests/unit/test_bookmark_store.js
+++ b/services/sync/tests/unit/test_bookmark_store.js
@@ -37,13 +37,20 @@ function run_test() {
     _("Have the store create a new record object. Verify that it has the same data.");
     let newrecord = store.createRecord(fxrecord.id, "http://fake/uri");
     for each (let property in ["type", "bmkUri", "title", "keyword",
                                "parentName", "parentid"])
       do_check_eq(newrecord[property], fxrecord[property]);      
 
     _("The calculated sort index is based on frecency data.");
     do_check_true(newrecord.sortindex >= 150);
+
+    _("Folders have high sort index to ensure they're synced first.");
+    let folder_id = Svc.Bookmark.createFolder(Svc.Bookmark.toolbarFolder,
+                                              "Test Folder", 0);
+    let folder_guid = Svc.Bookmark.getItemGUID(folder_id);
+    let folder_record = store.createRecord(folder_guid, "http://fake/uri");
+    do_check_eq(folder_record.sortindex, 1000000);
   } finally {
     _("Clean up.");
     store.wipe();
   }
 }