From 6ccff895ed73826734f9ae300f5c2cec23df762c Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Fri, 9 Feb 2018 11:21:14 +0000 Subject: [PATCH] Bug 1436966 - Remove the bookmark-observers & history-observers category listeners. r=mak MozReview-Commit-ID: 2dsyxZG98IR --HG-- extra : rebase_source : 89767cf42ee5e903f0b72900e7c8f85ac590a3c3 --- toolkit/components/places/nsNavBookmarks.cpp | 56 ++++++------------ toolkit/components/places/nsNavBookmarks.h | 1 - toolkit/components/places/nsNavHistory.cpp | 39 ++++-------- toolkit/components/places/nsNavHistory.h | 1 - .../components/places/nsPlacesExpiration.js | 6 ++ toolkit/components/places/nsPlacesMacros.h | 15 +---- .../places/tests/unit/nsDummyObserver.js | 45 -------------- .../tests/unit/nsDummyObserver.manifest | 4 -- .../places/tests/unit/test_bookmark_catobs.js | 59 ------------------- .../places/tests/unit/test_history_catobs.js | 44 -------------- .../components/places/tests/unit/xpcshell.ini | 4 -- .../components/places/toolkitplaces.manifest | 2 +- 12 files changed, 41 insertions(+), 235 deletions(-) delete mode 100644 toolkit/components/places/tests/unit/nsDummyObserver.js delete mode 100644 toolkit/components/places/tests/unit/nsDummyObserver.manifest delete mode 100644 toolkit/components/places/tests/unit/test_bookmark_catobs.js delete mode 100644 toolkit/components/places/tests/unit/test_history_catobs.js diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 1c36f9cf1cb2..454c9d86254a 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -163,7 +163,6 @@ nsNavBookmarks::nsNavBookmarks() , mToolbarRoot(0) , mMobileRoot(0) , mCanNotify(false) - , mCacheObservers("bookmark-observers") , mBatching(false) { NS_ASSERTION(!gBookmarksService, @@ -628,7 +627,7 @@ nsNavBookmarks::InsertBookmark(int64_t aFolder, rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, SKIP_TAGS(grandParentId == mTagsRoot), OnItemAdded(*aNewBookmarkId, aFolder, index, TYPE_BOOKMARK, aURI, title, dateAdded, @@ -647,8 +646,7 @@ nsNavBookmarks::InsertBookmark(int64_t aFolder, // Check that bookmarks doesn't include the current tag itemId. MOZ_ASSERT(bookmarks[i].id != *aNewBookmarkId); - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - DontSkip, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("tags"), false, @@ -758,7 +756,7 @@ nsNavBookmarks::RemoveItem(int64_t aItemId, uint16_t aSource) NS_WARNING_ASSERTION(uri, "Invalid URI in RemoveItem"); } - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, SKIP_TAGS(bookmark.parentId == tagsRootId || bookmark.grandParentId == tagsRootId), OnItemRemoved(bookmark.id, @@ -779,8 +777,7 @@ nsNavBookmarks::RemoveItem(int64_t aItemId, uint16_t aSource) NS_ENSURE_SUCCESS(rv, rv); for (uint32_t i = 0; i < bookmarks.Length(); ++i) { - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - DontSkip, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("tags"), false, @@ -881,7 +878,7 @@ nsNavBookmarks::CreateContainerWithID(int64_t aItemId, int64_t tagsRootId = TagsRootId(); - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, SKIP_TAGS(aParent == tagsRootId), OnItemAdded(*aNewFolder, aParent, index, FOLDER, nullptr, title, dateAdded, guid, @@ -937,8 +934,7 @@ nsNavBookmarks::InsertSeparator(int64_t aParent, rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - DontSkip, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip, OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR, nullptr, EmptyCString(), dateAdded, guid, folderGuid, aSource)); @@ -1211,7 +1207,7 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId, uint16_t aSource) NS_WARNING_ASSERTION(uri, "Invalid URI in RemoveFolderChildren"); } - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, ((child.grandParentId == tagsRootId) ? SkipTags : SkipDescendants), OnItemRemoved(child.id, child.parentId, @@ -1232,8 +1228,7 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId, uint16_t aSource) NS_ENSURE_SUCCESS(rv, rv); for (uint32_t i = 0; i < bookmarks.Length(); ++i) { - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - DontSkip, + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("tags"), false, @@ -1418,8 +1413,7 @@ nsNavBookmarks::MoveItem(int64_t aItemId, rv = transaction.Commit(); NS_ENSURE_SUCCESS(rv, rv); - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemMoved(bookmark.id, bookmark.parentId, bookmark.position, @@ -1587,8 +1581,7 @@ nsNavBookmarks::SetItemDateAdded(int64_t aItemId, PRTime aDateAdded, } // Note: mDBSetItemDateAdded also sets lastModified to aDateAdded. - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(bookmark.id, NS_LITERAL_CSTRING("dateAdded"), false, @@ -1658,8 +1651,7 @@ nsNavBookmarks::SetItemLastModified(int64_t aItemId, PRTime aLastModified, } // Note: mDBSetItemDateAdded also sets lastModified to aDateAdded. - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(bookmark.id, NS_LITERAL_CSTRING("lastModified"), false, @@ -1910,8 +1902,7 @@ nsNavBookmarks::SetItemTitle(int64_t aItemId, const nsACString& aTitle, NS_ENSURE_SUCCESS(rv, rv); } - NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - SKIP_TAGS(isChangingTagFolder), + NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, SKIP_TAGS(isChangingTagFolder), OnItemChanged(bookmark.id, NS_LITERAL_CSTRING("title"), false, @@ -2457,8 +2448,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId, NS_ENSURE_SUCCESS(rv, rv); for (uint32_t i = 0; i < bookmarks.Length(); ++i) { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("keyword"), false, @@ -2514,8 +2504,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId, rv = GetBookmarksForURI(oldUri, bookmarks); NS_ENSURE_SUCCESS(rv, rv); for (uint32_t i = 0; i < bookmarks.Length(); ++i) { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("keyword"), false, @@ -2585,8 +2574,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId, // In both cases, notify about the change. for (uint32_t i = 0; i < bookmarks.Length(); ++i) { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(bookmarks[i].id, NS_LITERAL_CSTRING("keyword"), false, @@ -2698,10 +2686,6 @@ nsNavBookmarks::GetObservers(uint32_t* _count, nsCOMArray observers; - // First add the category cache observers. - mCacheObservers.GetEntries(observers); - - // Then add the other observers. for (uint32_t i = 0; i < mObservers.Length(); ++i) { const nsCOMPtr &observer = mObservers.ElementAt(i).GetValue(); // Skip nullified weak observers. @@ -2727,8 +2711,7 @@ nsNavBookmarks::NotifyItemVisited(const ItemVisitData& aData) // couldn't gather enough data from the notification. // This should be false only if there's a bug in the code preceding us. if (uri) { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemVisited(aData.bookmark.id, aData.visitId, aData.time, @@ -2754,8 +2737,7 @@ nsNavBookmarks::NotifyItemChanged(const ItemChangeData& aData) aData.bookmark.id, lastModified)); } - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavBookmarkObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnItemChanged(aData.bookmark.id, aData.property, aData.isAnnotation, @@ -2794,7 +2776,7 @@ nsNavBookmarks::Observe(nsISupports *aSubject, const char *aTopic, NS_IMETHODIMP nsNavBookmarks::OnBeginUpdateBatch() { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnBeginUpdateBatch()); return NS_OK; } @@ -2807,7 +2789,7 @@ nsNavBookmarks::OnEndUpdateBatch() mBatching = false; } - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver, OnEndUpdateBatch()); return NS_OK; } diff --git a/toolkit/components/places/nsNavBookmarks.h b/toolkit/components/places/nsNavBookmarks.h index a59dab8555cd..bd2a932834aa 100644 --- a/toolkit/components/places/nsNavBookmarks.h +++ b/toolkit/components/places/nsNavBookmarks.h @@ -460,7 +460,6 @@ private: // Used to enable and disable the observer notifications. bool mCanNotify; - nsCategoryCache mCacheObservers; // Tracks whether we are in batch mode. // Note: this is only tracking bookmarks batches, not history ones. diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index 70a32da06a5d..682c7d163b16 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -286,7 +286,6 @@ nsNavHistory::nsNavHistory() , mLastCachedStartOfDay(INT64_MAX) , mLastCachedEndOfDay(0) , mCanNotify(true) - , mCacheObservers("history-observers") #ifdef XP_WIN , mCryptoProviderInitialized(false) #endif @@ -536,8 +535,7 @@ nsNavHistory::NotifyOnVisits(nsIVisitData** aVisits, uint32_t aVisitsCount) } } - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnVisits(aVisits, aVisitsCount)); } @@ -547,8 +545,8 @@ nsNavHistory::NotifyTitleChange(nsIURI* aURI, const nsACString& aGUID) { MOZ_ASSERT(!aGUID.IsEmpty()); - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, OnTitleChanged(aURI, aTitle, aGUID)); + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, + OnTitleChanged(aURI, aTitle, aGUID)); } void @@ -559,8 +557,7 @@ nsNavHistory::NotifyFrecencyChanged(nsIURI* aURI, PRTime aLastVisitDate) { MOZ_ASSERT(!aGUID.IsEmpty()); - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnFrecencyChanged(aURI, aNewFrecency, aGUID, aHidden, aLastVisitDate)); } @@ -568,8 +565,7 @@ nsNavHistory::NotifyFrecencyChanged(nsIURI* aURI, void nsNavHistory::NotifyManyFrecenciesChanged() { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnManyFrecenciesChanged()); } @@ -2379,9 +2375,6 @@ nsNavHistory::GetObservers(uint32_t* _count, nsCOMArray observers; - // First add the category cache observers. - mCacheObservers.GetEntries(observers); - // Then add the other observers. for (uint32_t i = 0; i < mObservers.Length(); ++i) { const nsCOMPtr &observer = mObservers.ElementAt(i).GetValue(); @@ -2408,8 +2401,7 @@ nsNavHistory::BeginUpdateBatch() mozIStorageConnection::TRANSACTION_DEFERRED, true); - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, OnBeginUpdateBatch()); + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnBeginUpdateBatch()); } return NS_OK; } @@ -2427,8 +2419,7 @@ nsNavHistory::EndUpdateBatch() mBatchDBTransaction = nullptr; } - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, OnEndUpdateBatch()); + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnEndUpdateBatch()); } return NS_OK; } @@ -2556,8 +2547,7 @@ nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString) else { // Notify that we will delete all visits for this page, but not the page // itself, since it's bookmarked or a place: query. - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnDeleteVisits(uri, 0, guid, nsINavHistoryObserver::REASON_DELETED, 0)); } } @@ -2604,8 +2594,7 @@ nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString) // Finally notify about the removed URIs. for (int32_t i = 0; i < URIs.Count(); ++i) { - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnDeleteURI(URIs[i], GUIDs[i], nsINavHistoryObserver::REASON_DELETED)); } @@ -2970,13 +2959,12 @@ nsNavHistory::NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime, MOZ_ASSERT(!aGUID.IsEmpty()); if (aWholeEntry) { // Notify our observers that the page has been removed. - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, OnDeleteURI(aURI, aGUID, aReason)); + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, + OnDeleteURI(aURI, aGUID, aReason)); } else { // Notify our observers that some visits for the page have been removed. - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnDeleteVisits(aURI, aVisitTime, aGUID, aReason, aTransitionType)); } @@ -4171,8 +4159,7 @@ nsNavHistory::SendPageChangedNotification(nsIURI* aURI, const nsACString& aGUID) { MOZ_ASSERT(!aGUID.IsEmpty()); - NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, - nsINavHistoryObserver, + NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnPageChanged(aURI, aChangedAttribute, aNewValue, aGUID)); } diff --git a/toolkit/components/places/nsNavHistory.h b/toolkit/components/places/nsNavHistory.h index f0f1abd89e45..535b5da57288 100644 --- a/toolkit/components/places/nsNavHistory.h +++ b/toolkit/components/places/nsNavHistory.h @@ -656,7 +656,6 @@ protected: // Used to enable and disable the observer notifications bool mCanNotify; - nsCategoryCache mCacheObservers; // Used to cache the call to CryptAcquireContext, which is expensive // when called thousands of times diff --git a/toolkit/components/places/nsPlacesExpiration.js b/toolkit/components/places/nsPlacesExpiration.js index 4d90efcf3690..8717449a86db 100644 --- a/toolkit/components/places/nsPlacesExpiration.js +++ b/toolkit/components/places/nsPlacesExpiration.js @@ -503,6 +503,12 @@ nsPlacesExpiration.prototype = { this._expireWithActionAndLimit(ACTION.IDLE_DAILY, LIMIT.LARGE); } else if (aTopic == TOPIC_TESTING_MODE) { this._testingMode = true; + } else if (aTopic == PlacesUtils.TOPIC_INIT_COMPLETE) { + // Ideally we'd add this observer only when notifications start being + // triggered. However, that's difficult to work out, so we do it on + // TOPIC_INIT_COMPLETE which means we have to take the hit of initializing + // this service slightly earlier. + PlacesUtils.history.addObserver(this, true); } }, diff --git a/toolkit/components/places/nsPlacesMacros.h b/toolkit/components/places/nsPlacesMacros.h index 47ebe17ac9be..db3d57a1c0fc 100644 --- a/toolkit/components/places/nsPlacesMacros.h +++ b/toolkit/components/places/nsPlacesMacros.h @@ -12,27 +12,16 @@ // Call a method on each observer in a category cache, then call the same // method on the observer array. -#define NOTIFY_OBSERVERS(canFire, cache, array, type, method) \ +#define NOTIFY_OBSERVERS(canFire, array, type, method) \ PR_BEGIN_MACRO \ if (canFire) { \ - nsCOMArray entries; \ - cache.GetEntries(entries); \ - for (int32_t idx = 0; idx < entries.Count(); ++idx) \ - entries[idx]->method; \ ENUMERATE_WEAKARRAY(array, type, method) \ } \ PR_END_MACRO; -#define NOTIFY_BOOKMARKS_OBSERVERS(canFire, cache, array, skipIf, method) \ +#define NOTIFY_BOOKMARKS_OBSERVERS(canFire, array, skipIf, method) \ PR_BEGIN_MACRO \ if (canFire) { \ - nsCOMArray entries; \ - cache.GetEntries(entries); \ - for (int32_t idx = 0; idx < entries.Count(); ++idx) { \ - if (skipIf(entries[idx])) \ - continue; \ - entries[idx]->method; \ - } \ for (uint32_t idx = 0; idx < array.Length(); ++idx) { \ const nsCOMPtr &e = array.ElementAt(idx).GetValue(); \ if (e) { \ diff --git a/toolkit/components/places/tests/unit/nsDummyObserver.js b/toolkit/components/places/tests/unit/nsDummyObserver.js deleted file mode 100644 index 7623d3fa3fa3..000000000000 --- a/toolkit/components/places/tests/unit/nsDummyObserver.js +++ /dev/null @@ -1,45 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -ChromeUtils.import("resource://gre/modules/Services.jsm"); - -// Dummy boomark/history observer -function DummyObserver() { - Services.obs.notifyObservers(null, "dummy-observer-created"); -} - -DummyObserver.prototype = { - // history observer - onBeginUpdateBatch() {}, - onEndUpdateBatch() {}, - onVisits(aVisits) { - Services.obs.notifyObservers(null, "dummy-observer-visited"); - }, - onTitleChanged() {}, - onDeleteURI() {}, - onClearHistory() {}, - onPageChanged() {}, - onDeleteVisits() {}, - - // bookmark observer - // onBeginUpdateBatch: function() {}, - // onEndUpdateBatch: function() {}, - onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI) { - Services.obs.notifyObservers(null, "dummy-observer-item-added"); - }, - onItemChanged() {}, - onItemRemoved() {}, - onItemVisited() {}, - onItemMoved() {}, - - classID: Components.ID("62e221d3-68c3-4e1a-8943-a27beb5005fe"), - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsINavBookmarkObserver, - Ci.nsINavHistoryObserver, - ]) -}; - -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DummyObserver]); diff --git a/toolkit/components/places/tests/unit/nsDummyObserver.manifest b/toolkit/components/places/tests/unit/nsDummyObserver.manifest deleted file mode 100644 index ed4d87fffadb..000000000000 --- a/toolkit/components/places/tests/unit/nsDummyObserver.manifest +++ /dev/null @@ -1,4 +0,0 @@ -component 62e221d3-68c3-4e1a-8943-a27beb5005fe nsDummyObserver.js -contract @mozilla.org/places/test/dummy-observer;1 62e221d3-68c3-4e1a-8943-a27beb5005fe -category bookmark-observers nsDummyObserver @mozilla.org/places/test/dummy-observer;1 -category history-observers nsDummyObserver @mozilla.org/places/test/dummy-observer;1 diff --git a/toolkit/components/places/tests/unit/test_bookmark_catobs.js b/toolkit/components/places/tests/unit/test_bookmark_catobs.js deleted file mode 100644 index 1903ff3951aa..000000000000 --- a/toolkit/components/places/tests/unit/test_bookmark_catobs.js +++ /dev/null @@ -1,59 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -add_task(async function test_observers() { - do_load_manifest("nsDummyObserver.manifest"); - - let dummyCreated = false; - let dummyReceivedOnItemAdded = false; - - Services.obs.addObserver(function created() { - Services.obs.removeObserver(created, "dummy-observer-created"); - dummyCreated = true; - }, "dummy-observer-created"); - Services.obs.addObserver(function added() { - Services.obs.removeObserver(added, "dummy-observer-item-added"); - dummyReceivedOnItemAdded = true; - }, "dummy-observer-item-added"); - - // This causes various Async API helpers to be initialised before the main - // part of the test runs - the helpers add their own listeners, which we don't - // want to count within the test (e.g. gKeywordsCachePromise & GuidHelper). - await PlacesUtils.promiseItemId(PlacesUtils.bookmarks.unfiledGuid); - - let initialObservers = PlacesUtils.bookmarks.getObservers(); - - // Add a common observer, it should be invoked after the category observer. - let notificationsPromised = new Promise((resolve, reject) => { - PlacesUtils.bookmarks.addObserver( { - __proto__: NavBookmarkObserver.prototype, - onItemAdded() { - let observers = PlacesUtils.bookmarks.getObservers(); - Assert.equal(observers.length, initialObservers.length + 1); - - // Check the common observer is the last one. - for (let i = 0; i < initialObservers.length; ++i) { - Assert.equal(initialObservers[i], observers[i]); - } - - PlacesUtils.bookmarks.removeObserver(this); - observers = PlacesUtils.bookmarks.getObservers(); - Assert.equal(observers.length, initialObservers.length); - - // Check the category observer has been invoked before this one. - Assert.ok(dummyCreated); - Assert.ok(dummyReceivedOnItemAdded); - resolve(); - } - }); - }); - - // Add a bookmark - await PlacesUtils.bookmarks.insert({ - parentGuid: PlacesUtils.bookmarks.unfiledGuid, - title: "bookmark", - url: "http://typed.mozilla.org", - }); - - await notificationsPromised; -}); diff --git a/toolkit/components/places/tests/unit/test_history_catobs.js b/toolkit/components/places/tests/unit/test_history_catobs.js deleted file mode 100644 index 271dba237ec7..000000000000 --- a/toolkit/components/places/tests/unit/test_history_catobs.js +++ /dev/null @@ -1,44 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -add_task(async function() { - do_load_manifest("nsDummyObserver.manifest"); - - let promises = []; - let resolved = 0; - promises.push(TestUtils.topicObserved("dummy-observer-created", () => ++resolved)); - promises.push(TestUtils.topicObserved("dummy-observer-visited", () => ++resolved)); - - let initialObservers = PlacesUtils.history.getObservers(); - - // Add a common observer, it should be invoked after the category observer. - promises.push(new Promise(resolve => { - let observer = new NavHistoryObserver(); - observer.onVisits = visits => { - Assert.equal(visits.length, 1, "Got the right number of visits"); - let uri = visits[0].uri; - info("Got visit for " + uri.spec); - let observers = PlacesUtils.history.getObservers(); - let observersCount = observers.length; - Assert.ok(observersCount > initialObservers.length); - - // Check the common observer is the last one. - for (let i = 0; i < initialObservers.length; ++i) { - Assert.equal(initialObservers[i], observers[i]); - } - - PlacesUtils.history.removeObserver(observer); - observers = PlacesUtils.history.getObservers(); - Assert.ok(observers.length < observersCount); - - // Check the category observer has been invoked before this one. - Assert.equal(resolved, 2); - resolve(); - }; - PlacesUtils.history.addObserver(observer); - })); - - info("Add a visit"); - await PlacesTestUtils.addVisits(uri("http://typed.mozilla.org")); - await Promise.all(promises); -}); diff --git a/toolkit/components/places/tests/unit/xpcshell.ini b/toolkit/components/places/tests/unit/xpcshell.ini index 7242e16cca5e..7594b9f031f3 100644 --- a/toolkit/components/places/tests/unit/xpcshell.ini +++ b/toolkit/components/places/tests/unit/xpcshell.ini @@ -14,8 +14,6 @@ support-files = mobile_bookmarks_multiple_folders.json mobile_bookmarks_root_import.json mobile_bookmarks_root_merge.json - nsDummyObserver.js - nsDummyObserver.manifest places.sparse.sqlite sync_utils_bookmarks.html sync_utils_bookmarks.json @@ -60,7 +58,6 @@ skip-if = os == "linux" [test_async_in_batchmode.js] [test_async_transactions.js] skip-if = (os == "win" && os_version == "5.1") # Bug 1158887 -[test_bookmark_catobs.js] [test_bookmarks_json.js] skip-if = (os == 'win' && ccov) # Bug 1423667 [test_bookmarks_json_corrupt.js] @@ -84,7 +81,6 @@ skip-if = (os == 'win' && ccov) # Bug 1423667 [test_getChildIndex.js] [test_hash.js] [test_history.js] -[test_history_catobs.js] [test_history_clear.js] [test_history_notifications.js] [test_history_observer.js] diff --git a/toolkit/components/places/toolkitplaces.manifest b/toolkit/components/places/toolkitplaces.manifest index b3c02c78e5d5..4dd54c5475d0 100644 --- a/toolkit/components/places/toolkitplaces.manifest +++ b/toolkit/components/places/toolkitplaces.manifest @@ -11,7 +11,7 @@ contract @mozilla.org/autocomplete/search;1?name=places-tag-autocomplete {1dcc23 # nsPlacesExpiration.js component {705a423f-2f69-42f3-b9fe-1517e0dee56f} nsPlacesExpiration.js contract @mozilla.org/places/expiration;1 {705a423f-2f69-42f3-b9fe-1517e0dee56f} -category history-observers nsPlacesExpiration @mozilla.org/places/expiration;1 +category places-init-complete nsPlacesExpiration @mozilla.org/places/expiration;1 # PlacesCategoriesStarter.js component {803938d5-e26d-4453-bf46-ad4b26e41114} PlacesCategoriesStarter.js