| 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 <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 protected: | 131 protected: |
| 132 TestOverrideStringCallback override_callback_; | 132 TestOverrideStringCallback override_callback_; |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest); | 135 DISALLOW_COPY_AND_ASSIGN(VariationsSeedProcessorTest); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) { | 138 TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) { |
| 139 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 139 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 140 | 140 |
| 141 base::FieldTrialList field_trial_list(NULL); | 141 base::FieldTrialList field_trial_list(NULL); |
| 142 | 142 |
| 143 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 143 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 144 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId); | 144 study.mutable_experiment(1)->set_google_web_experiment_id(kExperimentId); |
| 145 | 145 |
| 146 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 146 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 147 EXPECT_EQ(kFlagGroup1Name, | 147 EXPECT_EQ(kFlagGroup1Name, |
| 148 base::FieldTrialList::FindFullName(kFlagStudyName)); | 148 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 149 | 149 |
| 150 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, | 150 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, |
| 151 kFlagGroup1Name); | 151 kFlagGroup1Name); |
| 152 EXPECT_EQ(kExperimentId, id); | 152 EXPECT_EQ(kExperimentId, id); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Test that the group for kForcingFlag1 is forced. | 155 // Test that the group for kForcingFlag1 is forced. |
| 156 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { | 156 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { |
| 157 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 157 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 158 | 158 |
| 159 base::FieldTrialList field_trial_list(NULL); | 159 base::FieldTrialList field_trial_list(NULL); |
| 160 | 160 |
| 161 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 161 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 162 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 162 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 163 EXPECT_EQ(kFlagGroup1Name, | 163 EXPECT_EQ(kFlagGroup1Name, |
| 164 base::FieldTrialList::FindFullName(kFlagStudyName)); | 164 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Test that the group for kForcingFlag2 is forced. | 167 // Test that the group for kForcingFlag2 is forced. |
| 168 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag2) { | 168 TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag2) { |
| 169 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag2); | 169 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag2); |
| 170 | 170 |
| 171 base::FieldTrialList field_trial_list(NULL); | 171 base::FieldTrialList field_trial_list(NULL); |
| 172 | 172 |
| 173 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 173 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 174 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 174 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 175 EXPECT_EQ(kFlagGroup2Name, | 175 EXPECT_EQ(kFlagGroup2Name, |
| 176 base::FieldTrialList::FindFullName(kFlagStudyName)); | 176 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST_F(VariationsSeedProcessorTest, ForceGroup_ChooseFirstGroupWithFlag) { | 179 TEST_F(VariationsSeedProcessorTest, ForceGroup_ChooseFirstGroupWithFlag) { |
| 180 // Add the flag to the command line arguments so the flag group is forced. | 180 // Add the flag to the command line arguments so the flag group is forced. |
| 181 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 181 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 182 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag2); | 182 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag2); |
| 183 | 183 |
| 184 base::FieldTrialList field_trial_list(NULL); | 184 base::FieldTrialList field_trial_list(NULL); |
| 185 | 185 |
| 186 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 186 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 187 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 187 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 188 EXPECT_EQ(kFlagGroup1Name, | 188 EXPECT_EQ(kFlagGroup1Name, |
| 189 base::FieldTrialList::FindFullName(kFlagStudyName)); | 189 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(VariationsSeedProcessorTest, ForceGroup_DontChooseGroupWithFlag) { | 192 TEST_F(VariationsSeedProcessorTest, ForceGroup_DontChooseGroupWithFlag) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 TEST_F(VariationsSeedProcessorTest, OverrideUIStringsWithForcingFlag) { | 296 TEST_F(VariationsSeedProcessorTest, OverrideUIStringsWithForcingFlag) { |
| 297 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 297 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 298 ASSERT_EQ(kForcingFlag1, study.experiment(1).forcing_flag()); | 298 ASSERT_EQ(kForcingFlag1, study.experiment(1).forcing_flag()); |
| 299 | 299 |
| 300 study.set_activation_type(Study_ActivationType_ACTIVATION_AUTO); | 300 study.set_activation_type(Study_ActivationType_ACTIVATION_AUTO); |
| 301 Study_Experiment_OverrideUIString* override = | 301 Study_Experiment_OverrideUIString* override = |
| 302 study.mutable_experiment(1)->add_override_ui_string(); | 302 study.mutable_experiment(1)->add_override_ui_string(); |
| 303 override->set_name_hash(1234); | 303 override->set_name_hash(1234); |
| 304 override->set_value("test"); | 304 override->set_value("test"); |
| 305 | 305 |
| 306 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 306 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 307 base::FieldTrialList field_trial_list(NULL); | 307 base::FieldTrialList field_trial_list(NULL); |
| 308 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 308 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 309 EXPECT_EQ(kFlagGroup1Name, base::FieldTrialList::FindFullName(study.name())); | 309 EXPECT_EQ(kFlagGroup1Name, base::FieldTrialList::FindFullName(study.name())); |
| 310 | 310 |
| 311 const TestOverrideStringCallback::OverrideMap& overrides = | 311 const TestOverrideStringCallback::OverrideMap& overrides = |
| 312 override_callback_.overrides(); | 312 override_callback_.overrides(); |
| 313 EXPECT_EQ(1u, overrides.size()); | 313 EXPECT_EQ(1u, overrides.size()); |
| 314 TestOverrideStringCallback::OverrideMap::const_iterator it = | 314 TestOverrideStringCallback::OverrideMap::const_iterator it = |
| 315 overrides.find(1234); | 315 overrides.find(1234); |
| 316 EXPECT_EQ(base::ASCIIToUTF16("test"), it->second); | 316 EXPECT_EQ(base::ASCIIToUTF16("test"), it->second); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 EXPECT_EQ(std::string(), GetVariationParamValue("Study2", "x")); | 384 EXPECT_EQ(std::string(), GetVariationParamValue("Study2", "x")); |
| 385 } | 385 } |
| 386 | 386 |
| 387 TEST_F(VariationsSeedProcessorTest, VariationParamsWithForcingFlag) { | 387 TEST_F(VariationsSeedProcessorTest, VariationParamsWithForcingFlag) { |
| 388 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 388 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 389 ASSERT_EQ(kForcingFlag1, study.experiment(1).forcing_flag()); | 389 ASSERT_EQ(kForcingFlag1, study.experiment(1).forcing_flag()); |
| 390 Study_Experiment_Param* param = study.mutable_experiment(1)->add_param(); | 390 Study_Experiment_Param* param = study.mutable_experiment(1)->add_param(); |
| 391 param->set_name("x"); | 391 param->set_name("x"); |
| 392 param->set_value("y"); | 392 param->set_value("y"); |
| 393 | 393 |
| 394 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 394 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 395 base::FieldTrialList field_trial_list(NULL); | 395 base::FieldTrialList field_trial_list(NULL); |
| 396 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 396 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 397 EXPECT_EQ(kFlagGroup1Name, base::FieldTrialList::FindFullName(study.name())); | 397 EXPECT_EQ(kFlagGroup1Name, base::FieldTrialList::FindFullName(study.name())); |
| 398 EXPECT_EQ("y", GetVariationParamValue(study.name(), "x")); | 398 EXPECT_EQ("y", GetVariationParamValue(study.name(), "x")); |
| 399 } | 399 } |
| 400 | 400 |
| 401 TEST_F(VariationsSeedProcessorTest, StartsActive) { | 401 TEST_F(VariationsSeedProcessorTest, StartsActive) { |
| 402 base::FieldTrialList field_trial_list(NULL); | 402 base::FieldTrialList field_trial_list(NULL); |
| 403 | 403 |
| 404 VariationsSeed seed; | 404 VariationsSeed seed; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); | 442 EXPECT_EQ("BB", base::FieldTrialList::FindFullName("B")); |
| 443 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); | 443 EXPECT_EQ("CC", base::FieldTrialList::FindFullName("C")); |
| 444 | 444 |
| 445 // Now, all studies should be active. | 445 // Now, all studies should be active. |
| 446 EXPECT_TRUE(IsFieldTrialActive("A")); | 446 EXPECT_TRUE(IsFieldTrialActive("A")); |
| 447 EXPECT_TRUE(IsFieldTrialActive("B")); | 447 EXPECT_TRUE(IsFieldTrialActive("B")); |
| 448 EXPECT_TRUE(IsFieldTrialActive("C")); | 448 EXPECT_TRUE(IsFieldTrialActive("C")); |
| 449 } | 449 } |
| 450 | 450 |
| 451 TEST_F(VariationsSeedProcessorTest, StartsActiveWithFlag) { | 451 TEST_F(VariationsSeedProcessorTest, StartsActiveWithFlag) { |
| 452 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 452 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 453 | 453 |
| 454 base::FieldTrialList field_trial_list(NULL); | 454 base::FieldTrialList field_trial_list(NULL); |
| 455 | 455 |
| 456 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 456 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 457 study.set_activation_type(Study_ActivationType_ACTIVATION_AUTO); | 457 study.set_activation_type(Study_ActivationType_ACTIVATION_AUTO); |
| 458 | 458 |
| 459 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 459 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 460 EXPECT_TRUE(IsFieldTrialActive(kFlagStudyName)); | 460 EXPECT_TRUE(IsFieldTrialActive(kFlagStudyName)); |
| 461 | 461 |
| 462 EXPECT_EQ(kFlagGroup1Name, | 462 EXPECT_EQ(kFlagGroup1Name, |
| 463 base::FieldTrialList::FindFullName(kFlagStudyName)); | 463 base::FieldTrialList::FindFullName(kFlagStudyName)); |
| 464 } | 464 } |
| 465 | 465 |
| 466 TEST_F(VariationsSeedProcessorTest, ForcingFlagAlreadyForced) { | 466 TEST_F(VariationsSeedProcessorTest, ForcingFlagAlreadyForced) { |
| 467 Study study = CreateStudyWithFlagGroups(100, 0, 0); | 467 Study study = CreateStudyWithFlagGroups(100, 0, 0); |
| 468 ASSERT_EQ(kNonFlagGroupName, study.experiment(0).name()); | 468 ASSERT_EQ(kNonFlagGroupName, study.experiment(0).name()); |
| 469 Study_Experiment_Param* param = study.mutable_experiment(0)->add_param(); | 469 Study_Experiment_Param* param = study.mutable_experiment(0)->add_param(); |
| 470 param->set_name("x"); | 470 param->set_name("x"); |
| 471 param->set_value("y"); | 471 param->set_value("y"); |
| 472 study.mutable_experiment(0)->set_google_web_experiment_id(kExperimentId); | 472 study.mutable_experiment(0)->set_google_web_experiment_id(kExperimentId); |
| 473 | 473 |
| 474 base::FieldTrialList field_trial_list(NULL); | 474 base::FieldTrialList field_trial_list(NULL); |
| 475 base::FieldTrialList::CreateFieldTrial(kFlagStudyName, kNonFlagGroupName); | 475 base::FieldTrialList::CreateFieldTrial(kFlagStudyName, kNonFlagGroupName); |
| 476 | 476 |
| 477 CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); | 477 base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); |
| 478 EXPECT_TRUE(CreateTrialFromStudy(&study)); | 478 EXPECT_TRUE(CreateTrialFromStudy(&study)); |
| 479 // The previously forced experiment should still hold. | 479 // The previously forced experiment should still hold. |
| 480 EXPECT_EQ(kNonFlagGroupName, | 480 EXPECT_EQ(kNonFlagGroupName, |
| 481 base::FieldTrialList::FindFullName(study.name())); | 481 base::FieldTrialList::FindFullName(study.name())); |
| 482 | 482 |
| 483 // Check that params and experiment ids correspond. | 483 // Check that params and experiment ids correspond. |
| 484 EXPECT_EQ("y", GetVariationParamValue(study.name(), "x")); | 484 EXPECT_EQ("y", GetVariationParamValue(study.name(), "x")); |
| 485 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, | 485 VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, kFlagStudyName, |
| 486 kNonFlagGroupName); | 486 kNonFlagGroupName); |
| 487 EXPECT_EQ(kExperimentId, id); | 487 EXPECT_EQ(kExperimentId, id); |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace variations | 490 } // namespace variations |
| OLD | NEW |