Bug 1415522 - PlacesTransactions.Tag should take account of a URL that is already tagged. r?mak
MozReview-Commit-ID: 9Tev7BhbujQ
--- a/toolkit/components/places/PlacesTransactions.jsm
+++ b/toolkit/components/places/PlacesTransactions.jsm
@@ -1547,23 +1547,25 @@ PT.Tag.prototype = {
);
await createTxn.execute();
onUndo.unshift(createTxn.undo.bind(createTxn));
onRedo.push(createTxn.redo.bind(createTxn));
} else {
let uri = Services.io.newURI(url.href);
let currentTags = PlacesUtils.tagging.getTagsForURI(uri);
let newTags = tags.filter(t => !currentTags.includes(t));
- PlacesUtils.tagging.tagURI(uri, newTags);
- onUndo.unshift(() => {
- PlacesUtils.tagging.untagURI(uri, newTags);
- });
- onRedo.push(() => {
+ if (newTags.length) {
PlacesUtils.tagging.tagURI(uri, newTags);
- });
+ onUndo.unshift(() => {
+ PlacesUtils.tagging.untagURI(uri, newTags);
+ });
+ onRedo.push(() => {
+ PlacesUtils.tagging.tagURI(uri, newTags);
+ });
+ }
}
}
this.undo = async function() {
for (let f of onUndo) {
await f();
}
};
this.redo = async function() {
--- a/toolkit/components/places/tests/unit/test_async_transactions.js
+++ b/toolkit/components/places/tests/unit/test_async_transactions.js
@@ -1271,16 +1271,18 @@ add_task(async function test_tag_uri() {
await PT.undo();
await ensureTagsUnset();
}
await doTest({ url: bm_info_a.url, tags: ["MyTag"] });
await doTest({ urls: [bm_info_a.url], tag: "MyTag" });
await doTest({ urls: [bm_info_a.url, bm_info_b.url], tags: ["A, B"] });
await doTest({ urls: [bm_info_a.url, unbookmarked_uri], tag: "C" });
+ // Duplicate URLs listed.
+ await doTest({ urls: [bm_info_a.url, bm_info_b.url, bm_info_a.url], tag: "D" });
// Cleanup
observer.reset();
await PT.undo();
ensureItemsRemoved(bm_info_a, bm_info_b);
await PT.clearTransactionsHistory();
ensureUndoState();