Bug 992901 - Not all bookmarks are saved in the backup JSON or HTML. r=mano a=sylvestre
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 20 May 2014 12:10:20 +0200
changeset 192345 3fb029a11c05
parent 192344 cb78c3777143
child 192346 869aefb78e22
push id3576
push usermak77@bonardo.net
push date2014-05-21 11:02 +0000
Treeherderresults
reviewersmano, sylvestre
bugs992901
milestone30.0
Bug 992901 - Not all bookmarks are saved in the backup JSON or HTML. r=mano a=sylvestre
toolkit/components/places/PlacesBackups.jsm
toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
toolkit/components/places/tests/bookmarks/xpcshell.ini
--- a/toolkit/components/places/PlacesBackups.jsm
+++ b/toolkit/components/places/PlacesBackups.jsm
@@ -497,17 +497,17 @@ this.PlacesBackups = {
       for (let row of rows) {
         let id = row.getResultByName("id");
         try {
           let bookmark = sqliteRowToBookmarkObject(row);
           if (itemsMap.has(id)) {
             // Since children may be added before parents, we should merge with
             // the existing object.
             let original = itemsMap.get(id);
-            for (prop in bookmark) {
+            for (let prop of Object.getOwnPropertyNames(bookmark)) {
               original[prop] = bookmark[prop];
             }
             bookmark = original;
           }
           else {
             itemsMap.set(id, bookmark);
           }
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
@@ -0,0 +1,48 @@
+/* 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/. */
+
+/**
+ * Checks that backups properly include all of the bookmarks if the hierarchy
+ * in the database is unordered so that a hierarchy is defined before its
+ * ancestor in the bookmarks table.
+ */
+function run_test() {
+  run_next_test();
+}
+
+add_task(function() {
+  let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
+                                                NetUtil.newURI("http://mozilla.org/"),
+                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
+                                                "bookmark");
+  let f2 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f2",
+                                              PlacesUtils.bookmarks.DEFAULT_INDEX);
+  PlacesUtils.bookmarks.moveItem(bm, f2, PlacesUtils.bookmarks.DEFAULT_INDEX);
+  let f1 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f1",
+                                              PlacesUtils.bookmarks.DEFAULT_INDEX);
+  PlacesUtils.bookmarks.moveItem(f2, f1, PlacesUtils.bookmarks.DEFAULT_INDEX);
+
+  // Create a backup.
+  yield PlacesBackups.create();
+
+  // Remove the bookmarks, then restore the backup.
+  PlacesUtils.bookmarks.removeItem(f1);
+  yield BookmarkJSONUtils.importFromFile((yield PlacesBackups.getMostRecentBackup()), true);
+
+  do_log_info("Checking first level");
+  let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
+  let level1 = root.getChild(0);
+  do_check_eq(level1.title, "f1");
+  do_log_info("Checking second level");
+  PlacesUtils.asContainer(level1).containerOpen = true
+  let level2 = level1.getChild(0);
+  do_check_eq(level2.title, "f2");
+  do_log_info("Checking bookmark");
+  PlacesUtils.asContainer(level2).containerOpen = true
+  let bookmark = level2.getChild(0);
+  do_check_eq(bookmark.title, "bookmark");
+  level2.containerOpen = false;
+  level1.containerOpen = false;
+  root.containerOpen = false;
+});
--- a/toolkit/components/places/tests/bookmarks/xpcshell.ini
+++ b/toolkit/components/places/tests/bookmarks/xpcshell.ini
@@ -24,8 +24,9 @@ tail =
 [test_keywords.js]
 [test_nsINavBookmarkObserver.js]
 [test_removeItem.js]
 [test_savedsearches.js]
 [test_675416.js]
 [test_711914.js]
 [test_protectRoots.js]
 [test_818593-store-backup-metadata.js]
+[test_992901-backup-unsorted-hierarchy.js]