| OLD | NEW |
| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 virtual ~ChromeTestLauncherDelegate() { | 34 virtual ~ChromeTestLauncherDelegate() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void EarlyInitialize() OVERRIDE { | 37 virtual void EarlyInitialize() OVERRIDE { |
| 38 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
| 39 chrome_browser_application_mac::RegisterBrowserCrApp(); | 39 chrome_browser_application_mac::RegisterBrowserCrApp(); |
| 40 #endif | 40 #endif |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { | 43 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { |
| 44 #if defined(OS_WIN) |
| 44 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 45 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 45 | |
| 46 // TODO(pkasting): This "single_process vs. single-process" design is | |
| 47 // terrible UI. Instead, there should be some sort of signal flag on the | |
| 48 // command line, with all subsequent arguments passed through to the | |
| 49 // underlying browser. | |
| 50 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag) || | |
| 51 command_line->HasSwitch( | |
| 52 test_launcher::kSingleProcessTestsAndChromeFlag) || | |
| 53 command_line->HasSwitch(test_launcher::kGTestListTestsFlag) || | |
| 54 command_line->HasSwitch(test_launcher::kGTestHelpFlag)) { | |
| 55 #if defined(OS_WIN) | |
| 56 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag)) { | |
| 57 // This is the browser process, so setup the sandbox broker. | |
| 58 sandbox::BrokerServices* broker_services = | |
| 59 sandbox::SandboxFactory::GetBrokerServices(); | |
| 60 if (broker_services) { | |
| 61 sandbox::InitBrokerServices(broker_services); | |
| 62 // Precreate the desktop and window station used by the renderers. | |
| 63 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
| 64 sandbox::ResultCode result = policy->CreateAlternateDesktop(true); | |
| 65 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
| 66 policy->Release(); | |
| 67 } | |
| 68 } | |
| 69 #endif | |
| 70 *return_code = ChromeTestSuite(argc, argv).Run(); | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 #if defined(OS_WIN) | |
| 75 if (command_line->HasSwitch(switches::kProcessType)) { | 46 if (command_line->HasSwitch(switches::kProcessType)) { |
| 76 // This is a child process, call ChromeMain. | 47 // This is a child process, call ChromeMain. |
| 77 FilePath chrome_path(command_line->GetProgram().DirName()); | 48 FilePath chrome_path(command_line->GetProgram().DirName()); |
| 78 chrome_path = chrome_path.Append(chrome::kBrowserResourcesDll); | 49 chrome_path = chrome_path.Append(chrome::kBrowserResourcesDll); |
| 79 HMODULE dll = LoadLibrary(chrome_path.value().c_str()); | 50 HMODULE dll = LoadLibrary(chrome_path.value().c_str()); |
| 80 DLL_MAIN entry_point = | 51 DLL_MAIN entry_point = |
| 81 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll, "ChromeMain")); | 52 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll, "ChromeMain")); |
| 82 if (!entry_point) | 53 if (!entry_point) |
| 83 return false; | 54 return false; |
| 84 | 55 |
| 85 // Initialize the sandbox services. | 56 // Initialize the sandbox services. |
| 86 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 57 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 87 sandbox_info.target_services = | 58 sandbox_info.target_services = |
| 88 sandbox::SandboxFactory::GetTargetServices(); | 59 sandbox::SandboxFactory::GetTargetServices(); |
| 89 *return_code = | 60 *return_code = |
| 90 entry_point(GetModuleHandle(NULL), &sandbox_info, GetCommandLineW()); | 61 entry_point(GetModuleHandle(NULL), &sandbox_info, GetCommandLineW()); |
| 91 return true; | 62 return true; |
| 92 } | 63 } |
| 93 #endif // defined(OS_WIN) | 64 #endif // defined(OS_WIN) |
| 65 |
| 94 return false; | 66 return false; |
| 95 } | 67 } |
| 96 | 68 |
| 69 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { |
| 70 return ChromeTestSuite(argc, argv).Run(); |
| 71 } |
| 72 |
| 97 virtual bool AdjustChildProcessCommandLine( | 73 virtual bool AdjustChildProcessCommandLine( |
| 98 CommandLine* command_line) OVERRIDE { | 74 CommandLine* command_line) OVERRIDE { |
| 99 CommandLine new_command_line(command_line->GetProgram()); | 75 CommandLine new_command_line(command_line->GetProgram()); |
| 100 CommandLine::SwitchMap switches = command_line->GetSwitches(); | 76 CommandLine::SwitchMap switches = command_line->GetSwitches(); |
| 101 | 77 |
| 102 // Strip out user-data-dir if present. We will add it back in again later. | 78 // Strip out user-data-dir if present. We will add it back in again later. |
| 103 switches.erase(switches::kUserDataDir); | 79 switches.erase(switches::kUserDataDir); |
| 104 | 80 |
| 105 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 81 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| 106 iter != switches.end(); ++iter) { | 82 iter != switches.end(); ++iter) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 } | 99 } |
| 124 | 100 |
| 125 private: | 101 private: |
| 126 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); | 102 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); |
| 127 }; | 103 }; |
| 128 | 104 |
| 129 int main(int argc, char** argv) { | 105 int main(int argc, char** argv) { |
| 130 ChromeTestLauncherDelegate launcher_delegate; | 106 ChromeTestLauncherDelegate launcher_delegate; |
| 131 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); | 107 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); |
| 132 } | 108 } |
| OLD | NEW |