diff options
Diffstat (limited to 'toolkit/components/places/tests/unit/test_bookmark-tags-changed_frequency.js')
-rw-r--r-- | toolkit/components/places/tests/unit/test_bookmark-tags-changed_frequency.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_bookmark-tags-changed_frequency.js b/toolkit/components/places/tests/unit/test_bookmark-tags-changed_frequency.js new file mode 100644 index 0000000000..568ad43841 --- /dev/null +++ b/toolkit/components/places/tests/unit/test_bookmark-tags-changed_frequency.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// This test checks that changing a tag for a bookmark with multiple tags +// notifies bookmark-tags-changed event only once, and not once per tag. + +add_task(async function run_test() { + let tags = ["a", "b", "c"]; + let uri = Services.io.newURI("http://1.moz.org/"); + + let bookmark = await PlacesUtils.bookmarks.insert({ + parentGuid: PlacesUtils.bookmarks.unfiledGuid, + url: uri, + title: "Bookmark 1", + }); + PlacesUtils.tagging.tagURI(uri, tags); + + let promise = PromiseUtils.defer(); + + let bookmarksObserver = { + _changedCount: 0, + handlePlacesEvents(events) { + for (let event of events) { + switch (event.type) { + case "bookmark-removed": + if (event.guid == bookmark.guid) { + PlacesUtils.observers.removeListener( + ["bookmark-removed"], + this.handlePlacesEvents + ); + Assert.equal(this._changedCount, 2); + promise.resolve(); + } + break; + case "bookmark-tags-changed": + Assert.equal(event.guid, bookmark.guid); + this._changedCount++; + break; + } + } + }, + }; + bookmarksObserver.handlePlacesEvents = + bookmarksObserver.handlePlacesEvents.bind(bookmarksObserver); + PlacesUtils.observers.addListener( + ["bookmark-removed", "bookmark-tags-changed"], + bookmarksObserver.handlePlacesEvents + ); + + PlacesUtils.tagging.tagURI(uri, ["d"]); + PlacesUtils.tagging.tagURI(uri, ["e"]); + + await promise; + + await PlacesUtils.bookmarks.remove(bookmark.guid); +}); |