OLD | NEW |
---|---|
(Empty) | |
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 COMPONENTS_VARIATIONS_VARIATIONS_PARAMS_MANAGER_H_ | |
6 #define COMPONENTS_VARIATIONS_VARIATIONS_PARAMS_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <string> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/metrics/field_trial.h" | |
14 | |
15 namespace base { | |
16 class FieldTrialList; | |
17 | |
18 namespace test { | |
19 class ScopedFeatureList; | |
20 } // namespace test | |
21 | |
22 } // namespace base | |
23 | |
24 namespace variations { | |
25 | |
Alexei Svitkine (slow)
2016/09/12 16:54:13
Nit: Remove empty line
jkrcal
2016/09/23 13:40:09
Done.
| |
26 namespace testing { | |
27 | |
28 // Use this class as a member in your test class to set variation params for | |
29 // your tests. You can directly set the parameters in the constructor (if they | |
30 // are used by other members upon construction). You can change them later | |
31 // arbitrarily many times using the SetVariationParams function. Internally, it | |
32 // creates a FieldTrialList as a member. It works well for multiple tests of a | |
33 // given test class, as it clears the parameters when this class is destructed. | |
34 // Note that it clears all parameters (not just those registered here). | |
35 class VariationParamsManager { | |
36 public: | |
37 // Does not associate any parameters. | |
38 VariationParamsManager(); | |
39 // Calls directly SetVariationParams with the provided arguments. | |
40 VariationParamsManager( | |
41 const std::string& trial_name, | |
42 const std::map<std::string, std::string>& param_values, | |
43 const std::map<std::string, std::string>& param_features); | |
44 ~VariationParamsManager(); | |
45 | |
46 // Associates |param_values| with the given |trial_name|. |param_values| maps | |
47 // parameter names to their values. |param_features| maps parameter names to | |
48 // names of the features they should be associated with. The keys in | |
49 // |param_features| must be a subset of the keys in |param_values| | |
50 // (|param_features| may specify all the parameters, or only some, or even | |
51 // none). The function creates a new trial group, used only for testing. | |
52 // Between two calls of this function, ClearAllVariationParams() has to be | |
53 // called. | |
54 void SetVariationParams( | |
55 const std::string& trial_name, | |
56 const std::map<std::string, std::string>& param_values, | |
57 const std::map<std::string, std::string>& param_features); | |
58 | |
59 // Clears all of the mapped associations. | |
60 void ClearAllVariationIDs(); | |
61 | |
62 // Clears all of the associated params. | |
63 void ClearAllVariationParams(); | |
64 | |
65 private: | |
66 std::unique_ptr<base::FieldTrialList> field_trial_list_; | |
67 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(VariationParamsManager); | |
70 }; | |
71 | |
72 } // namespace testing | |
73 | |
Alexei Svitkine (slow)
2016/09/12 16:54:13
Nit: Remove empty line
jkrcal
2016/09/23 13:40:09
Done.
| |
74 } // namespace variations | |
75 | |
76 #endif // COMPONENTS_VARIATIONS_VARIATIONS_PARAMS_MANAGER_H_ | |
OLD | NEW |