[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 5 | #include "base/string_number_conversions.h" |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 6 | #include "base/utf_string_conversions.h" |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 7 | #include "base/values.h" |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 8 | #include "chrome/browser/about_flags.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 9 | #include "chrome/common/chrome_switches.h" |
| 10 | #include "chrome/common/pref_names.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 11 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 12 | #include "grit/chromium_strings.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 15 | const char kFlags1[] = "flag1"; |
| 16 | const char kFlags2[] = "flag2"; |
| 17 | const char kFlags3[] = "flag3"; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 18 | const char kFlags4[] = "flag4"; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 19 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 20 | const char kSwitch1[] = "switch"; |
| 21 | const char kSwitch2[] = "switch2"; |
| 22 | const char kSwitch3[] = "switch3"; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 23 | const char kValueForSwitch2[] = "value_for_switch2"; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 24 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 25 | const char kMultiSwitch1[] = "multi_switch1"; |
| 26 | const char kMultiSwitch2[] = "multi_switch2"; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 27 | const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 28 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 29 | namespace about_flags { |
| 30 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 31 | const Experiment::Choice kMultiChoices[] = { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 32 | { IDS_PRODUCT_NAME, "", "" }, |
| 33 | { IDS_PRODUCT_NAME, kMultiSwitch1, "" }, |
| 34 | { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 }, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | // The experiments that are set for these tests. The 3rd experiment is not |
| 38 | // supported on the current platform, all others are. |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 39 | static Experiment kExperiments[] = { |
| 40 | { |
| 41 | kFlags1, |
| 42 | IDS_PRODUCT_NAME, |
| 43 | IDS_PRODUCT_NAME, |
| 44 | 0, // Ends up being mapped to the current platform. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 45 | Experiment::SINGLE_VALUE, |
| 46 | kSwitch1, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 47 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 48 | NULL, |
| 49 | 0 |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 50 | }, |
| 51 | { |
| 52 | kFlags2, |
| 53 | IDS_PRODUCT_NAME, |
| 54 | IDS_PRODUCT_NAME, |
| 55 | 0, // Ends up being mapped to the current platform. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 56 | Experiment::SINGLE_VALUE, |
| 57 | kSwitch2, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 58 | kValueForSwitch2, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 59 | NULL, |
| 60 | 0 |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 61 | }, |
| 62 | { |
| 63 | kFlags3, |
| 64 | IDS_PRODUCT_NAME, |
| 65 | IDS_PRODUCT_NAME, |
| 66 | 0, // This ends up enabling for an OS other than the current. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 67 | Experiment::SINGLE_VALUE, |
| 68 | kSwitch3, |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 69 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 70 | NULL, |
| 71 | 0 |
| 72 | }, |
| 73 | { |
| 74 | kFlags4, |
| 75 | IDS_PRODUCT_NAME, |
| 76 | IDS_PRODUCT_NAME, |
| 77 | 0, // Ends up being mapped to the current platform. |
| 78 | Experiment::MULTI_VALUE, |
| 79 | "", |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 80 | "", |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 81 | kMultiChoices, |
| 82 | arraysize(kMultiChoices) |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 83 | }, |
| 84 | }; |
| 85 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 86 | class AboutFlagsTest : public ::testing::Test { |
| 87 | protected: |
| 88 | AboutFlagsTest() { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 89 | prefs_.RegisterListPref(prefs::kEnabledLabsExperiments, |
| 90 | PrefService::UNSYNCABLE_PREF); |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 91 | #if defined(OS_CHROMEOS) |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 92 | prefs_.RegisterBooleanPref(prefs::kLabsMediaplayerEnabled, |
| 93 | false, |
| 94 | PrefService::UNSYNCABLE_PREF); |
| 95 | prefs_.RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled, |
| 96 | false, |
| 97 | PrefService::UNSYNCABLE_PREF); |
| 98 | prefs_.RegisterBooleanPref(prefs::kUseVerticalTabs, |
| 99 | false, |
| 100 | PrefService::UNSYNCABLE_PREF); |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 101 | #endif |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 102 | testing::ClearState(); |
| 103 | } |
| 104 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 105 | virtual void SetUp() { |
| 106 | for (size_t i = 0; i < arraysize(kExperiments); ++i) |
| 107 | kExperiments[i].supported_platforms = GetCurrentPlatform(); |
| 108 | |
| 109 | int os_other_than_current = 1; |
| 110 | while (os_other_than_current == GetCurrentPlatform()) |
| 111 | os_other_than_current <<= 1; |
| 112 | kExperiments[2].supported_platforms = os_other_than_current; |
| 113 | |
| 114 | testing::SetExperiments(kExperiments, arraysize(kExperiments)); |
| 115 | } |
| 116 | |
| 117 | virtual void TearDown() { |
| 118 | testing::SetExperiments(NULL, 0); |
| 119 | } |
| 120 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 121 | TestingPrefService prefs_; |
| 122 | }; |
| 123 | |
| 124 | TEST_F(AboutFlagsTest, ChangeNeedsRestart) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 125 | EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 126 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 127 | EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
| 128 | } |
| 129 | |
| 130 | TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 131 | // Add two experiments, check they're there. |
| 132 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 133 | SetExperimentEnabled(&prefs_, kFlags2, true); |
| 134 | |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 135 | const ListValue* experiments_list = prefs_.GetList( |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 136 | prefs::kEnabledLabsExperiments); |
| 137 | ASSERT_TRUE(experiments_list != NULL); |
| 138 | |
| 139 | ASSERT_EQ(2u, experiments_list->GetSize()); |
| 140 | |
| 141 | std::string s0; |
| 142 | ASSERT_TRUE(experiments_list->GetString(0, &s0)); |
| 143 | std::string s1; |
| 144 | ASSERT_TRUE(experiments_list->GetString(1, &s1)); |
| 145 | |
| 146 | EXPECT_TRUE(s0 == kFlags1 || s1 == kFlags1); |
| 147 | EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2); |
| 148 | |
| 149 | // Remove one experiment, check the other's still around. |
| 150 | SetExperimentEnabled(&prefs_, kFlags2, false); |
| 151 | |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 152 | experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 153 | ASSERT_TRUE(experiments_list != NULL); |
| 154 | ASSERT_EQ(1u, experiments_list->GetSize()); |
| 155 | ASSERT_TRUE(experiments_list->GetString(0, &s0)); |
| 156 | EXPECT_TRUE(s0 == kFlags1); |
| 157 | } |
| 158 | |
| 159 | TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 160 | // Add two experiments, check the pref exists. |
| 161 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 162 | SetExperimentEnabled(&prefs_, kFlags2, true); |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 163 | const ListValue* experiments_list = prefs_.GetList( |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 164 | prefs::kEnabledLabsExperiments); |
| 165 | ASSERT_TRUE(experiments_list != NULL); |
| 166 | |
| 167 | // Remove both, the pref should have been removed completely. |
| 168 | SetExperimentEnabled(&prefs_, kFlags1, false); |
| 169 | SetExperimentEnabled(&prefs_, kFlags2, false); |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 170 | experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 171 | EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0); |
| 172 | } |
| 173 | |
| 174 | TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 175 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 176 | |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 177 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 178 | command_line.AppendSwitch("foo"); |
| 179 | |
| 180 | EXPECT_TRUE(command_line.HasSwitch("foo")); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 181 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 182 | |
| 183 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 184 | |
| 185 | EXPECT_TRUE(command_line.HasSwitch("foo")); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 186 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 190 | std::map<std::string, CommandLine::StringType> switch_list; |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 191 | switch_list[kSwitch1] = CommandLine::StringType(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 192 | switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); |
| 193 | switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); |
| 194 | switch_list["foo"] = CommandLine::StringType(); |
| 195 | |
| 196 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 197 | |
| 198 | // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. |
| 199 | RemoveFlagsSwitches(&switch_list); |
| 200 | ASSERT_EQ(4u, switch_list.size()); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 201 | EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end()); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 202 | EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) != |
| 203 | switch_list.end()); |
| 204 | EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) != |
| 205 | switch_list.end()); |
| 206 | EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 207 | |
| 208 | // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 209 | CommandLine command_line(CommandLine::NO_PROGRAM); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 210 | command_line.AppendSwitch("foo"); |
| 211 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 212 | RemoveFlagsSwitches(&switch_list); |
| 213 | |
| 214 | // Now the about:flags-related switch should have been removed. |
| 215 | ASSERT_EQ(1u, switch_list.size()); |
| 216 | EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 217 | } |
| 218 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 219 | // Tests enabling experiments that aren't supported on the current platform. |
| 220 | TEST_F(AboutFlagsTest, PersistAndPrune) { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 221 | // Enable experiments 1 and 3. |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 222 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 223 | SetExperimentEnabled(&prefs_, kFlags3, true); |
| 224 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 225 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 226 | EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 227 | |
| 228 | // Convert the flags to switches. Experiment 3 shouldn't be among the switches |
| 229 | // as it is not applicable to the current platform. |
| 230 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 231 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 232 | EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 233 | |
| 234 | // Experiment 3 should show still be persisted in preferences though. |
| 235 | scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 236 | ASSERT_TRUE(switch_prefs.get()); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 237 | EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
| 238 | } |
| 239 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 240 | // Tests that switches which should have values get them in the command |
| 241 | // line. |
| 242 | TEST_F(AboutFlagsTest, CheckValues) { |
| 243 | // Enable experiments 1 and 2. |
| 244 | SetExperimentEnabled(&prefs_, kFlags1, true); |
| 245 | SetExperimentEnabled(&prefs_, kFlags2, true); |
| 246 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 247 | EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 248 | EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 249 | |
| 250 | // Convert the flags to switches. |
| 251 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 252 | EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 253 | EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 254 | EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 255 | EXPECT_EQ(std::string(kValueForSwitch2), |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 256 | command_line.GetSwitchValueASCII(kSwitch2)); |
| 257 | |
| 258 | // Confirm that there is no '=' in the command line for simple switches. |
| 259 | std::string switch1_with_equals = std::string("--") + |
| 260 | std::string(kSwitch1) + |
| 261 | std::string("="); |
| 262 | #if defined(OS_WIN) |
| 263 | EXPECT_EQ(std::wstring::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 264 | command_line.GetCommandLineString().find( |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 265 | ASCIIToWide(switch1_with_equals))); |
| 266 | #else |
| 267 | EXPECT_EQ(std::string::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 268 | command_line.GetCommandLineString().find(switch1_with_equals)); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 269 | #endif |
| 270 | |
| 271 | // And confirm there is a '=' for switches with values. |
| 272 | std::string switch2_with_equals = std::string("--") + |
| 273 | std::string(kSwitch2) + |
| 274 | std::string("="); |
| 275 | #if defined(OS_WIN) |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 276 | EXPECT_NE(std::wstring::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 277 | command_line.GetCommandLineString().find( |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 278 | ASCIIToWide(switch2_with_equals))); |
| 279 | #else |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 280 | EXPECT_NE(std::string::npos, |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 281 | command_line.GetCommandLineString().find(switch2_with_equals)); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 282 | #endif |
| 283 | |
| 284 | // And it should persist |
| 285 | scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 286 | ASSERT_TRUE(switch_prefs.get()); |
| 287 | EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
| 288 | } |
| 289 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 290 | // Tests multi-value type experiments. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 291 | TEST_F(AboutFlagsTest, MultiValues) { |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 292 | // Initially, the first "deactivated" option of the multi experiment should |
| 293 | // be set. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 294 | { |
| 295 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 296 | ConvertFlagsToSwitches(&prefs_, &command_line); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 297 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 298 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 299 | } |
| 300 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 301 | // Enable the 2nd choice of the multi-value. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 302 | SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
| 303 | std::string(testing::kMultiSeparator) + |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 304 | base::IntToString(2), true); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 305 | { |
| 306 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 307 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 308 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
[email protected] | cd7fa99f | 2011-09-07 01:24:55 | [diff] [blame^] | 309 | EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); |
| 310 | EXPECT_EQ(std::string(kValueForMultiSwitch2), |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 311 | command_line.GetSwitchValueASCII(kMultiSwitch2)); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Disable the multi-value experiment. |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 315 | SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
| 316 | std::string(testing::kMultiSeparator) + |
| 317 | base::IntToString(0), true); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 318 | { |
| 319 | CommandLine command_line(CommandLine::NO_PROGRAM); |
| 320 | ConvertFlagsToSwitches(&prefs_, &command_line); |
| 321 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 322 | EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Makes sure there are no separators in any of the experiment names. |
| 327 | TEST_F(AboutFlagsTest, NoSeparators) { |
| 328 | testing::SetExperiments(NULL, 0); |
| 329 | size_t count; |
| 330 | const Experiment* experiments = testing::GetExperiments(&count); |
| 331 | for (size_t i = 0; i < count; ++i) { |
| 332 | std::string name = experiments->internal_name; |
| 333 | EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
| 334 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 337 | } // namespace about_flags |