Bug 1144571 - Pasting multiple bookmarks should retain their order. r=ttaubert
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 28 Mar 2015 14:00:11 +0100
changeset 266552 b7a9b5a6983b062aad92797eb3f8d876cc9b9ac7
parent 266551 ea17ed6738b56029e8302a6f0258da8e7fb20969
child 266553 9f25f9cf6ce1f6328c76858ddcb144143fc75949
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1144571
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1144571 - Pasting multiple bookmarks should retain their order. r=ttaubert
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");
+  }
 });