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

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

Issue 700953002: Send all field trials from the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@finch4
Patch Set: Responded to comments and fixed some minor issues. Created 6 years, 1 month 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
OLDNEW
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/build_time.h" 7 #include "base/build_time.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 for (size_t i = 0; i < active_groups.size(); ++i) { 304 for (size_t i = 0; i < active_groups.size(); ++i) {
305 // Order is not guaranteed, so check all values. 305 // Order is not guaranteed, so check all values.
306 EXPECT_NE(no_group, active_groups[i].trial_name); 306 EXPECT_NE(no_group, active_groups[i].trial_name);
307 EXPECT_TRUE(one_winner != active_groups[i].trial_name || 307 EXPECT_TRUE(one_winner != active_groups[i].trial_name ||
308 winner == active_groups[i].group_name); 308 winner == active_groups[i].group_name);
309 EXPECT_TRUE(multi_group != active_groups[i].trial_name || 309 EXPECT_TRUE(multi_group != active_groups[i].trial_name ||
310 multi_group_trial->group_name() == active_groups[i].group_name); 310 multi_group_trial->group_name() == active_groups[i].group_name);
311 } 311 }
312 } 312 }
313 313
314 TEST_F(FieldTrialTest, AllGroups) {
315 FieldTrial::FieldTrialState field_trial_state;
316 std::string one_winner("One Winner");
317 scoped_refptr<FieldTrial> trial =
318 CreateFieldTrial(one_winner, 10, "Default", NULL);
319 std::string winner("Winner");
320 trial->AppendGroup(winner, 10);
321 EXPECT_TRUE(trial->GetState(&field_trial_state));
322 EXPECT_EQ(one_winner, field_trial_state.trial_name);
323 EXPECT_EQ(winner, field_trial_state.group_name);
324 trial->group();
325 EXPECT_TRUE(trial->GetState(&field_trial_state));
326 EXPECT_EQ(one_winner, field_trial_state.trial_name);
327 EXPECT_EQ(winner, field_trial_state.group_name);
328
329 std::string multi_group("MultiGroup");
330 scoped_refptr<FieldTrial> multi_group_trial =
331 CreateFieldTrial(multi_group, 9, "Default", NULL);
332
333 multi_group_trial->AppendGroup("Me", 3);
334 multi_group_trial->AppendGroup("You", 3);
335 multi_group_trial->AppendGroup("Them", 3);
336 EXPECT_TRUE(multi_group_trial->GetState(&field_trial_state));
337 // Finalize the group selection by accessing the selected group.
338 multi_group_trial->group();
339 EXPECT_TRUE(multi_group_trial->GetState(&field_trial_state));
340 EXPECT_EQ(multi_group, field_trial_state.trial_name);
341 EXPECT_EQ(multi_group_trial->group_name(), field_trial_state.group_name);
342 }
343
314 TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) { 344 TEST_F(FieldTrialTest, ActiveGroupsNotFinalized) {
315 const char kTrialName[] = "TestTrial"; 345 const char kTrialName[] = "TestTrial";
316 const char kSecondaryGroupName[] = "SecondaryGroup"; 346 const char kSecondaryGroupName[] = "SecondaryGroup";
317 347
318 int default_group = -1; 348 int default_group = -1;
319 scoped_refptr<FieldTrial> trial = 349 scoped_refptr<FieldTrial> trial =
320 CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group); 350 CreateFieldTrial(kTrialName, 100, kDefaultGroupName, &default_group);
321 const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50); 351 const int secondary_group = trial->AppendGroup(kSecondaryGroupName, 50);
322 352
323 // Before |group()| is called, |GetActiveGroup()| should return false. 353 // Before |group()| is called, |GetActiveGroup()| should return false.
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 // Trying to instantiate a one-time randomized field trial before the 1049 // Trying to instantiate a one-time randomized field trial before the
1020 // FieldTrialList is created should crash. 1050 // FieldTrialList is created should crash.
1021 EXPECT_DEATH(FieldTrialList::FactoryGetFieldTrial( 1051 EXPECT_DEATH(FieldTrialList::FactoryGetFieldTrial(
1022 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName, 1052 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName,
1023 base::FieldTrialList::kNoExpirationYear, 1, 1, 1053 base::FieldTrialList::kNoExpirationYear, 1, 1,
1024 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL), ""); 1054 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL), "");
1025 } 1055 }
1026 #endif 1056 #endif
1027 1057
1028 } // namespace base 1058 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698