diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 20:31:41 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 20:31:41 +0000 |
commit | 87bf974e05e6d0f9dcc28f3c51cf46fd4b9a3145 (patch) | |
tree | ff4d2ef0b6c90739fd1feee1454cf41e05abbb78 | |
parent | e88079e395bf606c55e746bd618414abbcc6bc31 (diff) | |
download | chromium_src-87bf974e05e6d0f9dcc28f3c51cf46fd4b9a3145.zip chromium_src-87bf974e05e6d0f9dcc28f3c51cf46fd4b9a3145.tar.gz chromium_src-87bf974e05e6d0f9dcc28f3c51cf46fd4b9a3145.tar.bz2 |
Run in-process browser tests using the sandbox.
Review URL: http://codereview.chromium.org/2729002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49308 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 15 | ||||
-rw-r--r-- | chrome/test/interactive_ui/interactive_ui_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/test_launcher/out_of_proc_test_runner.cc | 47 |
4 files changed, 58 insertions, 7 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 32f857e..6d32746 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1408,6 +1408,7 @@ 'dependencies': [ 'chrome_dll_version', 'installer_util_strings', + '../sandbox/sandbox.gyp:sandbox', '<(allocator_target)', ], 'configurations': { @@ -2032,6 +2033,7 @@ 'chrome_dll_version', 'installer_util_strings', '../views/views.gyp:views', + '../sandbox/sandbox.gyp:sandbox', '<(allocator_target)', ], 'configurations': { diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 976a893..ac307de 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -137,10 +137,6 @@ void InProcessBrowserTest::SetUp() { command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir.ToWStringHack()); - // For some reason the sandbox wasn't happy running in test mode. These - // tests aren't intended to test the sandbox, so we turn it off. - command_line->AppendSwitch(switches::kNoSandbox); - // Don't show the first run ui. command_line->AppendSwitch(switches::kNoFirstRun); @@ -154,8 +150,14 @@ void InProcessBrowserTest::SetUp() { if (command_line->HasSwitch(switches::kSingleProcess)) RenderProcessHost::set_run_renderer_in_process(true); - // Explicitly set the path of the exe used for the renderer and plugin, - // otherwise they'll try to use unit_test.exe. +#if defined(OS_WIN) + // The Windows sandbox requires that the browser and child processes are the + // same binary. So we launch browser_process.exe which loads chrome.dll + command_line->AppendSwitchWithValue(switches::kBrowserSubprocessPath, + command_line->GetProgram().value()); +#else + // Explicitly set the path of the binary used for child processes, otherwise + // they'll try to use browser_tests which doesn't contain ChromeMain. FilePath subprocess_path; PathService::Get(base::FILE_EXE, &subprocess_path); subprocess_path = subprocess_path.DirName(); @@ -163,6 +165,7 @@ void InProcessBrowserTest::SetUp() { chrome::kBrowserProcessExecutablePath)); command_line->AppendSwitchWithValue(switches::kBrowserSubprocessPath, subprocess_path.ToWStringHack()); +#endif // Enable warning level logging so that we can see when bad stuff happens. command_line->AppendSwitch(switches::kEnableLogging); diff --git a/chrome/test/interactive_ui/interactive_ui_tests.gypi b/chrome/test/interactive_ui/interactive_ui_tests.gypi index ada1f5b..8bb48ac 100644 --- a/chrome/test/interactive_ui/interactive_ui_tests.gypi +++ b/chrome/test/interactive_ui/interactive_ui_tests.gypi @@ -110,6 +110,7 @@ '<(DEPTH)/chrome/chrome.gyp:chrome_dll_version', '<(DEPTH)/chrome/chrome.gyp:crash_service', # run time dependency '<(DEPTH)/chrome/chrome.gyp:installer_util_strings', + '<(DEPTH)/sandbox/sandbox.gyp:sandbox', ], 'sources': [ '<(DEPTH)/webkit/glue/resources/aliasb.cur', diff --git a/chrome/test/test_launcher/out_of_proc_test_runner.cc b/chrome/test/test_launcher/out_of_proc_test_runner.cc index c27b051..766314c 100644 --- a/chrome/test/test_launcher/out_of_proc_test_runner.cc +++ b/chrome/test/test_launcher/out_of_proc_test_runner.cc @@ -8,10 +8,21 @@ #include "base/logging.h" #include "base/process_util.h" #include "base/test/test_suite.h" - #include "chrome/test/test_launcher/test_runner.h" #include "chrome/test/unit/chrome_test_suite.h" +#if defined(OS_WIN) +#include "base/base_switches.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/sandbox_policy.h" +#include "sandbox/src/dep.h" +#include "sandbox/src/sandbox_factory.h" +#include "sandbox/src/sandbox_types.h" + +// The entry point signature of chrome.dll. +typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); +#endif + // This version of the test launcher forks a new process for each test it runs. namespace { @@ -146,9 +157,43 @@ int main(int argc, char** argv) { command_line->HasSwitch(kSingleProcessTestsAndChromeFlag) || command_line->HasSwitch(kGTestListTestsFlag) || command_line->HasSwitch(kGTestHelpFlag)) { + +#if defined(OS_WIN) + if (command_line->HasSwitch(kChildProcessFlag)) { + // This is the browser process, so setup the sandbox broker. + sandbox::BrokerServices* broker_services = + sandbox::SandboxFactory::GetBrokerServices(); + if (broker_services) { + sandbox::InitBrokerServices(broker_services); + // Precreate the desktop and window station used by the renderers. + sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); + sandbox::ResultCode result = policy->CreateAlternateDesktop(true); + CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); + policy->Release(); + } + } +#endif return ChromeTestSuite(argc, argv).Run(); } +#if defined(OS_WIN) + if (command_line->HasSwitch(switches::kProcessType)) { + // This is a child process, call ChromeMain. + FilePath chrome_path(command_line->GetProgram().DirName()); + chrome_path = chrome_path.Append(chrome::kBrowserResourcesDll); + HMODULE dll = LoadLibrary(chrome_path.value().c_str()); + DLL_MAIN entry_point = + reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll, "ChromeMain")); + if (!entry_point) + return -1; + + // Initialize the sandbox services. + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices(); + return entry_point(GetModuleHandle(NULL), &sandbox_info, GetCommandLineW()); + } +#endif + fprintf(stdout, "Starting tests...\n" "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" |