| Index: components/variations/variations_seed_processor_unittest.cc
|
| diff --git a/components/variations/variations_seed_processor_unittest.cc b/components/variations/variations_seed_processor_unittest.cc
|
| index 7b86def9eb3566f808012193305866d4e1a15d7e..326212479a51bded2ff8efe90b6d1d820cf7983e 100644
|
| --- a/components/variations/variations_seed_processor_unittest.cc
|
| +++ b/components/variations/variations_seed_processor_unittest.cc
|
| @@ -29,6 +29,8 @@ const char kNonFlagGroupName[] = "non_flag_group";
|
| const char kForcingFlag1[] = "flag_test1";
|
| const char kForcingFlag2[] = "flag_test2";
|
|
|
| +const VariationID kExperimentId = 123;
|
| +
|
| // Adds an experiment to |study| with the specified |name| and |probability|.
|
| Study_Experiment* AddExperiment(const std::string& name, int probability,
|
| Study* study) {
|
| @@ -90,6 +92,50 @@ class VariationsSeedProcessorTest : public ::testing::Test {
|
| DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest);
|
| };
|
|
|
| +TEST_F(VariationsSeedProcessorTest,
|
| + AllowForceGroupAndVariationIdWithoutCommandLine) {
|
| + base::FieldTrialList field_trial_list(NULL);
|
| +
|
| + Study study = CreateStudyWithFlagGroups(100, 0, 0);
|
| + study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
|
| + study.mutable_filter()->add_channel(Study_Channel_DEV);
|
| + study.mutable_filter()->add_channel(Study_Channel_CANARY);
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID);
|
| +
|
| + VariationsSeedProcessor().CreateTrialFromStudy(
|
| + ProcessedStudy(&study, 100, false));
|
| +
|
| + EXPECT_EQ(kNonFlagGroupName,
|
| + base::FieldTrialList::FindFullName(kFlagStudyName));
|
| +
|
| + VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
|
| + kFlagGroup1Name);
|
| + EXPECT_EQ(kExperimentId, id);
|
| +}
|
| +
|
| +TEST_F(VariationsSeedProcessorTest,
|
| + AllowForceGroupAndVariationIdWithCommandLine) {
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
|
| +
|
| + base::FieldTrialList field_trial_list(NULL);
|
| +
|
| + Study study = CreateStudyWithFlagGroups(100, 0, 0);
|
| + study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
|
| + study.mutable_filter()->add_channel(Study_Channel_DEV);
|
| + study.mutable_filter()->add_channel(Study_Channel_CANARY);
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID);
|
| +
|
| + VariationsSeedProcessor().CreateTrialFromStudy(
|
| + ProcessedStudy(&study, 100, false));
|
| +
|
| + EXPECT_EQ(kFlagGroup1Name,
|
| + base::FieldTrialList::FindFullName(kFlagStudyName));
|
| +
|
| + VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
|
| + kFlagGroup1Name);
|
| + EXPECT_EQ(kExperimentId, id);
|
| +}
|
| +
|
| TEST_F(VariationsSeedProcessorTest, CheckStudyChannel) {
|
| VariationsSeedProcessor seed_processor;
|
|
|
| @@ -424,6 +470,46 @@ TEST_F(VariationsSeedProcessorTest, FilterAndValidateStudies) {
|
| EXPECT_EQ(kTrial3Name, processed_studies[1].study->name());
|
| }
|
|
|
| +TEST_F(VariationsSeedProcessorTest,
|
| + ForbidForceGroupWithVariationIdWithoutCommandLine) {
|
| + base::FieldTrialList field_trial_list(NULL);
|
| +
|
| + Study study = CreateStudyWithFlagGroups(100, 0, 0);
|
| + study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
|
| + // Add windows platform makes forcing_flag and variation Id incompatible.
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS);
|
| +
|
| + VariationsSeedProcessor().CreateTrialFromStudy(
|
| + ProcessedStudy(&study, 100, false));
|
| +
|
| + EXPECT_EQ(kNonFlagGroupName,
|
| + base::FieldTrialList::FindFullName(kFlagStudyName));
|
| + VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
|
| + kFlagGroup1Name);
|
| + EXPECT_EQ(0, id);
|
| +}
|
| +
|
| +TEST_F(VariationsSeedProcessorTest,
|
| + ForbidForceGroupWithVariationIdWithCommandLine) {
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
|
| +
|
| + base::FieldTrialList field_trial_list(NULL);
|
| +
|
| + Study study = CreateStudyWithFlagGroups(100, 0, 0);
|
| + study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId);
|
| + // Add windows platform makes forcing_flag and variation Id incompatible.
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS);
|
| +
|
| + VariationsSeedProcessor().CreateTrialFromStudy(
|
| + ProcessedStudy(&study, 100, false));
|
| +
|
| + EXPECT_EQ(kFlagGroup1Name,
|
| + base::FieldTrialList::FindFullName(kFlagStudyName));
|
| + VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName,
|
| + kFlagGroup1Name);
|
| + EXPECT_EQ(0, id);
|
| +}
|
| +
|
| // Test that the group for kForcingFlag1 is forced.
|
| TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) {
|
| CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
|
| @@ -553,6 +639,34 @@ TEST_F(VariationsSeedProcessorTest,
|
| }
|
| }
|
|
|
| +TEST_F(VariationsSeedProcessorTest, TestAllowVariationIdWithForcingFlag) {
|
| + Study study = CreateStudyWithFlagGroups(100, 0, 0);
|
| + bool allowBoth = VariationsSeedProcessor().
|
| + AllowVariationIdWithForcingFlag(study);
|
| + EXPECT_FALSE(allowBoth);
|
| +
|
| + study.mutable_filter()->add_channel(Study_Channel_DEV);
|
| + allowBoth = VariationsSeedProcessor().
|
| + AllowVariationIdWithForcingFlag(study);
|
| + EXPECT_FALSE(allowBoth);
|
| +
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_ANDROID);
|
| + allowBoth = VariationsSeedProcessor().
|
| + AllowVariationIdWithForcingFlag(study);
|
| + EXPECT_TRUE(allowBoth);
|
| +
|
| + study.mutable_filter()->add_channel(Study_Channel_CANARY);
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_IOS);
|
| + allowBoth = VariationsSeedProcessor().
|
| + AllowVariationIdWithForcingFlag(study);
|
| + EXPECT_TRUE(allowBoth);
|
| +
|
| + study.mutable_filter()->add_platform(Study_Platform_PLATFORM_WINDOWS);
|
| + allowBoth = VariationsSeedProcessor().
|
| + AllowVariationIdWithForcingFlag(study);
|
| + EXPECT_FALSE(allowBoth);
|
| +}
|
| +
|
| TEST_F(VariationsSeedProcessorTest, ValidateStudy) {
|
| VariationsSeedProcessor seed_processor;
|
|
|
|
|