Index: chrome/browser/autocomplete/history_quick_provider_unittest.cc |
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
index 9b4cde953ece5ae3d78bb0e0ccc5485d510ca7c9..2345278472b331f927d16f3b5671bdf91ecb68f1 100644 |
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
@@ -19,7 +19,6 @@ |
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
#include "chrome/browser/autocomplete/history_url_provider.h" |
#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
-#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/history/history_backend.h" |
#include "chrome/browser/history/history_service.h" |
#include "chrome/browser/history/history_service_factory.h" |
@@ -31,6 +30,7 @@ |
#include "chrome/test/base/testing_profile.h" |
#include "components/bookmarks/test/bookmark_test_helpers.h" |
#include "components/history/core/browser/history_database.h" |
+#include "components/history/core/browser/history_service_observer.h" |
#include "components/history/core/browser/url_database.h" |
#include "components/metrics/proto/omnibox_event.pb.h" |
#include "components/omnibox/autocomplete_match.h" |
@@ -38,7 +38,6 @@ |
#include "components/search_engines/search_terms_data.h" |
#include "components/search_engines/template_url.h" |
#include "components/search_engines/template_url_service.h" |
-#include "content/public/browser/notification_service.h" |
#include "content/public/test/test_browser_thread.h" |
#include "content/public/test/test_utils.h" |
#include "sql/transaction.h" |
@@ -104,6 +103,51 @@ struct TestURLInfo { |
"83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} |
}; |
+// Waits for OnURLsDeletedNotification and when run quits the supplied run loop. |
+class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { |
+ public: |
+ explicit WaitForURLsDeletedObserver(base::RunLoop* runner); |
+ ~WaitForURLsDeletedObserver() override; |
+ |
+ private: |
+ // history::HistoryServiceObserver: |
+ void OnURLsDeleted(HistoryService* service, |
+ bool all_history, |
+ bool expired, |
+ const history::URLRows& deleted_rows, |
+ const std::set<GURL>& favicon_urls) override; |
+ |
+ // Weak. Owned by our owner. |
+ base::RunLoop* runner_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WaitForURLsDeletedObserver); |
+}; |
+ |
+WaitForURLsDeletedObserver::WaitForURLsDeletedObserver(base::RunLoop* runner) |
+ : runner_(runner) { |
+} |
+ |
+WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() { |
+} |
+ |
+void WaitForURLsDeletedObserver::OnURLsDeleted( |
+ HistoryService* service, |
+ bool all_history, |
+ bool expired, |
+ const history::URLRows& deleted_rows, |
+ const std::set<GURL>& favicon_urls) { |
+ runner_->Quit(); |
+} |
+ |
+void WaitForURLsDeletedNotification(HistoryService* history_service) { |
+ base::RunLoop runner; |
+ WaitForURLsDeletedObserver observer(&runner); |
+ ScopedObserver<HistoryService, history::HistoryServiceObserver> |
+ scoped_observer(&observer); |
+ scoped_observer.Add(history_service); |
+ runner.Run(); |
+} |
+ |
class HistoryQuickProviderTest : public testing::Test { |
public: |
HistoryQuickProviderTest() |
@@ -574,10 +618,7 @@ TEST_F(HistoryQuickProviderTest, DeleteMatch) { |
// InMemoryURLIndex) will drop any data they might have pertaining to the URL. |
// To ensure that the deletion has been propagated everywhere before we start |
// verifying post-deletion states, first wait until we see the notification. |
- content::WindowedNotificationObserver observer( |
- chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
- content::NotificationService::AllSources()); |
- observer.Wait(); |
+ WaitForURLsDeletedNotification(history_service_); |
EXPECT_FALSE(history_backend()->GetURL(test_url, NULL)); |
// Just to be on the safe side, explicitly verify that we have deleted enough |