Bug 561231 - Add a test for copying a separator from another instance, and also copying bookmarks within the same instance. r?mak draft
authorMark Banner <standard8@mozilla.com>
Mon, 09 Apr 2018 15:45:54 +0100
changeset 780356 c173ef823a816b3ffddd01d42d80462e3e3ab195
parent 779997 0528a414c2a86dad0623779abde5301d37337934
push id105978
push userbmo:standard8@mozilla.com
push dateWed, 11 Apr 2018 09:56:55 +0000
reviewersmak
bugs561231
milestone61.0a1
Bug 561231 - Add a test for copying a separator from another instance, and also copying bookmarks within the same instance. r?mak MozReview-Commit-ID: BJkpLbOlFmY
browser/components/places/tests/browser/browser_paste_bookmarks.js
--- a/browser/components/places/tests/browser/browser_paste_bookmarks.js
+++ b/browser/components/places/tests/browser/browser_paste_bookmarks.js
@@ -235,8 +235,137 @@ add_task(async function paste_from_diffe
                "Should be one bookmark in the unfiled folder.");
   Assert.equal(tree.children[0].title, "test",
                "Should have the correct title");
   Assert.equal(tree.children[0].uri, TEST_URL1,
                "Should have the correct URL");
 
   await PlacesUtils.bookmarks.remove(tree.children[0].guid);
 });
+
+
+add_task(async function paste_separator_from_different_instance() {
+  let xferable = Cc["@mozilla.org/widget/transferable;1"]
+                   .createInstance(Ci.nsITransferable);
+  xferable.init(null);
+
+  // Fake data on the clipboard to pretend this is from a different instance
+  // of Firefox.
+  let data = {
+    "title": "test",
+    "id": 32,
+    "instanceId": "FAKEFAKEFAKE",
+    "itemGuid": "ZBf_TYkrYGvW",
+    "parent": 452,
+    "dateAdded": 1464866275853000,
+    "lastModified": 1507638113352000,
+    "type": PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR
+  };
+  data = JSON.stringify(data);
+
+  xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_PLACE);
+  xferable.setTransferData(PlacesUtils.TYPE_X_MOZ_PLACE,
+                           PlacesUtils.toISupportsString(data),
+                           data.length * 2);
+
+  Services.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
+
+  info("Selecting UnfiledBookmarks in the left pane");
+  PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");
+
+  info("Pasting clipboard");
+  await ContentTree.view.controller.paste();
+
+  let tree = await PlacesUtils.promiseBookmarksTree(PlacesUtils.bookmarks.unfiledGuid);
+
+  Assert.equal(tree.children.length, 1,
+               "Should be one bookmark in the unfiled folder.");
+  Assert.equal(tree.children[0].type, PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
+               "Should have the correct type");
+
+  await PlacesUtils.bookmarks.remove(tree.children[0].guid);
+});
+
+add_task(async function paste_copy_check_indexes() {
+  info("Selecting BookmarksToolbar in the left pane");
+  PlacesOrganizer.selectLeftPaneBuiltIn("BookmarksToolbar");
+
+  let copyChildren = [];
+  let targetChildren = [];
+  for (let i = 0; i < 10; i++) {
+    copyChildren.push({
+      url: `${TEST_URL}${i}`,
+      title: `Copy ${i}`
+    });
+    targetChildren.push({
+      url: `${TEST_URL1}${i}`,
+      title: `Target ${i}`
+    });
+  }
+
+  let copyBookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.toolbarGuid,
+    children: copyChildren
+  });
+
+  let targetBookmarks = await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.unfiledGuid,
+    children: targetChildren
+  });
+
+  ContentTree.view.selectItems([
+    copyBookmarks[0].guid,
+    copyBookmarks[3].guid,
+    copyBookmarks[6].guid,
+    copyBookmarks[9].guid,
+  ]);
+
+  await promiseClipboard(() => {
+    info("Cutting multiple selection");
+    ContentTree.view.controller.copy();
+  }, PlacesUtils.TYPE_X_MOZ_PLACE);
+
+  info("Selecting UnfiledBookmarks in the left pane");
+  PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");
+
+  ContentTree.view.selectItems([targetBookmarks[4].guid]);
+
+  info("Pasting clipboard");
+  await ContentTree.view.controller.paste();
+
+  let tree = await PlacesUtils.promiseBookmarksTree(PlacesUtils.bookmarks.unfiledGuid);
+
+  const expectedBookmarkOrder = [
+    targetBookmarks[0].guid,
+    targetBookmarks[1].guid,
+    targetBookmarks[2].guid,
+    targetBookmarks[3].guid,
+    0,
+    3,
+    6,
+    9,
+    targetBookmarks[4].guid,
+    targetBookmarks[5].guid,
+    targetBookmarks[6].guid,
+    targetBookmarks[7].guid,
+    targetBookmarks[8].guid,
+    targetBookmarks[9].guid,
+  ];
+
+  Assert.equal(tree.children.length, expectedBookmarkOrder.length,
+               "Should be the expected amount of bookmarks in the unfiled folder.");
+
+  for (let i = 0; i < expectedBookmarkOrder.length; ++i) {
+    if (i > 3 && i <= 7) {
+      // Items 4 - 7 are copies of the original, so we need to compare data, rather
+      // than their guids.
+      Assert.equal(tree.children[i].title, copyChildren[expectedBookmarkOrder[i]].title,
+                   `Should have the correct bookmark title at index ${i}`);
+      Assert.equal(tree.children[i].uri, copyChildren[expectedBookmarkOrder[i]].url,
+                   `Should have the correct bookmark URL at index ${i}`);
+    } else {
+      Assert.equal(tree.children[i].guid, expectedBookmarkOrder[i],
+                   `Should be the expected item at index ${i}`);
+    }
+  }
+
+  await PlacesUtils.bookmarks.eraseEverything();
+});