diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2016-03-03 14:35:12 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-03 22:36:55 +0000 |
commit | 025ec1dc16aed7ff9ed633b76a33bd248a7fbaf8 (patch) | |
tree | 3098ebdc4dce4169666954ab1a6aabfec3b586f0 | |
parent | d862c72b081de56d1d9b87a59a397d9441d19725 (diff) | |
download | chromium_src-025ec1dc16aed7ff9ed633b76a33bd248a7fbaf8.zip chromium_src-025ec1dc16aed7ff9ed633b76a33bd248a7fbaf8.tar.gz chromium_src-025ec1dc16aed7ff9ed633b76a33bd248a7fbaf8.tar.bz2 |
[Extensions] Update FeatureSwitch logic to include Dogfood experiment groups
BUG=591783
Review URL: https://codereview.chromium.org/1757383003
Cr-Commit-Position: refs/heads/master@{#379120}
-rw-r--r-- | chrome/common/extensions/feature_switch_unittest.cc | 80 | ||||
-rw-r--r-- | extensions/common/feature_switch.cc | 6 |
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; } |