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

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: Review updates for --as-browser patch 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"
26 #include "content/public/common/sandbox_init.h" 28 #include "content/public/common/sandbox_init.h"
29 #include "content/public/common/content_switches.h"
jam 2012/09/05 15:26:51 nit: order
phoglund_chromium 2012/09/06 08:45:28 Done.
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"
36 #include "sandbox/win/src/sandbox_types.h" 39 #include "sandbox/win/src/sandbox_types.h"
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 const char kRunManualTestsFlag[] = "run-manual"; 639 const char kRunManualTestsFlag[] = "run-manual";
637 640
638 // The following is kept for historical reasons (so people that are used to 641 // The following is kept for historical reasons (so people that are used to
639 // using it don't get surprised). 642 // using it don't get surprised).
640 const char kChildProcessFlag[] = "child"; 643 const char kChildProcessFlag[] = "child";
641 644
642 const char kHelpFlag[] = "help"; 645 const char kHelpFlag[] = "help";
643 646
644 const char kWarmupFlag[] = "warmup"; 647 const char kWarmupFlag[] = "warmup";
645 648
649 const char kLaunchAsBrowser[] = "as-browser";
jam 2012/09/05 15:26:51 nit: order
phoglund_chromium 2012/09/06 08:45:28 Done. The other switches weren't in order so I sor
650
646 TestLauncherDelegate::~TestLauncherDelegate() { 651 TestLauncherDelegate::~TestLauncherDelegate() {
647 } 652 }
648 653
654 bool ShouldRunInBrowserMode() {
jam 2012/09/05 15:26:51 nit: this isn't just for running in browser, it's
phoglund_chromium 2012/09/06 08:45:28 Ok, then maybe it should even be ShouldRunContentM
655 #if defined(OS_WIN) || defined(OS_LINUX)
656 CommandLine* command_line = CommandLine::ForCurrentProcess();
657 return command_line->HasSwitch(switches::kProcessType) ||
658 command_line->HasSwitch(kLaunchAsBrowser);
659 #else
660 return false;
661 #endif // defined(OS_WIN) || defined(OS_LINUX)
662 }
663
664 int RunInBrowserMode(int argc, char** argv,
665 TestLauncherDelegate* launcher_delegate) {
666 #if defined(OS_WIN)
667 sandbox::SandboxInterfaceInfo sandbox_info = {0};
668 content::InitializeSandboxInfo(&sandbox_info);
669 scoped_ptr<content::ContentMainDelegate> chrome_main_delegate(
670 launcher_delegate->CreateContentMainDelegate());
671 return content::ContentMain(GetModuleHandle(NULL),
672 &sandbox_info,
673 chrome_main_delegate.get());
674 #elif defined(OS_LINUX)
675 scoped_ptr<content::ContentMainDelegate> chrome_main_delegate(
676 launcher_delegate->CreateContentMainDelegate());
677 return content::ContentMain(argc,
678 const_cast<const char**>(argv),
679 chrome_main_delegate.get());
680 #endif // defined(OS_WIN)
681 NOTREACHED();
682 return 0;
683 }
684
649 int LaunchTests(TestLauncherDelegate* launcher_delegate, 685 int LaunchTests(TestLauncherDelegate* launcher_delegate,
650 int argc, 686 int argc,
651 char** argv) { 687 char** argv) {
652 DCHECK(!g_launcher_delegate); 688 DCHECK(!g_launcher_delegate);
653 g_launcher_delegate = launcher_delegate; 689 g_launcher_delegate = launcher_delegate;
654 690
655 CommandLine::Init(argc, argv); 691 CommandLine::Init(argc, argv);
656 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 692 const CommandLine* command_line = CommandLine::ForCurrentProcess();
657 693
658 if (command_line->HasSwitch(kHelpFlag)) { 694 if (command_line->HasSwitch(kHelpFlag)) {
(...skipping 12 matching lines...) Expand all
671 #if defined(OS_WIN) 707 #if defined(OS_WIN)
672 if (command_line->HasSwitch(kSingleProcessTestsFlag)) { 708 if (command_line->HasSwitch(kSingleProcessTestsFlag)) {
673 sandbox::SandboxInterfaceInfo sandbox_info; 709 sandbox::SandboxInterfaceInfo sandbox_info;
674 content::InitializeSandboxInfo(&sandbox_info); 710 content::InitializeSandboxInfo(&sandbox_info);
675 content::InitializeSandbox(&sandbox_info); 711 content::InitializeSandbox(&sandbox_info);
676 } 712 }
677 #endif 713 #endif
678 return launcher_delegate->RunTestSuite(argc, argv); 714 return launcher_delegate->RunTestSuite(argc, argv);
679 } 715 }
680 716
681 int return_code = 0; 717 if (ShouldRunInBrowserMode()) {
jam 2012/09/05 15:26:51 what's the point of splitting this into two functi
phoglund_chromium 2012/09/06 08:45:28 I thought the code read better like this. The sema
682 if (launcher_delegate->Run(argc, argv, &return_code)) 718 return RunInBrowserMode(argc, argv, launcher_delegate);
683 return return_code; 719 }
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