Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Unified Diff: components/variations/variations_associated_data.h

Issue 2145963002: Add simpler API for changing parameters in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Alexei's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/variations/variations_associated_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/variations/variations_associated_data.h
diff --git a/components/variations/variations_associated_data.h b/components/variations/variations_associated_data.h
index 3eb9567cc3afe41848602b2fc9a2eabdaa00de77..b60192ea2b3c0a684829b0c01f91dfb33e965708 100644
--- a/components/variations/variations_associated_data.h
+++ b/components/variations/variations_associated_data.h
@@ -164,6 +164,31 @@ std::string GetVariationParamValueByFeature(const base::Feature& feature,
// Expose some functions for testing.
namespace testing {
+// Use this class as a member in your test class to set variation params for
+// your tests. You can directly set the parameters in the constructor (if they
+// are used by other members upon construction). You can change them later
+// arbitrarily many times using the SetVariationParams function. Internally, it
+// creates a FieldTrialList as a member. It works well for multiple tests of a
+// given test class, as it clears the parameters when this class is destructed.
+// Note that it clears all parameters (not just those registered here).
+class VariationParamsManager {
+ public:
+ VariationParamsManager(const std::string& trial_name,
+ const std::map<std::string, std::string>& params);
+ ~VariationParamsManager();
+
+ // Associates |params| with the given |trial_name|. It creates a new group,
+ // used only for testing. Between two calls of this function,
+ // ClearAllVariationParams() has to be called.
+ void SetVariationParams(const std::string& trial_name,
+ const std::map<std::string, std::string>& params);
+
+ private:
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(VariationParamsManager);
+};
+
// Clears all of the mapped associations.
void ClearAllVariationIDs();
« no previous file with comments | « no previous file | components/variations/variations_associated_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698