OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
11 | |
12 #include "chrome/test/test_launcher/test_runner.h" | 11 #include "chrome/test/test_launcher/test_runner.h" |
13 #include "chrome/test/unit/chrome_test_suite.h" | 12 #include "chrome/test/unit/chrome_test_suite.h" |
14 | 13 |
| 14 #if defined(OS_WIN) |
| 15 #include "base/base_switches.h" |
| 16 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/sandbox_policy.h" |
| 18 #include "sandbox/src/dep.h" |
| 19 #include "sandbox/src/sandbox_factory.h" |
| 20 #include "sandbox/src/sandbox_types.h" |
| 21 |
| 22 // The entry point signature of chrome.dll. |
| 23 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); |
| 24 #endif |
| 25 |
15 // This version of the test launcher forks a new process for each test it runs. | 26 // This version of the test launcher forks a new process for each test it runs. |
16 | 27 |
17 namespace { | 28 namespace { |
18 | 29 |
19 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 30 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
20 const char kGTestOutputFlag[] = "gtest_output"; | 31 const char kGTestOutputFlag[] = "gtest_output"; |
21 const char kGTestHelpFlag[] = "gtest_help"; | 32 const char kGTestHelpFlag[] = "gtest_help"; |
22 const char kSingleProcessTestsFlag[] = "single_process"; | 33 const char kSingleProcessTestsFlag[] = "single_process"; |
23 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; | 34 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; |
24 const char kTestTerminateTimeoutFlag[] = "test-terminate-timeout"; | 35 const char kTestTerminateTimeoutFlag[] = "test-terminate-timeout"; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 150 } |
140 | 151 |
141 // TODO(pkasting): This "single_process vs. single-process" design is terrible | 152 // TODO(pkasting): This "single_process vs. single-process" design is terrible |
142 // UI. Instead, there should be some sort of signal flag on the command line, | 153 // UI. Instead, there should be some sort of signal flag on the command line, |
143 // with all subsequent arguments passed through to the underlying browser. | 154 // with all subsequent arguments passed through to the underlying browser. |
144 if (command_line->HasSwitch(kChildProcessFlag) || | 155 if (command_line->HasSwitch(kChildProcessFlag) || |
145 command_line->HasSwitch(kSingleProcessTestsFlag) || | 156 command_line->HasSwitch(kSingleProcessTestsFlag) || |
146 command_line->HasSwitch(kSingleProcessTestsAndChromeFlag) || | 157 command_line->HasSwitch(kSingleProcessTestsAndChromeFlag) || |
147 command_line->HasSwitch(kGTestListTestsFlag) || | 158 command_line->HasSwitch(kGTestListTestsFlag) || |
148 command_line->HasSwitch(kGTestHelpFlag)) { | 159 command_line->HasSwitch(kGTestHelpFlag)) { |
| 160 |
| 161 #if defined(OS_WIN) |
| 162 if (command_line->HasSwitch(kChildProcessFlag)) { |
| 163 // This is the browser process, so setup the sandbox broker. |
| 164 sandbox::BrokerServices* broker_services = |
| 165 sandbox::SandboxFactory::GetBrokerServices(); |
| 166 if (broker_services) { |
| 167 sandbox::InitBrokerServices(broker_services); |
| 168 // Precreate the desktop and window station used by the renderers. |
| 169 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
| 170 sandbox::ResultCode result = policy->CreateAlternateDesktop(true); |
| 171 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
| 172 policy->Release(); |
| 173 } |
| 174 } |
| 175 #endif |
149 return ChromeTestSuite(argc, argv).Run(); | 176 return ChromeTestSuite(argc, argv).Run(); |
150 } | 177 } |
151 | 178 |
| 179 #if defined(OS_WIN) |
| 180 if (command_line->HasSwitch(switches::kProcessType)) { |
| 181 // This is a child process, call ChromeMain. |
| 182 FilePath chrome_path(command_line->GetProgram().DirName()); |
| 183 chrome_path = chrome_path.Append(chrome::kBrowserResourcesDll); |
| 184 HMODULE dll = LoadLibrary(chrome_path.value().c_str()); |
| 185 DLL_MAIN entry_point = |
| 186 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll, "ChromeMain")); |
| 187 if (!entry_point) |
| 188 return -1; |
| 189 |
| 190 // Initialize the sandbox services. |
| 191 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 192 sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices(); |
| 193 return entry_point(GetModuleHandle(NULL), &sandbox_info, GetCommandLineW()); |
| 194 } |
| 195 #endif |
| 196 |
152 fprintf(stdout, | 197 fprintf(stdout, |
153 "Starting tests...\n" | 198 "Starting tests...\n" |
154 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" | 199 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" |
155 "For debugging a test inside a debugger, use the\n" | 200 "For debugging a test inside a debugger, use the\n" |
156 "--gtest_filter=<your_test_name> flag along with either\n" | 201 "--gtest_filter=<your_test_name> flag along with either\n" |
157 "--single_process (to run all tests in one launcher/browser process) or\n" | 202 "--single_process (to run all tests in one launcher/browser process) or\n" |
158 "--single-process (to do the above, and also run Chrome in single-\n" | 203 "--single-process (to do the above, and also run Chrome in single-\n" |
159 "process mode).\n"); | 204 "process mode).\n"); |
160 OutOfProcTestRunnerFactory test_runner_factory; | 205 OutOfProcTestRunnerFactory test_runner_factory; |
161 return tests::RunTests(test_runner_factory) ? 0 : 1; | 206 return tests::RunTests(test_runner_factory) ? 0 : 1; |
162 } | 207 } |
OLD | NEW |