Chromium Code Reviews| Index: base/test/scoped_feature_list.h |
| diff --git a/base/test/scoped_feature_list.h b/base/test/scoped_feature_list.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02603e1c1239bebe69468d050a10e4c851562785 |
| --- /dev/null |
| +++ b/base/test/scoped_feature_list.h |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TEST_SCOPED_FEATURE_LIST_H_ |
| +#define BASE_TEST_SCOPED_FEATURE_LIST_H_ |
| + |
| +#include "base/feature_list.h" |
| + |
| +namespace base { |
| +namespace test { |
| + |
| +// ScopedFeatureList resets the global FeatureList instance to a new empty |
| +// instance and restores the original instance upon destruction. |
| +// Note: Re-using the same object is not allowed. To reset the feature |
| +// list and initialize it anew, destroy an existing scoped list and init |
| +// a new one. |
| +class ScopedFeatureList final { |
| + public: |
| + ScopedFeatureList(); |
| + ~ScopedFeatureList(); |
| + |
| + // Initializes and registers a FeatureList instance with no overrides. |
| + void Init(); |
|
Ilya Sherman
2016/08/09 01:06:57
Optional nit: I think it would be cleaner if each
Alexei Svitkine (slow)
2016/08/09 01:26:16
That doesn't fit some use cases - where e.g. the s
Ilya Sherman
2016/08/09 06:15:12
FWIW, my preferred solution to that would be for t
Alexei Svitkine (slow)
2016/08/09 15:27:43
Okay, I can take a look at it when I plan to do my
|
| + |
| + // Initializes and registers the given FeatureList instance. |
| + void InitWithFeatureList(std::unique_ptr<FeatureList> feature_list); |
| + |
| + // Initializes and registers a FeatureList instance with the given |
| + // enabled and disabled features (comma-separated names). |
| + void InitFromCommandLine(const std::string& enable_features, |
| + const std::string& disable_features); |
| + |
| + // Initializes and registers a FeatureList instance enabling a single |
| + // feature. |
| + void InitAndEnableFeature(const base::Feature& feature); |
| + |
| + // Initializes and registers a FeatureList instance disabling a single |
| + // feature. |
| + void InitAndDisableFeature(const base::Feature& feature); |
| + |
| + private: |
| + std::unique_ptr<FeatureList> original_feature_list_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList); |
| +}; |
| + |
| +} // namespace test |
| +} // namespace base |
| + |
| +#endif // BASE_TEST_SCOPED_FEATURE_LIST_H_ |