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