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 EXPECT_EQ(std::string(), processed_study.single_feature_name()); | |
rkaplow
2016/03/17 15:08:48
maybe note what this is testing (multiple features
Alexei Svitkine (slow)
2016/03/17 15:24:59
Done.
| |
388 | |
389 exp1->clear_feature_association(); | |
390 exp1->mutable_feature_association()->add_enable_feature(kFeature1Name); | |
391 exp2->mutable_feature_association()->add_enable_feature(kFeature1Name); | |
392 exp3->mutable_feature_association()->add_disable_feature(kFeature1Name); | |
393 EXPECT_TRUE(processed_study.Init(&study, false)); | |
394 EXPECT_EQ(kFeature1Name, processed_study.single_feature_name()); | |
395 | |
396 // Setting a different feature name on exp2 should cause |single_feature_name| | |
397 // to be not set. | |
398 exp2->mutable_feature_association()->set_enable_feature(0, kFeature2Name); | |
399 EXPECT_TRUE(processed_study.Init(&study, false)); | |
400 EXPECT_EQ(std::string(), processed_study.single_feature_name()); | |
401 } | |
402 | |
362 TEST_F(VariationsSeedProcessorTest, ProcessedStudyAllAssignmentsToOneGroup) { | 403 TEST_F(VariationsSeedProcessorTest, ProcessedStudyAllAssignmentsToOneGroup) { |
363 Study study; | 404 Study study; |
364 study.set_default_experiment_name("def"); | 405 study.set_default_experiment_name("def"); |
365 AddExperiment("def", 100, &study); | 406 AddExperiment("def", 100, &study); |
366 | 407 |
367 ProcessedStudy processed_study; | 408 ProcessedStudy processed_study; |
368 EXPECT_TRUE(processed_study.Init(&study, false)); | 409 EXPECT_TRUE(processed_study.Init(&study, false)); |
369 EXPECT_TRUE(processed_study.all_assignments_to_one_group()); | 410 EXPECT_TRUE(processed_study.all_assignments_to_one_group()); |
370 | 411 |
371 AddExperiment("abc", 0, &study); | 412 AddExperiment("abc", 0, &study); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 const char* disable_features_command_line; | 647 const char* disable_features_command_line; |
607 OneHundredPercentGroup one_hundred_percent_group; | 648 OneHundredPercentGroup one_hundred_percent_group; |
608 | 649 |
609 const char* expected_group; | 650 const char* expected_group; |
610 bool expected_feature_state; | 651 bool expected_feature_state; |
611 bool expected_trial_activated; | 652 bool expected_trial_activated; |
612 } test_cases[] = { | 653 } test_cases[] = { |
613 // Check what happens without and command-line forcing flags - that the | 654 // Check what happens without and command-line forcing flags - that the |
614 // |one_hundred_percent_group| gets correctly selected and does the right | 655 // |one_hundred_percent_group| gets correctly selected and does the right |
615 // thing w.r.t. to affecting the feature / activating the trial. | 656 // thing w.r.t. to affecting the feature / activating the trial. |
616 {kFeatureOffByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, false, | 657 {kFeatureOffByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, false, true}, |
617 false}, | |
618 {kFeatureOffByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, | 658 {kFeatureOffByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, |
619 {kFeatureOffByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, | 659 {kFeatureOffByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, |
620 true}, | 660 true}, |
621 | 661 |
622 // Do the same as above, but for kFeatureOnByDefault feature. | 662 // Do the same as above, but for kFeatureOnByDefault feature. |
623 {kFeatureOnByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, true, false}, | 663 {kFeatureOnByDefault, "", "", DEFAULT_GROUP, kDefaultGroup, true, true}, |
624 {kFeatureOnByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, | 664 {kFeatureOnByDefault, "", "", ENABLE_GROUP, kEnabledGroup, true, true}, |
625 {kFeatureOnByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, true}, | 665 {kFeatureOnByDefault, "", "", DISABLE_GROUP, kDisabledGroup, false, true}, |
626 | 666 |
627 // Test forcing each feature on and off through the command-line and that | 667 // Test forcing each feature on and off through the command-line and that |
628 // the correct associated experiment gets chosen. | 668 // the correct associated experiment gets chosen. |
629 {kFeatureOffByDefault, kFeatureOffByDefault.name, "", DEFAULT_GROUP, | 669 {kFeatureOffByDefault, kFeatureOffByDefault.name, "", DEFAULT_GROUP, |
630 kForcedOnGroup, true, true}, | 670 kForcedOnGroup, true, true}, |
631 {kFeatureOffByDefault, "", kFeatureOffByDefault.name, DEFAULT_GROUP, | 671 {kFeatureOffByDefault, "", kFeatureOffByDefault.name, DEFAULT_GROUP, |
632 kForcedOffGroup, false, true}, | 672 kForcedOffGroup, false, true}, |
633 {kFeatureOnByDefault, kFeatureOnByDefault.name, "", DEFAULT_GROUP, | 673 {kFeatureOnByDefault, kFeatureOnByDefault.name, "", DEFAULT_GROUP, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 // depending on the expected values. | 742 // depending on the expected values. |
703 EXPECT_FALSE(base::FieldTrialList::IsTrialActive(study.name())); | 743 EXPECT_FALSE(base::FieldTrialList::IsTrialActive(study.name())); |
704 EXPECT_EQ(test_case.expected_feature_state, | 744 EXPECT_EQ(test_case.expected_feature_state, |
705 base::FeatureList::IsEnabled(test_case.feature)); | 745 base::FeatureList::IsEnabled(test_case.feature)); |
706 EXPECT_EQ(test_case.expected_trial_activated, | 746 EXPECT_EQ(test_case.expected_trial_activated, |
707 base::FieldTrialList::IsTrialActive(study.name())); | 747 base::FieldTrialList::IsTrialActive(study.name())); |
708 } | 748 } |
709 } | 749 } |
710 | 750 |
711 } // namespace variations | 751 } // namespace variations |
OLD | NEW |