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

Unified Diff: components/variations/variations_associated_data_unittest.cc

Issue 1941963002: Add variations params api to get params from features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/variations/variations_associated_data.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/variations/variations_associated_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698