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

Unified Diff: components/variations/variations_associated_data_unittest.cc

Issue 2558743003: Add generic functions for getting typed variation parameter values (Closed)
Patch Set: Alexei's comments Created 4 years 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 40ff746d80af811ba504ae662b1efd94eef54bd3..2217bd5fb91dac2157eb24a1d2bac63e80363ba9 100644
--- a/components/variations/variations_associated_data_unittest.cc
+++ b/components/variations/variations_associated_data_unittest.cc
@@ -403,4 +403,89 @@ TEST_F(VariationsAssociatedDataTest, GetVariationParamValueByFeature_Disable) {
EXPECT_EQ(std::string(), GetVariationParamValueByFeature(kFeature, "x"));
}
+TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsInt) {
+ const std::string kTrialName = "GetVariationParamsByFeature";
+ const base::Feature kFeature{"TestFeature",
+ base::FEATURE_DISABLED_BY_DEFAULT};
+
+ std::map<std::string, std::string> params;
+ params["a"] = "1";
+ params["b"] = "1.5";
+ params["c"] = "foo";
+ params["d"] = "";
+ // "e" is not registered
+ 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(1, GetVariationParamByFeatureAsInt(kFeature, "a", 0));
+ EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "b", 0)); // invalid
+ EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "c", 0)); // invalid
+ EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "d", 0)); // empty
+ EXPECT_EQ(0, GetVariationParamByFeatureAsInt(kFeature, "e", 0)); // empty
+}
+
+TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsDouble) {
+ const std::string kTrialName = "GetVariationParamsByFeature";
+ const base::Feature kFeature{"TestFeature",
+ base::FEATURE_DISABLED_BY_DEFAULT};
+
+ std::map<std::string, std::string> params;
+ params["a"] = "1";
+ params["b"] = "1.5";
+ params["c"] = "1.0e-10";
+ params["d"] = "foo";
+ params["e"] = "";
+ // "f" is not registered
+ 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(1, GetVariationParamByFeatureAsDouble(kFeature, "a", 0));
+ EXPECT_EQ(1.5, GetVariationParamByFeatureAsDouble(kFeature, "b", 0));
+ EXPECT_EQ(1.0e-10, GetVariationParamByFeatureAsDouble(kFeature, "c", 0));
+ EXPECT_EQ(0,
+ GetVariationParamByFeatureAsDouble(kFeature, "d", 0)); // invalid
+ EXPECT_EQ(0, GetVariationParamByFeatureAsDouble(kFeature, "e", 0)); // empty
+ EXPECT_EQ(0, GetVariationParamByFeatureAsDouble(kFeature, "f", 0)); // empty
+}
+
+TEST_F(VariationsAssociatedDataTest, GetVariationParamByFeatureAsBool) {
+ const std::string kTrialName = "GetVariationParamsByFeature";
+ const base::Feature kFeature{"TestFeature",
+ base::FEATURE_DISABLED_BY_DEFAULT};
+
+ std::map<std::string, std::string> params;
+ params["a"] = "true";
+ params["b"] = "false";
+ params["c"] = "1";
+ params["d"] = "False";
+ params["e"] = "";
+ // "f" is not registered
+ 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(GetVariationParamByFeatureAsBool(kFeature, "a", false));
+ EXPECT_FALSE(GetVariationParamByFeatureAsBool(kFeature, "b", true));
+ EXPECT_FALSE(
+ GetVariationParamByFeatureAsBool(kFeature, "c", false)); // invalid
+ EXPECT_TRUE(
+ GetVariationParamByFeatureAsBool(kFeature, "d", true)); // invalid
+ EXPECT_TRUE(GetVariationParamByFeatureAsBool(kFeature, "e", true)); // empty
+ EXPECT_TRUE(GetVariationParamByFeatureAsBool(kFeature, "f", true)); // empty
+}
+
} // 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