Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7115)

Unified Diff: chrome/test/base/ui_test_utils.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 64f5115c8f5bf7e9619e68b34cf01ec3d02e16d9..f68f95ccfb0497e80e820300c97efee6efab2196 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_dialogs/app_modal_dialog.h"
#include "components/app_modal_dialogs/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"
@@ -363,14 +364,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());
@@ -540,4 +533,32 @@ void HistoryEnumerator::HistoryQueryComplete(
quit_task.Run();
}
+// Wait for HistoryService to load.
+class WaitHistoryLoadedObserver : public history::HistoryServiceObserver {
+ public:
+ explicit WaitHistoryLoadedObserver(content::MessageLoopRunner* runner)
+ : runner_(runner) {}
+ virtual ~WaitHistoryLoadedObserver() {}
sdefresne 2014/10/30 17:37:04 style: remove virtual, add override
nshaik 2014/10/30 21:48:36 Done.
+ // history::HistoryServiceObserver:
+ virtual void OnHistoryServiceLoaded(HistoryService* service) override {
sdefresne 2014/10/30 17:37:04 style: remove virtual
nshaik 2014/10/30 21:48:36 Done.
+ runner_->Quit();
+ }
+
+ private:
+ // weak
+ content::MessageLoopRunner* runner_;
+};
+
+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

Powered by Google App Engine
This is Rietveld 408576698