OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/common/variations/variations_util.h" | 5 #include "chrome/common/variations/variations_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 EXPECT_EQ("/", variations::GetVariationParamValue(kTrialName, "a")); | 43 EXPECT_EQ("/", variations::GetVariationParamValue(kTrialName, "a")); |
44 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "b")); | 44 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "b")); |
45 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "x")); | 45 EXPECT_EQ(std::string(), variations::GetVariationParamValue(kTrialName, "x")); |
46 | 46 |
47 std::map<std::string, std::string> params; | 47 std::map<std::string, std::string> params; |
48 EXPECT_TRUE(variations::GetVariationParams(kTrialName, ¶ms)); | 48 EXPECT_TRUE(variations::GetVariationParams(kTrialName, ¶ms)); |
49 EXPECT_EQ(1U, params.size()); | 49 EXPECT_EQ(1U, params.size()); |
50 EXPECT_EQ("/", params["a"]); | 50 EXPECT_EQ("/", params["a"]); |
51 } | 51 } |
52 | 52 |
53 TEST_F(VariationsUtilTest, AssociateParamsFromStringWithSameStudy) { | 53 TEST_F(VariationsUtilTest, AssociateParamsFromStringWithSameTrial) { |
54 const std::string kTrialName = "AssociateVariationParams"; | 54 const std::string kTrialName = "AssociateVariationParams"; |
55 const std::string kVariationsString = | 55 const std::string kVariationsString = |
56 "AssociateVariationParams.A:a/10/b/test,AssociateVariationParams.A:a/x"; | 56 "AssociateVariationParams.A:a/10/b/test,AssociateVariationParams.A:a/x"; |
57 ASSERT_FALSE(AssociateParamsFromString(kVariationsString)); | 57 ASSERT_FALSE(AssociateParamsFromString(kVariationsString)); |
58 } | 58 } |
59 | 59 |
60 TEST_F(VariationsUtilTest, AssociateParamsFromFieldTrialConfig) { | 60 TEST_F(VariationsUtilTest, AssociateParamsFromFieldTrialConfig) { |
61 const FieldTrialGroupParams array_kFieldTrialConfig_params[] = {{"x", "1"}, | 61 const FieldTrialTestingGroupParams array_kFieldTrialConfig_params_0[] = |
62 {"y", "2"}}; | 62 {{"x", "1"}, {"y", "2"}}; |
63 | 63 const FieldTrialTestingGroup array_kFieldTrialConfig_groups_0[] = { |
64 const FieldTrialTestingGroup array_kFieldTrialConfig_groups[] = { | 64 {"TestGroup1", array_kFieldTrialConfig_params_0, 2, NULL, 0, NULL, 0}, |
65 {"TestStudy1", "TestGroup1", array_kFieldTrialConfig_params, 2, NULL, 0, | 65 }; |
66 NULL, 0}, | 66 const FieldTrialTestingGroupParams array_kFieldTrialConfig_params_1[] = |
67 {"TestStudy2", "TestGroup2", NULL, 0, NULL, 0, NULL, 0}}; | 67 {{"x", "3"}, {"y", "4"}}; |
68 | 68 const FieldTrialTestingGroup array_kFieldTrialConfig_groups_1[] = { |
| 69 {"TestGroup2", array_kFieldTrialConfig_params_0, 2, NULL, 0, NULL, 0}, |
| 70 {"TestGroup2-2", array_kFieldTrialConfig_params_1, 2, NULL, 0, NULL, 0}, |
| 71 }; |
| 72 const FieldTrialTestingTrial array_kFieldTrialConfig_studies[] = { |
| 73 {"TestTrial1", array_kFieldTrialConfig_groups_0, 1}, |
| 74 {"TestTrial2", array_kFieldTrialConfig_groups_1, 2}, |
| 75 }; |
69 const FieldTrialTestingConfig kConfig = { | 76 const FieldTrialTestingConfig kConfig = { |
70 array_kFieldTrialConfig_groups, 2, | 77 array_kFieldTrialConfig_studies, 2 |
71 }; | 78 }; |
72 | 79 |
73 base::FeatureList feature_list; | 80 base::FeatureList feature_list; |
74 AssociateParamsFromFieldTrialConfig(kConfig, &feature_list); | 81 AssociateParamsFromFieldTrialConfig(kConfig, &feature_list); |
75 | 82 |
76 EXPECT_EQ("1", variations::GetVariationParamValue("TestStudy1", "x")); | 83 EXPECT_EQ("1", variations::GetVariationParamValue("TestTrial1", "x")); |
77 EXPECT_EQ("2", variations::GetVariationParamValue("TestStudy1", "y")); | 84 EXPECT_EQ("2", variations::GetVariationParamValue("TestTrial1", "y")); |
78 | 85 |
79 std::map<std::string, std::string> params; | 86 std::map<std::string, std::string> params; |
80 EXPECT_TRUE(variations::GetVariationParams("TestStudy1", ¶ms)); | 87 EXPECT_TRUE(variations::GetVariationParams("TestTrial1", ¶ms)); |
81 EXPECT_EQ(2U, params.size()); | 88 EXPECT_EQ(2U, params.size()); |
82 EXPECT_EQ("1", params["x"]); | 89 EXPECT_EQ("1", params["x"]); |
83 EXPECT_EQ("2", params["y"]); | 90 EXPECT_EQ("2", params["y"]); |
84 | 91 |
85 EXPECT_EQ("TestGroup1", base::FieldTrialList::FindFullName("TestStudy1")); | 92 EXPECT_EQ("TestGroup1", base::FieldTrialList::FindFullName("TestTrial1")); |
86 EXPECT_EQ("TestGroup2", base::FieldTrialList::FindFullName("TestStudy2")); | 93 EXPECT_EQ("TestGroup2", base::FieldTrialList::FindFullName("TestTrial2")); |
87 } | 94 } |
88 | 95 |
89 TEST_F(VariationsUtilTest, AssociateFeaturesFromFieldTrialConfig) { | 96 TEST_F(VariationsUtilTest, AssociateFeaturesFromFieldTrialConfig) { |
90 const base::Feature kFeatureA{"A", base::FEATURE_DISABLED_BY_DEFAULT}; | 97 const base::Feature kFeatureA{"A", base::FEATURE_DISABLED_BY_DEFAULT}; |
91 const base::Feature kFeatureB{"B", base::FEATURE_ENABLED_BY_DEFAULT}; | 98 const base::Feature kFeatureB{"B", base::FEATURE_ENABLED_BY_DEFAULT}; |
92 const base::Feature kFeatureC{"C", base::FEATURE_DISABLED_BY_DEFAULT}; | 99 const base::Feature kFeatureC{"C", base::FEATURE_DISABLED_BY_DEFAULT}; |
93 const base::Feature kFeatureD{"D", base::FEATURE_ENABLED_BY_DEFAULT}; | 100 const base::Feature kFeatureD{"D", base::FEATURE_ENABLED_BY_DEFAULT}; |
94 | 101 |
95 const char* enable_features[] = {"A", "B"}; | 102 const char* enable_features[] = {"A", "B"}; |
96 const char* disable_features[] = {"C", "D"}; | 103 const char* disable_features[] = {"C", "D"}; |
97 | 104 |
98 const FieldTrialTestingGroup array_kFieldTrialConfig_groups[] = { | 105 const FieldTrialTestingGroup array_kFieldTrialConfig_groups_0[] = { |
99 {"TestStudy1", "TestGroup1", NULL, 0, enable_features, 2, NULL, 0}, | 106 {"TestGroup1", NULL, 0, enable_features, 2, NULL, 0}, |
100 {"TestStudy2", "TestGroup2", NULL, 0, NULL, 0, disable_features, 2}}; | 107 }; |
| 108 const FieldTrialTestingGroup array_kFieldTrialConfig_groups_1[] = { |
| 109 {"TestGroup2", NULL, 0, NULL, 0, disable_features, 2}, |
| 110 {"TestGroup2-2", NULL, 0, NULL, 0, NULL, 0}, |
| 111 }; |
| 112 |
| 113 const FieldTrialTestingTrial array_kFieldTrialConfig_studies[] = { |
| 114 {"TestTrial1", array_kFieldTrialConfig_groups_0, 1}, |
| 115 {"TestTrial2", array_kFieldTrialConfig_groups_1, 2}, |
| 116 }; |
101 | 117 |
102 const FieldTrialTestingConfig kConfig = { | 118 const FieldTrialTestingConfig kConfig = { |
103 array_kFieldTrialConfig_groups, 2, | 119 array_kFieldTrialConfig_studies, 2 |
104 }; | 120 }; |
105 | 121 |
106 base::FeatureList::ClearInstanceForTesting(); | 122 base::FeatureList::ClearInstanceForTesting(); |
107 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 123 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
108 AssociateParamsFromFieldTrialConfig(kConfig, feature_list.get()); | 124 AssociateParamsFromFieldTrialConfig(kConfig, feature_list.get()); |
109 base::FeatureList::SetInstance(std::move(feature_list)); | 125 base::FeatureList::SetInstance(std::move(feature_list)); |
110 | 126 |
111 // Check the resulting feature and field trial states. Trials should not be | 127 // Check the resulting feature and field trial states. Trials should not be |
112 // active until their associated features are queried. | 128 // active until their associated features are queried. |
113 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestStudy1")); | 129 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial1")); |
114 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureA)); | 130 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureA)); |
115 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureB)); | 131 EXPECT_TRUE(base::FeatureList::IsEnabled(kFeatureB)); |
116 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestStudy1")); | 132 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestTrial1")); |
117 | 133 |
118 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestStudy2")); | 134 EXPECT_FALSE(base::FieldTrialList::IsTrialActive("TestTrial2")); |
119 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureC)); | 135 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureC)); |
120 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureD)); | 136 EXPECT_FALSE(base::FeatureList::IsEnabled(kFeatureD)); |
121 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestStudy2")); | 137 EXPECT_TRUE(base::FieldTrialList::IsTrialActive("TestTrial2")); |
122 } | 138 } |
123 | 139 |
124 } // namespace chrome_variations | 140 } // namespace chrome_variations |
OLD | NEW |