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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 128 } |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 132 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
133 TestSuite test_suite(argc, argv); | 133 TestSuite test_suite(argc, argv); |
134 return LaunchUnitTests(argc, argv, | 134 return LaunchUnitTests(argc, argv, |
135 Bind(&TestSuite::Run, Unretained(&test_suite))); | 135 Bind(&TestSuite::Run, Unretained(&test_suite))); |
136 } | 136 } |
137 | 137 |
138 TestSuite::TestSuite(int argc, char** argv) | 138 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
139 : initialized_command_line_(false), created_feature_list_(false) { | |
140 PreInitialize(); | 139 PreInitialize(); |
141 InitializeFromCommandLine(argc, argv); | 140 InitializeFromCommandLine(argc, argv); |
142 // Logging must be initialized before any thread has a chance to call logging | 141 // Logging must be initialized before any thread has a chance to call logging |
143 // functions. | 142 // functions. |
144 InitializeLogging(); | 143 InitializeLogging(); |
145 } | 144 } |
146 | 145 |
147 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
148 TestSuite::TestSuite(int argc, wchar_t** argv) | 147 TestSuite::TestSuite(int argc, wchar_t** argv) |
149 : initialized_command_line_(false), created_feature_list_(false) { | 148 : initialized_command_line_(false) { |
150 PreInitialize(); | 149 PreInitialize(); |
151 InitializeFromCommandLine(argc, argv); | 150 InitializeFromCommandLine(argc, argv); |
152 // Logging must be initialized before any thread has a chance to call logging | 151 // Logging must be initialized before any thread has a chance to call logging |
153 // functions. | 152 // functions. |
154 InitializeLogging(); | 153 InitializeLogging(); |
155 } | 154 } |
156 #endif // defined(OS_WIN) | 155 #endif // defined(OS_WIN) |
157 | 156 |
158 TestSuite::~TestSuite() { | 157 TestSuite::~TestSuite() { |
159 if (initialized_command_line_) | 158 if (initialized_command_line_) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 #endif // defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) | 334 #endif // defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) |
336 #endif // defined(OS_WIN) | 335 #endif // defined(OS_WIN) |
337 } | 336 } |
338 | 337 |
339 void TestSuite::Initialize() { | 338 void TestSuite::Initialize() { |
340 #if !defined(OS_IOS) | 339 #if !defined(OS_IOS) |
341 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { | 340 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { |
342 debug::WaitForDebugger(60, true); | 341 debug::WaitForDebugger(60, true); |
343 } | 342 } |
344 #endif | 343 #endif |
345 | |
346 // Set up a FeatureList instance, so that code using that API will not hit a | 344 // Set up a FeatureList instance, so that code using that API will not hit a |
347 // an error that it's not set. If a FeatureList was created in this way (i.e. | 345 // an error that it's not set. it will be cleared automatically. |
Ilya Sherman
2017/06/07 21:32:36
nit: s/it/It
| |
348 // one didn't exist previously), it will be cleared in Shutdown() via | 346 scoped_feature_list_.InitFromCommandLine( |
349 // ClearInstanceForTesting(). | 347 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("enable-features"), |
350 created_feature_list_ = | 348 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
351 FeatureList::InitializeInstance(std::string(), std::string()); | 349 "disable-features")); |
350 // Remove enable-features and disable-features here and DCHECK in | |
351 // BrowserTestBase. Ensure we don't try to use command line to modify | |
352 // FeatureList | |
Ilya Sherman
2017/06/07 21:32:36
nit: It's a bit odd to mention BrowserTestBase fro
| |
353 CommandLine::ForCurrentProcess()->RemoveSwitchASCIIForTesting( | |
354 "enable-features"); | |
355 CommandLine::ForCurrentProcess()->RemoveSwitchASCIIForTesting( | |
356 "disable-features"); | |
352 | 357 |
353 #if defined(OS_IOS) | 358 #if defined(OS_IOS) |
354 InitIOSTestMessageLoop(); | 359 InitIOSTestMessageLoop(); |
355 #endif // OS_IOS | 360 #endif // OS_IOS |
356 | 361 |
357 #if defined(OS_ANDROID) | 362 #if defined(OS_ANDROID) |
358 InitAndroidTestMessageLoop(); | 363 InitAndroidTestMessageLoop(); |
359 #endif // else defined(OS_ANDROID) | 364 #endif // else defined(OS_ANDROID) |
360 | 365 |
361 CHECK(debug::EnableInProcessStackDumping()); | 366 CHECK(debug::EnableInProcessStackDumping()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 410 |
406 TestTimeouts::Initialize(); | 411 TestTimeouts::Initialize(); |
407 | 412 |
408 trace_to_file_.BeginTracingFromCommandLineOptions(); | 413 trace_to_file_.BeginTracingFromCommandLineOptions(); |
409 | 414 |
410 base::debug::StartProfiling(GetProfileName()); | 415 base::debug::StartProfiling(GetProfileName()); |
411 } | 416 } |
412 | 417 |
413 void TestSuite::Shutdown() { | 418 void TestSuite::Shutdown() { |
414 base::debug::StopProfiling(); | 419 base::debug::StopProfiling(); |
415 | |
416 // Clear the FeatureList that was created by Initialize(). | |
417 if (created_feature_list_) | |
418 FeatureList::ClearInstanceForTesting(); | |
419 } | 420 } |
420 | 421 |
421 } // namespace base | 422 } // namespace base |
OLD | NEW |