Index: chrome/test/base/ui_test_utils.cc |
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc |
index 4438ad61936be6b12be0ec8fc301c1e3cc3a33f3..e5300b5209b67d4a62c39ef8aeaae38909727ad7 100644 |
--- a/chrome/test/base/ui_test_utils.cc |
+++ b/chrome/test/base/ui_test_utils.cc |
@@ -49,6 +49,7 @@ |
#include "components/app_modal/app_modal_dialog.h" |
#include "components/app_modal/app_modal_dialog_queue.h" |
#include "components/bookmarks/browser/bookmark_model.h" |
+#include "components/history/core/browser/history_service_observer.h" |
#include "components/search_engines/template_url_service.h" |
#include "content/public/browser/dom_operation_notification_details.h" |
#include "content/public/browser/download_item.h" |
@@ -364,14 +365,6 @@ void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { |
ASSERT_TRUE(service->loaded()); |
} |
-void WaitForHistoryToLoad(HistoryService* history_service) { |
- content::WindowedNotificationObserver history_loaded_observer( |
- chrome::NOTIFICATION_HISTORY_LOADED, |
- content::NotificationService::AllSources()); |
- if (!history_service->BackendLoaded()) |
- history_loaded_observer.Wait(); |
-} |
- |
void DownloadURL(Browser* browser, const GURL& download_url) { |
base::ScopedTempDir downloads_directory; |
ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); |
@@ -541,4 +534,43 @@ void HistoryEnumerator::HistoryQueryComplete( |
quit_task.Run(); |
} |
+// Wait for HistoryService to load. |
+class WaitHistoryLoadedObserver : public history::HistoryServiceObserver { |
+ public: |
+ explicit WaitHistoryLoadedObserver(content::MessageLoopRunner* runner); |
+ ~WaitHistoryLoadedObserver() override; |
+ |
+ // history::HistoryServiceObserver: |
+ void OnHistoryServiceLoaded(HistoryService* service) override; |
+ |
+ private: |
+ // weak |
+ content::MessageLoopRunner* runner_; |
+}; |
+ |
+WaitHistoryLoadedObserver::WaitHistoryLoadedObserver( |
+ content::MessageLoopRunner* runner) |
+ : runner_(runner) { |
+} |
+ |
+WaitHistoryLoadedObserver::~WaitHistoryLoadedObserver() { |
+} |
+ |
+void WaitHistoryLoadedObserver::OnHistoryServiceLoaded( |
+ HistoryService* service) { |
+ runner_->Quit(); |
+} |
+ |
+void WaitForHistoryToLoad(HistoryService* history_service) { |
+ if (!history_service->BackendLoaded()) { |
+ scoped_refptr<content::MessageLoopRunner> runner = |
+ new content::MessageLoopRunner; |
+ WaitHistoryLoadedObserver observer(runner.get()); |
+ ScopedObserver<HistoryService, history::HistoryServiceObserver> |
+ scoped_observer(&observer); |
+ scoped_observer.Add(history_service); |
+ runner->Run(); |
+ } |
+} |
+ |
} // namespace ui_test_utils |