Bug 1415522 - PlacesTransactions.Tag should take account of a URL that is already tagged. r?mak draft
authorMark Banner <standard8@mozilla.com>
Wed, 08 Nov 2017 13:08:21 +0000
changeset 694950 1b543f4c91af44a09aa53b46bd69b13c1169d4d5
parent 694943 f63559d7e6a570e4e73ba367964099394248e18d
child 739468 9b9c3a590828fc1e47200b6c3c352c600d7701fc
push id88282
push userbmo:standard8@mozilla.com
push dateWed, 08 Nov 2017 13:08:36 +0000
reviewersmak
bugs1415522
milestone58.0a1
Bug 1415522 - PlacesTransactions.Tag should take account of a URL that is already tagged. r?mak MozReview-Commit-ID: 9Tev7BhbujQ
toolkit/components/places/PlacesTransactions.jsm
toolkit/components/places/tests/unit/test_async_transactions.js
--- 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();