summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/common/extensions/feature_switch_unittest.cc80
-rw-r--r--extensions/common/feature_switch.cc6
2 files changed, 84 insertions, 2 deletions
diff --git a/chrome/common/extensions/feature_switch_unittest.cc b/chrome/common/extensions/feature_switch_unittest.cc
index 1f5e608..752e194 100644
--- a/chrome/common/extensions/feature_switch_unittest.cc
+++ b/chrome/common/extensions/feature_switch_unittest.cc
@@ -189,6 +189,38 @@ TEST_F(FeatureSwitchEnabledTest, TrueFieldTrialValue) {
}
}
+TEST_F(FeatureSwitchEnabledTest, TrueFieldTrialDogfoodValue) {
+ // Construct a fake field trial that defaults to the group "Enabled_Dogfood".
+ base::FieldTrialList field_trials(nullptr);
+ scoped_refptr<base::FieldTrial> enabled_trial =
+ CreateFieldTrial("Enabled_Dogfood");
+ {
+ // A default-enabled switch should be enabled (naturally).
+ FeatureSwitch default_enabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_ENABLED);
+ EXPECT_TRUE(default_enabled_switch.IsEnabled());
+ // Scoped overrides override everything.
+ FeatureSwitch::ScopedOverride scoped_override(&default_enabled_switch,
+ false);
+ EXPECT_FALSE(default_enabled_switch.IsEnabled());
+ }
+
+ {
+ // A default-disabled switch should be enabled because of the field trial.
+ FeatureSwitch default_disabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_DISABLED);
+ EXPECT_TRUE(default_disabled_switch.IsEnabled());
+ // Scoped overrides override everything.
+ FeatureSwitch::ScopedOverride scoped_override(&default_disabled_switch,
+ false);
+ EXPECT_FALSE(default_disabled_switch.IsEnabled());
+ }
+}
+
TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialValue) {
// Construct a fake field trial that defaults to the group "Disabled".
base::FieldTrialList field_trials(nullptr);
@@ -220,6 +252,54 @@ TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialValue) {
}
}
+TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialDogfoodValue) {
+ // Construct a fake field trial that defaults to the group "Disabled_Dogfood".
+ base::FieldTrialList field_trials(nullptr);
+ scoped_refptr<base::FieldTrial> disabled_trial =
+ CreateFieldTrial("Disabled_Dogfood");
+ {
+ // A default-enabled switch should be disabled because of the field trial.
+ FeatureSwitch default_enabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_ENABLED);
+ EXPECT_FALSE(default_enabled_switch.IsEnabled());
+ }
+
+ {
+ // A default-disabled switch should remain disabled.
+ FeatureSwitch default_disabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_DISABLED);
+ EXPECT_FALSE(default_disabled_switch.IsEnabled());
+ }
+}
+
+TEST_F(FeatureSwitchEnabledTest, InvalidGroupFieldTrial) {
+ // Construct a fake field trial that defaults to the group "InvalidGroup".
+ base::FieldTrialList field_trials(nullptr);
+ scoped_refptr<base::FieldTrial> disabled_trial =
+ CreateFieldTrial("InvalidGroup");
+ {
+ // A default-enabled switch should be enabled (the group has no effect).
+ FeatureSwitch default_enabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_ENABLED);
+ EXPECT_TRUE(default_enabled_switch.IsEnabled());
+ }
+
+ {
+ // A default-disabled switch should remain disabled.
+ FeatureSwitch default_disabled_switch(
+ &command_line_, kSwitchName,
+ std::vector<std::string>(1, kFieldTrialName),
+ FeatureSwitch::DEFAULT_DISABLED);
+ EXPECT_FALSE(default_disabled_switch.IsEnabled());
+ }
+}
+
TEST_F(FeatureSwitchEnabledTest,
TrueFieldTrialValueAndTrueRequiredFieldTrialValue) {
std::vector<std::string> required_trials;
diff --git a/extensions/common/feature_switch.cc b/extensions/common/feature_switch.cc
index ca73db0..88301f1 100644
--- a/extensions/common/feature_switch.cc
+++ b/extensions/common/feature_switch.cc
@@ -235,9 +235,11 @@ bool FeatureSwitch::IsEnabled() const {
for (const std::string& field_trial_name : required_field_trials_) {
std::string group_name =
base::FieldTrialList::FindFullName(field_trial_name);
- if (group_name != "Enabled") {
+ if (!base::StartsWith(group_name, "Enabled",
+ base::CompareCase::SENSITIVE)) {
enabled_by_field_trial = false;
- if (group_name == "Disabled") {
+ if (base::StartsWith(group_name, "Disabled",
+ base::CompareCase::SENSITIVE)) {
disabled_by_field_trial = true;
break;
}