OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/variations/variations_seed_processor.h" | 5 #include "components/variations/variations_seed_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Converts |time| to Study proto format. | 33 // Converts |time| to Study proto format. |
34 int64_t TimeToProtoTime(const base::Time& time) { | 34 int64_t TimeToProtoTime(const base::Time& time) { |
35 return (time - base::Time::UnixEpoch()).InSeconds(); | 35 return (time - base::Time::UnixEpoch()).InSeconds(); |
36 } | 36 } |
37 | 37 |
38 // Constants for testing associating command line flags with trial groups. | 38 // Constants for testing associating command line flags with trial groups. |
39 const char kFlagStudyName[] = "flag_test_trial"; | 39 const char kFlagStudyName[] = "flag_test_trial"; |
40 const char kFlagGroup1Name[] = "flag_group1"; | 40 const char kFlagGroup1Name[] = "flag_group1"; |
41 const char kFlagGroup2Name[] = "flag_group2"; | 41 const char kFlagGroup2Name[] = "flag_group2"; |
42 const char kNonFlagGroupName[] = "non_flag_group"; | 42 const char kNonFlagGroupName[] = "non_flag_group"; |
| 43 const char kOtherGroupName[] = "other_group"; |
43 const char kForcingFlag1[] = "flag_test1"; | 44 const char kForcingFlag1[] = "flag_test1"; |
44 const char kForcingFlag2[] = "flag_test2"; | 45 const char kForcingFlag2[] = "flag_test2"; |
45 | 46 |
46 const VariationID kExperimentId = 123; | 47 const VariationID kExperimentId = 123; |
47 | 48 |
48 // Adds an experiment to |study| with the specified |name| and |probability|. | 49 // Adds an experiment to |study| with the specified |name| and |probability|. |
49 Study_Experiment* AddExperiment(const std::string& name, int probability, | 50 Study_Experiment* AddExperiment(const std::string& name, int probability, |
50 Study* study) { | 51 Study* study) { |
51 Study_Experiment* experiment = study->add_experiment(); | 52 Study_Experiment* experiment = study->add_experiment(); |
52 experiment->set_name(name); | 53 experiment->set_name(name); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 221 |
221 // The two flag groups are given high probability, which would normally make | 222 // The two flag groups are given high probability, which would normally make |
222 // them very likely to be chosen. They won't be chosen since flag groups are | 223 // them very likely to be chosen. They won't be chosen since flag groups are |
223 // never chosen when their flag isn't present. | 224 // never chosen when their flag isn't present. |
224 Study study = CreateStudyWithFlagGroups(1, 999, 999); | 225 Study study = CreateStudyWithFlagGroups(1, 999, 999); |
225 EXPECT_TRUE(CreateTrialFromStudy(study)); | 226 EXPECT_TRUE(CreateTrialFromStudy(study)); |
226 EXPECT_EQ(kNonFlagGroupName, | 227 EXPECT_EQ(kNonFlagGroupName, |
227 base::FieldTrialList::FindFullName(kFlagStudyName)); | 228 base::FieldTrialList::FindFullName(kFlagStudyName)); |
228 } | 229 } |
229 | 230 |
| 231 TEST_F(VariationsSeedProcessorTest, CreateTrialForRegisteredGroup) { |
| 232 base::FieldTrialList field_trial_list(nullptr); |
| 233 |
| 234 base::FieldTrialList::CreateFieldTrial(kFlagStudyName, kOtherGroupName); |
| 235 |
| 236 // Create an arbitrary study that does not have group named |kOtherGroupName|. |
| 237 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 238 // Creating the trial should not crash. |
| 239 EXPECT_TRUE(CreateTrialFromStudy(study)); |
| 240 // And the previous group should still be selected. |
| 241 EXPECT_EQ(kOtherGroupName, |
| 242 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 243 } |
| 244 |
230 TEST_F(VariationsSeedProcessorTest, | 245 TEST_F(VariationsSeedProcessorTest, |
231 NonExpiredStudyPrioritizedOverExpiredStudy) { | 246 NonExpiredStudyPrioritizedOverExpiredStudy) { |
232 VariationsSeedProcessor seed_processor; | 247 VariationsSeedProcessor seed_processor; |
233 | 248 |
234 const std::string kTrialName = "A"; | 249 const std::string kTrialName = "A"; |
235 const std::string kGroup1Name = "Group1"; | 250 const std::string kGroup1Name = "Group1"; |
236 | 251 |
237 VariationsSeed seed; | 252 VariationsSeed seed; |
238 Study* study1 = seed.add_study(); | 253 Study* study1 = seed.add_study(); |
239 study1->set_name(kTrialName); | 254 study1->set_name(kTrialName); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Since no experiment in study1 sends experiment IDs, it will use the high | 887 // Since no experiment in study1 sends experiment IDs, it will use the high |
873 // entropy provider, which selects the non-default group. | 888 // entropy provider, which selects the non-default group. |
874 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); | 889 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); |
875 | 890 |
876 // Since an experiment in study2 has google_web_experiment_id set, it will use | 891 // Since an experiment in study2 has google_web_experiment_id set, it will use |
877 // the low entropy provider, which selects the default group. | 892 // the low entropy provider, which selects the default group. |
878 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); | 893 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); |
879 } | 894 } |
880 | 895 |
881 } // namespace variations | 896 } // namespace variations |
OLD | NEW |