Index: base/test/test_suite.cc |
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc |
index 7211ff5a4b1007c99faae5865c76e06871ac3a4e..81ea744e5088545126dd56bd9bc44dc37d50454f 100644 |
--- a/base/test/test_suite.cc |
+++ b/base/test/test_suite.cc |
@@ -100,14 +100,15 @@ int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
Bind(&TestSuite::Run, Unretained(&test_suite))); |
} |
-TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
+TestSuite::TestSuite(int argc, char** argv) |
+ : initialized_command_line_(false), created_feature_list_(false) { |
PreInitialize(); |
InitializeFromCommandLine(argc, argv); |
} |
#if defined(OS_WIN) |
TestSuite::TestSuite(int argc, wchar_t** argv) |
- : initialized_command_line_(false) { |
+ : initialized_command_line_(false), created_feature_list_(false) { |
PreInitialize(); |
InitializeFromCommandLine(argc, argv); |
} |
@@ -226,15 +227,8 @@ int TestSuite::Run() { |
test_listener_ios::RegisterTestEndListener(); |
#endif |
- // Set up a FeatureList instance, so that code using that API will not hit a |
- // an error that it's not set. Cleared by ClearInstanceForTesting() below. |
- base::FeatureList::SetInstance(WrapUnique(new base::FeatureList)); |
- |
int result = RUN_ALL_TESTS(); |
- // Clear the FeatureList that was registered above. |
- FeatureList::ClearInstanceForTesting(); |
- |
#if defined(OS_MACOSX) |
// This MUST happen before Shutdown() since Shutdown() tears down |
// objects (such as NotificationService::current()) that Cocoa |
@@ -296,6 +290,13 @@ void TestSuite::Initialize() { |
} |
#endif |
+ // Set up a FeatureList instance, so that code using that API will not hit a |
+ // an error that it's not set. If a FeatureList was created in this way (i.e. |
+ // one didn't exist previously), it will be cleared in Shutdown() via |
+ // ClearInstanceForTesting(). |
+ created_feature_list_ = |
+ FeatureList::InitializeInstance(std::string(), std::string()); |
+ |
#if defined(OS_IOS) |
InitIOSTestMessageLoop(); |
#endif // OS_IOS |
@@ -364,6 +365,9 @@ void TestSuite::Initialize() { |
} |
void TestSuite::Shutdown() { |
+ // Clear the FeatureList that was created by Initialize(). |
+ if (created_feature_list_) |
+ FeatureList::ClearInstanceForTesting(); |
} |
} // namespace base |