OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
6 #define COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 6 #define COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // variation params, returns false and does not modify |params|. Calling this | 157 // variation params, returns false and does not modify |params|. Calling this |
158 // function will result in the associated field trial being marked as active if | 158 // function will result in the associated field trial being marked as active if |
159 // found (i.e. group() will be called on it), if it wasn't already. Currently, | 159 // found (i.e. group() will be called on it), if it wasn't already. Currently, |
160 // this information is only available from the browser process. Thread safe. | 160 // this information is only available from the browser process. Thread safe. |
161 std::string GetVariationParamValueByFeature(const base::Feature& feature, | 161 std::string GetVariationParamValueByFeature(const base::Feature& feature, |
162 const std::string& param_name); | 162 const std::string& param_name); |
163 | 163 |
164 // Expose some functions for testing. | 164 // Expose some functions for testing. |
165 namespace testing { | 165 namespace testing { |
166 | 166 |
| 167 // Use this class as a member in your test class to set variation params for |
| 168 // your tests. You can directly set the parameters in the constructor (if they |
| 169 // are used by other members upon construction). You can change them later |
| 170 // arbitrarily many times using the SetVariationParams function. Internally, it |
| 171 // creates a FieldTrialList as a member. It works well for multiple tests of a |
| 172 // given test class, as it clears the parameters when this class is destructed. |
| 173 // Note that it clears all parameters (not just those registered here). |
| 174 class VariationParamsManager { |
| 175 public: |
| 176 VariationParamsManager(const std::string& trial_name, |
| 177 const std::map<std::string, std::string>& params); |
| 178 ~VariationParamsManager(); |
| 179 |
| 180 // Associates |params| with the given |trial_name|. It creates a new group, |
| 181 // used only for testing. Between two calls of this function, |
| 182 // ClearAllVariationParams() has to be called. |
| 183 void SetVariationParams(const std::string& trial_name, |
| 184 const std::map<std::string, std::string>& params); |
| 185 |
| 186 private: |
| 187 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| 188 |
| 189 DISALLOW_COPY_AND_ASSIGN(VariationParamsManager); |
| 190 }; |
| 191 |
167 // Clears all of the mapped associations. | 192 // Clears all of the mapped associations. |
168 void ClearAllVariationIDs(); | 193 void ClearAllVariationIDs(); |
169 | 194 |
170 // Clears all of the associated params. | 195 // Clears all of the associated params. |
171 void ClearAllVariationParams(); | 196 void ClearAllVariationParams(); |
172 | 197 |
173 } // namespace testing | 198 } // namespace testing |
174 | 199 |
175 } // namespace variations | 200 } // namespace variations |
176 | 201 |
177 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 202 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
OLD | NEW |