OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/mac/scoped_nsautorelease_pool.h" | |
12 #include "base/path_service.h" | 11 #include "base/path_service.h" |
13 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
14 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/io_thread.h" | 15 #include "chrome/browser/io_thread.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/tabs/tab_strip_model.h" | 18 #include "chrome/browser/tabs/tab_strip_model.h" |
20 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
33 #include "content/browser/renderer_host/render_process_host.h" | 32 #include "content/browser/renderer_host/render_process_host.h" |
34 #include "content/browser/tab_contents/tab_contents.h" | 33 #include "content/browser/tab_contents/tab_contents.h" |
35 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
37 #include "content/renderer/mock_content_renderer_client.h" | 36 #include "content/renderer/mock_content_renderer_client.h" |
38 #include "net/base/mock_host_resolver.h" | 37 #include "net/base/mock_host_resolver.h" |
39 #include "net/test/test_server.h" | 38 #include "net/test/test_server.h" |
40 | 39 |
41 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
42 #include "chrome/browser/chromeos/audio_handler.h" | 41 #include "chrome/browser/chromeos/audio_handler.h" |
42 #elif defined(OS_MACOSX) | |
43 #include "base/mac/scoped_nsautorelease_pool.h" | |
43 #endif | 44 #endif |
44 | 45 |
45 // Passed as value of kTestType. | 46 // Passed as value of kTestType. |
46 static const char kBrowserTestType[] = "browser"; | 47 static const char kBrowserTestType[] = "browser"; |
47 | 48 |
48 InProcessBrowserTest::InProcessBrowserTest() | 49 InProcessBrowserTest::InProcessBrowserTest() |
49 : browser_(NULL), | 50 : browser_(NULL), |
50 show_window_(false), | 51 show_window_(false), |
51 dom_automation_enabled_(false), | 52 dom_automation_enabled_(false), |
52 tab_closeable_state_watcher_enabled_(false) { | 53 tab_closeable_state_watcher_enabled_(false) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 base::debug::StackTrace().PrintBacktrace(); | 249 base::debug::StackTrace().PrintBacktrace(); |
249 _exit(128 + signal); | 250 _exit(128 + signal); |
250 } | 251 } |
251 #endif // defined(OS_POSIX) | 252 #endif // defined(OS_POSIX) |
252 | 253 |
253 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 254 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
254 #if defined(OS_POSIX) | 255 #if defined(OS_POSIX) |
255 signal(SIGTERM, DumpStackTraceSignalHandler); | 256 signal(SIGTERM, DumpStackTraceSignalHandler); |
256 #endif // defined(OS_POSIX) | 257 #endif // defined(OS_POSIX) |
257 | 258 |
259 #if defined(OS_MACOSX) | |
258 // On Mac, without the following autorelease pool, code which is directly | 260 // On Mac, without the following autorelease pool, code which is directly |
259 // executed (as opposed to executed inside a message loop) would autorelease | 261 // executed (as opposed to executed inside a message loop) would autorelease |
260 // objects into a higher-level pool. This pool is not recycled in-sync with | 262 // objects into a higher-level pool. This pool is not recycled in-sync with |
261 // the message loops' pools and causes problems with code relying on | 263 // the message loops' pools and causes problems with code relying on |
262 // deallocation via an autorelease pool (such as browser window closure and | 264 // deallocation via an autorelease pool (such as browser window closure and |
263 // browser shutdown). To avoid this, the following pool is recycled after each | 265 // browser shutdown). To avoid this, the following pool is recycled after each |
264 // time code is directly executed. | 266 // time code is directly executed. |
265 base::mac::ScopedNSAutoreleasePool pool; | 267 base::mac::ScopedNSAutoreleasePool pool; |
268 #endif | |
266 | 269 |
267 // Pump startup related events. | 270 // Pump startup related events. |
268 MessageLoopForUI::current()->RunAllPending(); | 271 MessageLoopForUI::current()->RunAllPending(); |
272 #if defined(OS_MACOSX) | |
269 pool.Recycle(); | 273 pool.Recycle(); |
274 #endif | |
270 | 275 |
271 browser_ = CreateBrowser(ProfileManager::GetDefaultProfile()); | 276 browser_ = CreateBrowser(ProfileManager::GetDefaultProfile()); |
277 #if defined(OS_MACOSX) | |
272 pool.Recycle(); | 278 pool.Recycle(); |
279 #endif | |
273 | 280 |
274 // Pump any pending events that were created as a result of creating a | 281 // Pump any pending events that were created as a result of creating a |
275 // browser. | 282 // browser. |
276 MessageLoopForUI::current()->RunAllPending(); | 283 MessageLoopForUI::current()->RunAllPending(); |
277 | 284 |
278 SetUpOnMainThread(); | 285 SetUpOnMainThread(); |
286 #if defined(OS_MACOSX) | |
cpu_(ooo_6.6-7.5)
2011/10/29 01:35:39
I think the sprinkling of ifdefs on the test are a
jam
2011/10/29 01:49:10
I agree this test suffered the most. I wasn't that
| |
279 pool.Recycle(); | 287 pool.Recycle(); |
288 #endif | |
280 | 289 |
281 RunTestOnMainThread(); | 290 RunTestOnMainThread(); |
291 #if defined(OS_MACOSX) | |
282 pool.Recycle(); | 292 pool.Recycle(); |
293 #endif | |
283 | 294 |
284 CleanUpOnMainThread(); | 295 CleanUpOnMainThread(); |
296 #if defined(OS_MACOSX) | |
285 pool.Recycle(); | 297 pool.Recycle(); |
298 #endif | |
286 | 299 |
287 QuitBrowsers(); | 300 QuitBrowsers(); |
301 #if defined(OS_MACOSX) | |
288 pool.Recycle(); | 302 pool.Recycle(); |
303 #endif | |
289 } | 304 } |
290 | 305 |
291 void InProcessBrowserTest::QuitBrowsers() { | 306 void InProcessBrowserTest::QuitBrowsers() { |
292 if (BrowserList::size() == 0) | 307 if (BrowserList::size() == 0) |
293 return; | 308 return; |
294 | 309 |
295 // Invoke CloseAllBrowsersAndMayExit on a running message loop. | 310 // Invoke CloseAllBrowsersAndMayExit on a running message loop. |
296 // CloseAllBrowsersAndMayExit exits the message loop after everything has been | 311 // CloseAllBrowsersAndMayExit exits the message loop after everything has been |
297 // shut down properly. | 312 // shut down properly. |
298 MessageLoopForUI::current()->PostTask( | 313 MessageLoopForUI::current()->PostTask( |
299 FROM_HERE, | 314 FROM_HERE, |
300 NewRunnableFunction(&BrowserList::AttemptExit)); | 315 NewRunnableFunction(&BrowserList::AttemptExit)); |
301 ui_test_utils::RunMessageLoop(); | 316 ui_test_utils::RunMessageLoop(); |
302 } | 317 } |
OLD | NEW |