mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 06:15:43 +00:00
Bug 1103636 - PlacesTransactions.Remove(guids), PlacesTransactions.RemoveBookmarksForUrls. r=mak.
This commit is contained in:
parent
9c9d73d42e
commit
f07bafbc06
@ -1396,28 +1396,61 @@ PT.SortByName.prototype = {
|
||||
/**
|
||||
* Transaction for removing an item (any type).
|
||||
*
|
||||
* Required Input Properties: guid.
|
||||
* Required Input Properties: guids.
|
||||
*/
|
||||
PT.Remove = DefineTransaction(["guid"]);
|
||||
PT.Remove = DefineTransaction(["guids"]);
|
||||
PT.Remove.prototype = {
|
||||
execute: function* (aGuid) {
|
||||
const bms = PlacesUtils.bookmarks;
|
||||
*execute(aGuids) {
|
||||
function promiseBookmarksTree(guid) {
|
||||
try {
|
||||
return PlacesUtils.promiseBookmarksTree(guid);
|
||||
}
|
||||
catch(ex) {
|
||||
throw new Error("Failed to get info for the specified item (guid: " +
|
||||
guid + "). Ex: " + ex);
|
||||
}
|
||||
}
|
||||
let toRestore = [for (guid of aGuids) yield promiseBookmarksTree(guid)];
|
||||
|
||||
let itemInfo = null;
|
||||
try {
|
||||
itemInfo = yield PlacesUtils.promiseBookmarksTree(aGuid);
|
||||
}
|
||||
catch(ex) {
|
||||
throw new Error("Failed to get info for the specified item (guid: " +
|
||||
aGuid + "). Ex: " + ex);
|
||||
}
|
||||
PlacesUtils.bookmarks.removeItem(yield PlacesUtils.promiseItemId(aGuid));
|
||||
this.undo = createItemsFromBookmarksTree.bind(null, itemInfo, true);
|
||||
let removeThem = Task.async(function* () {
|
||||
for (let guid of aGuids) {
|
||||
PlacesUtils.bookmarks.removeItem(yield PlacesUtils.promiseItemId(guid));
|
||||
}
|
||||
});
|
||||
yield removeThem();
|
||||
|
||||
this.undo = Task.async(function* () {
|
||||
for (let info of toRestore) {
|
||||
yield createItemsFromBookmarksTree(info, true);
|
||||
}
|
||||
});
|
||||
this.redo = removeThem;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Transaction for tagging a URI.
|
||||
* Transactions for removing all bookmarks for one or more urls.
|
||||
*
|
||||
* Required Input Properties: urls.
|
||||
*/
|
||||
PT.RemoveBookmarksForUrls = DefineTransaction(["urls"]);
|
||||
PT.RemoveBookmarksForUrls.prototype = {
|
||||
*execute(aUrls) {
|
||||
let guids = [];
|
||||
for (let url of aUrls) {
|
||||
yield PlacesUtils.bookmarks.fetch({ url }, info => {
|
||||
guids.push(info.guid);
|
||||
});
|
||||
}
|
||||
let removeTxn = TransactionsHistory.getRawTransaction(PT.Remove(guids));
|
||||
yield removeTxn.execute();
|
||||
this.undo = removeTxn.undo.bind(removeTxn);
|
||||
this.redo = removeTxn.redo.bind(removeTxn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Transaction for tagging urls.
|
||||
*
|
||||
* Required Input Properties: urls, tags.
|
||||
*/
|
||||
|
@ -312,10 +312,12 @@ function* ensureEqualBookmarksTrees(aOriginal,
|
||||
yield ensureLivemarkCreatedByAddLivemark(aNew.guid);
|
||||
}
|
||||
|
||||
function* ensureBookmarksTreeRestoredCorrectly(aOriginalBookmarksTree) {
|
||||
let restoredTree =
|
||||
yield PlacesUtils.promiseBookmarksTree(aOriginalBookmarksTree.guid);
|
||||
yield ensureEqualBookmarksTrees(aOriginalBookmarksTree, restoredTree);
|
||||
function* ensureBookmarksTreeRestoredCorrectly(...aOriginalBookmarksTrees) {
|
||||
for (let originalTree of aOriginalBookmarksTrees) {
|
||||
let restoredTree =
|
||||
yield PlacesUtils.promiseBookmarksTree(originalTree.guid);
|
||||
yield ensureEqualBookmarksTrees(originalTree, restoredTree);
|
||||
}
|
||||
}
|
||||
|
||||
function* ensureNonExistent(...aGuids) {
|
||||
@ -1573,6 +1575,84 @@ add_task(function* test_annotate_multiple_items() {
|
||||
yield PT.undo();
|
||||
yield PT.undo();
|
||||
yield ensureNonExistent(...guids);
|
||||
PT.clearTransactionsHistory();
|
||||
yield PT.clearTransactionsHistory();
|
||||
observer.reset();
|
||||
});
|
||||
|
||||
add_task(function* test_remove_multiple() {
|
||||
let guids = [];
|
||||
yield PT.batch(function* () {
|
||||
let folderGuid = yield PT.NewFolder({ title: "Test Folder"
|
||||
, parentGuid: rootGuid }).transact();
|
||||
let nestedFolderGuid =
|
||||
yield PT.NewFolder({ title: "Nested Test Folder"
|
||||
, parentGuid: folderGuid }).transact();
|
||||
let nestedSepGuid = yield PT.NewSeparator(nestedFolderGuid).transact();
|
||||
|
||||
guids.push(folderGuid);
|
||||
|
||||
let bmGuid =
|
||||
yield PT.NewBookmark({ url: new URL("http://test.bookmark.removed")
|
||||
, parentGuid: rootGuid }).transact();
|
||||
guids.push(bmGuid);
|
||||
});
|
||||
|
||||
let originalInfos = [for (guid of guids)
|
||||
yield PlacesUtils.promiseBookmarksTree(guid)];
|
||||
|
||||
yield PT.Remove(guids).transact();
|
||||
yield ensureNonExistent(...guids);
|
||||
yield PT.undo();
|
||||
yield ensureBookmarksTreeRestoredCorrectly(...originalInfos);
|
||||
yield PT.redo();
|
||||
yield ensureNonExistent(...guids);
|
||||
yield PT.undo();
|
||||
yield ensureBookmarksTreeRestoredCorrectly(...originalInfos);
|
||||
|
||||
// Undo the New* transactions batch.
|
||||
yield PT.undo();
|
||||
yield ensureNonExistent(...guids);
|
||||
|
||||
// Redo it.
|
||||
yield PT.redo();
|
||||
yield ensureBookmarksTreeRestoredCorrectly(...originalInfos);
|
||||
|
||||
// Redo remove.
|
||||
yield PT.redo();
|
||||
yield ensureNonExistent(...guids);
|
||||
|
||||
// Cleanup
|
||||
yield PT.clearTransactionsHistory();
|
||||
observer.reset();
|
||||
});
|
||||
|
||||
add_task(function* test_remove_bookmarks_for_urls() {
|
||||
let urls = [new URL("http://test.url.1"), new URL("http://test.url.2")];
|
||||
let guids = [];
|
||||
yield PT.batch(function* () {
|
||||
for (let url of urls) {
|
||||
for (let title of ["test title a", "test title b"]) {
|
||||
let txn = PT.NewBookmark({ url, title, parentGuid: rootGuid });
|
||||
guids.push(yield txn.transact());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let originalInfos = [for (guid of guids)
|
||||
yield PlacesUtils.promiseBookmarksTree(guid)];
|
||||
|
||||
yield PT.RemoveBookmarksForUrls(urls).transact();
|
||||
yield ensureNonExistent(...guids);
|
||||
yield PT.undo();
|
||||
yield ensureBookmarksTreeRestoredCorrectly(...originalInfos);
|
||||
yield PT.redo();
|
||||
yield ensureNonExistent(...guids);
|
||||
yield PT.undo();
|
||||
yield ensureBookmarksTreeRestoredCorrectly(...originalInfos);
|
||||
|
||||
// Cleanup.
|
||||
yield PT.redo();
|
||||
yield ensureNonExistent(...guids);
|
||||
yield PT.clearTransactionsHistory();
|
||||
observer.reset();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user