summaryrefslogtreecommitdiff
path: root/base/test/scoped_feature_list.h
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2017-04-05 09:22:29 -0700
committerJakub Pawlowski <jpawlowski@google.com>2018-10-12 19:25:59 +0200
commite280f12834190c543be1ad4fddf6a642f65b998a (patch)
treea398a922d546c95123c3cc6e78091bef5378969b /base/test/scoped_feature_list.h
parent23b27ba5c54bf6368980117d91bc51c4495e2c50 (diff)
downloadlibchrome-e280f12834190c543be1ad4fddf6a642f65b998a.tar.gz
Uprev libchrome to r576279 (1/many)
This patch brings the latest and greatest features of libchrome to android. It contains ~2600 patches. Reason for uprev: libbluetooth want to use some of the most recent features avaliable. Test: libchrome_test Change-Id: Iccdec267948daab29e6328694f4c7d2f71ea26ca Merged-In: Iccdec267948daab29e6328694f4c7d2f71ea26ca
Diffstat (limited to 'base/test/scoped_feature_list.h')
-rw-r--r--base/test/scoped_feature_list.h93
1 files changed, 79 insertions, 14 deletions
diff --git a/base/test/scoped_feature_list.h b/base/test/scoped_feature_list.h
index 99e07f5374..6e13543ff1 100644
--- a/base/test/scoped_feature_list.h
+++ b/base/test/scoped_feature_list.h
@@ -5,9 +5,14 @@
#ifndef BASE_TEST_SCOPED_FEATURE_LIST_H_
#define BASE_TEST_SCOPED_FEATURE_LIST_H_
-#include <initializer_list>
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
#include "base/feature_list.h"
+#include "base/memory/ref_counted.h"
+#include "base/metrics/field_trial.h"
namespace base {
namespace test {
@@ -17,38 +22,98 @@ namespace test {
// 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.
+//
+// ScopedFeatureList needs to be initialized (via one of Init... methods)
+// before running code that inspects the state of features. In practice this
+// means:
+// - In browser tests, one of Init... methods should be called from the
+// overriden ::testing::Test::SetUp method. For example:
+// void SetUp() override {
+// scoped_feature_list_.InitAndEnableFeature(features::kMyFeatureHere);
+// InProcessBrowserTest::SetUp();
+// }
class ScopedFeatureList final {
public:
ScopedFeatureList();
~ScopedFeatureList();
+ // WARNING: This method will reset any globally configured features to their
+ // default values, which can hide feature interaction bugs. Please use
+ // sparingly. https://crbug.com/713390
// Initializes and registers a FeatureList instance with no overrides.
void Init();
+ // WARNING: This method will reset any globally configured features to their
+ // default values, which can hide feature interaction bugs. Please use
+ // sparingly. https://crbug.com/713390
// 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.
- void InitWithFeatures(
- const std::initializer_list<base::Feature>& enabled_features,
- const std::initializer_list<base::Feature>& disabled_features);
-
- // Initializes and registers a FeatureList instance with the given
+ // WARNING: This method will reset any globally configured features to their
+ // default values, which can hide feature interaction bugs. Please use
+ // sparingly. https://crbug.com/713390
+ // Initializes and registers a FeatureList instance with only 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 based on present
+ // FeatureList and overridden with the given enabled and disabled features.
+ // Any feature overrides already present in the global FeatureList will
+ // continue to apply, unless they conflict with the overrides passed into this
+ // method. This is important for testing potentially unexpected feature
+ // interactions.
+ void InitWithFeatures(const std::vector<Feature>& enabled_features,
+ const std::vector<Feature>& disabled_features);
+
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overridden with single enabled feature.
+ void InitAndEnableFeature(const Feature& feature);
+
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overridden with single enabled feature and associated field
+ // trial parameters.
+ // Note: this creates a scoped global field trial list if there is not
+ // currently one.
+ void InitAndEnableFeatureWithParameters(
+ const Feature& feature,
+ const std::map<std::string, std::string>& feature_parameters);
- // Initializes and registers a FeatureList instance disabling a single
- // feature.
- void InitAndDisableFeature(const base::Feature& feature);
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overridden with single disabled feature.
+ void InitAndDisableFeature(const Feature& feature);
+
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overriden with a single feature either enabled or
+ // disabled depending on |enabled|.
+ void InitWithFeatureState(const Feature& feature, bool enabled);
private:
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overridden with the given enabled and disabled features.
+ // Any feature overrides already present in the global FeatureList will
+ // continue to apply, unless they conflict with the overrides passed into this
+ // method.
+ // Field trials will apply to the enabled features, in the same order. The
+ // number of trials must be less (or equal) than the number of enabled
+ // features.
+ // Trials are expected to outlive the ScopedFeatureList.
+ void InitWithFeaturesAndFieldTrials(
+ const std::vector<Feature>& enabled_features,
+ const std::vector<FieldTrial*>& trials_for_enabled_features,
+ const std::vector<Feature>& disabled_features);
+
+ // Initializes and registers a FeatureList instance based on present
+ // FeatureList and overridden with single enabled feature and associated field
+ // trial override.
+ // |trial| is expected to outlive the ScopedFeatureList.
+ void InitAndEnableFeatureWithFieldTrialOverride(const Feature& feature,
+ FieldTrial* trial);
+
+ bool init_called_ = false;
std::unique_ptr<FeatureList> original_feature_list_;
+ scoped_refptr<FieldTrial> field_trial_override_;
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
DISALLOW_COPY_AND_ASSIGN(ScopedFeatureList);
};