Bug 1333304 - fix reordering an empty folder when missing children are specified. r?mak draft
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 24 Jan 2017 14:51:39 +1100
changeset 465460 fadc7c6d6126189ae4d7d7bd818953233af98506
parent 464862 d5e37c0a776f1f2c21ddac4612529f819e13733b
child 543148 b968b71255bb93a86b57471f0eb4510a362fd5ed
push id42599
push userbmo:markh@mozilla.com
push dateTue, 24 Jan 2017 03:52:08 +0000
reviewersmak
bugs1333304
milestone53.0a1
Bug 1333304 - fix reordering an empty folder when missing children are specified. r?mak MozReview-Commit-ID: CpbpnO7WLgR
toolkit/components/places/Bookmarks.jsm
toolkit/components/places/tests/bookmarks/test_bookmarks_reorder.js
--- a/toolkit/components/places/Bookmarks.jsm
+++ b/toolkit/components/places/Bookmarks.jsm
@@ -1273,18 +1273,19 @@ function removeBookmark(item, options) {
 
 // Reorder implementation.
 
 function reorderChildren(parent, orderedChildrenGuids, options) {
   return PlacesUtils.withConnectionWrapper("Bookmarks.jsm: updateBookmark",
     db => db.executeTransaction(function* () {
       // Select all of the direct children for the given parent.
       let children = yield fetchBookmarksByParent({ parentGuid: parent.guid });
-      if (!children.length)
-        return undefined;
+      if (!children.length) {
+        return [];
+      }
 
       // Build a map of GUIDs to indices for fast lookups in the comparator
       // function.
       let guidIndices = new Map();
       for (let i = 0; i < orderedChildrenGuids.length; ++i) {
         let guid = orderedChildrenGuids[i];
         guidIndices.set(guid, i);
       }
--- a/toolkit/components/places/tests/bookmarks/test_bookmarks_reorder.js
+++ b/toolkit/components/places/tests/bookmarks/test_bookmarks_reorder.js
@@ -170,8 +170,21 @@ add_task(function* move_and_reorder() {
   Assert.equal(bm2.index, 1);
   bm3 = yield PlacesUtils.bookmarks.fetch(bm3.guid);
   Assert.equal(bm3.index, 2);
   bm4 = yield PlacesUtils.bookmarks.fetch(bm4.guid);
   Assert.equal(bm4.index, 1);
   bm5 = yield PlacesUtils.bookmarks.fetch(bm5.guid);
   Assert.equal(bm5.index, 0);
 });
+
+add_task(function* reorder_empty_folder_invalid_children() {
+  // Start clean.
+  yield PlacesUtils.bookmarks.eraseEverything();
+
+  let f1 = yield PlacesUtils.bookmarks.insert({
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid
+  });
+  // Specifying a child that doesn't exist should cause that to be ignored.
+  // However, before bug 1333304, doing this on an empty folder threw.
+  yield PlacesUtils.bookmarks.reorder(f1.guid, ['123456789012']);
+});