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

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

Issue 7861024: Adds testing infrastructure to web_ui_browsertest to support testing HtmlDialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add description of what triggers notifications and why it's not a race condition. Created 9 years, 3 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/test_html_dialog_observer.cc
diff --git a/chrome/test/base/test_html_dialog_observer.cc b/chrome/test/base/test_html_dialog_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..66a7fa8bc6b31b819f14f21c6085c47df9e3ddaf
--- /dev/null
+++ b/chrome/test/base/test_html_dialog_observer.cc
@@ -0,0 +1,69 @@
+// 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/base/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. This depends
+ // on receiving the notification of the HtmlDialog being shown before the
+ // NavigationController finishes loading. The HtmlDialog notification is
+ // issued from html_dialog_ui.cc on RenderView creation which results from
+ // the call to render_manager_.Navigate in the method
+ // TabContents::NavigateToEntry. The new RenderView is later told to
+ // navigate in this method, ensuring that this is not a race condition.
+ 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_;
+}

Powered by Google App Engine
This is Rietveld 408576698