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

Unified Diff: chrome/common/extensions/feature_switch_unittest.cc

Issue 1680823004: [Feature Switch][Media Router] Add required field trials to MR switch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | extensions/common/feature_switch.h » ('j') | extensions/common/feature_switch.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/feature_switch_unittest.cc
diff --git a/chrome/common/extensions/feature_switch_unittest.cc b/chrome/common/extensions/feature_switch_unittest.cc
index 91c56335a984b202f45b41affdee8cdb697679f6..277c2e5478f0a440d4c778429e6c810c266cb245 100644
--- a/chrome/common/extensions/feature_switch_unittest.cc
+++ b/chrome/common/extensions/feature_switch_unittest.cc
@@ -16,9 +16,10 @@ namespace {
const char kSwitchName[] = "test-switch";
const char kFieldTrialName[] = "field-trial";
-// Create and register a field trial that will always return the given
-// |group_name|.
-scoped_refptr<base::FieldTrial> CreateFieldTrial(
+// Create and register a field trial named |field_trial_name| that will always
+// return the given |group_name|.
+scoped_refptr<base::FieldTrial> CreateFieldTrialWithName(
+ const std::string& field_trial_name,
const std::string& group_name) {
const int kTotalProbability = 10;
// Note: This code will probably fail in the year 5000. But all the cycles we
@@ -26,12 +27,19 @@ scoped_refptr<base::FieldTrial> CreateFieldTrial(
// worth it.
scoped_refptr<base::FieldTrial> trial =
base::FieldTrialList::FactoryGetFieldTrial(
- kFieldTrialName, kTotalProbability, "default", 5000, 1, 1,
+ field_trial_name, kTotalProbability, "default", 5000, 1, 1,
base::FieldTrial::SESSION_RANDOMIZED, nullptr);
trial->AppendGroup(group_name, kTotalProbability);
return trial;
}
+// Create and register a field trial that will always return the given
+// |group_name|.
+scoped_refptr<base::FieldTrial> CreateFieldTrial(
+ const std::string& group_name) {
+ return CreateFieldTrialWithName(kFieldTrialName, group_name);
+}
+
template<FeatureSwitch::DefaultValue T>
class FeatureSwitchTest : public testing::Test {
public:
@@ -156,9 +164,9 @@ TEST_F(FeatureSwitchEnabledTest, TrueFieldTrialValue) {
scoped_refptr<base::FieldTrial> enabled_trial = CreateFieldTrial("Enabled");
{
// A default-enabled switch should be enabled (naturally).
- FeatureSwitch default_enabled_switch(&command_line_, kSwitchName,
- kFieldTrialName,
- FeatureSwitch::DEFAULT_ENABLED);
+ FeatureSwitch default_enabled_switch(
+ &command_line_, kSwitchName, kFieldTrialName,
+ std::vector<const char*>(), FeatureSwitch::DEFAULT_ENABLED);
EXPECT_TRUE(default_enabled_switch.IsEnabled());
// Scoped overrides override everything.
FeatureSwitch::ScopedOverride scoped_override(&default_enabled_switch,
@@ -168,9 +176,9 @@ TEST_F(FeatureSwitchEnabledTest, TrueFieldTrialValue) {
{
// A default-disabled switch should be enabled because of the field trial.
- FeatureSwitch default_disabled_switch(&command_line_, kSwitchName,
- kFieldTrialName,
- FeatureSwitch::DEFAULT_DISABLED);
+ FeatureSwitch default_disabled_switch(
+ &command_line_, kSwitchName, kFieldTrialName,
+ std::vector<const char*>(), FeatureSwitch::DEFAULT_DISABLED);
EXPECT_TRUE(default_disabled_switch.IsEnabled());
// Scoped overrides override everything.
FeatureSwitch::ScopedOverride scoped_override(&default_disabled_switch,
@@ -185,9 +193,9 @@ TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialValue) {
scoped_refptr<base::FieldTrial> disabled_trial = CreateFieldTrial("Disabled");
{
// A default-enabled switch should be disabled because of the field trial.
- FeatureSwitch default_enabled_switch(&command_line_, kSwitchName,
- kFieldTrialName,
- FeatureSwitch::DEFAULT_ENABLED);
+ FeatureSwitch default_enabled_switch(
+ &command_line_, kSwitchName, kFieldTrialName,
+ std::vector<const char*>(), FeatureSwitch::DEFAULT_ENABLED);
EXPECT_FALSE(default_enabled_switch.IsEnabled());
// Scoped overrides override everything.
FeatureSwitch::ScopedOverride scoped_override(&default_enabled_switch,
@@ -197,9 +205,9 @@ TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialValue) {
{
// A default-disabled switch should remain disabled.
- FeatureSwitch default_disabled_switch(&command_line_, kSwitchName,
- kFieldTrialName,
- FeatureSwitch::DEFAULT_DISABLED);
+ FeatureSwitch default_disabled_switch(
+ &command_line_, kSwitchName, kFieldTrialName,
+ std::vector<const char*>(), FeatureSwitch::DEFAULT_DISABLED);
EXPECT_FALSE(default_disabled_switch.IsEnabled());
// Scoped overrides override everything.
FeatureSwitch::ScopedOverride scoped_override(&default_disabled_switch,
@@ -207,3 +215,33 @@ TEST_F(FeatureSwitchEnabledTest, FalseFieldTrialValue) {
EXPECT_TRUE(default_disabled_switch.IsEnabled());
}
}
+
+TEST_F(FeatureSwitchEnabledTest,
+ TrueFieldTrialValueAndTrueDependentFieldTrialValue) {
+ const char* dependent_trial_name = "dependent-trial";
+ base::FieldTrialList field_trials(nullptr);
+ scoped_refptr<base::FieldTrial> enabled_trial = CreateFieldTrial("Enabled");
+ scoped_refptr<base::FieldTrial> enabled_dependent_trial =
+ CreateFieldTrialWithName(dependent_trial_name, "Enabled");
+ std::vector<const char*> dependent_trials;
+ dependent_trials.push_back(dependent_trial_name);
+ FeatureSwitch trial_enabled_switch(&command_line_, kSwitchName,
+ kFieldTrialName, dependent_trials,
+ FeatureSwitch::DEFAULT_DISABLED);
+ EXPECT_TRUE(trial_enabled_switch.IsEnabled());
+}
+
+TEST_F(FeatureSwitchEnabledTest,
+ TrueFieldTrialValueAndFalseDependentFieldTrialValue) {
+ const char* dependent_trial_name = "dependent-trial";
+ base::FieldTrialList field_trials(nullptr);
+ scoped_refptr<base::FieldTrial> enabled_trial = CreateFieldTrial("Enabled");
+ scoped_refptr<base::FieldTrial> enabled_dependent_trial =
+ CreateFieldTrialWithName(dependent_trial_name, "Disabled");
+ std::vector<const char*> dependent_trials;
+ dependent_trials.push_back(dependent_trial_name);
+ FeatureSwitch trial_enabled_switch(&command_line_, kSwitchName,
+ kFieldTrialName, dependent_trials,
+ FeatureSwitch::DEFAULT_DISABLED);
+ EXPECT_FALSE(trial_enabled_switch.IsEnabled());
+}
« no previous file with comments | « no previous file | extensions/common/feature_switch.h » ('j') | extensions/common/feature_switch.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698