Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: content/public/test/test_launcher.cc

Issue 10912070: Makes it possible to run content_browsertests with --as-browser and fake WebRTC devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit fixes Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/test/test_launcher.h ('k') | content/test/content_test_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/process_util.h" 17 #include "base/process_util.h"
18 #include "base/scoped_temp_dir.h" 18 #include "base/scoped_temp_dir.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/test/test_suite.h" 21 #include "base/test/test_suite.h"
22 #include "base/test/test_timeouts.h" 22 #include "base/test/test_timeouts.h"
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #include "content/public/app/content_main.h"
26 #include "content/public/app/content_main_delegate.h"
25 #include "content/public/app/startup_helper_win.h" 27 #include "content/public/app/startup_helper_win.h"
28 #include "content/public/common/content_switches.h"
26 #include "content/public/common/sandbox_init.h" 29 #include "content/public/common/sandbox_init.h"
27 #include "content/public/test/browser_test.h" 30 #include "content/public/test/browser_test.h"
28 #include "net/base/escape.h" 31 #include "net/base/escape.h"
29 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
30 33
31 #if defined(OS_WIN) 34 #if defined(OS_WIN)
32 #include "base/base_switches.h" 35 #include "base/base_switches.h"
33 #include "content/common/sandbox_policy.h" 36 #include "content/common/sandbox_policy.h"
34 #include "sandbox/win/src/dep.h" 37 #include "sandbox/win/src/dep.h"
35 #include "sandbox/win/src/sandbox_factory.h" 38 #include "sandbox/win/src/sandbox_factory.h"
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 " --single-process\n" 618 " --single-process\n"
616 " Same as above, and also runs Chrome in single-process mode.\n" 619 " Same as above, and also runs Chrome in single-process mode.\n"
617 " --help\n" 620 " --help\n"
618 " Shows this message.\n" 621 " Shows this message.\n"
619 " --gtest_help\n" 622 " --gtest_help\n"
620 " Shows the gtest help message.\n"); 623 " Shows the gtest help message.\n");
621 } 624 }
622 625
623 } // namespace 626 } // namespace
624 627
628 // The following is kept for historical reasons (so people that are used to
629 // using it don't get surprised).
630 const char kChildProcessFlag[] = "child";
tommi (sloooow) - chröme 2012/09/06 09:57:29 only one space on each side of =
631
625 const char kGTestFilterFlag[] = "gtest_filter"; 632 const char kGTestFilterFlag[] = "gtest_filter";
626 const char kGTestHelpFlag[] = "gtest_help"; 633 const char kGTestHelpFlag[] = "gtest_help";
tommi (sloooow) - chröme 2012/09/06 09:57:29 please fix here as well and for "help" + "single-p
627 const char kGTestListTestsFlag[] = "gtest_list_tests"; 634 const char kGTestListTestsFlag[] = "gtest_list_tests";
628 const char kGTestRepeatFlag[] = "gtest_repeat"; 635 const char kGTestRepeatFlag[] = "gtest_repeat";
629 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; 636 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests";
630 const char kGTestOutputFlag[] = "gtest_output"; 637 const char kGTestOutputFlag[] = "gtest_output";
631 638
639 const char kHelpFlag[] = "help";
640
641 const char kLaunchAsBrowser[] = "as-browser";
642
643 // See kManualTestPrefix above.
644 const char kRunManualTestsFlag[] = "run-manual";
645
632 const char kSingleProcessTestsFlag[] = "single_process"; 646 const char kSingleProcessTestsFlag[] = "single_process";
633 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; 647 const char kSingleProcessTestsAndChromeFlag[] = "single-process";
634 648
635 // See kManualTestPrefix above.
636 const char kRunManualTestsFlag[] = "run-manual";
637
638 // The following is kept for historical reasons (so people that are used to
639 // using it don't get surprised).
640 const char kChildProcessFlag[] = "child";
641
642 const char kHelpFlag[] = "help";
643
644 const char kWarmupFlag[] = "warmup"; 649 const char kWarmupFlag[] = "warmup";
645 650
651
646 TestLauncherDelegate::~TestLauncherDelegate() { 652 TestLauncherDelegate::~TestLauncherDelegate() {
647 } 653 }
648 654
655 bool ShouldRunContentMain() {
656 #if defined(OS_WIN) || defined(OS_LINUX)
657 CommandLine* command_line = CommandLine::ForCurrentProcess();
658 return command_line->HasSwitch(switches::kProcessType) ||
659 command_line->HasSwitch(kLaunchAsBrowser);
660 #else
661 return false;
662 #endif // defined(OS_WIN) || defined(OS_LINUX)
663 }
664
665 int RunContentMain(int argc, char** argv,
666 TestLauncherDelegate* launcher_delegate) {
667 #if defined(OS_WIN)
668 sandbox::SandboxInterfaceInfo sandbox_info = {0};
669 content::InitializeSandboxInfo(&sandbox_info);
670 scoped_ptr<content::ContentMainDelegate> chrome_main_delegate(
671 launcher_delegate->CreateContentMainDelegate());
672 return content::ContentMain(GetModuleHandle(NULL),
673 &sandbox_info,
674 chrome_main_delegate.get());
675 #elif defined(OS_LINUX)
676 scoped_ptr<content::ContentMainDelegate> chrome_main_delegate(
677 launcher_delegate->CreateContentMainDelegate());
678 return content::ContentMain(argc,
679 const_cast<const char**>(argv),
680 chrome_main_delegate.get());
681 #endif // defined(OS_WIN)
682 NOTREACHED();
683 return 0;
684 }
685
649 int LaunchTests(TestLauncherDelegate* launcher_delegate, 686 int LaunchTests(TestLauncherDelegate* launcher_delegate,
650 int argc, 687 int argc,
651 char** argv) { 688 char** argv) {
652 DCHECK(!g_launcher_delegate); 689 DCHECK(!g_launcher_delegate);
653 g_launcher_delegate = launcher_delegate; 690 g_launcher_delegate = launcher_delegate;
654 691
655 CommandLine::Init(argc, argv); 692 CommandLine::Init(argc, argv);
656 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 693 const CommandLine* command_line = CommandLine::ForCurrentProcess();
657 694
658 if (command_line->HasSwitch(kHelpFlag)) { 695 if (command_line->HasSwitch(kHelpFlag)) {
(...skipping 12 matching lines...) Expand all
671 #if defined(OS_WIN) 708 #if defined(OS_WIN)
672 if (command_line->HasSwitch(kSingleProcessTestsFlag)) { 709 if (command_line->HasSwitch(kSingleProcessTestsFlag)) {
673 sandbox::SandboxInterfaceInfo sandbox_info; 710 sandbox::SandboxInterfaceInfo sandbox_info;
674 content::InitializeSandboxInfo(&sandbox_info); 711 content::InitializeSandboxInfo(&sandbox_info);
675 content::InitializeSandbox(&sandbox_info); 712 content::InitializeSandbox(&sandbox_info);
676 } 713 }
677 #endif 714 #endif
678 return launcher_delegate->RunTestSuite(argc, argv); 715 return launcher_delegate->RunTestSuite(argc, argv);
679 } 716 }
680 717
681 int return_code = 0; 718 if (ShouldRunContentMain())
682 if (launcher_delegate->Run(argc, argv, &return_code)) 719 return RunContentMain(argc, argv, launcher_delegate);
683 return return_code;
684 720
685 base::AtExitManager at_exit; 721 base::AtExitManager at_exit;
686 722
687 int32 total_shards; 723 int32 total_shards;
688 int32 shard_index; 724 int32 shard_index;
689 bool should_shard = ShouldShard(&total_shards, &shard_index); 725 bool should_shard = ShouldShard(&total_shards, &shard_index);
690 726
691 fprintf(stdout, 727 fprintf(stdout,
692 "Starting tests...\n" 728 "Starting tests...\n"
693 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" 729 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 cycles--; 779 cycles--;
744 } 780 }
745 return exit_code; 781 return exit_code;
746 } 782 }
747 783
748 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { 784 TestLauncherDelegate* GetCurrentTestLauncherDelegate() {
749 return g_launcher_delegate; 785 return g_launcher_delegate;
750 } 786 }
751 787
752 } // namespace test_launcher 788 } // namespace test_launcher
OLDNEW
« no previous file with comments | « content/public/test/test_launcher.h ('k') | content/test/content_test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698