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

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

Issue 2919143002: Fix variations crashes when the chosen trial group is not in study. (Closed)
Patch Set: Created 3 years, 6 months 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 856
857 EXPECT_TRUE(CreateTrialFromStudy(study)); 857 EXPECT_TRUE(CreateTrialFromStudy(study));
858 858
859 base::FieldTrial* trial = base::FieldTrialList::Find("Study1"); 859 base::FieldTrial* trial = base::FieldTrialList::Find("Study1");
860 trial->Disable(); 860 trial->Disable();
861 861
862 EXPECT_EQ(ProcessedStudy::kGenericDefaultExperimentName, 862 EXPECT_EQ(ProcessedStudy::kGenericDefaultExperimentName,
863 base::FieldTrialList::FindFullName("Study1")); 863 base::FieldTrialList::FindFullName("Study1"));
864 } 864 }
865 865
866 TEST_F(VariationsSeedProcessorTest, ExistingFieldTrial_ExpiredByConfig) {
867 static struct base::Feature kFeature {
868 "FeatureName", base::FEATURE_ENABLED_BY_DEFAULT
869 };
870 base::FieldTrialList field_trial_list(nullptr);
871
872 // In this case, an existing forced trial exists with a different default
873 // group than the study config, which is expired. This tests that we don't
874 // crash in such a case.
875 auto* trial = base::FieldTrialList::FactoryGetFieldTrial(
876 "Study1", 100, "ExistingDefault", base::FieldTrialList::kNoExpirationYear,
877 1, 1, base::FieldTrial::SESSION_RANDOMIZED, nullptr);
878 trial->AppendGroup("A", 100);
879 trial->SetForced();
880
881 Study study;
882 study.set_name("Study1");
883 const base::Time year_ago =
884 base::Time::Now() - base::TimeDelta::FromDays(365);
885 study.set_expiry_date(TimeToProtoTime(year_ago));
886 auto* exp1 = AddExperiment("A", 1, &study);
887 exp1->mutable_feature_association()->add_enable_feature(kFeature.name);
888 AddExperiment("Default", 1, &study);
889 study.set_default_experiment_name("Default");
890
891 EXPECT_TRUE(CreateTrialFromStudy(study));
892
893 // The expected effect is that processing the server config will expire
894 // the existing trial.
895 EXPECT_EQ("ExistingDefault", trial->group_name());
896 }
897
898 TEST_F(VariationsSeedProcessorTest, ExpiredStudy_NoDefaultGroup) {
899 static struct base::Feature kFeature {
900 "FeatureName", base::FEATURE_ENABLED_BY_DEFAULT
901 };
902 base::FieldTrialList field_trial_list(nullptr);
903
904 // Although it's not expected for the server to provide a study with an expiry
905 // date set, but not default experiment, this tests that we don't crash if
906 // that happens.
907 Study study;
908 study.set_name("Study1");
909 const base::Time year_ago =
910 base::Time::Now() - base::TimeDelta::FromDays(365);
911 study.set_expiry_date(TimeToProtoTime(year_ago));
912 auto* exp1 = AddExperiment("A", 1, &study);
913 exp1->mutable_feature_association()->add_enable_feature(kFeature.name);
914
915 EXPECT_TRUE(CreateTrialFromStudy(study));
916 EXPECT_EQ("VariationsDefaultExperiment",
917 base::FieldTrialList::FindFullName("Study1"));
918 }
919
866 TEST_F(VariationsSeedProcessorTest, LowEntropyStudyTest) { 920 TEST_F(VariationsSeedProcessorTest, LowEntropyStudyTest) {
867 const std::string kTrial1Name = "A"; 921 const std::string kTrial1Name = "A";
868 const std::string kTrial2Name = "B"; 922 const std::string kTrial2Name = "B";
869 const std::string kGroup1Name = "AA"; 923 const std::string kGroup1Name = "AA";
870 const std::string kDefaultName = "Default"; 924 const std::string kDefaultName = "Default";
871 925
872 VariationsSeed seed; 926 VariationsSeed seed;
873 Study* study1 = seed.add_study(); 927 Study* study1 = seed.add_study();
874 study1->set_name(kTrial1Name); 928 study1->set_name(kTrial1Name);
875 study1->set_consistency(variations::Study_Consistency_PERMANENT); 929 study1->set_consistency(variations::Study_Consistency_PERMANENT);
(...skipping 26 matching lines...) Expand all
902 // Since no experiment in study1 sends experiment IDs, it will use the high 956 // Since no experiment in study1 sends experiment IDs, it will use the high
903 // entropy provider, which selects the non-default group. 957 // entropy provider, which selects the non-default group.
904 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name)); 958 EXPECT_EQ(kGroup1Name, base::FieldTrialList::FindFullName(kTrial1Name));
905 959
906 // Since an experiment in study2 has google_web_experiment_id set, it will use 960 // Since an experiment in study2 has google_web_experiment_id set, it will use
907 // the low entropy provider, which selects the default group. 961 // the low entropy provider, which selects the default group.
908 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name)); 962 EXPECT_EQ(kDefaultName, base::FieldTrialList::FindFullName(kTrial2Name));
909 } 963 }
910 964
911 } // namespace variations 965 } // namespace 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