| 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..05cdecea048f6245a73f3f21bbc0f01fa939cf51 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,
|
| + base::FieldTrial* trial) {
|
| + base::FeatureList::ClearInstanceForTesting();
|
| + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
|
| + feature_list->RegisterFieldTrialOverride(feature.name, override_state,
|
| + trial);
|
| + base::FeatureList::SetInstance(std::move(feature_list));
|
| +}
|
| +
|
| } // namespace
|
|
|
| class VariationsAssociatedDataTest : public ::testing::Test {
|
| @@ -346,4 +357,77 @@ TEST_F(VariationsAssociatedDataTest, GetVariationParamValue_ActivatesTrial) {
|
| ASSERT_TRUE(base::FieldTrialList::IsTrialActive(kTrialName));
|
| }
|
|
|
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamsByFeature) {
|
| + const std::string kTrialName = "GetVariationParamsByFeature";
|
| + const base::Feature kFeature{"TestFeature",
|
| + base::FEATURE_DISABLED_BY_DEFAULT};
|
| +
|
| + 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));
|
| +
|
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE,
|
| + trial.get());
|
| +
|
| + 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";
|
| + const base::Feature kFeature{"TestFeature",
|
| + base::FEATURE_DISABLED_BY_DEFAULT};
|
| +
|
| + 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));
|
| +
|
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_ENABLE_FEATURE,
|
| + trial.get());
|
| +
|
| + std::map<std::string, std::string> actualParams;
|
| + EXPECT_EQ(params["x"], GetVariationParamValueByFeature(kFeature, "x"));
|
| +}
|
| +
|
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamsByFeature_Disable) {
|
| + const std::string kTrialName = "GetVariationParamsByFeature";
|
| + const base::Feature kFeature{"TestFeature",
|
| + base::FEATURE_DISABLED_BY_DEFAULT};
|
| +
|
| + 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));
|
| +
|
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE,
|
| + trial.get());
|
| +
|
| + std::map<std::string, std::string> actualParams;
|
| + EXPECT_FALSE(GetVariationParamsByFeature(kFeature, &actualParams));
|
| +}
|
| +
|
| +TEST_F(VariationsAssociatedDataTest, GetVariationParamValueByFeature_Disable) {
|
| + const std::string kTrialName = "GetVariationParamsByFeature";
|
| + const base::Feature kFeature{"TestFeature",
|
| + base::FEATURE_DISABLED_BY_DEFAULT};
|
| +
|
| + 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));
|
| +
|
| + CreateFeatureWithTrial(kFeature, base::FeatureList::OVERRIDE_DISABLE_FEATURE,
|
| + trial.get());
|
| +
|
| + std::map<std::string, std::string> actualParams;
|
| + EXPECT_EQ(std::string(), GetVariationParamValueByFeature(kFeature, "x"));
|
| +}
|
| +
|
| } // namespace variations
|
|
|