Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor about_flags.cc to make defining enabled/disabled/default fla…

…gs easier.

BUG=177023
TEST=Unit tests.

Review URL: https://chromiumcodereview.appspot.com/12326019

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@184458 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit 79e62e2bc67f21d27b99c3ca74cfe27b9b4e2616 1 parent 991930e
asvitkine@chromium.org authored
Showing with 194 additions and 113 deletions.
  1. +99 −103 about_flags.cc
  2. +21 −2 about_flags.h
  3. +74 −8 about_flags_unittest.cc
202 about_flags.cc
View
@@ -8,6 +8,7 @@
#include <iterator>
#include <map>
#include <set>
+#include <utility>
#include "base/command_line.h"
#include "base/memory/singleton.h"
@@ -50,11 +51,18 @@ namespace about_flags {
// Macros to simplify specifying the type.
#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
- Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
+ Experiment::SINGLE_VALUE, \
+ command_line_switch, switch_value, NULL, NULL, NULL, 0
#define SINGLE_VALUE_TYPE(command_line_switch) \
SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
+#define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \
+ disable_switch, disable_value) \
+ Experiment::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \
+ disable_switch, disable_value, NULL, 3
+#define ENABLE_DISABLE_VALUE_TYPE(enable_switch, disable_switch) \
+ ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, "", disable_switch, "")
#define MULTI_VALUE_TYPE(choices) \
- Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
+ Experiment::MULTI_VALUE, NULL, NULL, NULL, NULL, choices, arraysize(choices)
namespace {
@@ -112,14 +120,6 @@ const Experiment::Choice kOmniboxInlineHistoryQuickProviderChoices[] = {
switches::kOmniboxInlineHistoryQuickProviderProhibited }
};
-const Experiment::Choice kFixedPositionCreatesStackingContextChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kEnableFixedPositionCreatesStackingContext, ""},
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kDisableFixedPositionCreatesStackingContext, ""}
-};
-
const Experiment::Choice kEnableCompositingForFixedPositionChoices[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
{ IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
@@ -130,30 +130,6 @@ const Experiment::Choice kEnableCompositingForFixedPositionChoices[] = {
switches::kEnableHighDpiCompositingForFixedPosition, ""}
};
-const Experiment::Choice kForceCompositingModeChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kForceCompositingMode, ""},
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kDisableForceCompositingMode, ""}
-};
-
-const Experiment::Choice kThreadedCompositingModeChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kDisableThreadedCompositing, ""},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kEnableThreadedCompositing, ""}
-};
-
-const Experiment::Choice kForceAcceleratedOverflowScrollModeChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kDisableAcceleratedOverflowScroll, ""},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kEnableAcceleratedOverflowScroll, ""}
-};
-
const Experiment::Choice kGDIPresentChoices[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
{ IDS_FLAGS_PRESENT_WITH_GDI_FIRST_SHOW,
@@ -162,7 +138,6 @@ const Experiment::Choice kGDIPresentChoices[] = {
switches::kDoAllShowPresentWithGDI, ""}
};
-
const Experiment::Choice kTouchEventsChoices[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_AUTOMATIC, "", "" },
{ IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
@@ -183,14 +158,6 @@ const Experiment::Choice kTouchOptimizedUIChoices[] = {
switches::kTouchOptimizedUIDisabled }
};
-const Experiment::Choice kAsyncDnsChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kDisableAsyncDns, ""},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kEnableAsyncDns, ""}
-};
-
const Experiment::Choice kNaClDebugMaskChoices[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
// Secure shell can be used on ChromeOS for forwarding the TCP port opened by
@@ -202,30 +169,6 @@ const Experiment::Choice kNaClDebugMaskChoices[] = {
switches::kNaClDebugMask, "*://*/*debug.nmf" }
};
-const Experiment::Choice kActionBoxChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kActionBox, "0"},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kActionBox, "1"}
-};
-
-const Experiment::Choice kScriptBubbleChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kScriptBubble, "0"},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kScriptBubble, "1"}
-};
-
-const Experiment::Choice kTabCaptureChoices[] = {
- { IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
- { IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
- switches::kTabCapture, "0"},
- { IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
- switches::kTabCapture, "1"}
-};
-
#if defined(OS_CHROMEOS)
const Experiment::Choice kAshBootAnimationFunction[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
@@ -359,21 +302,24 @@ const Experiment kExperiments[] = {
IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
kOsMac | kOsWin | kOsLinux,
- MULTI_VALUE_TYPE(kForceCompositingModeChoices)
+ ENABLE_DISABLE_VALUE_TYPE(switches::kForceCompositingMode,
+ switches::kDisableForceCompositingMode)
},
{
"threaded-compositing-mode",
IDS_FLAGS_THREADED_COMPOSITING_MODE_NAME,
IDS_FLAGS_THREADED_COMPOSITING_MODE_DESCRIPTION,
kOsDesktop & ~kOsCrOS,
- MULTI_VALUE_TYPE(kThreadedCompositingModeChoices)
+ ENABLE_DISABLE_VALUE_TYPE(switches::kEnableThreadedCompositing,
+ switches::kDisableThreadedCompositing)
},
{
"force-accelerated-composited-scrolling",
IDS_FLAGS_FORCE_ACCELERATED_OVERFLOW_SCROLL_MODE_NAME,
IDS_FLAGS_FORCE_ACCELERATED_OVERFLOW_SCROLL_MODE_DESCRIPTION,
kOsAll,
- MULTI_VALUE_TYPE(kForceAcceleratedOverflowScrollModeChoices)
+ ENABLE_DISABLE_VALUE_TYPE(switches::kEnableAcceleratedOverflowScroll,
+ switches::kDisableAcceleratedOverflowScroll)
},
{
"present-with-GDI",
@@ -469,7 +415,9 @@ const Experiment kExperiments[] = {
IDS_FLAGS_FIXED_POSITION_CREATES_STACKING_CONTEXT_NAME,
IDS_FLAGS_FIXED_POSITION_CREATES_STACKING_CONTEXT_DESCRIPTION,
kOsAll,
- MULTI_VALUE_TYPE(kFixedPositionCreatesStackingContextChoices)
+ ENABLE_DISABLE_VALUE_TYPE(
+ switches::kEnableFixedPositionCreatesStackingContext,
+ switches::kDisableFixedPositionCreatesStackingContext)
},
{
"enable-compositing-for-fixed-position",
@@ -528,7 +476,8 @@ const Experiment kExperiments[] = {
IDS_FLAGS_ACTION_BOX_NAME,
IDS_FLAGS_ACTION_BOX_DESCRIPTION,
kOsDesktop,
- MULTI_VALUE_TYPE(kActionBoxChoices),
+ ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(switches::kActionBox, "1",
+ switches::kActionBox, "0")
},
{
"script-badges",
@@ -542,7 +491,8 @@ const Experiment kExperiments[] = {
IDS_FLAGS_SCRIPT_BUBBLE_NAME,
IDS_FLAGS_SCRIPT_BUBBLE_DESCRIPTION,
kOsDesktop,
- MULTI_VALUE_TYPE(kScriptBubbleChoices),
+ ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(switches::kScriptBubble, "1",
+ switches::kScriptBubble, "0")
},
{
"apps-new-install-bubble",
@@ -697,7 +647,8 @@ const Experiment kExperiments[] = {
IDS_FLAGS_ENABLE_ASYNC_DNS_NAME,
IDS_FLAGS_ENABLE_ASYNC_DNS_DESCRIPTION,
kOsWin | kOsMac | kOsLinux | kOsCrOS,
- MULTI_VALUE_TYPE(kAsyncDnsChoices)
+ ENABLE_DISABLE_VALUE_TYPE(switches::kEnableAsyncDns,
+ switches::kDisableAsyncDns)
},
{
"disable-media-source",
@@ -884,7 +835,8 @@ const Experiment kExperiments[] = {
IDS_ENABLE_TAB_CAPTURE_NAME,
IDS_ENABLE_TAB_CAPTURE_DESCRIPTION,
kOsWin | kOsMac | kOsLinux | kOsCrOS,
- MULTI_VALUE_TYPE(kTabCaptureChoices)
+ ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(switches::kTabCapture, "1",
+ switches::kTabCapture, "0")
},
#if defined(OS_CHROMEOS)
{
@@ -1359,22 +1311,15 @@ void SetEnabledFlags(
}
}
-// Returns the name used in prefs for the choice at the specified index.
-std::string NameForChoice(const Experiment& e, int index) {
- DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
- DCHECK_LT(index, e.num_choices);
- return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
- base::IntToString(index);
-}
-
// Adds the internal names for the specified experiment to |names|.
void AddInternalName(const Experiment& e, std::set<std::string>* names) {
if (e.type == Experiment::SINGLE_VALUE) {
names->insert(e.internal_name);
} else {
- DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
+ DCHECK(e.type == Experiment::MULTI_VALUE ||
+ e.type == Experiment::ENABLE_DISABLE_VALUE);
for (int i = 0; i < e.num_choices; ++i)
- names->insert(NameForChoice(e, i));
+ names->insert(e.NameForChoice(i));
}
}
@@ -1392,6 +1337,14 @@ bool ValidateExperiment(const Experiment& e) {
DCHECK(e.choices[0].command_line_switch);
DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
break;
+ case Experiment::ENABLE_DISABLE_VALUE:
+ DCHECK_EQ(3, e.num_choices);
+ DCHECK(!e.choices);
+ DCHECK(e.command_line_switch);
+ DCHECK(e.command_line_value);
+ DCHECK(e.disable_command_line_switch);
+ DCHECK(e.disable_command_line_value);
+ break;
default:
NOTREACHED();
}
@@ -1455,15 +1408,14 @@ void GetSanitizedEnabledFlagsForCurrentPlatform(
// Returns the Value representing the choice data in the specified experiment.
Value* CreateChoiceData(const Experiment& experiment,
const std::set<std::string>& enabled_experiments) {
- DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
+ DCHECK(experiment.type == Experiment::MULTI_VALUE ||
+ experiment.type == Experiment::ENABLE_DISABLE_VALUE);
ListValue* result = new ListValue;
for (int i = 0; i < experiment.num_choices; ++i) {
- const Experiment::Choice& choice = experiment.choices[i];
DictionaryValue* value = new DictionaryValue;
- std::string name = NameForChoice(experiment, i);
- value->SetString("description",
- l10n_util::GetStringUTF16(choice.description_id));
+ const std::string name = experiment.NameForChoice(i);
value->SetString("internal_name", name);
+ value->SetString("description", experiment.DescriptionForChoice(i));
value->SetBoolean("selected", enabled_experiments.count(name) > 0);
result->Append(value);
}
@@ -1472,6 +1424,32 @@ Value* CreateChoiceData(const Experiment& experiment,
} // namespace
+std::string Experiment::NameForChoice(int index) const {
+ DCHECK(type == Experiment::MULTI_VALUE ||
+ type == Experiment::ENABLE_DISABLE_VALUE);
+ DCHECK_LT(index, num_choices);
+ return std::string(internal_name) + testing::kMultiSeparator +
+ base::IntToString(index);
+}
+
+string16 Experiment::DescriptionForChoice(int index) const {
+ DCHECK(type == Experiment::MULTI_VALUE ||
+ type == Experiment::ENABLE_DISABLE_VALUE);
+ DCHECK_LT(index, num_choices);
+ int description_id;
+ if (type == Experiment::ENABLE_DISABLE_VALUE) {
+ const int kEnableDisableDescriptionIds[] = {
+ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT,
+ IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
+ IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
+ };
+ description_id = kEnableDisableDescriptionIds[index];
+ } else {
+ description_id = choices[index].description_id;
+ }
+ return l10n_util::GetStringUTF16(description_id);
+}
+
void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
}
@@ -1507,6 +1485,7 @@ ListValue* GetFlagsExperimentsData(PrefService* prefs) {
enabled_experiments.count(experiment.internal_name) > 0);
break;
case Experiment::MULTI_VALUE:
+ case Experiment::ENABLE_DISABLE_VALUE:
data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
break;
default:
@@ -1573,6 +1552,17 @@ void RecordUMAStatistics(const PrefService* prefs) {
namespace {
+typedef std::map<std::string, std::pair<std::string, std::string> >
+ NameToSwitchAndValueMap;
+
+void SetFlagToSwitchMapping(const std::string& key,
+ const std::string& switch_name,
+ const std::string& switch_value,
+ NameToSwitchAndValueMap* name_to_switch_map) {
+ DCHECK(name_to_switch_map->end() == name_to_switch_map->find(key));
+ (*name_to_switch_map)[key] = std::make_pair(switch_name, switch_value);
+}
+
void FlagsState::ConvertFlagsToSwitches(
PrefService* prefs, CommandLine* command_line) {
if (command_line->HasSwitch(switches::kNoExperiments))
@@ -1582,21 +1572,27 @@ void FlagsState::ConvertFlagsToSwitches(
GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
- typedef std::map<std::string, std::pair<std::string, std::string> >
- NameToSwitchAndValueMap;
NameToSwitchAndValueMap name_to_switch_map;
for (size_t i = 0; i < num_experiments; ++i) {
const Experiment& e = experiments[i];
if (e.type == Experiment::SINGLE_VALUE) {
- name_to_switch_map[e.internal_name] =
- std::pair<std::string, std::string>(e.command_line_switch,
- e.command_line_value);
+ SetFlagToSwitchMapping(e.internal_name, e.command_line_switch,
+ e.command_line_value, &name_to_switch_map);
+ } else if (e.type == Experiment::MULTI_VALUE) {
+ for (int j = 0; j < e.num_choices; ++j) {
+ SetFlagToSwitchMapping(e.NameForChoice(j),
+ e.choices[j].command_line_switch,
+ e.choices[j].command_line_value,
+ &name_to_switch_map);
+ }
} else {
- for (int j = 0; j < e.num_choices; ++j)
- name_to_switch_map[NameForChoice(e, j)] =
- std::pair<std::string, std::string>(
- e.choices[j].command_line_switch,
- e.choices[j].command_line_value);
+ DCHECK_EQ(e.type, Experiment::ENABLE_DISABLE_VALUE);
+ SetFlagToSwitchMapping(e.NameForChoice(0), std::string(), std::string(),
+ &name_to_switch_map);
+ SetFlagToSwitchMapping(e.NameForChoice(1), e.command_line_switch,
+ e.command_line_value, &name_to_switch_map);
+ SetFlagToSwitchMapping(e.NameForChoice(2), e.disable_command_line_switch,
+ e.disable_command_line_value, &name_to_switch_map);
}
}
@@ -1636,7 +1632,7 @@ void FlagsState::SetExperimentEnabled(
PrefService* prefs, const std::string& internal_name, bool enable) {
needs_restart_ = true;
- size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
+ size_t at_index = internal_name.find(testing::kMultiSeparator);
if (at_index != std::string::npos) {
DCHECK(enable);
// We're being asked to enable a multi-choice experiment. Disable the
@@ -1675,11 +1671,11 @@ void FlagsState::SetExperimentEnabled(
} else {
if (enable) {
// Enable the first choice.
- enabled_experiments.insert(NameForChoice(*e, 0));
+ enabled_experiments.insert(e->NameForChoice(0));
} else {
// Find the currently enabled choice and disable it.
for (int i = 0; i < e->num_choices; ++i) {
- std::string choice_name = NameForChoice(*e, i);
+ std::string choice_name = e->NameForChoice(i);
if (enabled_experiments.find(choice_name) !=
enabled_experiments.end()) {
enabled_experiments.erase(choice_name);
23 about_flags.h
View
@@ -9,6 +9,7 @@
#include <string>
#include "base/command_line.h"
+#include "base/string16.h"
class PrefService;
@@ -37,6 +38,12 @@ struct Experiment {
// command_line of the Experiment is not used. If the experiment is enabled
// the command line of the selected Choice is enabled.
MULTI_VALUE,
+
+ // The experiment has three possible values: Default, Enabled and Disabled.
+ // This should be used for experiments that may have their own logic to
+ // decide if the feature should be on when not explicitly specified via
+ // about flags - for example via FieldTrials.
+ ENABLE_DISABLE_VALUE,
};
// Used for MULTI_VALUE types to describe one of the possible values the user
@@ -69,20 +76,31 @@ struct Experiment {
// Type of experiment.
Type type;
- // The commandline switch and value that are added when this lab is active.
+ // The commandline switch and value that are added when this flag is active.
// This is different from |internal_name| so that the commandline flag can be
// renamed without breaking the prefs file.
- // This is used if type is SINGLE_VALUE.
+ // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE.
const char* command_line_switch;
// Simple switches that have no value should use "" for command_line_value.
const char* command_line_value;
+ // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly
+ // disable the feature.
+ const char* disable_command_line_switch;
+ const char* disable_command_line_value;
+
// This is used if type is MULTI_VALUE.
const Choice* choices;
// Number of |choices|.
// This is used if type is MULTI_VALUE.
int num_choices;
+
+ // Returns the name used in prefs for the choice at the specified |index|.
+ std::string NameForChoice(int index) const;
+
+ // Returns the human readable description for the choice at |index|.
+ string16 DescriptionForChoice(int index) const;
};
// Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the
@@ -117,6 +135,7 @@ int GetCurrentPlatform();
void RecordUMAStatistics(const PrefService* prefs);
namespace testing {
+
// Clears internal global state, for unit tests.
void ClearState();
82 about_flags_unittest.cc
View
@@ -17,6 +17,7 @@ const char kFlags1[] = "flag1";
const char kFlags2[] = "flag2";
const char kFlags3[] = "flag3";
const char kFlags4[] = "flag4";
+const char kFlags5[] = "flag5";
const char kSwitch1[] = "switch";
const char kSwitch2[] = "switch2";
@@ -27,6 +28,9 @@ const char kMultiSwitch1[] = "multi_switch1";
const char kMultiSwitch2[] = "multi_switch2";
const char kValueForMultiSwitch2[] = "value_for_multi_switch2";
+const char kEnableDisableValue1[] = "value1";
+const char kEnableDisableValue2[] = "value2";
+
namespace about_flags {
const Experiment::Choice kMultiChoices[] = {
@@ -47,6 +51,8 @@ static Experiment kExperiments[] = {
kSwitch1,
"",
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -58,6 +64,8 @@ static Experiment kExperiments[] = {
kSwitch2,
kValueForSwitch2,
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -69,6 +77,8 @@ static Experiment kExperiments[] = {
kSwitch3,
"",
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -79,9 +89,24 @@ static Experiment kExperiments[] = {
Experiment::MULTI_VALUE,
"",
"",
+ "",
+ "",
kMultiChoices,
arraysize(kMultiChoices)
},
+ {
+ kFlags5,
+ IDS_PRODUCT_NAME,
+ IDS_PRODUCT_NAME,
+ 0, // Ends up being mapped to the current platform.
+ Experiment::ENABLE_DISABLE_VALUE,
+ kSwitch1,
+ kEnableDisableValue1,
+ kSwitch2,
+ kEnableDisableValue2,
+ NULL,
+ 3
+ },
};
class AboutFlagsTest : public ::testing::Test {
@@ -91,7 +116,7 @@ class AboutFlagsTest : public ::testing::Test {
testing::ClearState();
}
- virtual void SetUp() {
+ virtual void SetUp() OVERRIDE {
for (size_t i = 0; i < arraysize(kExperiments); ++i)
kExperiments[i].supported_platforms = GetCurrentPlatform();
@@ -103,7 +128,7 @@ class AboutFlagsTest : public ::testing::Test {
testing::SetExperiments(kExperiments, arraysize(kExperiments));
}
- virtual void TearDown() {
+ virtual void TearDown() OVERRIDE {
testing::SetExperiments(NULL, 0);
}
@@ -278,6 +303,9 @@ TEST_F(AboutFlagsTest, CheckValues) {
// Tests multi-value type experiments.
TEST_F(AboutFlagsTest, MultiValues) {
+ const Experiment& experiment = kExperiments[3];
+ ASSERT_EQ(kFlags4, experiment.internal_name);
+
// Initially, the first "deactivated" option of the multi experiment should
// be set.
{
@@ -288,9 +316,7 @@ TEST_F(AboutFlagsTest, MultiValues) {
}
// Enable the 2nd choice of the multi-value.
- SetExperimentEnabled(&prefs_, std::string(kFlags4) +
- std::string(testing::kMultiSeparator) +
- base::IntToString(2), true);
+ SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
ConvertFlagsToSwitches(&prefs_, &command_line);
@@ -301,9 +327,49 @@ TEST_F(AboutFlagsTest, MultiValues) {
}
// Disable the multi-value experiment.
- SetExperimentEnabled(&prefs_, std::string(kFlags4) +
- std::string(testing::kMultiSeparator) +
- base::IntToString(0), true);
+ SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+ {
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ ConvertFlagsToSwitches(&prefs_, &command_line);
+ EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
+ EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
+ }
+}
+
+TEST_F(AboutFlagsTest, EnableDisableValues) {
+ const Experiment& experiment = kExperiments[4];
+ ASSERT_EQ(kFlags5, experiment.internal_name);
+
+ // Nothing selected.
+ {
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ ConvertFlagsToSwitches(&prefs_, &command_line);
+ EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
+ EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
+ }
+
+ // "Enable" option selected.
+ SetExperimentEnabled(&prefs_, experiment.NameForChoice(1), true);
+ {
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ ConvertFlagsToSwitches(&prefs_, &command_line);
+ EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
+ EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
+ EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
+ }
+
+ // "Disable" option selected.
+ SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+ {
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ ConvertFlagsToSwitches(&prefs_, &command_line);
+ EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
+ EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
+ EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
+ }
+
+ // "Default" option selected, same as nothing selected.
+ SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
ConvertFlagsToSwitches(&prefs_, &command_line);
Please sign in to comment.
Something went wrong with that request. Please try again.