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 "base/test/test_suite.h" | 5 #include "base/test/test_suite.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 }; | 93 }; |
94 | 94 |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 97 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
98 TestSuite test_suite(argc, argv); | 98 TestSuite test_suite(argc, argv); |
99 return LaunchUnitTests(argc, argv, | 99 return LaunchUnitTests(argc, argv, |
100 Bind(&TestSuite::Run, Unretained(&test_suite))); | 100 Bind(&TestSuite::Run, Unretained(&test_suite))); |
101 } | 101 } |
102 | 102 |
103 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 103 TestSuite::TestSuite(int argc, char** argv) |
| 104 : initialized_command_line_(false), created_feature_list_(false) { |
104 PreInitialize(); | 105 PreInitialize(); |
105 InitializeFromCommandLine(argc, argv); | 106 InitializeFromCommandLine(argc, argv); |
106 } | 107 } |
107 | 108 |
108 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
109 TestSuite::TestSuite(int argc, wchar_t** argv) | 110 TestSuite::TestSuite(int argc, wchar_t** argv) |
110 : initialized_command_line_(false) { | 111 : initialized_command_line_(false), created_feature_list_(false) { |
111 PreInitialize(); | 112 PreInitialize(); |
112 InitializeFromCommandLine(argc, argv); | 113 InitializeFromCommandLine(argc, argv); |
113 } | 114 } |
114 #endif // defined(OS_WIN) | 115 #endif // defined(OS_WIN) |
115 | 116 |
116 TestSuite::~TestSuite() { | 117 TestSuite::~TestSuite() { |
117 if (initialized_command_line_) | 118 if (initialized_command_line_) |
118 CommandLine::Reset(); | 119 CommandLine::Reset(); |
119 } | 120 } |
120 | 121 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 220 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
220 switches::kTestChildProcess); | 221 switches::kTestChildProcess); |
221 | 222 |
222 // Check to see if we are being run as a client process. | 223 // Check to see if we are being run as a client process. |
223 if (!client_func.empty()) | 224 if (!client_func.empty()) |
224 return multi_process_function_list::InvokeChildProcessTest(client_func); | 225 return multi_process_function_list::InvokeChildProcessTest(client_func); |
225 #if defined(OS_IOS) | 226 #if defined(OS_IOS) |
226 test_listener_ios::RegisterTestEndListener(); | 227 test_listener_ios::RegisterTestEndListener(); |
227 #endif | 228 #endif |
228 | 229 |
229 // Set up a FeatureList instance, so that code using that API will not hit a | |
230 // an error that it's not set. Cleared by ClearInstanceForTesting() below. | |
231 base::FeatureList::SetInstance(WrapUnique(new base::FeatureList)); | |
232 | |
233 int result = RUN_ALL_TESTS(); | 230 int result = RUN_ALL_TESTS(); |
234 | 231 |
235 // Clear the FeatureList that was registered above. | |
236 FeatureList::ClearInstanceForTesting(); | |
237 | |
238 #if defined(OS_MACOSX) | 232 #if defined(OS_MACOSX) |
239 // This MUST happen before Shutdown() since Shutdown() tears down | 233 // This MUST happen before Shutdown() since Shutdown() tears down |
240 // objects (such as NotificationService::current()) that Cocoa | 234 // objects (such as NotificationService::current()) that Cocoa |
241 // objects use to remove themselves as observers. | 235 // objects use to remove themselves as observers. |
242 scoped_pool.Recycle(); | 236 scoped_pool.Recycle(); |
243 #endif | 237 #endif |
244 | 238 |
245 Shutdown(); | 239 Shutdown(); |
246 | 240 |
247 return result; | 241 return result; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 #endif // defined(OS_WIN) | 283 #endif // defined(OS_WIN) |
290 } | 284 } |
291 | 285 |
292 void TestSuite::Initialize() { | 286 void TestSuite::Initialize() { |
293 #if !defined(OS_IOS) | 287 #if !defined(OS_IOS) |
294 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { | 288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { |
295 debug::WaitForDebugger(60, true); | 289 debug::WaitForDebugger(60, true); |
296 } | 290 } |
297 #endif | 291 #endif |
298 | 292 |
| 293 // Set up a FeatureList instance, so that code using that API will not hit a |
| 294 // an error that it's not set. If a FeatureList was created in this way (i.e. |
| 295 // one didn't exist previously), it will be cleared in Shutdown() via |
| 296 // ClearInstanceForTesting(). |
| 297 created_feature_list_ = |
| 298 FeatureList::InitializeInstance(std::string(), std::string()); |
| 299 |
299 #if defined(OS_IOS) | 300 #if defined(OS_IOS) |
300 InitIOSTestMessageLoop(); | 301 InitIOSTestMessageLoop(); |
301 #endif // OS_IOS | 302 #endif // OS_IOS |
302 | 303 |
303 #if defined(OS_ANDROID) | 304 #if defined(OS_ANDROID) |
304 InitAndroidTest(); | 305 InitAndroidTest(); |
305 #else | 306 #else |
306 // Initialize logging. | 307 // Initialize logging. |
307 FilePath exe; | 308 FilePath exe; |
308 PathService::Get(FILE_EXE, &exe); | 309 PathService::Get(FILE_EXE, &exe); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 CatchMaybeTests(); | 358 CatchMaybeTests(); |
358 ResetCommandLine(); | 359 ResetCommandLine(); |
359 AddTestLauncherResultPrinter(); | 360 AddTestLauncherResultPrinter(); |
360 | 361 |
361 TestTimeouts::Initialize(); | 362 TestTimeouts::Initialize(); |
362 | 363 |
363 trace_to_file_.BeginTracingFromCommandLineOptions(); | 364 trace_to_file_.BeginTracingFromCommandLineOptions(); |
364 } | 365 } |
365 | 366 |
366 void TestSuite::Shutdown() { | 367 void TestSuite::Shutdown() { |
| 368 // Clear the FeatureList that was created by Initialize(). |
| 369 if (created_feature_list_) |
| 370 FeatureList::ClearInstanceForTesting(); |
367 } | 371 } |
368 | 372 |
369 } // namespace base | 373 } // namespace base |
OLD | NEW |