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

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, UIDs) {
225 std::string no_group("No Group");
226 size_t no_group_id = BASE_HASH_NAMESPACE::hash_value(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 UID should be returned for this trial.
231 FieldTrial::UID uid;
232 EXPECT_FALSE(trial->GetUID(&uid));
233
234 // Create a single winning group.
235 std::string one_winner("One Winner");
236 size_t one_winner_id = BASE_HASH_NAMESPACE::hash_value(one_winner);
237 trial = new FieldTrial(one_winner, 10, "Default", next_year_, 12, 31);
238 int winner_group_id = trial->AppendGroup("Winner", 10);
239 EXPECT_TRUE(trial->GetUID(&uid));
240 EXPECT_EQ(one_winner_id, uid.first);
241 EXPECT_EQ(winner_group_id, uid.second);
242
243 std::string multi_group("MultiGroup");
244 size_t multi_group_id = BASE_HASH_NAMESPACE::hash_value(multi_group);
245 scoped_refptr<FieldTrial> multi_group_trial =
246 new FieldTrial(multi_group, 9, "Default", next_year_, 12, 31);
247
248 multi_group_trial->AppendGroup("Me", 3);
249 multi_group_trial->AppendGroup("You", 3);
250 multi_group_trial->AppendGroup("Them", 3);
251 EXPECT_TRUE(multi_group_trial->GetUID(&uid));
252 EXPECT_EQ(multi_group_id, uid.first);
253 EXPECT_EQ(multi_group_trial->group(), uid.second);
254
255 // Now check if the list is built properly...
256 std::vector<FieldTrial::UID> uids;
257 FieldTrialList::GetFieldTrialUIDs(&uids);
258 EXPECT_EQ(2, uids.size());
259 for (size_t i = 0; i < uids.size(); ++i) {
260 // Order is not guaranteed, so check all values.
261 EXPECT_NE(no_group_id, uids[i].first);
262 EXPECT_TRUE(one_winner_id != uids[i].first ||
263 winner_group_id == uids[i].second);
264 EXPECT_TRUE(multi_group_id != uids[i].first ||
265 multi_group_trial->group() == uids[i].second);
266 }
267 }
268
224 TEST_F(FieldTrialTest, Save) { 269 TEST_F(FieldTrialTest, Save) {
225 std::string save_string; 270 std::string save_string;
226 271
227 FieldTrial* trial = 272 FieldTrial* trial =
228 new FieldTrial( 273 new FieldTrial(
229 "Some name", 10, "Default some name", next_year_, 12, 31); 274 "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. 275 // There is no winner yet, so no textual group name is associated with trial.
231 // In this case, the trial should not be included. 276 // In this case, the trial should not be included.
232 EXPECT_EQ("", trial->group_name_internal()); 277 EXPECT_EQ("", trial->group_name_internal());
233 FieldTrialList::StatesToString(&save_string); 278 FieldTrialList::StatesToString(&save_string);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 TEST_F(FieldTrialTest, DisableAfterInitialization) { 471 TEST_F(FieldTrialTest, DisableAfterInitialization) {
427 FieldTrial* trial = 472 FieldTrial* trial =
428 new FieldTrial("trial", 100, "default", next_year_, 12, 31); 473 new FieldTrial("trial", 100, "default", next_year_, 12, 31);
429 trial->AppendGroup("non_default", 100); 474 trial->AppendGroup("non_default", 100);
430 ASSERT_EQ("non_default", trial->group_name()); 475 ASSERT_EQ("non_default", trial->group_name());
431 trial->Disable(); 476 trial->Disable();
432 ASSERT_EQ("default", trial->group_name()); 477 ASSERT_EQ("default", trial->group_name());
433 } 478 }
434 479
435 } // namespace base 480 } // 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