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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 } | 22 } |
23 | 23 |
24 // Constants for testing associating command line flags with trial groups. | 24 // Constants for testing associating command line flags with trial groups. |
25 const char kFlagStudyName[] = "flag_test_trial"; | 25 const char kFlagStudyName[] = "flag_test_trial"; |
26 const char kFlagGroup1Name[] = "flag_group1"; | 26 const char kFlagGroup1Name[] = "flag_group1"; |
27 const char kFlagGroup2Name[] = "flag_group2"; | 27 const char kFlagGroup2Name[] = "flag_group2"; |
28 const char kNonFlagGroupName[] = "non_flag_group"; | 28 const char kNonFlagGroupName[] = "non_flag_group"; |
29 const char kForcingFlag1[] = "flag_test1"; | 29 const char kForcingFlag1[] = "flag_test1"; |
30 const char kForcingFlag2[] = "flag_test2"; | 30 const char kForcingFlag2[] = "flag_test2"; |
31 | 31 |
32 const VariationID kExperimentId = 123; | |
33 const VariationID kEmptyExperimentId = 0; | |
Alexei Svitkine (slow)
2013/11/15 19:26:00
EMPTY_ID is already defined in components/variatio
| |
34 | |
32 // Adds an experiment to |study| with the specified |name| and |probability|. | 35 // Adds an experiment to |study| with the specified |name| and |probability|. |
33 Study_Experiment* AddExperiment(const std::string& name, int probability, | 36 Study_Experiment* AddExperiment(const std::string& name, int probability, |
34 Study* study) { | 37 Study* study) { |
35 Study_Experiment* experiment = study->add_experiment(); | 38 Study_Experiment* experiment = study->add_experiment(); |
36 experiment->set_name(name); | 39 experiment->set_name(name); |
37 experiment->set_probability_weight(probability); | 40 experiment->set_probability_weight(probability); |
38 return experiment; | 41 return experiment; |
39 } | 42 } |
40 | 43 |
41 // Populates |study| with test data used for testing associating command line | 44 // Populates |study| with test data used for testing associating command line |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // Ensure that the maps are cleared between tests, since they are stored as | 86 // Ensure that the maps are cleared between tests, since they are stored as |
84 // process singletons. | 87 // process singletons. |
85 testing::ClearAllVariationIDs(); | 88 testing::ClearAllVariationIDs(); |
86 testing::ClearAllVariationParams(); | 89 testing::ClearAllVariationParams(); |
87 } | 90 } |
88 | 91 |
89 private: | 92 private: |
90 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest); | 93 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest); |
91 }; | 94 }; |
92 | 95 |
96 TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) { | |
97 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | |
98 | |
99 base::FieldTrialList field_trial_list(NULL); | |
100 | |
101 Study study = CreateStudyWithFlagGroups(100, 0, 0); | |
102 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId); | |
103 study.mutable_filter()->add_channel(Study_Channel_DEV); | |
104 study.mutable_filter()->add_channel(Study_Channel_CANARY); | |
105 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID); | |
106 | |
107 VariationsSeedProcessor().CreateTrialFromStudy( | |
108 ProcessedStudy(&study, 100, false)); | |
109 | |
110 EXPECT_EQ(kFlagGroup1Name, | |
111 base::FieldTrialList::FindFullName(kFlagStudyName)); | |
112 | |
113 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, | |
114 kFlagGroup1Name); | |
115 EXPECT_EQ(kExperimentId, id); | |
116 } | |
117 | |
118 TEST_F(VariationsSeedProcessorTest, AllowVariationIdWithForcingFlag) { | |
119 VariationsSeedProcessor seed_processor; | |
120 Study study = CreateStudyWithFlagGroups(100, 0, 0); | |
121 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study)); | |
122 | |
123 study.mutable_filter()->add_channel(Study_Channel_DEV); | |
124 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study)); | |
125 | |
126 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID); | |
127 EXPECT_TRUE(seed_processor.AllowVariationIdWithForcingFlag(study)); | |
128 | |
129 study.mutable_filter()->add_channel(Study_Channel_CANARY); | |
130 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_IOS); | |
131 EXPECT_TRUE(seed_processor.AllowVariationIdWithForcingFlag(study)); | |
132 | |
133 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS); | |
134 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study)); | |
135 } | |
136 | |
93 TEST_F(VariationsSeedProcessorTest, CheckStudyChannel) { | 137 TEST_F(VariationsSeedProcessorTest, CheckStudyChannel) { |
94 VariationsSeedProcessor seed_processor; | 138 VariationsSeedProcessor seed_processor; |
95 | 139 |
96 const Study_Channel channels[] = { | 140 const Study_Channel channels[] = { |
97 Study_Channel_CANARY, | 141 Study_Channel_CANARY, |
98 Study_Channel_DEV, | 142 Study_Channel_DEV, |
99 Study_Channel_BETA, | 143 Study_Channel_BETA, |
100 Study_Channel_STABLE, | 144 Study_Channel_STABLE, |
101 }; | 145 }; |
102 bool channel_added[arraysize(channels)] = { 0 }; | 146 bool channel_added[arraysize(channels)] = { 0 }; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 seed, "en-CA", base::Time::Now(), base::Version("20.0.0.0"), | 461 seed, "en-CA", base::Time::Now(), base::Version("20.0.0.0"), |
418 Study_Channel_STABLE, Study_FormFactor_DESKTOP, &processed_studies); | 462 Study_Channel_STABLE, Study_FormFactor_DESKTOP, &processed_studies); |
419 | 463 |
420 // Check that only the first kTrial1Name study was kept. | 464 // Check that only the first kTrial1Name study was kept. |
421 ASSERT_EQ(2U, processed_studies.size()); | 465 ASSERT_EQ(2U, processed_studies.size()); |
422 EXPECT_EQ(kTrial1Name, processed_studies[0].study->name()); | 466 EXPECT_EQ(kTrial1Name, processed_studies[0].study->name()); |
423 EXPECT_EQ(kGroup1Name, processed_studies[0].study->experiment(0).name()); | 467 EXPECT_EQ(kGroup1Name, processed_studies[0].study->experiment(0).name()); |
424 EXPECT_EQ(kTrial3Name, processed_studies[1].study->name()); | 468 EXPECT_EQ(kTrial3Name, processed_studies[1].study->name()); |
425 } | 469 } |
426 | 470 |
471 TEST_F(VariationsSeedProcessorTest, ForbidForceGroupWithVariationId) { | |
472 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | |
473 | |
474 base::FieldTrialList field_trial_list(NULL); | |
475 | |
476 Study study = CreateStudyWithFlagGroups(100, 0, 0); | |
477 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId); | |
478 // Adding windows platform makes forcing_flag and variation Id incompatible. | |
479 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS); | |
480 | |
481 VariationsSeedProcessor().CreateTrialFromStudy( | |
482 ProcessedStudy(&study, 100, false)); | |
483 | |
484 EXPECT_EQ(kFlagGroup1Name, | |
485 base::FieldTrialList::FindFullName(kFlagStudyName)); | |
486 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, | |
487 kFlagGroup1Name); | |
488 EXPECT_EQ(kEmptyExperimentId, id); | |
489 } | |
490 | |
427 // Test that the group for kForcingFlag1 is forced. | 491 // Test that the group for kForcingFlag1 is forced. |
428 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { | 492 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { |
429 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 493 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
430 | 494 |
431 base::FieldTrialList field_trial_list(NULL); | 495 base::FieldTrialList field_trial_list(NULL); |
432 | 496 |
433 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 497 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
434 VariationsSeedProcessor().CreateTrialFromStudy( | 498 VariationsSeedProcessor().CreateTrialFromStudy( |
435 ProcessedStudy(&study, 100, false)); | 499 ProcessedStudy(&study, 100, false)); |
436 | 500 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); | 767 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); |
704 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); | 768 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); |
705 | 769 |
706 // Now, all studies should be active. | 770 // Now, all studies should be active. |
707 EXPECT_TRUE(IsFieldTrialActive("A")); | 771 EXPECT_TRUE(IsFieldTrialActive("A")); |
708 EXPECT_TRUE(IsFieldTrialActive("B")); | 772 EXPECT_TRUE(IsFieldTrialActive("B")); |
709 EXPECT_TRUE(IsFieldTrialActive("C")); | 773 EXPECT_TRUE(IsFieldTrialActive("C")); |
710 } | 774 } |
711 | 775 |
712 } // namespace chrome_variations | 776 } // namespace chrome_variations |
OLD | NEW |