OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Note: FieldTrialList should delete the objects at shutdown. | 107 // Note: FieldTrialList should delete the objects at shutdown. |
108 } | 108 } |
109 | 109 |
110 TEST_F(FieldTrialTest, AbsoluteProbabilities) { | 110 TEST_F(FieldTrialTest, AbsoluteProbabilities) { |
111 char always_true[] = " always true"; | 111 char always_true[] = " always true"; |
112 char default_always_true[] = " default always true"; | 112 char default_always_true[] = " default always true"; |
113 char always_false[] = " always false"; | 113 char always_false[] = " always false"; |
114 char default_always_false[] = " default always false"; | 114 char default_always_false[] = " default always false"; |
115 for (int i = 1; i < 250; ++i) { | 115 for (int i = 1; i < 250; ++i) { |
116 // Try lots of names, by changing the first character of the name. | 116 // Try lots of names, by changing the first character of the name. |
117 always_true[0] = i; | 117 char c = static_cast<char>(i); |
118 default_always_true[0] = i; | 118 always_true[0] = c; |
119 always_false[0] = i; | 119 default_always_true[0] = c; |
120 default_always_false[0] = i; | 120 always_false[0] = c; |
| 121 default_always_false[0] = c; |
121 | 122 |
122 scoped_refptr<FieldTrial> trial_true = | 123 scoped_refptr<FieldTrial> trial_true = |
123 CreateFieldTrial(always_true, 10, default_always_true, NULL); | 124 CreateFieldTrial(always_true, 10, default_always_true, NULL); |
124 const std::string winner = "TheWinner"; | 125 const std::string winner = "TheWinner"; |
125 int winner_group = trial_true->AppendGroup(winner, 10); | 126 int winner_group = trial_true->AppendGroup(winner, 10); |
126 | 127 |
127 EXPECT_EQ(winner_group, trial_true->group()); | 128 EXPECT_EQ(winner_group, trial_true->group()); |
128 EXPECT_EQ(winner, trial_true->group_name()); | 129 EXPECT_EQ(winner, trial_true->group_name()); |
129 | 130 |
130 scoped_refptr<FieldTrial> trial_false = | 131 scoped_refptr<FieldTrial> trial_false = |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 EXPECT_TRUE(second_winner); | 184 EXPECT_TRUE(second_winner); |
184 EXPECT_TRUE(first_winner); | 185 EXPECT_TRUE(first_winner); |
185 } | 186 } |
186 | 187 |
187 TEST_F(FieldTrialTest, MiddleProbabilities) { | 188 TEST_F(FieldTrialTest, MiddleProbabilities) { |
188 char name[] = " same name"; | 189 char name[] = " same name"; |
189 char default_group_name[] = " default same name"; | 190 char default_group_name[] = " default same name"; |
190 bool false_event_seen = false; | 191 bool false_event_seen = false; |
191 bool true_event_seen = false; | 192 bool true_event_seen = false; |
192 for (int i = 1; i < 250; ++i) { | 193 for (int i = 1; i < 250; ++i) { |
193 name[0] = i; | 194 char c = static_cast<char>(i); |
194 default_group_name[0] = i; | 195 name[0] = c; |
| 196 default_group_name[0] = c; |
195 scoped_refptr<FieldTrial> trial = | 197 scoped_refptr<FieldTrial> trial = |
196 CreateFieldTrial(name, 10, default_group_name, NULL); | 198 CreateFieldTrial(name, 10, default_group_name, NULL); |
197 int might_win = trial->AppendGroup("MightWin", 5); | 199 int might_win = trial->AppendGroup("MightWin", 5); |
198 | 200 |
199 if (trial->group() == might_win) { | 201 if (trial->group() == might_win) { |
200 true_event_seen = true; | 202 true_event_seen = true; |
201 } else { | 203 } else { |
202 false_event_seen = true; | 204 false_event_seen = true; |
203 } | 205 } |
204 if (false_event_seen && true_event_seen) | 206 if (false_event_seen && true_event_seen) |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 EXPECT_TRUE(active_groups.empty()); | 986 EXPECT_TRUE(active_groups.empty()); |
985 | 987 |
986 // The trial shouldn't be listed in the |StatesToString()| result. | 988 // The trial shouldn't be listed in the |StatesToString()| result. |
987 std::string states; | 989 std::string states; |
988 FieldTrialList::StatesToString(&states); | 990 FieldTrialList::StatesToString(&states); |
989 EXPECT_TRUE(states.empty()); | 991 EXPECT_TRUE(states.empty()); |
990 } | 992 } |
991 } | 993 } |
992 | 994 |
993 } // namespace base | 995 } // namespace base |
OLD | NEW |