Bug 1144571 - Pasting multiple bookmarks should retain their order. r=ttaubert, a=sledru
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 28 Mar 2015 14:00:11 +0100
changeset 248540 615a00a095521ada40fc19ed92986c2cb8a6ce70
parent 248539 7049015f9ce37e4957231fbc33f3651baf734efb
child 248541 04038d160c05b03c727c8d3a448d3c9e9a9af446
push id7857
push userryanvm@gmail.com
push dateMon, 30 Mar 2015 15:03:09 +0000
treeherdermozilla-aurora@04038d160c05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, sledru
bugs1144571
milestone38.0a2
Bug 1144571 - Pasting multiple bookmarks should retain their order. r=ttaubert, a=sledru
browser/components/places/content/controller.js
browser/components/places/tests/browser/browser_416459_cut.js
--- a/browser/components/places/content/controller.js
+++ b/browser/components/places/content/controller.js
@@ -1339,18 +1339,18 @@ PlacesController.prototype = {
             if (insertionIndex != PlacesUtils.bookmarks.DEFAULT_INDEX)
               insertionIndex++;
           }
         });
       }
     }
     else {
       let transactions = [];
+      let insertionIndex = ip.index;
       for (let i = 0; i < items.length; ++i) {
-        let insertionIndex = ip.index + i;
         if (ip.isTag) {
           // Pasting into a tag container means tagging the item, regardless of
           // the requested action.
           let tagTxn = new PlacesTagURITransaction(NetUtil.newURI(items[i].uri),
                                                    [ip.itemId]);
           transactions.push(tagTxn);
           continue;
         }
--- a/browser/components/places/tests/browser/browser_416459_cut.js
+++ b/browser/components/places/tests/browser/browser_416459_cut.js
@@ -1,59 +1,83 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TEST_URL = "http://example.com/";
 
 add_task(function* () {
+  yield PlacesUtils.bookmarks.eraseEverything();
   let organizer = yield promiseLibrary();
+
+  registerCleanupFunction(function* () {
+    yield promiseLibraryClosed(organizer);
+    yield PlacesUtils.bookmarks.eraseEverything();
+  });
+
   let PlacesOrganizer = organizer.PlacesOrganizer;
   let ContentTree = organizer.ContentTree;
 
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils in scope");
   ok(PlacesUIUtils, "PlacesUIUtils in scope");
   ok(PlacesOrganizer, "PlacesOrganizer in scope");
   ok(ContentTree, "ContentTree is in scope");
 
-  let bm = yield PlacesUtils.bookmarks.insert({
+  // Test with multiple entries to ensure they retain their order.
+  let bookmarks = [];
+  bookmarks.push(yield PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+    url: TEST_URL,
+    title: "0"
+  }));
+  bookmarks.push(yield PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
-    url: TEST_URL
-  });
+    url: TEST_URL,
+    title: "1"
+  }));
+  bookmarks.push(yield PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+    url: TEST_URL,
+    title: "2"
+  }));
 
-  yield selectBookmarkIn(organizer, bm, "BookmarksToolbar");
+  yield selectBookmarksIn(organizer, bookmarks, "BookmarksToolbar");
 
   yield promiseClipboard(() => {
     info("Cutting selection");
     ContentTree.view.controller.cut();
   }, PlacesUtils.TYPE_X_MOZ_PLACE);
 
   info("Selecting UnfiledBookmarks in the left pane");
   PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks");
   info("Pasting clipboard");
   ContentTree.view.controller.paste();
 
-  yield selectBookmarkIn(organizer, bm, "UnfiledBookmarks");
-
-  yield promiseLibraryClosed(organizer);
-  yield PlacesUtils.bookmarks.eraseEverything();
+  yield selectBookmarksIn(organizer, bookmarks, "UnfiledBookmarks");
 });
 
-let selectBookmarkIn = Task.async(function* (organizer, bm, aLeftPaneQuery) {
+let selectBookmarksIn = Task.async(function* (organizer, bookmarks, aLeftPaneQuery) {
   let PlacesOrganizer = organizer.PlacesOrganizer;
   let ContentTree = organizer.ContentTree;
-
   info("Selecting " + aLeftPaneQuery + " in the left pane");
   PlacesOrganizer.selectLeftPaneQuery(aLeftPaneQuery);
-  let rootId = PlacesUtils.getConcreteItemId(PlacesOrganizer._places.selectedNode);
 
-  bm = yield PlacesUtils.bookmarks.fetch(bm.guid);
-  is((yield PlacesUtils.promiseItemId(bm.parentGuid)), rootId,
-     "Bookmark has the right parent");
+  let ids = [];
+  for (let {guid} of bookmarks) {
+    let bookmark = yield PlacesUtils.bookmarks.fetch(guid);
+    is (bookmark.parentGuid, PlacesOrganizer._places.selectedNode.targetFolderGuid,
+        "Bookmark has the right parent");
+    ids.push(yield PlacesUtils.promiseItemId(bookmark.guid));
+  }
 
-  info("Selecting the bookmark in the right pane");
-  ContentTree.view.selectItems([yield PlacesUtils.promiseItemId(bm.guid)]);
-  let bookmarkNode = ContentTree.view.selectedNode;
-  is(bookmarkNode.uri, TEST_URL, "Found the expected bookmark");
+  info("Selecting the bookmarks in the right pane");
+  ContentTree.view.selectItems(ids);
+
+  for (let node of ContentTree.view.selectedNodes) {
+    is(node.bookmarkIndex, node.title,
+       "Found the expected bookmark in the expected position");
+  }
 });