| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef BASE_TEST_SCOPED_FEATURE_LIST_H_ | 5 #ifndef BASE_TEST_SCOPED_FEATURE_LIST_H_ |
| 6 #define BASE_TEST_SCOPED_FEATURE_LIST_H_ | 6 #define BASE_TEST_SCOPED_FEATURE_LIST_H_ |
| 7 | 7 |
| 8 #include <initializer_list> | 8 #include <initializer_list> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // overriden ::testing::Test::SetUp method. For example: | 25 // overriden ::testing::Test::SetUp method. For example: |
| 26 // void SetUp() override { | 26 // void SetUp() override { |
| 27 // scoped_feature_list_.InitAndEnableFeature(features::kMyFeatureHere); | 27 // scoped_feature_list_.InitAndEnableFeature(features::kMyFeatureHere); |
| 28 // InProcessBrowserTest::SetUp(); | 28 // InProcessBrowserTest::SetUp(); |
| 29 // } | 29 // } |
| 30 class ScopedFeatureList final { | 30 class ScopedFeatureList final { |
| 31 public: | 31 public: |
| 32 ScopedFeatureList(); | 32 ScopedFeatureList(); |
| 33 ~ScopedFeatureList(); | 33 ~ScopedFeatureList(); |
| 34 | 34 |
| 35 // WARNING: This method will reset any globally configured features to their |
| 36 // default values, which can hide feature interaction bugs. Please use |
| 37 // sparingly. https://crbug.com/713390 |
| 35 // Initializes and registers a FeatureList instance with no overrides. | 38 // Initializes and registers a FeatureList instance with no overrides. |
| 36 void Init(); | 39 void Init(); |
| 37 | 40 |
| 41 // WARNING: This method will reset any globally configured features to their |
| 42 // default values, which can hide feature interaction bugs. Please use |
| 43 // sparingly. https://crbug.com/713390 |
| 38 // Initializes and registers the given FeatureList instance. | 44 // Initializes and registers the given FeatureList instance. |
| 39 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); | 45 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); |
| 40 | 46 |
| 41 // Initializes and registers a FeatureList instance with the given enabled | 47 // WARNING: This method will reset any globally configured features to their |
| 42 // and disabled features. | 48 // default values, which can hide feature interaction bugs. Please use |
| 49 // sparingly. https://crbug.com/713390 |
| 50 // Initializes and registers a FeatureList instance with only the given |
| 51 // enabled and disabled features (comma-separated names). |
| 52 void InitFromCommandLine(const std::string& enable_features, |
| 53 const std::string& disable_features); |
| 54 |
| 55 // Initializes and registers a FeatureList instance based on present |
| 56 // FeatureList and overridden with the given enabled and disabled features. |
| 57 // Any feature overrides already present in the global FeatureList will |
| 58 // continue to apply, unless they conflict with the overrides passed into this |
| 59 // method. This is important for testing potentially unexpected feature |
| 60 // interactions. |
| 43 void InitWithFeatures( | 61 void InitWithFeatures( |
| 44 const std::initializer_list<base::Feature>& enabled_features, | 62 const std::initializer_list<base::Feature>& enabled_features, |
| 45 const std::initializer_list<base::Feature>& disabled_features); | 63 const std::initializer_list<base::Feature>& disabled_features); |
| 46 | 64 |
| 47 // Initializes and registers a FeatureList instance with the given | 65 // Initializes and registers a FeatureList instance based on present |
| 48 // enabled and disabled features (comma-separated names). | 66 // FeatureList and overridden with single enabled feature. |
| 49 void InitFromCommandLine(const std::string& enable_features, | |
| 50 const std::string& disable_features); | |
| 51 | |
| 52 // Initializes and registers a FeatureList instance enabling a single | |
| 53 // feature. | |
| 54 void InitAndEnableFeature(const base::Feature& feature); | 67 void InitAndEnableFeature(const base::Feature& feature); |
| 55 | 68 |
| 56 // Initializes and registers a FeatureList instance disabling a single | 69 // Initializes and registers a FeatureList instance based on present |
| 57 // feature. | 70 // FeatureList and overridden with single disabled feature. |
| 58 void InitAndDisableFeature(const base::Feature& feature); | 71 void InitAndDisableFeature(const base::Feature& feature); |
| 59 | 72 |
| 60 private: | 73 private: |
| 61 std::unique_ptr<FeatureList> original_feature_list_; | 74 std::unique_ptr<FeatureList> original_feature_list_; |
| 62 | 75 |
| 63 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); | 76 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); |
| 64 }; | 77 }; |
| 65 | 78 |
| 66 } // namespace test | 79 } // namespace test |
| 67 } // namespace base | 80 } // namespace base |
| 68 | 81 |
| 69 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ | 82 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ |
| OLD | NEW |