diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 21:59:33 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 21:59:33 +0000 |
commit | c1f87b2a4f2d08b92db6f0c7f4f6661d5166feb9 (patch) | |
tree | d1348080214f9bab7a2f3d2b7f6e474b55cb24d5 /content/test | |
parent | 5435643695ec7f4e77fd4a2cda5bfa1222ec198f (diff) | |
download | chromium_src-c1f87b2a4f2d08b92db6f0c7f4f6661d5166feb9.zip chromium_src-c1f87b2a4f2d08b92db6f0c7f4f6661d5166feb9.tar.gz chromium_src-c1f87b2a4f2d08b92db6f0c7f4f6661d5166feb9.tar.bz2 |
Make an empty content browser test work.
BUG=90448
Review URL: http://codereview.chromium.org/8137012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/test')
-rw-r--r-- | content/test/content_browser_test.cc | 15 | ||||
-rw-r--r-- | content/test/content_browser_test.h | 9 | ||||
-rw-r--r-- | content/test/content_test_launcher.cc | 39 | ||||
-rw-r--r-- | content/test/test_launcher.cc | 36 | ||||
-rw-r--r-- | content/test/test_launcher.h | 1 |
5 files changed, 71 insertions, 29 deletions
diff --git a/content/test/content_browser_test.cc b/content/test/content_browser_test.cc index f43c011..2f97e0e 100644 --- a/content/test/content_browser_test.cc +++ b/content/test/content_browser_test.cc @@ -7,6 +7,8 @@ #include "base/debug/stack_trace.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/message_loop.h" +#include "content/shell/shell.h" +#include "content/shell/shell_main_delegate.h" #include "content/test/test_content_client.h" ContentBrowserTest::ContentBrowserTest() { @@ -17,11 +19,8 @@ ContentBrowserTest::~ContentBrowserTest() { void ContentBrowserTest::SetUp() { DCHECK(!content::GetContentClient()); - content_client_.reset(new TestContentClient); - content::SetContentClient(content_client_.get()); - - content_browser_client_.reset(new content::MockContentBrowserClient()); - content_client_->set_browser(content_browser_client_.get()); + shell_main_delegate_.reset(new ShellMainDelegate); + shell_main_delegate_->PreSandboxStartup(); BrowserTestBase::SetUp(); } @@ -29,11 +28,7 @@ void ContentBrowserTest::SetUp() { void ContentBrowserTest::TearDown() { BrowserTestBase::TearDown(); - DCHECK_EQ(content_client_.get(), content::GetContentClient()); - content::SetContentClient(NULL); - content_client_.reset(); - - content_browser_client_.reset(); + shell_main_delegate_.reset(); } #if defined(OS_POSIX) diff --git a/content/test/content_browser_test.h b/content/test/content_browser_test.h index c3410f5..7626b3b 100644 --- a/content/test/content_browser_test.h +++ b/content/test/content_browser_test.h @@ -7,13 +7,9 @@ #pragma once #include "base/memory/scoped_ptr.h" -#include "content/browser/mock_content_browser_client.h" #include "content/test/browser_test_base.h" -namespace content { -class ContentBrowserClient; -class ContentClient; -} +class ShellMainDelegate; class ContentBrowserTest : public BrowserTestBase { protected: @@ -28,8 +24,7 @@ class ContentBrowserTest : public BrowserTestBase { virtual void RunTestOnMainThreadLoop() OVERRIDE; private: - scoped_ptr<content::ContentClient> content_client_; - scoped_ptr<content::ContentBrowserClient> content_browser_client_; + scoped_ptr<ShellMainDelegate> shell_main_delegate_; }; #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_H_ diff --git a/content/test/content_test_launcher.cc b/content/test/content_test_launcher.cc index 5e1ba50..0fe5ba5 100644 --- a/content/test/content_test_launcher.cc +++ b/content/test/content_test_launcher.cc @@ -4,10 +4,20 @@ #include "content/test/test_launcher.h" +#include "base/base_paths.h" #include "base/command_line.h" #include "base/logging.h" +#include "base/path_service.h" #include "base/scoped_temp_dir.h" -#include "content/test/content_test_suite.h" +#include "base/test/test_suite.h" +#include "content/app/content_main.h" +#include "content/common/content_switches.h" +#include "content/shell/shell_main_delegate.h" + +#if defined(OS_WIN) +#include "content/app/startup_helper_win.h" +#include "sandbox/src/sandbox_types.h" +#endif // defined(OS_WIN) class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { public: @@ -21,26 +31,31 @@ class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { } virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { +#if defined(OS_WIN) CommandLine* command_line = CommandLine::ForCurrentProcess(); - - // TODO(pkasting): This "single_process vs. single-process" design is - // terrible UI. Instead, there should be some sort of signal flag on the - // command line, with all subsequent arguments passed through to the - // underlying browser. - if (command_line->HasSwitch(test_launcher::kSingleProcessTestsFlag) || - command_line->HasSwitch( - test_launcher::kSingleProcessTestsAndChromeFlag) || - command_line->HasSwitch(test_launcher::kGTestListTestsFlag) || - command_line->HasSwitch(test_launcher::kGTestHelpFlag)) { - *return_code = ContentTestSuite(argc, argv).Run(); + if (command_line->HasSwitch(switches::kProcessType)) { + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + content::InitializeSandboxInfo(&sandbox_info); + ShellMainDelegate delegate; + *return_code = + content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate); return true; } +#endif // defined(OS_WIN) return false; } + virtual int RunTestSuite(int argc, char** argv) OVERRIDE { + return base::TestSuite(argc, argv).Run(); + } + virtual bool AdjustChildProcessCommandLine( CommandLine* command_line) OVERRIDE { + FilePath file_exe; + if (!PathService::Get(base::FILE_EXE, &file_exe)) + return false; + command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, file_exe); return true; } diff --git a/content/test/test_launcher.cc b/content/test/test_launcher.cc index 4b44763..d2492c3 100644 --- a/content/test/test_launcher.cc +++ b/content/test/test_launcher.cc @@ -27,6 +27,14 @@ #include "net/base/escape.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_WIN) +#include "base/base_switches.h" +#include "content/common/sandbox_policy.h" +#include "sandbox/src/dep.h" +#include "sandbox/src/sandbox_factory.h" +#include "sandbox/src/sandbox_types.h" +#endif + namespace test_launcher { namespace { @@ -550,10 +558,38 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate, return 0; } + // TODO(pkasting): This "single_process vs. single-process" design is + // terrible UI. Instead, there should be some sort of signal flag on the + // command line, with all subsequent arguments passed through to the + // underlying browser. + if (command_line->HasSwitch(kSingleProcessTestsFlag) || + command_line->HasSwitch(kSingleProcessTestsAndChromeFlag) || + command_line->HasSwitch(kGTestListTestsFlag) || + command_line->HasSwitch(kGTestHelpFlag)) { +#if defined(OS_WIN) + if (command_line->HasSwitch(kSingleProcessTestsFlag)) { + // 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 launcher_delegate->RunTestSuite(argc, argv); + } + int return_code = 0; if (launcher_delegate->Run(argc, argv, &return_code)) return return_code; + base::AtExitManager at_exit; + int32 total_shards; int32 shard_index; bool should_shard = ShouldShard(&total_shards, &shard_index); diff --git a/content/test/test_launcher.h b/content/test/test_launcher.h index a6adb41..b7c2fdf 100644 --- a/content/test/test_launcher.h +++ b/content/test/test_launcher.h @@ -29,6 +29,7 @@ class TestLauncherDelegate { public: virtual void EarlyInitialize() = 0; virtual bool Run(int argc, char** argv, int* return_code) = 0; + virtual int RunTestSuite(int argc, char** argv) = 0; virtual bool AdjustChildProcessCommandLine(CommandLine* command_line) = 0; protected: |