[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7d855a1 | 2012-06-04 06:08:09 | [diff] [blame] | 5 | #include "content/public/test/test_launcher.h" |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 6 | |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 7 | #include "base/base_paths.h" |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 8 | #include "base/command_line.h" |
| 9 | #include "base/logging.h" |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 11 | #include "base/scoped_temp_dir.h" |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 12 | #include "base/test/test_suite.h" |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 13 | #include "content/public/app/content_main.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 14 | #include "content/public/common/content_switches.h" |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 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" |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 18 | #include "content/shell/shell_main_delegate.h" |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 19 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 20 | |
| 21 | #if defined(OS_WIN) |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 22 | #include "content/public/app/startup_helper_win.h" |
[email protected] | 18149178 | 2012-07-18 00:59:15 | [diff] [blame] | 23 | #include "sandbox/win/src/sandbox_types.h" |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 24 | #include "ui/base/win/scoped_ole_initializer.h" |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 25 | #endif // defined(OS_WIN) |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 26 | |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 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 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); |
| 86 | }; |
| 87 | |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 88 | class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { |
| 89 | public: |
| 90 | ContentTestLauncherDelegate() { |
| 91 | } |
| 92 | |
| 93 | virtual ~ContentTestLauncherDelegate() { |
| 94 | } |
| 95 | |
| 96 | virtual void EarlyInitialize() OVERRIDE { |
| 97 | } |
| 98 | |
| 99 | virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 100 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 101 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 102 | if (command_line->HasSwitch(switches::kProcessType)) { |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 103 | ShellMainDelegate delegate; |
| 104 | #if defined(OS_WIN) |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 105 | sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 106 | InitializeSandboxInfo(&sandbox_info); |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 107 | *return_code = |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 108 | ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate); |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 109 | #elif defined(OS_LINUX) |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 110 | *return_code = ContentMain(argc, |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 111 | const_cast<const char**>(argv), |
| 112 | &delegate); |
| 113 | #endif // defined(OS_WIN) |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 114 | return true; |
| 115 | } |
[email protected] | 78089f0 | 2012-07-19 06:11:28 | [diff] [blame] | 116 | #endif // defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 117 | |
| 118 | return false; |
| 119 | } |
| 120 | |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 121 | virtual int RunTestSuite(int argc, char** argv) OVERRIDE { |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 122 | return ContentBrowserTestSuite(argc, argv).Run(); |
[email protected] | c1f87b2 | 2011-10-05 21:59:33 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 125 | virtual bool AdjustChildProcessCommandLine( |
| 126 | CommandLine* command_line) OVERRIDE { |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); |
| 132 | }; |
| 133 | |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 134 | } // namespace content |
| 135 | |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 136 | int main(int argc, char** argv) { |
[email protected] | 84e0de0 | 2012-07-19 07:16:03 | [diff] [blame] | 137 | #if defined(USE_AURA) |
| 138 | LOG(INFO) << "content_browsertests not supported on aura yet."; |
| 139 | return 0; |
| 140 | #endif |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame^] | 141 | content::ContentTestLauncherDelegate launcher_delegate; |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 142 | return test_launcher::LaunchTests(&launcher_delegate, argc, argv); |
[email protected] | 76df8e36 | 2011-09-30 21:23:58 | [diff] [blame] | 143 | } |