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 "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 // See kManualTestPrefix above. | 421 // See kManualTestPrefix above. |
422 const char kRunManualTestsFlag[] = "run-manual"; | 422 const char kRunManualTestsFlag[] = "run-manual"; |
423 | 423 |
424 const char kSingleProcessTestsFlag[] = "single_process"; | 424 const char kSingleProcessTestsFlag[] = "single_process"; |
425 | 425 |
426 | 426 |
427 TestLauncherDelegate::~TestLauncherDelegate() { | 427 TestLauncherDelegate::~TestLauncherDelegate() { |
428 } | 428 } |
429 | 429 |
| 430 #if defined(OS_WIN) || defined(OS_LINUX) |
430 bool ShouldRunContentMain() { | 431 bool ShouldRunContentMain() { |
431 #if defined(OS_WIN) || defined(OS_LINUX) | |
432 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 432 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
433 return command_line->HasSwitch(switches::kProcessType) || | 433 return command_line->HasSwitch(switches::kProcessType) || |
434 command_line->HasSwitch(kLaunchAsBrowser); | 434 command_line->HasSwitch(kLaunchAsBrowser); |
435 #else | |
436 return false; | 435 return false; |
437 #endif // defined(OS_WIN) || defined(OS_LINUX) | |
438 } | 436 } |
439 | 437 |
440 int RunContentMain(int argc, char** argv, | 438 int RunContentMain(int argc, char** argv, |
441 TestLauncherDelegate* launcher_delegate) { | 439 TestLauncherDelegate* launcher_delegate) { |
| 440 scoped_ptr<ContentMainDelegate> chrome_main_delegate( |
| 441 launcher_delegate->CreateContentMainDelegate()); |
| 442 ContentMainParams params(chrome_main_delegate.get()); |
| 443 |
442 #if defined(OS_WIN) | 444 #if defined(OS_WIN) |
443 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 445 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
444 InitializeSandboxInfo(&sandbox_info); | 446 InitializeSandboxInfo(&sandbox_info); |
445 scoped_ptr<ContentMainDelegate> chrome_main_delegate( | 447 |
446 launcher_delegate->CreateContentMainDelegate()); | 448 params.instance = GetModuleHandle(NULL); |
447 return ContentMain(GetModuleHandle(NULL), | 449 params.sandbox_info = &sandbox_info; |
448 &sandbox_info, | |
449 chrome_main_delegate.get()); | |
450 #elif defined(OS_LINUX) | 450 #elif defined(OS_LINUX) |
451 scoped_ptr<ContentMainDelegate> chrome_main_delegate( | 451 params.argc = argc; |
452 launcher_delegate->CreateContentMainDelegate()); | 452 params.argv = const_cast<const char**>(argv); |
453 return ContentMain(argc, const_cast<const char**>(argv), | |
454 chrome_main_delegate.get()); | |
455 #endif // defined(OS_WIN) | 453 #endif // defined(OS_WIN) |
456 NOTREACHED(); | 454 |
457 return 0; | 455 return ContentMain(params); |
458 } | 456 } |
| 457 #endif |
459 | 458 |
460 int LaunchTests(TestLauncherDelegate* launcher_delegate, | 459 int LaunchTests(TestLauncherDelegate* launcher_delegate, |
461 int default_jobs, | 460 int default_jobs, |
462 int argc, | 461 int argc, |
463 char** argv) { | 462 char** argv) { |
464 DCHECK(!g_launcher_delegate); | 463 DCHECK(!g_launcher_delegate); |
465 g_launcher_delegate = launcher_delegate; | 464 g_launcher_delegate = launcher_delegate; |
466 | 465 |
467 CommandLine::Init(argc, argv); | 466 CommandLine::Init(argc, argv); |
468 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 467 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
(...skipping 11 matching lines...) Expand all Loading... |
480 #if defined(OS_WIN) | 479 #if defined(OS_WIN) |
481 if (command_line->HasSwitch(kSingleProcessTestsFlag)) { | 480 if (command_line->HasSwitch(kSingleProcessTestsFlag)) { |
482 sandbox::SandboxInterfaceInfo sandbox_info; | 481 sandbox::SandboxInterfaceInfo sandbox_info; |
483 InitializeSandboxInfo(&sandbox_info); | 482 InitializeSandboxInfo(&sandbox_info); |
484 InitializeSandbox(&sandbox_info); | 483 InitializeSandbox(&sandbox_info); |
485 } | 484 } |
486 #endif | 485 #endif |
487 return launcher_delegate->RunTestSuite(argc, argv); | 486 return launcher_delegate->RunTestSuite(argc, argv); |
488 } | 487 } |
489 | 488 |
| 489 #if defined(OS_WIN) || defined(OS_LINUX) |
490 if (ShouldRunContentMain()) | 490 if (ShouldRunContentMain()) |
491 return RunContentMain(argc, argv, launcher_delegate); | 491 return RunContentMain(argc, argv, launcher_delegate); |
| 492 #endif |
492 | 493 |
493 base::AtExitManager at_exit; | 494 base::AtExitManager at_exit; |
494 testing::InitGoogleTest(&argc, argv); | 495 testing::InitGoogleTest(&argc, argv); |
495 TestTimeouts::Initialize(); | 496 TestTimeouts::Initialize(); |
496 | 497 |
497 fprintf(stdout, | 498 fprintf(stdout, |
498 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" | 499 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" |
499 "For debugging a test inside a debugger, use the\n" | 500 "For debugging a test inside a debugger, use the\n" |
500 "--gtest_filter=<your_test_name> flag along with either\n" | 501 "--gtest_filter=<your_test_name> flag along with either\n" |
501 "--single_process (to run the test in one launcher/browser process) or\n" | 502 "--single_process (to run the test in one launcher/browser process) or\n" |
502 "--single-process (to do the above, and also run Chrome in single-" | 503 "--single-process (to do the above, and also run Chrome in single-" |
503 "process mode).\n"); | 504 "process mode).\n"); |
504 | 505 |
505 base::MessageLoopForIO message_loop; | 506 base::MessageLoopForIO message_loop; |
506 | 507 |
507 // Allow the |launcher_delegate| to modify |default_jobs|. | 508 // Allow the |launcher_delegate| to modify |default_jobs|. |
508 launcher_delegate->AdjustDefaultParallelJobs(&default_jobs); | 509 launcher_delegate->AdjustDefaultParallelJobs(&default_jobs); |
509 | 510 |
510 WrapperTestLauncherDelegate delegate(launcher_delegate); | 511 WrapperTestLauncherDelegate delegate(launcher_delegate); |
511 base::TestLauncher launcher(&delegate, default_jobs); | 512 base::TestLauncher launcher(&delegate, default_jobs); |
512 bool success = launcher.Run(argc, argv); | 513 bool success = launcher.Run(argc, argv); |
513 return (success ? 0 : 1); | 514 return (success ? 0 : 1); |
514 } | 515 } |
515 | 516 |
516 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 517 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
517 return g_launcher_delegate; | 518 return g_launcher_delegate; |
518 } | 519 } |
519 | 520 |
520 } // namespace content | 521 } // namespace content |
OLD | NEW |