| 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 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_FALSE(processed_study.Init(&study, false)); | 352 EXPECT_FALSE(processed_study.Init(&study, false)); |
| 353 | 353 |
| 354 default_group->set_name("def"); | 354 default_group->set_name("def"); |
| 355 EXPECT_TRUE(processed_study.Init(&study, false)); | 355 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 356 Study_Experiment* repeated_group = study.add_experiment(); | 356 Study_Experiment* repeated_group = study.add_experiment(); |
| 357 repeated_group->set_name("abc"); | 357 repeated_group->set_name("abc"); |
| 358 repeated_group->set_probability_weight(1); | 358 repeated_group->set_probability_weight(1); |
| 359 EXPECT_FALSE(processed_study.Init(&study, false)); | 359 EXPECT_FALSE(processed_study.Init(&study, false)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 TEST_F(VariationsSeedProcessorTest, ValidateStudySingleFeature) { |
| 363 Study study; |
| 364 study.set_default_experiment_name("def"); |
| 365 Study_Experiment* exp1 = AddExperiment("exp1", 100, &study); |
| 366 Study_Experiment* exp2 = AddExperiment("exp2", 100, &study); |
| 367 Study_Experiment* exp3 = AddExperiment("exp3", 100, &study); |
| 368 AddExperiment("def", 100, &study); |
| 369 |
| 370 ProcessedStudy processed_study; |
| 371 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 372 EXPECT_EQ(400, processed_study.total_probability()); |
| 373 |
| 374 EXPECT_EQ(std::string(), processed_study.single_feature_name()); |
| 375 |
| 376 const char kFeature1Name[] = "Feature1"; |
| 377 const char kFeature2Name[] = "Feature2"; |
| 378 |
| 379 exp1->mutable_feature_association()->add_enable_feature(kFeature1Name); |
| 380 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 381 EXPECT_EQ(kFeature1Name, processed_study.single_feature_name()); |
| 382 |
| 383 exp1->clear_feature_association(); |
| 384 exp1->mutable_feature_association()->add_enable_feature(kFeature1Name); |
| 385 exp1->mutable_feature_association()->add_enable_feature(kFeature2Name); |
| 386 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 387 // Since there's multiple different features, |single_feature_name| should be |
| 388 // unset. |
| 389 EXPECT_EQ(std::string(), processed_study.single_feature_name()); |
| 390 |
| 391 exp1->clear_feature_association(); |
| 392 exp1->mutable_feature_association()->add_enable_feature(kFeature1Name); |
| 393 exp2->mutable_feature_association()->add_enable_feature(kFeature1Name); |
| 394 exp3->mutable_feature_association()->add_disable_feature(kFeature1Name); |
| 395 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 396 EXPECT_EQ(kFeature1Name, processed_study.single_feature_name()); |
| 397 |
| 398 // Setting a different feature name on exp2 should cause |single_feature_name| |
| 399 // to be not set. |
| 400 exp2->mutable_feature_association()->set_enable_feature(0, kFeature2Name); |
| 401 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 402 EXPECT_EQ(std::string(), processed_study.single_feature_name()); |
| 403 } |
| 404 |
| 362 TEST_F(VariationsSeedProcessorTest, ProcessedStudyAllAssignmentsToOneGroup) { | 405 TEST_F(VariationsSeedProcessorTest, ProcessedStudyAllAssignmentsToOneGroup) { |
| 363 Study study; | 406 Study study; |
| 364 study.set_default_experiment_name("def"); | 407 study.set_default_experiment_name("def"); |
| 365 AddExperiment("def", 100, &study); | 408 AddExperiment("def", 100, &study); |
| 366 | 409 |
| 367 ProcessedStudy processed_study; | 410 ProcessedStudy processed_study; |
| 368 EXPECT_TRUE(processed_study.Init(&study, false)); | 411 EXPECT_TRUE(processed_study.Init(&study, false)); |
| 369 EXPECT_TRUE(processed_study.all_assignments_to_one_group()); | 412 EXPECT_TRUE(processed_study.all_assignments_to_one_group()); |
| 370 | 413 |
| 371 AddExperiment("abc", 0, &study); | 414 AddExperiment("abc", 0, &study); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 const char* disable_features_command_line; | 649 const char* disable_features_command_line; |
| 607 OneHundredPercentGroup one_hundred_percent_group; | 650 OneHundredPercentGroup one_hundred_percent_group; |
| 608 | 651 |
| 609 const char* expected_group; | 652 const char* expected_group; |
| 610 bool expected_feature_state; | 653 bool expected_feature_state; |
| 611 bool expected_trial_activated; | 654 bool expected_trial_activated; |
| 612 } test_cases[] = { | 655 } test_cases[] = { |
| 613 // Check what happens without and command-line forcing flags - that the | 656 // Check what happens without and command-line forcing flags - that the |
| 614 // |one_hundred_percent_group| gets correctly selected and does the right | 657 // |one_hundred_percent_group| gets correctly selected and does the right |
| 615 // thing w.r.t. to affecting the feature / activating the trial. | 658 // thing w.r.t. to affecting the feature / activating the trial. |
| 616 {kFeatureOffByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, false, | 659 {kFeatureOffByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, false, true}, |
| 617 false}, | |
| 618 {kFeatureOffByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, | 660 {kFeatureOffByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, |
| 619 {kFeatureOffByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, | 661 {kFeatureOffByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, |
| 620 true}, | 662 true}, |
| 621 | 663 |
| 622 // Do the same as above, but for kFeatureOnByDefault feature. | 664 // Do the same as above, but for kFeatureOnByDefault feature. |
| 623 {kFeatureOnByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, true, false}, | 665 {kFeatureOnByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, true, true}, |
| 624 {kFeatureOnByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, | 666 {kFeatureOnByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, |
| 625 {kFeatureOnByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, true}, | 667 {kFeatureOnByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, true}, |
| 626 | 668 |
| 627 // Test forcing each feature on and off through the command-line and that | 669 // Test forcing each feature on and off through the command-line and that |
| 628 // the correct associated experiment gets chosen. | 670 // the correct associated experiment gets chosen. |
| 629 {kFeatureOffByDefault, kFeatureOffByDefault.name, "", DEFAULT_GROUP, | 671 {kFeatureOffByDefault, kFeatureOffByDefault.name, "", DEFAULT_GROUP, |
| 630 kForcedOnGroup, true, true}, | 672 kForcedOnGroup, true, true}, |
| 631 {kFeatureOffByDefault, "", kFeatureOffByDefault.name, DEFAULT_GROUP, | 673 {kFeatureOffByDefault, "", kFeatureOffByDefault.name, DEFAULT_GROUP, |
| 632 kForcedOffGroup, false, true}, | 674 kForcedOffGroup, false, true}, |
| 633 {kFeatureOnByDefault, kFeatureOnByDefault.name, "", DEFAULT_GROUP, | 675 {kFeatureOnByDefault, kFeatureOnByDefault.name, "", DEFAULT_GROUP, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 // depending on the expected values. | 744 // depending on the expected values. |
| 703 EXPECT_FALSE(base::FieldTrialList::IsTrialActive(study.name())); | 745 EXPECT_FALSE(base::FieldTrialList::IsTrialActive(study.name())); |
| 704 EXPECT_EQ(test_case.expected_feature_state, | 746 EXPECT_EQ(test_case.expected_feature_state, |
| 705 base::FeatureList::IsEnabled(test_case.feature)); | 747 base::FeatureList::IsEnabled(test_case.feature)); |
| 706 EXPECT_EQ(test_case.expected_trial_activated, | 748 EXPECT_EQ(test_case.expected_trial_activated, |
| 707 base::FieldTrialList::IsTrialActive(study.name())); | 749 base::FieldTrialList::IsTrialActive(study.name())); |
| 708 } | 750 } |
| 709 } | 751 } |
| 710 | 752 |
| 711 } // namespace variations | 753 } // namespace variations |
| OLD | NEW |