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

Unified Diff: chrome/browser/about_flags_unittest.cc

Issue 12326019: Refactor about_flags.cc to make defining enabled/disabled/default flags easier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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 | « chrome/browser/about_flags.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/about_flags_unittest.cc
===================================================================
--- chrome/browser/about_flags_unittest.cc (revision 183834)
+++ chrome/browser/about_flags_unittest.cc (working copy)
@@ -17,6 +17,7 @@
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 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 @@
kSwitch1,
"",
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -58,6 +64,8 @@
kSwitch2,
kValueForSwitch2,
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -69,6 +77,8 @@
kSwitch3,
"",
NULL,
+ NULL,
+ NULL,
0
},
{
@@ -79,9 +89,24 @@
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 @@
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 @@
testing::SetExperiments(kExperiments, arraysize(kExperiments));
}
- virtual void TearDown() {
+ virtual void TearDown() OVERRIDE {
testing::SetExperiments(NULL, 0);
}
@@ -278,6 +303,9 @@
// 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 @@
}
// 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,7 @@
}
// 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);
@@ -312,6 +336,48 @@
}
}
+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);
+ EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
+ EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
+ }
+}
+
// Makes sure there are no separators in any of the experiment names.
TEST_F(AboutFlagsTest, NoSeparators) {
testing::SetExperiments(NULL, 0);
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698