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 | |
28 // Initializes and registers a FeatureList instance with no overrides. | 25 // Initializes and registers a FeatureList instance with no overrides. |
29 void Init(); | 26 void Init(); |
30 | 27 |
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 | |
34 // Initializes and registers the given FeatureList instance. | 28 // Initializes and registers the given FeatureList instance. |
35 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); | 29 void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); |
36 | 30 |
37 // WARNING: This method will reset any globally configured features to their | 31 // Initializes and registers a FeatureList instance with the given enabled |
38 // default values, which can hide feature interaction bugs. Please use | 32 // and disabled features. |
39 // sparingly. https://crbug.com/713390 | 33 void InitWithFeatures( |
40 // Initializes and registers a FeatureList instance with only the given | 34 const std::initializer_list<base::Feature>& enabled_features, |
| 35 const std::initializer_list<base::Feature>& disabled_features); |
| 36 |
| 37 // Initializes and registers a FeatureList instance with the given |
41 // enabled and disabled features (comma-separated names). | 38 // enabled and disabled features (comma-separated names). |
42 void InitFromCommandLine(const std::string& enable_features, | 39 void InitFromCommandLine(const std::string& enable_features, |
43 const std::string& disable_features); | 40 const std::string& disable_features); |
44 | 41 |
45 // Initializes and registers a FeatureList instance based on present | 42 // Initializes and registers a FeatureList instance enabling a single |
46 // FeatureList and overridden with the given enabled and disabled features. | 43 // feature. |
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. | |
51 void InitWithFeatures( | |
52 const std::initializer_list<base::Feature>& enabled_features, | |
53 const std::initializer_list<base::Feature>& disabled_features); | |
54 | |
55 // Initializes and registers a FeatureList instance based on present | |
56 // FeatureList and overridden with single enabled feature. | |
57 void InitAndEnableFeature(const base::Feature& feature); | 44 void InitAndEnableFeature(const base::Feature& feature); |
58 | 45 |
59 // Initializes and registers a FeatureList instance based on present | 46 // Initializes and registers a FeatureList instance disabling a single |
60 // FeatureList and overridden with single disabled feature. | 47 // feature. |
61 void InitAndDisableFeature(const base::Feature& feature); | 48 void InitAndDisableFeature(const base::Feature& feature); |
62 | 49 |
63 private: | 50 private: |
64 std::unique_ptr<FeatureList> original_feature_list_; | 51 std::unique_ptr<FeatureList> original_feature_list_; |
65 | 52 |
66 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); | 53 DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); |
67 }; | 54 }; |
68 | 55 |
69 } // namespace test | 56 } // namespace test |
70 } // namespace base | 57 } // namespace base |
71 | 58 |
72 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ | 59 #endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ |
OLD | NEW |