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

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

Issue 648833004: Componentize app_modal_dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: git cl try 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 e017345010e36ad4766e7c5acc50ac8c2b4ae139..cddceb4c08737c8d792d85a4c8bed1eeb754f9ed 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -30,8 +30,6 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
-#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
@@ -48,6 +46,8 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/find_in_page_observer.h"
+#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/search_engines/template_url_service.h"
#include "content/public/browser/dom_operation_notification_details.h"
@@ -107,6 +107,39 @@ Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
return new_browser;
}
+class AppModalDialogWaiter : public AppModalDialogNotifier {
+ public:
+ AppModalDialogWaiter()
+ : dialog_(NULL) {
+ }
+ virtual ~AppModalDialogWaiter() {
msw 2014/10/23 18:41:21 nit: I think even this can be marked override with
oshima 2014/10/23 21:44:18 Done.
+ }
+
+ AppModalDialog* Wait() {
+ if (dialog_)
+ return dialog_;
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ EXPECT_TRUE(dialog_);
+ return dialog_;
+ }
+
+ // AppModalDialogWaiter:
+ virtual void Notify(AppModalDialog* dialog) override {
+ DCHECK(!dialog_);
+ dialog_ = dialog;
+ if (!message_loop_runner_.get() || !message_loop_runner_->loop_running())
msw 2014/10/23 18:41:21 nit: reverse to conditionally Quit().
oshima 2014/10/23 21:44:18 Done.
+ return;
+ message_loop_runner_->Quit();
+ }
+
+ private:
+ AppModalDialog* dialog_;
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppModalDialogWaiter);
+};
+
} // namespace
bool GetCurrentTabTitle(const Browser* browser, base::string16* title) {
@@ -296,12 +329,8 @@ AppModalDialog* WaitForAppModalDialog() {
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
if (dialog_queue->HasActiveDialog())
return dialog_queue->active_dialog();
-
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
- content::NotificationService::AllSources());
- observer.Wait();
- return content::Source<AppModalDialog>(observer.source()).ptr();
+ AppModalDialogWaiter waiter;
+ return waiter.Wait();
}
int FindInPage(WebContents* tab,

Powered by Google App Engine
This is Rietveld 408576698