Chromium Code Reviews| Index: components/variations/variations_associated_data_unittest.cc |
| diff --git a/components/variations/variations_associated_data_unittest.cc b/components/variations/variations_associated_data_unittest.cc |
| index 470490dacdd3c3e4bf402b691b39294a577b0a26..5ab23011ad52be63ee5f2143af8479e50450bb3a 100644 |
| --- a/components/variations/variations_associated_data_unittest.cc |
| +++ b/components/variations/variations_associated_data_unittest.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/variations/variations_associated_data.h" |
| +#include "base/feature_list.h" |
| #include "base/macros.h" |
| #include "base/metrics/field_trial.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -33,6 +34,16 @@ scoped_refptr<base::FieldTrial> CreateFieldTrial( |
| base::FieldTrial::SESSION_RANDOMIZED, default_group_number); |
| } |
| +void CreateFeatureWithTrial(const base::Feature& feature, |
| + base::FeatureList::OverrideState override_state, |
| + scoped_refptr<base::FieldTrial> trial) { |
|
Alexei Svitkine (slow)
2016/05/03 17:04:25
Nit: Just pass by FieldTrial*.
jwd
2016/05/03 20:12:27
Done.
|
| + base::FeatureList::ClearInstanceForTesting(); |
| + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| + feature_list->RegisterFieldTrialOverride(feature.name, override_state, |
| + trial.get()); |
| + base::FeatureList::SetInstance(std::move(feature_list)); |
| +} |
| + |
| } // namespace |
| class VariationsAssociatedDataTest : public ::testing::Test { |
| @@ -346,4 +357,81 @@ TEST_F(VariationsAssociatedDataTest, GetVariationParamValue_ActivatesTrial) { |
| ASSERT_TRUE(base::FieldTrialList::IsTrialActive(kTrialName)); |
| } |
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamsByFeature) { |
| + const std::string kTrialName = "GetVariationParamsByFeature"; |
| + |
| + std::map<std::string, std::string> params; |
| + params["x"] = "1"; |
| + variations::AssociateVariationParams(kTrialName, "A", params); |
| + scoped_refptr<base::FieldTrial> trial( |
| + CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| + |
| + const base::Feature kFeature{"TestFeature", |
| + base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| + trial); |
| + |
| + std::map<std::string, std::string> actualParams; |
| + EXPECT_TRUE(GetVariationParamsByFeature(kFeature, &actualParams)); |
| + EXPECT_EQ(params, actualParams); |
| +} |
| + |
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamValueByFeature) { |
| + const std::string kTrialName = "GetVariationParamsByFeature"; |
| + |
| + std::map<std::string, std::string> params; |
| + params["x"] = "1"; |
| + variations::AssociateVariationParams(kTrialName, "A", params); |
| + scoped_refptr<base::FieldTrial> trial( |
| + CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| + |
| + const base::Feature kFeature{"TestFeature", |
| + base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| + trial); |
| + |
| + std::map<std::string, std::string> actualParams; |
| + EXPECT_EQ(params["x"], GetVariationParamValueByFeature(kFeature, "x")); |
| +} |
| + |
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamsByFeature_Disable) { |
| + const std::string kTrialName = "GetVariationParamsByFeature"; |
| + |
| + std::map<std::string, std::string> params; |
| + params["x"] = "1"; |
| + variations::AssociateVariationParams(kTrialName, "A", params); |
| + scoped_refptr<base::FieldTrial> trial( |
| + CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| + |
| + const base::Feature kFeature{"TestFeature", |
| + base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE, |
| + trial); |
| + |
| + std::map<std::string, std::string> actualParams; |
| + EXPECT_FALSE(GetVariationParamsByFeature(kFeature, &actualParams)); |
| +} |
| + |
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamValueByFeature_Disable) { |
| + const std::string kTrialName = "GetVariationParamsByFeature"; |
| + |
| + std::map<std::string, std::string> params; |
| + params["x"] = "1"; |
| + variations::AssociateVariationParams(kTrialName, "A", params); |
| + scoped_refptr<base::FieldTrial> trial( |
| + CreateFieldTrial(kTrialName, 100, "A", NULL)); |
| + |
| + const base::Feature kFeature{"TestFeature", |
|
Alexei Svitkine (slow)
2016/05/03 17:04:25
Nit: Maybe move this to the top of the function be
jwd
2016/05/03 20:12:27
Done.
|
| + base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE, |
| + trial); |
| + |
| + std::map<std::string, std::string> actualParams; |
| + EXPECT_EQ(std::string(), GetVariationParamValueByFeature(kFeature, "x")); |
| +} |
| + |
| } // namespace variations |