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 "chrome/test/base/chrome_test_suite.h" | 5 #include "chrome/test/base/chrome_test_suite.h" |
| 6 | 6 |
| 7 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #endif | 10 #endif |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 class ChromeTestSuiteInitializer : public testing::EmptyTestEventListener { | 87 class ChromeTestSuiteInitializer : public testing::EmptyTestEventListener { |
| 88 public: | 88 public: |
| 89 ChromeTestSuiteInitializer() { | 89 ChromeTestSuiteInitializer() { |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | 92 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| 93 DCHECK(!g_browser_process); | 93 DCHECK(!g_browser_process); |
| 94 g_browser_process = new TestingBrowserProcess; | 94 g_browser_process = new TestingBrowserProcess; |
| 95 | 95 |
| 96 SetUpContentClients(); | |
| 97 SetUpExtensionsClients(); | |
| 98 } | |
| 99 | |
| 100 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
| 101 TearDownExtensionsClients(); | |
| 102 TearDownContentClients(); | |
|
James Cook
2013/11/04 19:09:31
This teardown has no significant side effects, so
| |
| 103 | |
| 104 if (g_browser_process) { | |
| 105 BrowserProcess* browser_process = g_browser_process; | |
| 106 // g_browser_process must be NULL during its own destruction. | |
| 107 g_browser_process = NULL; | |
| 108 delete browser_process; | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 void SetUpContentClients() { | |
| 96 content_client_.reset(new chrome::ChromeContentClient); | 114 content_client_.reset(new chrome::ChromeContentClient); |
| 97 content::SetContentClient(content_client_.get()); | 115 content::SetContentClient(content_client_.get()); |
| 98 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. | 116 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. |
| 99 #if !defined(OS_IOS) | 117 #if !defined(OS_IOS) |
| 100 browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); | 118 browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); |
| 101 content::SetBrowserClientForTesting(browser_content_client_.get()); | 119 content::SetBrowserClientForTesting(browser_content_client_.get()); |
| 102 utility_content_client_.reset(new chrome::ChromeContentUtilityClient()); | 120 utility_content_client_.reset(new chrome::ChromeContentUtilityClient()); |
| 103 content::SetUtilityClientForTesting(utility_content_client_.get()); | 121 content::SetUtilityClientForTesting(utility_content_client_.get()); |
| 104 #endif | 122 #endif |
| 105 } | 123 } |
| 106 | 124 |
| 107 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 125 void TearDownContentClients() { |
| 108 if (g_browser_process) { | |
| 109 BrowserProcess* browser_process = g_browser_process; | |
| 110 // g_browser_process must be NULL during its own destruction. | |
| 111 g_browser_process = NULL; | |
| 112 delete browser_process; | |
| 113 } | |
| 114 | |
| 115 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. | 126 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. |
| 116 #if !defined(OS_IOS) | 127 #if !defined(OS_IOS) |
| 117 browser_content_client_.reset(); | 128 browser_content_client_.reset(); |
| 118 utility_content_client_.reset(); | 129 utility_content_client_.reset(); |
| 119 #endif | 130 #endif |
| 120 content_client_.reset(); | 131 content_client_.reset(); |
| 121 content::SetContentClient(NULL); | 132 content::SetContentClient(NULL); |
| 122 } | 133 } |
| 123 | 134 |
| 124 private: | 135 void SetUpExtensionsClients() { |
| 136 extensions_browser_client_.reset( | |
| 137 new extensions::ChromeExtensionsBrowserClient); | |
| 138 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); | |
| 139 } | |
| 140 | |
| 141 void TearDownExtensionsClients() { | |
| 142 extensions_browser_client_.reset(); | |
| 143 extensions::ExtensionsBrowserClient::Set(NULL); | |
| 144 } | |
| 145 | |
| 146 // Client implementations for the content module. | |
| 125 scoped_ptr<chrome::ChromeContentClient> content_client_; | 147 scoped_ptr<chrome::ChromeContentClient> content_client_; |
| 126 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. | 148 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. |
| 127 #if !defined(OS_IOS) | 149 #if !defined(OS_IOS) |
| 128 scoped_ptr<chrome::ChromeContentBrowserClient> browser_content_client_; | 150 scoped_ptr<chrome::ChromeContentBrowserClient> browser_content_client_; |
| 129 scoped_ptr<chrome::ChromeContentUtilityClient> utility_content_client_; | 151 scoped_ptr<chrome::ChromeContentUtilityClient> utility_content_client_; |
| 130 #endif | 152 #endif |
| 131 | 153 |
| 154 // Client implementations for the extensions module. | |
| 155 scoped_ptr<extensions::ChromeExtensionsBrowserClient> | |
| 156 extensions_browser_client_; | |
| 157 | |
| 132 DISALLOW_COPY_AND_ASSIGN(ChromeTestSuiteInitializer); | 158 DISALLOW_COPY_AND_ASSIGN(ChromeTestSuiteInitializer); |
| 133 }; | 159 }; |
| 134 | 160 |
| 135 } // namespace | 161 } // namespace |
| 136 | 162 |
| 137 ChromeTestSuite::ChromeTestSuite(int argc, char** argv) | 163 ChromeTestSuite::ChromeTestSuite(int argc, char** argv) |
| 138 : content::ContentTestSuiteBase(argc, argv) { | 164 : content::ContentTestSuiteBase(argc, argv) { |
| 139 } | 165 } |
| 140 | 166 |
| 141 ChromeTestSuite::~ChromeTestSuite() { | 167 ChromeTestSuite::~ChromeTestSuite() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 165 if (!browser_dir_.empty()) { | 191 if (!browser_dir_.empty()) { |
| 166 PathService::Override(base::DIR_EXE, browser_dir_); | 192 PathService::Override(base::DIR_EXE, browser_dir_); |
| 167 PathService::Override(base::DIR_MODULE, browser_dir_); | 193 PathService::Override(base::DIR_MODULE, browser_dir_); |
| 168 } | 194 } |
| 169 | 195 |
| 170 #if !defined(OS_IOS) | 196 #if !defined(OS_IOS) |
| 171 extensions::RegisterPathProvider(); | 197 extensions::RegisterPathProvider(); |
| 172 | 198 |
| 173 extensions::ExtensionsClient::Set( | 199 extensions::ExtensionsClient::Set( |
| 174 extensions::ChromeExtensionsClient::GetInstance()); | 200 extensions::ChromeExtensionsClient::GetInstance()); |
| 175 extensions::ExtensionsBrowserClient::Set( | |
| 176 extensions::ChromeExtensionsBrowserClient::GetInstance()); | |
| 177 | 201 |
| 178 // Only want to do this for unit tests. | 202 // Only want to do this for unit tests. |
| 179 if (!content::GetCurrentTestLauncherDelegate()) { | 203 if (!content::GetCurrentTestLauncherDelegate()) { |
| 180 // For browser tests, this won't create the right object since | 204 // For browser tests, this won't create the right object since |
| 181 // TestChromeWebUIControllerFactory is used. That's created and | 205 // TestChromeWebUIControllerFactory is used. That's created and |
| 182 // registered in ChromeBrowserMainParts as in normal startup. | 206 // registered in ChromeBrowserMainParts as in normal startup. |
| 183 content::WebUIControllerFactory::RegisterFactory( | 207 content::WebUIControllerFactory::RegisterFactory( |
| 184 ChromeWebUIControllerFactory::GetInstance()); | 208 ChromeWebUIControllerFactory::GetInstance()); |
| 185 } | 209 } |
| 186 #endif | 210 #endif |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 #if defined(OS_MACOSX) && !defined(OS_IOS) | 262 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 239 base::mac::SetOverrideFrameworkBundle(NULL); | 263 base::mac::SetOverrideFrameworkBundle(NULL); |
| 240 #endif | 264 #endif |
| 241 | 265 |
| 242 base::StatsTable::set_current(NULL); | 266 base::StatsTable::set_current(NULL); |
| 243 stats_table_.reset(); | 267 stats_table_.reset(); |
| 244 RemoveSharedMemoryFile(stats_filename_); | 268 RemoveSharedMemoryFile(stats_filename_); |
| 245 | 269 |
| 246 base::TestSuite::Shutdown(); | 270 base::TestSuite::Shutdown(); |
| 247 } | 271 } |
| OLD | NEW |