Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/test/test_launcher.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/scoped_temp_dir.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/common/chrome_constants.h" | |
| 12 #include "chrome/test/base/chrome_test_suite.h" | |
| 13 | |
| 14 #if defined(OS_MACOSX) | |
| 15 #include "chrome/browser/chrome_browser_application_mac.h" | |
| 16 #endif // defined(OS_MACOSX) | |
| 17 | |
| 18 #if defined(OS_WIN) | |
| 19 #include "base/base_switches.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 | |
| 25 // The entry point signature of chrome.dll. | |
| 26 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); | |
| 27 #endif // defined(OS_WIN) | |
| 28 | |
| 29 class ChromeTestLauncherDelegate : public test_launcher::TestLauncherDelegate { | |
| 30 public: | |
| 31 ChromeTestLauncherDelegate() { | |
| 32 } | |
| 33 | |
| 34 virtual ~ChromeTestLauncherDelegate() { | |
| 35 } | |
| 36 | |
| 37 virtual void EarlyInitialize() OVERRIDE { | |
| 38 #if defined(OS_MACOSX) | |
| 39 chrome_browser_application_mac::RegisterBrowserCrApp(); | |
| 40 #endif | |
| 41 } | |
| 42 | |
| 43 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { | |
| 44 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 45 | |
| 46 // TODO(pkasting): This "single_process vs. single-process" design is terrib le | |
|
jam
2011/09/29 21:21:37
it seems that we would want to share all the sandb
Paweł Hajdan Jr.
2011/09/29 22:55:30
Not sure yet. I don't want to be speculative, so m
jam
2011/09/29 23:07:06
ok sounds good to move this later. you'll definite
| |
| 47 // UI. Instead, there should be some sort of signal flag on the command lin e, | |
| 48 // with all subsequent arguments passed through to the underlying browser. | |
| 49 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag) || | |
| 50 command_line->HasSwitch(test_launcher::kSingleProcessTestsAndChromeFlag) || | |
| 51 command_line->HasSwitch(test_launcher::kGTestListTestsFlag) || | |
| 52 command_line->HasSwitch(test_launcher::kGTestHelpFlag)) { | |
| 53 #if defined(OS_WIN) | |
| 54 if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag)) { | |
| 55 // This is the browser process, so setup the sandbox broker. | |
| 56 sandbox::BrokerServices* broker_services = | |
| 57 sandbox::SandboxFactory::GetBrokerServices(); | |
| 58 if (broker_services) { | |
| 59 sandbox::InitBrokerServices(broker_services); | |
| 60 // Precreate the desktop and window station used by the renderers. | |
| 61 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
| 62 sandbox::ResultCode result = policy->CreateAlternateDesktop(true); | |
| 63 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
| 64 policy->Release(); | |
| 65 } | |
| 66 } | |
| 67 #endif | |
| 68 *return_code = ChromeTestSuite(argc, argv).Run(); | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 #if defined(OS_WIN) | |
| 73 if (command_line->HasSwitch(switches::kProcessType)) { | |
| 74 // This is a child process, call ChromeMain. | |
| 75 FilePath chrome_path(command_line->GetProgram().DirName()); | |
| 76 chrome_path = chrome_path.Append(chrome::kBrowserResourcesDll); | |
| 77 HMODULE dll = LoadLibrary(chrome_path.value().c_str()); | |
| 78 DLL_MAIN entry_point = | |
| 79 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll, "ChromeMain")); | |
| 80 if (!entry_point) | |
| 81 return false; | |
| 82 | |
| 83 // Initialize the sandbox services. | |
| 84 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | |
| 85 sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices( ); | |
| 86 *return_code = entry_point(GetModuleHandle(NULL), &sandbox_info, GetComman dLineW()); | |
| 87 return true; | |
| 88 } | |
| 89 #endif // defined(OS_WIN) | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 virtual bool AdjustChildProcessCommandLine( | |
| 94 CommandLine* command_line) OVERRIDE { | |
| 95 CommandLine new_command_line(command_line->GetProgram()); | |
| 96 CommandLine::SwitchMap switches = command_line->GetSwitches(); | |
| 97 | |
| 98 // Strip out user-data-dir if present. We will add it back in again later. | |
| 99 switches.erase(switches::kUserDataDir); | |
| 100 | |
| 101 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | |
| 102 iter != switches.end(); ++iter) { | |
| 103 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); | |
| 104 } | |
| 105 | |
| 106 // Create a new user data dir and pass it to the child. | |
| 107 ScopedTempDir temp_dir; | |
| 108 if (!temp_dir.CreateUniqueTempDir() || !temp_dir.IsValid()) { | |
| 109 LOG(ERROR) << "Error creating temp profile directory"; | |
| 110 return false; | |
| 111 } | |
| 112 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_dir.path()); | |
| 113 | |
| 114 // file:// access for ChromeOS. | |
| 115 new_command_line.AppendSwitch(switches::kAllowFileAccess); | |
| 116 | |
| 117 *command_line = new_command_line; | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 private: | |
| 122 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); | |
| 123 }; | |
| 124 | |
| 125 int main(int argc, char** argv) { | |
| 126 ChromeTestLauncherDelegate launcher_delegate; | |
| 127 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); | |
| 128 } | |
| OLD | NEW |