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

Unified Diff: components/variations/variations_associated_data_unittest.cc

Issue 2667553002: Move API for field trial params to base from variations. (Closed)
Patch Set: Created 3 years, 11 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 2217bd5fb91dac2157eb24a1d2bac63e80363ba9..221be57a010986c28f40b289b0b7a358e98c3f1a 100644
--- a/components/variations/variations_associated_data_unittest.cc
+++ b/components/variations/variations_associated_data_unittest.cc
@@ -4,10 +4,8 @@
#include "components/variations/variations_associated_data.h"
-#include "base/feature_list.h"
#include "base/macros.h"
#include "base/metrics/field_trial.h"
-#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace variations {
@@ -46,21 +44,10 @@ class VariationsAssociatedDataTest : public ::testing::Test {
// Ensure that the maps are cleared between tests, since they are stored as
// process singletons.
testing::ClearAllVariationIDs();
- testing::ClearAllVariationParams();
- }
-
- void CreateFeatureWithTrial(const base::Feature& feature,
- base::FeatureList::OverrideState override_state,
- base::FieldTrial* trial) {
- std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
- feature_list->RegisterFieldTrialOverride(feature.name, override_state,
- trial);
- scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
}
private:
base::FieldTrialList field_trial_list_;
- base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(VariationsAssociatedDataTest);
};
@@ -216,276 +203,4 @@ TEST_F(VariationsAssociatedDataTest, CollectionsCoexist) {
GetIDForTrial(CHROME_SYNC_SERVICE, trial_true.get()));
}
-TEST_F(VariationsAssociatedDataTest, AssociateVariationParams) {
- const std::string kTrialName = "AssociateVariationParams";
-
- {
- std::map<std::string, std::string> params;
- params["a"] = "10";
- params["b"] = "test";
- ASSERT_TRUE(AssociateVariationParams(kTrialName, "A", params));
- }
- {
- std::map<std::string, std::string> params;
- params["a"] = "5";
- ASSERT_TRUE(AssociateVariationParams(kTrialName, "B", params));
- }
-
- base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
- EXPECT_EQ("5", GetVariationParamValue(kTrialName, "a"));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "b"));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x"));
-
- std::map<std::string, std::string> params;
- EXPECT_TRUE(GetVariationParams(kTrialName, &params));
- EXPECT_EQ(1U, params.size());
- EXPECT_EQ("5", params["a"]);
-}
-
-TEST_F(VariationsAssociatedDataTest, AssociateVariationParams_Fail) {
- const std::string kTrialName = "AssociateVariationParams_Fail";
- const std::string kGroupName = "A";
-
- std::map<std::string, std::string> params;
- params["a"] = "10";
- ASSERT_TRUE(AssociateVariationParams(kTrialName, kGroupName, params));
- params["a"] = "1";
- params["b"] = "2";
- ASSERT_FALSE(AssociateVariationParams(kTrialName, kGroupName, params));
-
- base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName);
- EXPECT_EQ("10", GetVariationParamValue(kTrialName, "a"));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "b"));
-}
-
-TEST_F(VariationsAssociatedDataTest, AssociateVariationParams_TrialActiveFail) {
- const std::string kTrialName = "AssociateVariationParams_TrialActiveFail";
- base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
- ASSERT_EQ("A", base::FieldTrialList::FindFullName(kTrialName));
-
- std::map<std::string, std::string> params;
- params["a"] = "10";
- EXPECT_FALSE(AssociateVariationParams(kTrialName, "B", params));
- EXPECT_FALSE(AssociateVariationParams(kTrialName, "A", params));
-}
-
-TEST_F(VariationsAssociatedDataTest,
- AssociateVariationParams_DoesntActivateTrial) {
- const std::string kTrialName = "AssociateVariationParams_DoesntActivateTrial";
-
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
- scoped_refptr<base::FieldTrial> trial(
- CreateFieldTrial(kTrialName, 100, "A", NULL));
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
-
- std::map<std::string, std::string> params;
- params["a"] = "10";
- EXPECT_TRUE(AssociateVariationParams(kTrialName, "A", params));
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
-}
-
-TEST_F(VariationsAssociatedDataTest, GetVariationParams_NoTrial) {
- const std::string kTrialName = "GetVariationParams_NoParams";
-
- std::map<std::string, std::string> params;
- EXPECT_FALSE(GetVariationParams(kTrialName, &params));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x"));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "y"));
-}
-
-TEST_F(VariationsAssociatedDataTest, GetVariationParams_NoParams) {
- const std::string kTrialName = "GetVariationParams_NoParams";
-
- base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
-
- std::map<std::string, std::string> params;
- EXPECT_FALSE(GetVariationParams(kTrialName, &params));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x"));
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "y"));
-}
-
-TEST_F(VariationsAssociatedDataTest, GetVariationParams_ActivatesTrial) {
- const std::string kTrialName = "GetVariationParams_ActivatesTrial";
-
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
- scoped_refptr<base::FieldTrial> trial(
- CreateFieldTrial(kTrialName, 100, "A", NULL));
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
-
- std::map<std::string, std::string> params;
- EXPECT_FALSE(GetVariationParams(kTrialName, &params));
- ASSERT_TRUE(base::FieldTrialList::IsTrialActive(kTrialName));
-}
-
-TEST_F(VariationsAssociatedDataTest, GetVariationParamValue_ActivatesTrial) {
- const std::string kTrialName = "GetVariationParamValue_ActivatesTrial";
-
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
- scoped_refptr<base::FieldTrial> trial(
- CreateFieldTrial(kTrialName, 100, "A", NULL));
- ASSERT_FALSE(base::FieldTrialList::IsTrialActive(kTrialName));
-
- std::map<std::string, std::string> params;
- EXPECT_EQ(std::string(), GetVariationParamValue(kTrialName, "x"));
- 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"));
-}
-
-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