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

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 9117037: Added a Unique ID for a Field Trial containing it's hashed name and the selected group ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« base/metrics/field_trial.cc ('K') | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Test of FieldTrial class 5 // Test of FieldTrial class
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 name, 1000000000, default_group_name, last_year_, 1, 1); 214 name, 1000000000, default_group_name, last_year_, 1, 1);
215 trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen. 215 trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen.
216 216
217 // Because trial has expired, we should always be in the default group. 217 // Because trial has expired, we should always be in the default group.
218 EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group()); 218 EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group());
219 219
220 // And that default_group_name should ALWAYS win. 220 // And that default_group_name should ALWAYS win.
221 EXPECT_EQ(default_group_name, trial->group_name()); 221 EXPECT_EQ(default_group_name, trial->group_name());
222 } 222 }
223 223
224 TEST_F(FieldTrialTest, NameGroupIds) {
225 std::string no_group("No Group");
226 uint32 no_group_id = FieldTrial::HashName(no_group);
227 scoped_refptr<FieldTrial> trial(new FieldTrial(
228 no_group, 10, "Default", next_year_, 12, 31));
229
230 // There is no winner yet, so no NameGroupId should be returned.
231 FieldTrial::NameGroupId name_group_id;
232 EXPECT_FALSE(trial->GetNameGroupId(&name_group_id));
233
234 // Create a single winning group.
235 std::string one_winner("One Winner");
236 uint32 one_winner_id = FieldTrial::HashName(one_winner);
237 trial = new FieldTrial(one_winner, 10, "Default", next_year_, 12, 31);
238 std::string winner("Winner");
239 uint32 winner_group_id = FieldTrial::HashName(winner);
240 trial->AppendGroup(winner, 10);
241 EXPECT_TRUE(trial->GetNameGroupId(&name_group_id));
242 EXPECT_EQ(one_winner_id, name_group_id.name);
243 EXPECT_EQ(winner_group_id, name_group_id.group);
244
245 std::string multi_group("MultiGroup");
246 uint32 multi_group_id = FieldTrial::HashName(multi_group);
247 scoped_refptr<FieldTrial> multi_group_trial =
248 new FieldTrial(multi_group, 9, "Default", next_year_, 12, 31);
249
250 multi_group_trial->AppendGroup("Me", 3);
251 multi_group_trial->AppendGroup("You", 3);
252 multi_group_trial->AppendGroup("Them", 3);
253 EXPECT_TRUE(multi_group_trial->GetNameGroupId(&name_group_id));
254 EXPECT_EQ(multi_group_id, name_group_id.name);
255 uint32 multi_group_winner_id =
256 FieldTrial::HashName(multi_group_trial->group_name());
257 EXPECT_EQ(multi_group_winner_id, name_group_id.group);
258
259 // Now check if the list is built properly...
260 std::vector<FieldTrial::NameGroupId> name_group_ids;
261 FieldTrialList::GetFieldTrialNameGroupIds(&name_group_ids);
262 EXPECT_EQ(2U, name_group_ids.size());
263 for (size_t i = 0; i < name_group_ids.size(); ++i) {
264 // Order is not guaranteed, so check all values.
265 EXPECT_NE(no_group_id, name_group_ids[i].name);
266 EXPECT_TRUE(one_winner_id != name_group_ids[i].name ||
267 winner_group_id == name_group_ids[i].group);
268 EXPECT_TRUE(multi_group_id != name_group_ids[i].name ||
269 multi_group_winner_id == name_group_ids[i].group);
270 }
271 }
272
224 TEST_F(FieldTrialTest, Save) { 273 TEST_F(FieldTrialTest, Save) {
225 std::string save_string; 274 std::string save_string;
226 275
227 FieldTrial* trial = 276 FieldTrial* trial =
228 new FieldTrial( 277 new FieldTrial(
229 "Some name", 10, "Default some name", next_year_, 12, 31); 278 "Some name", 10, "Default some name", next_year_, 12, 31);
230 // There is no winner yet, so no textual group name is associated with trial. 279 // There is no winner yet, so no textual group name is associated with trial.
231 // In this case, the trial should not be included. 280 // In this case, the trial should not be included.
232 EXPECT_EQ("", trial->group_name_internal()); 281 EXPECT_EQ("", trial->group_name_internal());
233 FieldTrialList::StatesToString(&save_string); 282 FieldTrialList::StatesToString(&save_string);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 TEST_F(FieldTrialTest, DisableAfterInitialization) { 475 TEST_F(FieldTrialTest, DisableAfterInitialization) {
427 FieldTrial* trial = 476 FieldTrial* trial =
428 new FieldTrial("trial", 100, "default", next_year_, 12, 31); 477 new FieldTrial("trial", 100, "default", next_year_, 12, 31);
429 trial->AppendGroup("non_default", 100); 478 trial->AppendGroup("non_default", 100);
430 ASSERT_EQ("non_default", trial->group_name()); 479 ASSERT_EQ("non_default", trial->group_name());
431 trial->Disable(); 480 trial->Disable();
432 ASSERT_EQ("default", trial->group_name()); 481 ASSERT_EQ("default", trial->group_name());
433 } 482 }
434 483
435 } // namespace base 484 } // namespace base
OLDNEW
« base/metrics/field_trial.cc ('K') | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698