summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-13 22:30:01 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-13 22:30:01 +0000
commit64f1931aa2983137f070ad9bb4fbe6219b447bd8 (patch)
treec4fc6267f7b4cd00346bcb2a4824e5e0007b5dde /chrome/test
parentd689bddd30ebfa891b5fa440d4a79237fc1035f9 (diff)
downloadchromium_src-64f1931aa2983137f070ad9bb4fbe6219b447bd8.zip
chromium_src-64f1931aa2983137f070ad9bb4fbe6219b447bd8.tar.gz
chromium_src-64f1931aa2983137f070ad9bb4fbe6219b447bd8.tar.bz2
Changes browser_tests to not run a nested message loop.
BUG=none TEST=none TBR=jcivelli Review URL: http://codereview.chromium.org/1606018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/in_process_browser_test.cc70
-rw-r--r--chrome/test/in_process_browser_test.h15
2 files changed, 75 insertions, 10 deletions
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index 78ba891..7463476 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -162,8 +162,14 @@ void InProcessBrowserTest::SetUp() {
SandboxInitWrapper sandbox_wrapper;
MainFunctionParams params(*command_line, sandbox_wrapper, NULL);
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
+ params.ui_task =
+ NewRunnableMethod(this,
+ &InProcessBrowserTest::RunTestOnMainThreadLoopDeprecated);
+#else
params.ui_task =
NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop);
+#endif
host_resolver_ = new net::RuleBasedHostResolverProc(
new IntranetRedirectHostResolverProc(NULL));
@@ -247,7 +253,8 @@ Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
return browser;
}
-void InProcessBrowserTest::RunTestOnMainThreadLoop() {
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
+void InProcessBrowserTest::RunTestOnMainThreadLoopDeprecated() {
// In the long term it would be great if we could use a TestingProfile
// here and only enable services you want tested, but that requires all
// consumers of Profile to handle NULL services.
@@ -298,20 +305,67 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
// Stop the HTTP server.
http_server_ = NULL;
}
+#endif // defined(OS_MACOSX) || defined(OS_CHROMEOS)
-void InProcessBrowserTest::TimedOut() {
- DCHECK(MessageLoopForUI::current()->IsNested());
+void InProcessBrowserTest::RunTestOnMainThreadLoop() {
+ // Pump startup related events.
+ MessageLoopForUI::current()->RunAllPending();
- std::string error_message = "Test timed out. Each test runs for a max of ";
- error_message += IntToString(kInitialTimeoutInMS);
- error_message += " ms (kInitialTimeoutInMS).";
+ // In the long term it would be great if we could use a TestingProfile
+ // here and only enable services you want tested, but that requires all
+ // consumers of Profile to handle NULL services.
+ Profile* profile = ProfileManager::GetDefaultProfile();
+ if (!profile) {
+ // We should only be able to get here if the profile already exists and
+ // has been created.
+ NOTREACHED();
+ return;
+ }
- GTEST_NONFATAL_FAILURE_(error_message.c_str());
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true));
+
+ browser_ = CreateBrowser(profile);
// Start the timeout timer to prevent hangs.
MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
- kSubsequentTimeoutInMS);
+ initial_timeout_);
+
+ // Pump any pending events that were created as a result of creating a
+ // browser.
+ MessageLoopForUI::current()->RunAllPending();
+
+ RunTestOnMainThread();
+
+ CleanUpOnMainThread();
+
+ QuitBrowsers();
+
+ // Stop the HTTP server.
+ http_server_ = NULL;
+}
+
+void InProcessBrowserTest::QuitBrowsers() {
+ if (BrowserList::size() == 0)
+ return;
+
+ // Invoke CloseAllBrowsersAndExit on a running message loop.
+ // CloseAllBrowsersAndExit exits the message loop after everything has been
+ // shut down properly.
+ MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit));
+ ui_test_utils::RunMessageLoop();
+}
+
+void InProcessBrowserTest::TimedOut() {
+ std::string error_message = "Test timed out. Each test runs for a max of ";
+ error_message += IntToString(kInitialTimeoutInMS);
+ error_message += " ms (kInitialTimeoutInMS).";
+
+ GTEST_NONFATAL_FAILURE_(error_message.c_str());
MessageLoopForUI::current()->Quit();
}
diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h
index 6e922d9..0c26123 100644
--- a/chrome/test/in_process_browser_test.h
+++ b/chrome/test/in_process_browser_test.h
@@ -115,10 +115,21 @@ class InProcessBrowserTest : public testing::Test {
void EnableSingleProcess() { single_process_ = true; }
private:
- // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and
- // destroys the browser.
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
+ // Old variant of RunTestOnMainThreadLoop that assumes a nested message loop.
+ // TODO(sky): nuke this once we straighten out properly exiting on the mac
+ // and chromeos sides.
+ void RunTestOnMainThreadLoopDeprecated();
+#endif
+
+ // This is invoked from main after browser_init/browser_main have completed.
+ // This prepares for the test by creating a new browser, runs the test
+ // (RunTestOnMainThread), quits the browsers and returns.
void RunTestOnMainThreadLoop();
+ // Quits all open browsers and waits until there are no more browsers.
+ void QuitBrowsers();
+
// Browser created from CreateBrowser.
Browser* browser_;