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

Unified Diff: chrome/browser/ui/webui/web_ui_browsertest.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: 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/browser/ui/webui/web_ui_browsertest.cc
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc
index 96204d134809ab658afea8db38c32642bb9835b8..414f2ee069b5dc7c140174316471073a613a7a4a 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/web_ui_browsertest.cc
@@ -15,11 +15,13 @@
#include "chrome/browser/ui/webui/chrome_web_ui.h"
#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/test_tab_strip_model_observer.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "content/common/content_notification_types.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "ui/base/resource/resource_bundle.h"
@@ -207,7 +209,10 @@ const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL";
WebUIBrowserTest::WebUIBrowserTest()
: test_handler_(new WebUITestHandler()),
- libraries_preloaded_(false) {}
+ libraries_preloaded_(false),
+ web_ui_instance_(NULL),
+ web_ui_instance_ready_(false),
+ message_loop_running_(false) {}
namespace {
@@ -249,6 +254,11 @@ void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() {
AddLibrary(FilePath(kWebUILibraryJS));
}
+void WebUIBrowserTest::ObserveNextHtmlDialog() {
+ registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
+ NotificationService::AllSources());
+}
+
void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() {
InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
TestChromeWebUIFactory::RemoveFactoryOverride(GURL(kDummyURL).host());
@@ -273,6 +283,39 @@ void WebUIBrowserTest::OnJsInjectionReady(RenderViewHost* render_view_host) {
render_view_host);
}
+void WebUIBrowserTest::Observe(int type,
Sheridan Rawlins 2011/09/09 15:47:50 I would prefer to see this and other logic broken
flackr 2011/09/15 18:41:52 Done.
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_HTML_DIALOG_SHOWN) {
Sheridan Rawlins 2011/09/09 15:47:50 Even though only 2 cases, this looks like a switch
flackr 2011/09/15 18:41:52 Done.
+ web_ui_instance_ = Source<WebUI>(source).ptr();
+ registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
+ NotificationService::AllSources());
+ // Wait for navigation to complete.
+ web_ui_instance_ready_ = false;
+ registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
Paweł Hajdan Jr. 2011/09/09 22:13:55 Is this possibly racy?
flackr 2011/09/15 18:41:52 I don't so, but I'm not certain. The first notific
+ Source<NavigationController>(
+ &web_ui_instance_->tab_contents()->controller()));
+ } else if (type == content::NOTIFICATION_LOAD_STOP) {
+ registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP,
+ Source<NavigationController>(
+ &web_ui_instance_->tab_contents()->controller()));
+ web_ui_instance_ready_ = true;
+ if (message_loop_running_) {
+ message_loop_running_ = false;
+ MessageLoopForUI::current()->Quit();
+ }
+ } else {
+ NOTREACHED() << "Unhandled notification type";
Sheridan Rawlins 2011/09/09 15:47:50 Don't bloat with message that doesn't add info (yo
flackr 2011/09/15 18:41:52 Done.
+ }
+}
+
+void WebUIBrowserTest::WaitForHtmlDialogLoad() {
+ if (!web_ui_instance_ready_) {
+ message_loop_running_ = true;
+ ui_test_utils::RunMessageLoop();
+ }
+}
+
void WebUIBrowserTest::BuildJavascriptLibraries(string16* content) {
ASSERT_TRUE(content != NULL);
std::string utf8_content;
@@ -363,7 +406,7 @@ bool WebUIBrowserTest::RunJavascriptUsingHandler(
}
void WebUIBrowserTest::SetupHandlers() {
- WebUI* web_ui_instance =
+ WebUI* web_ui_instance = web_ui_instance_ ? web_ui_instance_ :
browser()->GetSelectedTabContents()->web_ui();
ASSERT_TRUE(web_ui_instance != NULL);
web_ui_instance->register_callback_overwrites(true);

Powered by Google App Engine
This is Rietveld 408576698