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

Side by Side Diff: content/test/content_test_launcher.cc

Issue 8137012: Make an empty content browser test work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
OLDNEW
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 "content/test/test_launcher.h" 5 #include "content/test/test_launcher.h"
6 6
7 #include "base/base_paths.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
10 #include "content/test/content_test_suite.h" 12 #include "base/test/test_suite.h"
13 #include "content/app/content_main.h"
14 #include "content/common/content_switches.h"
15 #include "content/shell/shell_main_delegate.h"
16
17 #if defined(OS_WIN)
18 #include "base/base_switches.h"
19 #include "content/app/startup_helper_win.h"
20 #include "content/common/sandbox_policy.h"
21 #include "sandbox/src/dep.h"
22 #include "sandbox/src/sandbox_factory.h"
23 #include "sandbox/src/sandbox_types.h"
24 #endif // defined(OS_WIN)
11 25
12 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { 26 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
13 public: 27 public:
14 ContentTestLauncherDelegate() { 28 ContentTestLauncherDelegate() {
15 } 29 }
16 30
17 virtual ~ContentTestLauncherDelegate() { 31 virtual ~ContentTestLauncherDelegate() {
18 } 32 }
19 33
20 virtual void EarlyInitialize() OVERRIDE { 34 virtual void EarlyInitialize() OVERRIDE {
21 } 35 }
22 36
23 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { 37 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE {
24 CommandLine* command_line = CommandLine::ForCurrentProcess(); 38 CommandLine* command_line = CommandLine::ForCurrentProcess();
25 39
26 // TODO(pkasting): This "single_process vs. single-process" design is 40 // TODO(pkasting): This "single_process vs. single-process" design is
27 // terrible UI. Instead, there should be some sort of signal flag on the 41 // terrible UI. Instead, there should be some sort of signal flag on the
28 // command line, with all subsequent arguments passed through to the 42 // command line, with all subsequent arguments passed through to the
29 // underlying browser. 43 // underlying browser.
30 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag) || 44 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag) ||
31 command_line->HasSwitch( 45 command_line->HasSwitch(
32 test_launcher::kSingleProcessTestsAndChromeFlag) || 46 test_launcher::kSingleProcessTestsAndChromeFlag) ||
33 command_line->HasSwitch(test_launcher::kGTestListTestsFlag) || 47 command_line->HasSwitch(test_launcher::kGTestListTestsFlag) ||
34 command_line->HasSwitch(test_launcher::kGTestHelpFlag)) { 48 command_line->HasSwitch(test_launcher::kGTestHelpFlag)) {
35 *return_code = ContentTestSuite(argc, argv).Run(); 49 #if defined(OS_WIN)
jam 2011/10/04 22:21:13 we shouldn't copy all this code from chrome_test_l
Paweł Hajdan Jr. 2011/10/04 23:19:48 Done.
50 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag)) {
51 // This is the browser process, so setup the sandbox broker.
52 sandbox::BrokerServices* broker_services =
53 sandbox::SandboxFactory::GetBrokerServices();
54 if (broker_services) {
55 sandbox::InitBrokerServices(broker_services);
56 // Precreate the desktop and window station used by the renderers.
57 sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
58 sandbox::ResultCode result = policy->CreateAlternateDesktop(true);
59 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
60 policy->Release();
61 }
62 }
63 #endif
64 *return_code = base::TestSuite(argc, argv).Run();
36 return true; 65 return true;
37 } 66 }
38 67
68 #if defined(OS_WIN)
69 if (command_line->HasSwitch(switches::kProcessType)) {
70 sandbox::SandboxInterfaceInfo sandbox_info = {0};
71 content::InitializeSandboxInfo(&sandbox_info);
72 ShellMainDelegate delegate;
73 *return_code = content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate);
74 return true;
75 }
76 #endif // defined(OS_WIN)
77
39 return false; 78 return false;
40 } 79 }
41 80
42 virtual bool AdjustChildProcessCommandLine( 81 virtual bool AdjustChildProcessCommandLine(
43 CommandLine* command_line) OVERRIDE { 82 CommandLine* command_line) OVERRIDE {
83 FilePath file_exe;
84 if (!PathService::Get(base::FILE_EXE, &file_exe))
85 return false;
86 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, file_exe);
44 return true; 87 return true;
45 } 88 }
46 89
47 private: 90 private:
48 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); 91 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
49 }; 92 };
50 93
51 int main(int argc, char** argv) { 94 int main(int argc, char** argv) {
52 ContentTestLauncherDelegate launcher_delegate; 95 ContentTestLauncherDelegate launcher_delegate;
53 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); 96 return test_launcher::LaunchTests(&launcher_delegate, argc, argv);
54 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698