diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-08 21:30:42 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-08 21:30:42 +0000 |
commit | 5c00ca86b708b403eef2a9ee616286b3aa91afb1 (patch) | |
tree | c28669570ae2e6db2bbcc3496926e1c33f241bb7 | |
parent | 94b3935dc10b4df5e017697fcad97d127fe03fcb (diff) | |
download | chromium_src-5c00ca86b708b403eef2a9ee616286b3aa91afb1.zip chromium_src-5c00ca86b708b403eef2a9ee616286b3aa91afb1.tar.gz chromium_src-5c00ca86b708b403eef2a9ee616286b3aa91afb1.tar.bz2 |
Changes browser_tests to not run a nested message loop.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1513014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44004 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 72 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.h | 15 |
3 files changed, 80 insertions, 14 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 25df1a8..fae898f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1129,8 +1129,15 @@ int BrowserMain(const MainFunctionParams& parameters) { // We are in test mode. Run one task and enter the main message loop. if (pool) pool->Recycle(); + // TODO(sky): revisit once Trung fixs mac exiting, mac should be just like + // windows/linux. +#if defined(OS_MACOSX) MessageLoopForUI::current()->PostTask(FROM_HERE, parameters.ui_task); RunUIMessageLoop(browser_process.get()); +#else + parameters.ui_task->Run(); + delete parameters.ui_task; +#endif } else { // We are in regular browser boot sequence. Open initial stabs and enter // the main message loop. diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 78ba891..d8f54d1 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) + 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) +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. @@ -278,12 +285,11 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { // may need to wait for beforeunload and unload handlers to fire in a tab. // When all windows are closed, the last window will call Quit(). Call // Quit() explicitly if no windows are open. -#if defined(OS_MACOSX) + // // When the browser window closes, Cocoa will generate an inner-loop that // processes the RenderProcessHost delete task, so allow task nesting. bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); MessageLoopForUI::current()->SetNestableTasksAllowed(true); -#endif BrowserList::const_iterator browser = BrowserList::begin(); if (browser == BrowserList::end()) { MessageLoopForUI::current()->Quit(); @@ -291,27 +297,69 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { for (; browser != BrowserList::end(); ++browser) (*browser)->CloseWindow(); } -#if defined(OS_MACOSX) MessageLoopForUI::current()->SetNestableTasksAllowed(old_state); -#endif // Stop the HTTP server. http_server_ = NULL; } +#endif // defined(OS_MACOSX) -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() { + // 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..d23b884 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) + // Old variant of RunTestOnMainThreadLoop that assumes a nested message loop. + // TODO(sky): nuke this once we straighten out properly exiting on the mac + // side. + 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_; |