[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 5 | #include "chrome/test/base/in_process_browser_test.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 6 | |
| 7 | #include "base/command_line.h" |
[email protected] | b25e61d | 2011-08-23 09:02:01 | [diff] [blame] | 8 | #include "base/debug/stack_trace.h" |
[email protected] | d841205 | 2009-04-21 22:01:01 | [diff] [blame] | 9 | #include "base/file_path.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 10 | #include "base/file_util.h" |
[email protected] | c2818d4 | 2010-10-18 02:47:39 | [diff] [blame] | 11 | #include "base/mac/scoped_nsautorelease_pool.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 12 | #include "base/path_service.h" |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame] | 13 | #include "base/string_number_conversions.h" |
[email protected] | fb895c6 | 2009-10-09 18:20:30 | [diff] [blame] | 14 | #include "base/test/test_file_util.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 15 | #include "chrome/browser/browser_process.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 16 | #include "chrome/browser/io_thread.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
| 18 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 19 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | f46be6e | 2010-11-16 03:52:32 | [diff] [blame] | 20 | #include "chrome/browser/ui/browser.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 21 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 339d6dd | 2010-11-12 00:41:58 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 24 | #include "chrome/common/chrome_constants.h" |
| 25 | #include "chrome/common/chrome_paths.h" |
| 26 | #include "chrome/common/chrome_switches.h" |
[email protected] | 0750b144 | 2010-11-02 21:59:37 | [diff] [blame] | 27 | #include "chrome/common/logging_chrome.h" |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 28 | #include "chrome/common/url_constants.h" |
[email protected] | aecb6ca | 2011-07-29 22:56:14 | [diff] [blame] | 29 | #include "chrome/test/base/test_launcher_utils.h" |
[email protected] | bf925774 | 2011-08-11 21:01:15 | [diff] [blame] | 30 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 31 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 1bda9755 | 2011-03-01 20:11:52 | [diff] [blame] | 32 | #include "content/browser/browser_thread.h" |
| 33 | #include "content/browser/renderer_host/render_process_host.h" |
| 34 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 35 | #include "content/common/content_notification_types.h" |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 36 | #include "content/common/main_function_params.h" |
[email protected] | a77e4bc | 2011-06-29 02:06:28 | [diff] [blame] | 37 | #include "content/renderer/mock_content_renderer_client.h" |
[email protected] | c4ff495 | 2010-01-08 19:12:47 | [diff] [blame] | 38 | #include "net/base/mock_host_resolver.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 39 | #include "net/test/test_server.h" |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 40 | #include "sandbox/src/dep.h" |
| 41 | |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 42 | #if defined(OS_MACOSX) |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 43 | #include "base/mac/mac_util.h" |
[email protected] | 7e15d35 | 2011-07-04 04:18:41 | [diff] [blame] | 44 | #include "base/system_monitor/system_monitor.h" |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 45 | #endif |
| 46 | |
[email protected] | e2e2411a | 2011-04-12 20:56:28 | [diff] [blame] | 47 | #if defined(OS_CHROMEOS) |
| 48 | #include "chrome/browser/chromeos/audio_handler.h" |
| 49 | #endif |
| 50 | |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 51 | extern int BrowserMain(const MainFunctionParams&); |
| 52 | |
[email protected] | ddf8a4b0 | 2010-03-22 23:08:30 | [diff] [blame] | 53 | // Passed as value of kTestType. |
| 54 | static const char kBrowserTestType[] = "browser"; |
| 55 | |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 56 | InProcessBrowserTest::InProcessBrowserTest() |
| 57 | : browser_(NULL), |
| 58 | show_window_(false), |
[email protected] | 56cdae3 | 2009-03-12 19:58:20 | [diff] [blame] | 59 | dom_automation_enabled_(false), |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 60 | tab_closeable_state_watcher_enabled_(false) { |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 61 | #if defined(OS_MACOSX) |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 62 | base::mac::SetOverrideAmIBundled(true); |
[email protected] | 7e15d35 | 2011-07-04 04:18:41 | [diff] [blame] | 63 | base::SystemMonitor::AllocateSystemIOPorts(); |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | // Before we run the browser, we have to hack the path to the exe to match |
| 67 | // what it would be if Chrome was running, because it is used to fork renderer |
| 68 | // processes, on Linux at least (failure to do so will cause a browser_test to |
| 69 | // be run instead of a renderer). |
| 70 | FilePath chrome_path; |
| 71 | CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
| 72 | chrome_path = chrome_path.DirName(); |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 73 | chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 74 | CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
| 75 | |
| 76 | test_server_.reset(new net::TestServer( |
| 77 | net::TestServer::TYPE_HTTP, |
| 78 | FilePath(FILE_PATH_LITERAL("chrome/test/data")))); |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | c4ff495 | 2010-01-08 19:12:47 | [diff] [blame] | 81 | InProcessBrowserTest::~InProcessBrowserTest() { |
| 82 | } |
| 83 | |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 84 | void InProcessBrowserTest::SetUp() { |
[email protected] | fc82ccf0 | 2010-10-15 18:12:47 | [diff] [blame] | 85 | // Create a temporary user data directory if required. |
| 86 | ASSERT_TRUE(CreateUserDataDirectory()) |
| 87 | << "Could not create user data directory."; |
[email protected] | 4a44bc3 | 2010-05-28 22:22:44 | [diff] [blame] | 88 | |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 89 | // Undo TestingBrowserProcess creation in ChromeTestSuite. |
| 90 | // TODO(phajdan.jr): Extract a smaller test suite so we don't need this. |
| 91 | DCHECK(g_browser_process); |
| 92 | delete g_browser_process; |
| 93 | g_browser_process = NULL; |
[email protected] | 298883bc | 2010-04-30 14:50:58 | [diff] [blame] | 94 | |
[email protected] | 470f7a5 | 2010-09-23 20:20:38 | [diff] [blame] | 95 | // Allow subclasses the opportunity to make changes to the default user data |
| 96 | // dir before running any tests. |
[email protected] | fc82ccf0 | 2010-10-15 18:12:47 | [diff] [blame] | 97 | ASSERT_TRUE(SetUpUserDataDirectory()) |
| 98 | << "Could not set up user data directory."; |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 99 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 100 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 101 | // Allow subclasses to change the command line before running any tests. |
[email protected] | 9665fa6 | 2009-04-13 22:15:29 | [diff] [blame] | 102 | SetUpCommandLine(command_line); |
[email protected] | 03c79d50 | 2010-11-16 00:38:26 | [diff] [blame] | 103 | // Add command line arguments that are used by all InProcessBrowserTests. |
| 104 | PrepareTestCommandLine(command_line); |
[email protected] | 9665fa6 | 2009-04-13 22:15:29 | [diff] [blame] | 105 | |
[email protected] | 15fd0df | 2011-04-29 16:00:16 | [diff] [blame] | 106 | // Single-process mode is not set in BrowserMain, so process it explicitly, |
| 107 | // and set up renderer. |
| 108 | if (command_line->HasSwitch(switches::kSingleProcess)) { |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 109 | RenderProcessHost::set_run_renderer_in_process(true); |
[email protected] | a77e4bc | 2011-06-29 02:06:28 | [diff] [blame] | 110 | single_process_renderer_client_.reset( |
| 111 | new content::MockContentRendererClient); |
[email protected] | 15fd0df | 2011-04-29 16:00:16 | [diff] [blame] | 112 | content::GetContentClient()->set_renderer( |
| 113 | single_process_renderer_client_.get()); |
| 114 | } |
[email protected] | 8bcdec9 | 2009-02-25 16:15:18 | [diff] [blame] | 115 | |
[email protected] | 02dbca0b | 2010-09-17 07:44:10 | [diff] [blame] | 116 | #if defined(OS_CHROMEOS) |
[email protected] | 0750b144 | 2010-11-02 21:59:37 | [diff] [blame] | 117 | // Make sure that the log directory exists. |
| 118 | FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); |
| 119 | file_util::CreateDirectory(log_dir); |
[email protected] | 02dbca0b | 2010-09-17 07:44:10 | [diff] [blame] | 120 | #endif // defined(OS_CHROMEOS) |
| 121 | |
[email protected] | 6777043 | 2011-09-21 18:12:32 | [diff] [blame] | 122 | host_resolver_ = new net::RuleBasedHostResolverProc(NULL); |
[email protected] | c7ad50f | 2009-09-11 06:28:15 | [diff] [blame] | 123 | |
| 124 | // Something inside the browser does this lookup implicitly. Make it fail |
| 125 | // to avoid external dependency. It won't break the tests. |
| 126 | host_resolver_->AddSimulatedFailure("*.google.com"); |
| 127 | |
| 128 | // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 129 | // We don't want the test code to use it. |
| 130 | host_resolver_->AddSimulatedFailure("wpad"); |
| 131 | |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 132 | net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( |
[email protected] | c7ad50f | 2009-09-11 06:28:15 | [diff] [blame] | 133 | host_resolver_.get()); |
[email protected] | 5c5de8c | 2009-09-23 17:11:26 | [diff] [blame] | 134 | |
[email protected] | 6777043 | 2011-09-21 18:12:32 | [diff] [blame] | 135 | SandboxInitWrapper sandbox_wrapper; |
| 136 | MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
| 137 | params.ui_task = |
| 138 | NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); |
[email protected] | 60a782e | 2010-02-24 22:41:35 | [diff] [blame] | 139 | |
[email protected] | 6777043 | 2011-09-21 18:12:32 | [diff] [blame] | 140 | SetUpInProcessBrowserTestFixture(); |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 141 | BrowserMain(params); |
[email protected] | 5c5de8c | 2009-09-23 17:11:26 | [diff] [blame] | 142 | TearDownInProcessBrowserTestFixture(); |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 143 | } |
| 144 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 145 | void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { |
[email protected] | 03c79d50 | 2010-11-16 00:38:26 | [diff] [blame] | 146 | // Propagate commandline settings from test_launcher_utils. |
| 147 | test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
| 148 | |
[email protected] | 03c79d50 | 2010-11-16 00:38:26 | [diff] [blame] | 149 | if (dom_automation_enabled_) |
| 150 | command_line->AppendSwitch(switches::kDomAutomationController); |
| 151 | |
| 152 | // This is a Browser test. |
| 153 | command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); |
| 154 | |
| 155 | #if defined(OS_WIN) |
| 156 | // The Windows sandbox requires that the browser and child processes are the |
| 157 | // same binary. So we launch browser_process.exe which loads chrome.dll |
| 158 | command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 159 | command_line->GetProgram()); |
| 160 | #else |
| 161 | // Explicitly set the path of the binary used for child processes, otherwise |
| 162 | // they'll try to use browser_tests which doesn't contain ChromeMain. |
| 163 | FilePath subprocess_path; |
| 164 | PathService::Get(base::FILE_EXE, &subprocess_path); |
| 165 | #if defined(OS_MACOSX) |
| 166 | // Recreate the real environment, run the helper within the app bundle. |
| 167 | subprocess_path = subprocess_path.DirName().DirName(); |
| 168 | DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
| 169 | subprocess_path = |
| 170 | subprocess_path.Append("Versions").Append(chrome::kChromeVersion); |
| 171 | subprocess_path = |
| 172 | subprocess_path.Append(chrome::kHelperProcessExecutablePath); |
| 173 | #endif |
| 174 | command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 175 | subprocess_path); |
| 176 | #endif |
| 177 | |
[email protected] | 7c8b2067 | 2011-02-11 21:18:01 | [diff] [blame] | 178 | // If neccessary, disable TabCloseableStateWatcher. |
[email protected] | 03c79d50 | 2010-11-16 00:38:26 | [diff] [blame] | 179 | if (!tab_closeable_state_watcher_enabled_) |
| 180 | command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); |
| 181 | } |
| 182 | |
[email protected] | fc82ccf0 | 2010-10-15 18:12:47 | [diff] [blame] | 183 | bool InProcessBrowserTest::CreateUserDataDirectory() { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 184 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | fc82ccf0 | 2010-10-15 18:12:47 | [diff] [blame] | 185 | FilePath user_data_dir = |
| 186 | command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 187 | if (user_data_dir.empty()) { |
| 188 | if (temp_user_data_dir_.CreateUniqueTempDir() && |
| 189 | temp_user_data_dir_.IsValid()) { |
| 190 | user_data_dir = temp_user_data_dir_.path(); |
| 191 | } else { |
| 192 | LOG(ERROR) << "Could not create temporary user data directory \"" |
| 193 | << temp_user_data_dir_.path().value() << "\"."; |
| 194 | return false; |
| 195 | } |
| 196 | } |
| 197 | return test_launcher_utils::OverrideUserDataDir(user_data_dir); |
| 198 | } |
| 199 | |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 200 | void InProcessBrowserTest::TearDown() { |
[email protected] | b7c64d6 | 2011-08-11 00:08:04 | [diff] [blame] | 201 | DCHECK(!g_browser_process); |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 204 | void InProcessBrowserTest::AddTabAtIndexToBrowser( |
| 205 | Browser* browser, |
| 206 | int index, |
| 207 | const GURL& url, |
| 208 | PageTransition::Type transition) { |
| 209 | browser::NavigateParams params(browser, url, transition); |
| 210 | params.tabstrip_index = index; |
| 211 | params.disposition = NEW_FOREGROUND_TAB; |
| 212 | browser::Navigate(¶ms); |
| 213 | } |
| 214 | |
| 215 | void InProcessBrowserTest::AddTabAtIndex( |
| 216 | int index, |
| 217 | const GURL& url, |
| 218 | PageTransition::Type transition) { |
| 219 | AddTabAtIndexToBrowser(browser(), index, url, transition); |
| 220 | } |
| 221 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 222 | bool InProcessBrowserTest::SetUpUserDataDirectory() { |
| 223 | return true; |
| 224 | } |
| 225 | |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 226 | // Creates a browser with a single tab (about:blank), waits for the tab to |
| 227 | // finish loading and shows the browser. |
| 228 | Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { |
| 229 | Browser* browser = Browser::Create(profile); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 230 | AddBlankTabAndShow(browser); |
[email protected] | e1c10f18 | 2010-09-30 08:53:06 | [diff] [blame] | 231 | return browser; |
| 232 | } |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 233 | |
[email protected] | 46f979d | 2011-01-10 17:08:44 | [diff] [blame] | 234 | Browser* InProcessBrowserTest::CreateIncognitoBrowser() { |
| 235 | // Create a new browser with using the incognito profile. |
| 236 | Browser* incognito = |
| 237 | Browser::Create(browser()->profile()->GetOffTheRecordProfile()); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 238 | AddBlankTabAndShow(incognito); |
[email protected] | 46f979d | 2011-01-10 17:08:44 | [diff] [blame] | 239 | return incognito; |
| 240 | } |
| 241 | |
[email protected] | e1c10f18 | 2010-09-30 08:53:06 | [diff] [blame] | 242 | Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) { |
[email protected] | 1b74d212 | 2010-10-06 16:49:16 | [diff] [blame] | 243 | Browser* browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 244 | AddBlankTabAndShow(browser); |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 245 | return browser; |
| 246 | } |
| 247 | |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 248 | void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) { |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 249 | ui_test_utils::WindowedNotificationObserver observer( |
| 250 | content::NOTIFICATION_LOAD_STOP, |
| 251 | NotificationService::AllSources()); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 252 | browser->AddSelectedTabWithURL( |
| 253 | GURL(chrome::kAboutBlankURL), PageTransition::START_PAGE); |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 254 | observer.Wait(); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 255 | |
[email protected] | fab6ffb | 2011-09-22 18:35:34 | [diff] [blame^] | 256 | browser->window()->Show(); |
[email protected] | de4943f | 2011-07-28 16:25:14 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | b25e61d | 2011-08-23 09:02:01 | [diff] [blame] | 259 | #if defined(OS_POSIX) |
| 260 | // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make |
| 261 | // debugging easier) and also exit with a known error code (so that the test |
| 262 | // framework considers this a failure -- http://crbug.com/57578). |
| 263 | static void DumpStackTraceSignalHandler(int signal) { |
| 264 | base::debug::StackTrace().PrintBacktrace(); |
| 265 | _exit(128 + signal); |
| 266 | } |
| 267 | #endif // defined(OS_POSIX) |
| 268 | |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 269 | void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
[email protected] | 00d0ac2 | 2010-10-05 09:30:00 | [diff] [blame] | 270 | #if defined(OS_POSIX) |
[email protected] | b25e61d | 2011-08-23 09:02:01 | [diff] [blame] | 271 | signal(SIGTERM, DumpStackTraceSignalHandler); |
[email protected] | 00d0ac2 | 2010-10-05 09:30:00 | [diff] [blame] | 272 | #endif // defined(OS_POSIX) |
| 273 | |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 274 | // On Mac, without the following autorelease pool, code which is directly |
| 275 | // executed (as opposed to executed inside a message loop) would autorelease |
| 276 | // objects into a higher-level pool. This pool is not recycled in-sync with |
| 277 | // the message loops' pools and causes problems with code relying on |
| 278 | // deallocation via an autorelease pool (such as browser window closure and |
| 279 | // browser shutdown). To avoid this, the following pool is recycled after each |
| 280 | // time code is directly executed. |
[email protected] | c2818d4 | 2010-10-18 02:47:39 | [diff] [blame] | 281 | base::mac::ScopedNSAutoreleasePool pool; |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 282 | |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 283 | // Pump startup related events. |
| 284 | MessageLoopForUI::current()->RunAllPending(); |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 285 | pool.Recycle(); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 286 | |
[email protected] | 6777043 | 2011-09-21 18:12:32 | [diff] [blame] | 287 | browser_ = CreateBrowser(ProfileManager::GetDefaultProfile()); |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 288 | pool.Recycle(); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 289 | |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 290 | // Pump any pending events that were created as a result of creating a |
| 291 | // browser. |
| 292 | MessageLoopForUI::current()->RunAllPending(); |
| 293 | |
[email protected] | 28dabab7 | 2011-01-05 03:31:26 | [diff] [blame] | 294 | SetUpOnMainThread(); |
| 295 | pool.Recycle(); |
| 296 | |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 297 | RunTestOnMainThread(); |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 298 | pool.Recycle(); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 299 | |
| 300 | CleanUpOnMainThread(); |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 301 | pool.Recycle(); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 302 | |
| 303 | QuitBrowsers(); |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 304 | pool.Recycle(); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void InProcessBrowserTest::QuitBrowsers() { |
| 308 | if (BrowserList::size() == 0) |
| 309 | return; |
| 310 | |
[email protected] | bc63a07 | 2011-06-28 21:12:57 | [diff] [blame] | 311 | // Invoke CloseAllBrowsersAndMayExit on a running message loop. |
| 312 | // CloseAllBrowsersAndMayExit exits the message loop after everything has been |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 313 | // shut down properly. |
| 314 | MessageLoopForUI::current()->PostTask( |
| 315 | FROM_HERE, |
[email protected] | bc63a07 | 2011-06-28 21:12:57 | [diff] [blame] | 316 | NewRunnableFunction(&BrowserList::AttemptExit)); |
[email protected] | 64f1931 | 2010-04-13 22:30:01 | [diff] [blame] | 317 | ui_test_utils::RunMessageLoop(); |
| 318 | } |