Index: chrome/test/test_html_dialog_observer.cc |
diff --git a/chrome/test/test_html_dialog_observer.cc b/chrome/test/test_html_dialog_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..90a75526bbab1ce54d58c7e0c471cfbe4dec7d69 |
--- /dev/null |
+++ b/chrome/test/test_html_dialog_observer.cc |
@@ -0,0 +1,63 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/test/test_html_dialog_observer.h" |
+ |
+#include "chrome/common/chrome_notification_types.h" |
+#include "content/common/content_notification_types.h" |
+#include "content/common/notification_details.h" |
+#include "content/common/notification_service.h" |
+#include "content/common/notification_source.h" |
+#include "content/browser/tab_contents/navigation_controller.h" |
+#include "content/browser/tab_contents/tab_contents.h" |
+#include "content/browser/webui/web_ui.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+ |
+TestHtmlDialogObserver::TestHtmlDialogObserver() |
+ : web_ui_(NULL), done_(false), running_(false) { |
+ registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
+ NotificationService::AllSources()); |
+} |
+ |
+TestHtmlDialogObserver::~TestHtmlDialogObserver() { |
+} |
+ |
+void TestHtmlDialogObserver::Observe(int type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ switch (type) { |
+ case chrome::NOTIFICATION_HTML_DIALOG_SHOWN: |
+ web_ui_ = Source<WebUI>(source).ptr(); |
+ registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
+ NotificationService::AllSources()); |
+ // Wait for navigation on the new WebUI instance to complete. |
+ registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
+ Source<NavigationController>( |
+ &web_ui_->tab_contents()->controller())); |
+ break; |
+ case content::NOTIFICATION_LOAD_STOP: |
+ DCHECK(web_ui_); |
+ registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, |
+ Source<NavigationController>( |
+ &web_ui_->tab_contents()->controller())); |
+ done_ = true; |
+ // If the message loop is running stop it. |
+ if (running_) { |
+ running_ = false; |
+ MessageLoopForUI::current()->Quit(); |
+ } |
+ break; |
+ default: |
+ NOTREACHED(); |
+ }; |
+} |
+ |
+WebUI* TestHtmlDialogObserver::GetWebUI() { |
+ if (!done_) { |
+ EXPECT_FALSE(running_); |
+ running_ = true; |
+ ui_test_utils::RunMessageLoop(); |
+ } |
+ return web_ui_; |
+} |