OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/stack_trace.h" | |
11 #include "base/file_path.h" | 10 #include "base/file_path.h" |
12 #include "base/file_util.h" | 11 #include "base/file_util.h" |
13 #include "base/path_service.h" | 12 #include "base/path_service.h" |
14 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
15 #include "base/test/test_file_util.h" | 14 #include "base/test/test_file_util.h" |
16 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/captive_portal/captive_portal_service.h" | 16 #include "chrome/browser/captive_portal/captive_portal_service.h" |
18 #include "chrome/browser/io_thread.h" | 17 #include "chrome/browser/io_thread.h" |
19 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 52 |
54 namespace { | 53 namespace { |
55 | 54 |
56 // Passed as value of kTestType. | 55 // Passed as value of kTestType. |
57 const char kBrowserTestType[] = "browser"; | 56 const char kBrowserTestType[] = "browser"; |
58 | 57 |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 InProcessBrowserTest::InProcessBrowserTest() | 60 InProcessBrowserTest::InProcessBrowserTest() |
62 : browser_(NULL) | 61 : browser_(NULL) |
63 #if defined(OS_POSIX) | |
64 , handle_sigterm_(true) | |
65 #endif | |
66 #if defined(OS_MACOSX) | 62 #if defined(OS_MACOSX) |
67 , autorelease_pool_(NULL) | 63 , autorelease_pool_(NULL) |
68 #endif // OS_MACOSX | 64 #endif // OS_MACOSX |
69 { | 65 { |
70 #if defined(OS_MACOSX) | 66 #if defined(OS_MACOSX) |
71 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. | 67 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. |
72 // Before we run the browser, we have to hack the path to the exe to match | 68 // Before we run the browser, we have to hack the path to the exe to match |
73 // what it would be if Chrome was running, because it is used to fork renderer | 69 // what it would be if Chrome was running, because it is used to fork renderer |
74 // processes, on Linux at least (failure to do so will cause a browser_test to | 70 // processes, on Linux at least (failure to do so will cause a browser_test to |
75 // be run instead of a renderer). | 71 // be run instead of a renderer). |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 new_command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); | 305 new_command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
310 | 306 |
311 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 307 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
312 iter != switches.end(); ++iter) { | 308 iter != switches.end(); ++iter) { |
313 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); | 309 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); |
314 } | 310 } |
315 return new_command_line; | 311 return new_command_line; |
316 } | 312 } |
317 #endif | 313 #endif |
318 | 314 |
319 #if defined(OS_POSIX) | |
320 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make | |
321 // debugging easier) and also exit with a known error code (so that the test | |
322 // framework considers this a failure -- http://crbug.com/57578). | |
323 static void DumpStackTraceSignalHandler(int signal) { | |
324 base::debug::StackTrace().PrintBacktrace(); | |
325 _exit(128 + signal); | |
326 } | |
327 #endif // defined(OS_POSIX) | |
328 | |
329 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 315 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
330 #if defined(OS_POSIX) | |
331 if (handle_sigterm_) | |
332 signal(SIGTERM, DumpStackTraceSignalHandler); | |
333 #endif // defined(OS_POSIX) | |
334 | |
335 // Pump startup related events. | 316 // Pump startup related events. |
336 content::RunAllPendingInMessageLoop(); | 317 content::RunAllPendingInMessageLoop(); |
337 | 318 |
338 #if defined(OS_MACOSX) | 319 #if defined(OS_MACOSX) |
339 autorelease_pool_->Recycle(); | 320 autorelease_pool_->Recycle(); |
340 #endif | 321 #endif |
341 | 322 |
342 if (!BrowserList::empty()) { | 323 if (!BrowserList::empty()) { |
343 browser_ = *BrowserList::begin(); | 324 browser_ = *BrowserList::begin(); |
344 content::WaitForLoadStop(chrome::GetActiveWebContents(browser_)); | 325 content::WaitForLoadStop(chrome::GetActiveWebContents(browser_)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // On the Mac, this eventually reaches | 376 // On the Mac, this eventually reaches |
396 // -[BrowserWindowController windowWillClose:], which will post a deferred | 377 // -[BrowserWindowController windowWillClose:], which will post a deferred |
397 // -autorelease on itself to ultimately destroy the Browser object. The line | 378 // -autorelease on itself to ultimately destroy the Browser object. The line |
398 // below is necessary to pump these pending messages to ensure all Browsers | 379 // below is necessary to pump these pending messages to ensure all Browsers |
399 // get deleted. | 380 // get deleted. |
400 content::RunAllPendingInMessageLoop(); | 381 content::RunAllPendingInMessageLoop(); |
401 delete autorelease_pool_; | 382 delete autorelease_pool_; |
402 autorelease_pool_ = NULL; | 383 autorelease_pool_ = NULL; |
403 #endif | 384 #endif |
404 } | 385 } |
OLD | NEW |