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

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: 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
« no previous file with comments | « chrome/common/chrome_constants.cc ('k') | components/OWNERS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..64f5115c8f5bf7e9619e68b34cf01ec3d02e16d9 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,38 @@ Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
return new_browser;
}
+class AppModalDialogWaiter : public AppModalDialogObserver {
+ public:
+ AppModalDialogWaiter()
+ : dialog_(NULL) {
+ }
+ ~AppModalDialogWaiter() override {
+ }
+
+ 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())
+ 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 +328,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,
« no previous file with comments | « chrome/common/chrome_constants.cc ('k') | components/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698