| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/scoped_feature_list.h" |
| 6 |
| 7 namespace base { |
| 8 namespace test { |
| 9 |
| 10 ScopedFeatureList::ScopedFeatureList() {} |
| 11 |
| 12 ScopedFeatureList::~ScopedFeatureList() { |
| 13 if (original_feature_list_) { |
| 14 base::FeatureList::ClearInstanceForTesting(); |
| 15 base::FeatureList::RestoreInstanceForTesting( |
| 16 std::move(original_feature_list_)); |
| 17 } |
| 18 } |
| 19 |
| 20 void ScopedFeatureList::Init() { |
| 21 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 22 feature_list->InitializeFromCommandLine(std::string(), std::string()); |
| 23 InitWithFeatureList(std::move(feature_list)); |
| 24 } |
| 25 |
| 26 void ScopedFeatureList::InitWithFeatureList( |
| 27 std::unique_ptr<FeatureList> feature_list) { |
| 28 DCHECK(!original_feature_list_); |
| 29 original_feature_list_ = base::FeatureList::ClearInstanceForTesting(); |
| 30 base::FeatureList::SetInstance(std::move(feature_list)); |
| 31 } |
| 32 |
| 33 void ScopedFeatureList::InitFromCommandLine( |
| 34 const std::string& enable_features, |
| 35 const std::string& disable_features) { |
| 36 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 37 feature_list->InitializeFromCommandLine(enable_features, disable_features); |
| 38 InitWithFeatureList(std::move(feature_list)); |
| 39 } |
| 40 |
| 41 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) { |
| 42 InitFromCommandLine(feature.name, std::string()); |
| 43 } |
| 44 |
| 45 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { |
| 46 InitFromCommandLine(std::string(), feature.name); |
| 47 } |
| 48 |
| 49 } // namespace test |
| 50 } // namespace base |
| OLD | NEW |