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

--HG--
extra : rebase_source : 7a89b3818118ad33f50a5417f85c0500fc960c1b
This commit is contained in:
Mark Banner 2018-04-09 15:45:54 +01:00
Родитель 9ab1873cd3
Коммит 4a6483313a
1 изменённых файлов: 129 добавлений и 0 удалений

Просмотреть файл

@ -240,3 +240,132 @@ add_task(async function paste_from_different_instance() {
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();
});