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

Side by Side Diff: components/variations/variations_seed_processor_unittest.cc

Issue 71753004: Allow variation id with forcing flag for special setup & unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 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
« no previous file with comments | « components/variations/variations_seed_processor.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 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
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
32 // Adds an experiment to |study| with the specified |name| and |probability|. 34 // Adds an experiment to |study| with the specified |name| and |probability|.
33 Study_Experiment* AddExperiment(const std::string& name, int probability, 35 Study_Experiment* AddExperiment(const std::string& name, int probability,
34 Study* study) { 36 Study* study) {
35 Study_Experiment* experiment = study->add_experiment(); 37 Study_Experiment* experiment = study->add_experiment();
36 experiment->set_name(name); 38 experiment->set_name(name);
37 experiment->set_probability_weight(probability); 39 experiment->set_probability_weight(probability);
38 return experiment; 40 return experiment;
39 } 41 }
40 42
41 // Populates |study| with test data used for testing associating command line 43 // Populates |study| with test data used for testing associating command line
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Ensure that the maps are cleared between tests, since they are stored as 85 // Ensure that the maps are cleared between tests, since they are stored as
84 // process singletons. 86 // process singletons.
85 testing::ClearAllVariationIDs(); 87 testing::ClearAllVariationIDs();
86 testing::ClearAllVariationParams(); 88 testing::ClearAllVariationParams();
87 } 89 }
88 90
89 private: 91 private:
90 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest); 92 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest);
91 }; 93 };
92 94
95 TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) {
96 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
97
98 base::FieldTrialList field_trial_list(NULL);
99
100 Study study = CreateStudyWithFlagGroups(100, 0, 0);
101 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
102 study.mutable_filter()->add_channel(Study_Channel_DEV);
103 study.mutable_filter()->add_channel(Study_Channel_CANARY);
104 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID);
105
106 VariationsSeedProcessor().CreateTrialFromStudy(
107 ProcessedStudy(&study, 100, false));
108
109 EXPECT_EQ(kFlagGroup1Name,
110 base::FieldTrialList::FindFullName(kFlagStudyName));
111
112 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
113 kFlagGroup1Name);
114 EXPECT_EQ(kExperimentId, id);
115 }
116
117 TEST_F(VariationsSeedProcessorTest, AllowVariationIdWithForcingFlag) {
118 VariationsSeedProcessor seed_processor;
119 Study study = CreateStudyWithFlagGroups(100, 0, 0);
120 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study));
121
122 study.mutable_filter()->add_channel(Study_Channel_DEV);
123 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study));
124
125 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID);
126 EXPECT_TRUE(seed_processor.AllowVariationIdWithForcingFlag(study));
127
128 study.mutable_filter()->add_channel(Study_Channel_CANARY);
129 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_IOS);
130 EXPECT_TRUE(seed_processor.AllowVariationIdWithForcingFlag(study));
131
132 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS);
133 EXPECT_FALSE(seed_processor.AllowVariationIdWithForcingFlag(study));
134 }
135
93 TEST_F(VariationsSeedProcessorTest, CheckStudyChannel) { 136 TEST_F(VariationsSeedProcessorTest, CheckStudyChannel) {
94 VariationsSeedProcessor seed_processor; 137 VariationsSeedProcessor seed_processor;
95 138
96 const Study_Channel channels[] = { 139 const Study_Channel channels[] = {
97 Study_Channel_CANARY, 140 Study_Channel_CANARY,
98 Study_Channel_DEV, 141 Study_Channel_DEV,
99 Study_Channel_BETA, 142 Study_Channel_BETA,
100 Study_Channel_STABLE, 143 Study_Channel_STABLE,
101 }; 144 };
102 bool channel_added[arraysize(channels)] = { 0 }; 145 bool channel_added[arraysize(channels)] = { 0 };
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 seed, "en-CA", base::Time::Now(), base::Version("20.0.0.0"), 460 seed, "en-CA", base::Time::Now(), base::Version("20.0.0.0"),
418 Study_Channel_STABLE, Study_FormFactor_DESKTOP, &processed_studies); 461 Study_Channel_STABLE, Study_FormFactor_DESKTOP, &processed_studies);
419 462
420 // Check that only the first kTrial1Name study was kept. 463 // Check that only the first kTrial1Name study was kept.
421 ASSERT_EQ(2U, processed_studies.size()); 464 ASSERT_EQ(2U, processed_studies.size());
422 EXPECT_EQ(kTrial1Name, processed_studies[0].study->name()); 465 EXPECT_EQ(kTrial1Name, processed_studies[0].study->name());
423 EXPECT_EQ(kGroup1Name, processed_studies[0].study->experiment(0).name()); 466 EXPECT_EQ(kGroup1Name, processed_studies[0].study->experiment(0).name());
424 EXPECT_EQ(kTrial3Name, processed_studies[1].study->name()); 467 EXPECT_EQ(kTrial3Name, processed_studies[1].study->name());
425 } 468 }
426 469
470 TEST_F(VariationsSeedProcessorTest, ForbidForceGroupWithVariationId) {
471 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
472
473 base::FieldTrialList field_trial_list(NULL);
474
475 Study study = CreateStudyWithFlagGroups(100, 0, 0);
476 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
477 // Adding windows platform makes forcing_flag and variation Id incompatible.
478 study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS);
479
480 VariationsSeedProcessor().CreateTrialFromStudy(
481 ProcessedStudy(&study, 100, false));
482
483 EXPECT_EQ(kFlagGroup1Name,
484 base::FieldTrialList::FindFullName(kFlagStudyName));
485 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
486 kFlagGroup1Name);
487 EXPECT_EQ(EMPTY_ID, id);
488 }
489
427 // Test that the group for kForcingFlag1 is forced. 490 // Test that the group for kForcingFlag1 is forced.
428 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { 491 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) {
429 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); 492 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
430 493
431 base::FieldTrialList field_trial_list(NULL); 494 base::FieldTrialList field_trial_list(NULL);
432 495
433 Study study = CreateStudyWithFlagGroups(100, 0, 0); 496 Study study = CreateStudyWithFlagGroups(100, 0, 0);
434 VariationsSeedProcessor().CreateTrialFromStudy( 497 VariationsSeedProcessor().CreateTrialFromStudy(
435 ProcessedStudy(&study, 100, false)); 498 ProcessedStudy(&study, 100, false));
436 499
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); 766 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B"));
704 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); 767 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C"));
705 768
706 // Now, all studies should be active. 769 // Now, all studies should be active.
707 EXPECT_TRUE(IsFieldTrialActive("A")); 770 EXPECT_TRUE(IsFieldTrialActive("A"));
708 EXPECT_TRUE(IsFieldTrialActive("B")); 771 EXPECT_TRUE(IsFieldTrialActive("B"));
709 EXPECT_TRUE(IsFieldTrialActive("C")); 772 EXPECT_TRUE(IsFieldTrialActive("C"));
710 } 773 }
711 774
712 } // namespace chrome_variations 775 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « components/variations/variations_seed_processor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698