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" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace test { | 13 namespace test { |
14 | 14 |
15 // ScopedFeatureList resets the global FeatureList instance to a new empty | 15 // ScopedFeatureList resets the global FeatureList instance to a new empty |
16 // instance and restores the original instance upon destruction. | 16 // instance and restores the original instance upon destruction. |
17 // Note: Re-using the same object is not allowed. To reset the feature | 17 // Note: Re-using the same object is not allowed. To reset the feature |
18 // list and initialize it anew, destroy an existing scoped list and init | 18 // list and initialize it anew, destroy an existing scoped list and init |
19 // a new one. | 19 // a new one. |
20 class ScopedFeatureList final { | 20 class ScopedFeatureList final { |
21 public: | 21 public: |
22 ScopedFeatureList(); | 22 ScopedFeatureList(); |
23 ~ScopedFeatureList(); | 23 ~ScopedFeatureList(); |
24 | 24 |
| 25 // WARNING: This method will reset any globally configured features to their |
| 26 // default values, which can hide feature interaction bugs. Please use |
| 27 // sparingly. https://crbug.com/713390 |
25 // Initializes and registers a FeatureList instance with no overrides. | 28 // Initializes and registers a FeatureList instance with no overrides. |
26 void Init(); | 29 void Init(); |
27 | 30 |
| 31 // WARNING: This method will reset any globally configured features to their |
| 32 // default values, which can hide feature interaction bugs. Please use |
| 33 // sparingly. https://crbug.com/713390 |
28 // Initializes and registers the given FeatureList instance. | 34 // Initializes and registers the given FeatureList instance. |
29 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); | 35 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); |
30 | 36 |
31 // Initializes and registers a FeatureList instance with the given enabled | 37 // WARNING: This method will reset any globally configured features to their |
32 // and disabled features. | 38 // default values, which can hide feature interaction bugs. Please use |
| 39 // sparingly. https://crbug.com/713390 |
| 40 // Initializes and registers a FeatureList instance with only the given |
| 41 // enabled and disabled features (comma-separated names). |
| 42 void InitFromCommandLine(const std::string& enable_features, |
| 43 const std::string& disable_features); |
| 44 |
| 45 // Initializes and registers a FeatureList instance based on present |
| 46 // FeatureList and overridden with the given enabled and disabled features. |
| 47 // Any feature overrides already present in the global FeatureList will |
| 48 // continue to apply, unless they conflict with the overrides passed into this |
| 49 // method. This is important for testing potentially unexpected feature |
| 50 // interactions. |
33 void InitWithFeatures( | 51 void InitWithFeatures( |
34 const std::initializer_list<base::Feature>& enabled_features, | 52 const std::initializer_list<base::Feature>& enabled_features, |
35 const std::initializer_list<base::Feature>& disabled_features); | 53 const std::initializer_list<base::Feature>& disabled_features); |
36 | 54 |
37 // Initializes and registers a FeatureList instance with the given | 55 // Initializes and registers a FeatureList instance based on present |
38 // enabled and disabled features (comma-separated names). | 56 // FeatureList and overridden with single enabled feature. |
39 void InitFromCommandLine(const std::string& enable_features, | |
40 const std::string& disable_features); | |
41 | |
42 // Initializes and registers a FeatureList instance enabling a single | |
43 // feature. | |
44 void InitAndEnableFeature(const base::Feature& feature); | 57 void InitAndEnableFeature(const base::Feature& feature); |
45 | 58 |
46 // Initializes and registers a FeatureList instance disabling a single | 59 // Initializes and registers a FeatureList instance based on present |
47 // feature. | 60 // FeatureList and overridden with single disabled feature. |
48 void InitAndDisableFeature(const base::Feature& feature); | 61 void InitAndDisableFeature(const base::Feature& feature); |
49 | 62 |
50 private: | 63 private: |
51 std::unique_ptr<FeatureList> original_feature_list_; | 64 std::unique_ptr<FeatureList> original_feature_list_; |
52 | 65 |
53 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); | 66 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); |
54 }; | 67 }; |
55 | 68 |
56 } // namespace test | 69 } // namespace test |
57 } // namespace base | 70 } // namespace base |
58 | 71 |
59 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ | 72 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ |
OLD | NEW |