Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "base/test/test_suite.h" | 12 #include "base/test/test_suite.h" |
| 13 #include "content/public/app/content_main.h" | 13 #include "content/public/app/content_main.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/content_test_suite_base.h" | |
| 16 #include "content/shell/shell_content_browser_client.h" | |
| 17 #include "content/shell/shell_content_client.h" | |
| 15 #include "content/shell/shell_main_delegate.h" | 18 #include "content/shell/shell_main_delegate.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | 20 |
| 17 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 18 #include "content/public/app/startup_helper_win.h" | 22 #include "content/public/app/startup_helper_win.h" |
| 19 #include "sandbox/src/sandbox_types.h" | 23 #include "sandbox/src/sandbox_types.h" |
| 24 #include "ui/base/win/scoped_ole_initializer.h" | |
| 20 #endif // defined(OS_WIN) | 25 #endif // defined(OS_WIN) |
| 21 | 26 |
| 27 namespace content { | |
| 28 | |
| 29 class ContentShellTestSuiteInitializer | |
| 30 : public testing::EmptyTestEventListener { | |
| 31 public: | |
| 32 ContentShellTestSuiteInitializer() { | |
| 33 } | |
| 34 | |
| 35 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | |
| 36 DCHECK(!GetContentClient()); | |
| 37 content_client_.reset(new ShellContentClient); | |
| 38 browser_content_client_.reset(new ShellContentBrowserClient()); | |
| 39 content_client_->set_browser_for_testing(browser_content_client_.get()); | |
| 40 SetContentClient(content_client_.get()); | |
| 41 } | |
| 42 | |
| 43 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
| 44 DCHECK_EQ(content_client_.get(), GetContentClient()); | |
| 45 browser_content_client_.reset(); | |
| 46 content_client_.reset(); | |
| 47 SetContentClient(NULL); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 scoped_ptr<ShellContentClient> content_client_; | |
| 52 scoped_ptr<ShellContentBrowserClient> browser_content_client_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(ContentShellTestSuiteInitializer); | |
| 55 }; | |
| 56 | |
| 57 class ContentBrowserTestSuite : public ContentTestSuiteBase { | |
| 58 public: | |
| 59 ContentBrowserTestSuite(int argc, char** argv) | |
| 60 : ContentTestSuiteBase(argc, argv) { | |
| 61 } | |
| 62 virtual ~ContentBrowserTestSuite() { | |
| 63 } | |
| 64 | |
| 65 protected: | |
| 66 virtual void Initialize() OVERRIDE { | |
| 67 ContentTestSuiteBase::Initialize(); | |
| 68 | |
| 69 testing::TestEventListeners& listeners = | |
| 70 testing::UnitTest::GetInstance()->listeners(); | |
| 71 listeners.Append(new ContentShellTestSuiteInitializer); | |
| 72 } | |
| 73 virtual void Shutdown() OVERRIDE { | |
| 74 base::TestSuite::Shutdown(); | |
| 75 } | |
| 76 | |
| 77 virtual ContentClient* CreateClientForInitialization() OVERRIDE { | |
| 78 return new ShellContentClient(); | |
| 79 } | |
| 80 | |
| 81 #if defined(OS_WIN) | |
| 82 ui::ScopedOleInitializer ole_initializer_; | |
| 83 #endif | |
| 84 }; | |
|
sky
2012/07/18 23:23:35
DISALLOW_...
jam
2012/07/18 23:44:06
Done.
| |
| 85 | |
| 86 } // namespace content | |
| 87 | |
| 22 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { | 88 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { |
| 23 public: | 89 public: |
| 24 ContentTestLauncherDelegate() { | 90 ContentTestLauncherDelegate() { |
| 25 } | 91 } |
| 26 | 92 |
| 27 virtual ~ContentTestLauncherDelegate() { | 93 virtual ~ContentTestLauncherDelegate() { |
| 28 } | 94 } |
| 29 | 95 |
| 30 virtual void EarlyInitialize() OVERRIDE { | 96 virtual void EarlyInitialize() OVERRIDE { |
| 31 } | 97 } |
| 32 | 98 |
| 33 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { | 99 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { |
| 34 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 35 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 101 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 36 if (command_line->HasSwitch(switches::kProcessType)) { | 102 if (command_line->HasSwitch(switches::kProcessType)) { |
| 37 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 103 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 38 content::InitializeSandboxInfo(&sandbox_info); | 104 content::InitializeSandboxInfo(&sandbox_info); |
| 39 ShellMainDelegate delegate; | 105 ShellMainDelegate delegate; |
| 40 *return_code = | 106 *return_code = |
| 41 content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate); | 107 content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate); |
| 42 return true; | 108 return true; |
| 43 } | 109 } |
| 44 #endif // defined(OS_WIN) | 110 #endif // defined(OS_WIN) |
| 45 | 111 |
| 46 return false; | 112 return false; |
| 47 } | 113 } |
| 48 | 114 |
| 49 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { | 115 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { |
| 50 return base::TestSuite(argc, argv).Run(); | 116 return content::ContentBrowserTestSuite(argc, argv).Run(); |
| 51 } | 117 } |
| 52 | 118 |
| 53 virtual bool AdjustChildProcessCommandLine( | 119 virtual bool AdjustChildProcessCommandLine( |
| 54 CommandLine* command_line) OVERRIDE { | 120 CommandLine* command_line) OVERRIDE { |
| 55 FilePath file_exe; | 121 FilePath file_exe; |
| 56 if (!PathService::Get(base::FILE_EXE, &file_exe)) | 122 if (!PathService::Get(base::FILE_EXE, &file_exe)) |
| 57 return false; | 123 return false; |
| 58 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, file_exe); | 124 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, file_exe); |
| 59 return true; | 125 return true; |
| 60 } | 126 } |
| 61 | 127 |
| 62 private: | 128 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); | 129 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); |
| 64 }; | 130 }; |
| 65 | 131 |
| 66 int main(int argc, char** argv) { | 132 int main(int argc, char** argv) { |
| 67 ContentTestLauncherDelegate launcher_delegate; | 133 ContentTestLauncherDelegate launcher_delegate; |
| 68 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); | 134 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); |
| 69 } | 135 } |
| OLD | NEW |