• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BASE_TEST_SCOPED_FEATURE_LIST_H_
6 #define BASE_TEST_SCOPED_FEATURE_LIST_H_
7 
8 #include <initializer_list>
9 
10 #include "base/feature_list.h"
11 
12 namespace base {
13 namespace test {
14 
15 // ScopedFeatureList resets the global FeatureList instance to a new empty
16 // instance and restores the original instance upon destruction.
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
19 // a new one.
20 class ScopedFeatureList final {
21  public:
22   ScopedFeatureList();
23   ~ScopedFeatureList();
24 
25   // Initializes and registers a FeatureList instance with no overrides.
26   void Init();
27 
28   // Initializes and registers the given FeatureList instance.
29   void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list);
30 
31   // Initializes and registers a FeatureList instance with the given enabled
32   // and disabled features.
33   void InitWithFeatures(
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
38   // enabled and disabled features (comma-separated names).
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);
45 
46   // Initializes and registers a FeatureList instance disabling a single
47   // feature.
48   void InitAndDisableFeature(const base::Feature& feature);
49 
50  private:
51   std::unique_ptr<FeatureList> original_feature_list_;
52 
53   DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList);
54 };
55 
56 }  // namespace test
57 }  // namespace base
58 
59 #endif  // BASE_TEST_SCOPED_FEATURE_LIST_H_
60