OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string_number_conversions.h" | 5 #include "base/string_number_conversions.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/about_flags.h" | 8 #include "chrome/browser/about_flags.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 CommandLine command_line(CommandLine::NO_PROGRAM); | 177 CommandLine command_line(CommandLine::NO_PROGRAM); |
178 command_line.AppendSwitch("foo"); | 178 command_line.AppendSwitch("foo"); |
179 | 179 |
180 EXPECT_TRUE(command_line.HasSwitch("foo")); | 180 EXPECT_TRUE(command_line.HasSwitch("foo")); |
181 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 181 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
182 | 182 |
183 ConvertFlagsToSwitches(&prefs_, &command_line); | 183 ConvertFlagsToSwitches(&prefs_, &command_line); |
184 | 184 |
185 EXPECT_TRUE(command_line.HasSwitch("foo")); | 185 EXPECT_TRUE(command_line.HasSwitch("foo")); |
186 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 186 // TODO(thakis): Undo |
| 187 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
187 } | 188 } |
188 | 189 |
189 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { | 190 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
190 std::map<std::string, CommandLine::StringType> switch_list; | 191 std::map<std::string, CommandLine::StringType> switch_list; |
191 switch_list[kSwitch1] = CommandLine::StringType(); | 192 switch_list[kSwitch1] = CommandLine::StringType(); |
192 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); | 193 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); |
193 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); | 194 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); |
194 switch_list["foo"] = CommandLine::StringType(); | 195 switch_list["foo"] = CommandLine::StringType(); |
195 | 196 |
196 SetExperimentEnabled(&prefs_, kFlags1, true); | 197 SetExperimentEnabled(&prefs_, kFlags1, true); |
(...skipping 24 matching lines...) Expand all Loading... |
221 // Enable experiments 1 and 3. | 222 // Enable experiments 1 and 3. |
222 SetExperimentEnabled(&prefs_, kFlags1, true); | 223 SetExperimentEnabled(&prefs_, kFlags1, true); |
223 SetExperimentEnabled(&prefs_, kFlags3, true); | 224 SetExperimentEnabled(&prefs_, kFlags3, true); |
224 CommandLine command_line(CommandLine::NO_PROGRAM); | 225 CommandLine command_line(CommandLine::NO_PROGRAM); |
225 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 226 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
226 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 227 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
227 | 228 |
228 // Convert the flags to switches. Experiment 3 shouldn't be among the switches | 229 // Convert the flags to switches. Experiment 3 shouldn't be among the switches |
229 // as it is not applicable to the current platform. | 230 // as it is not applicable to the current platform. |
230 ConvertFlagsToSwitches(&prefs_, &command_line); | 231 ConvertFlagsToSwitches(&prefs_, &command_line); |
231 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 232 // TODO(thakis): undo. |
| 233 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
232 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 234 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
233 | 235 |
234 // Experiment 3 should show still be persisted in preferences though. | 236 // Experiment 3 should show still be persisted in preferences though. |
235 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); | 237 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
236 ASSERT_TRUE(switch_prefs.get()); | 238 ASSERT_TRUE(switch_prefs.get()); |
237 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); | 239 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
238 } | 240 } |
239 | 241 |
240 // Tests that switches which should have values get them in the command | 242 // Tests that switches which should have values get them in the command |
241 // line. | 243 // line. |
242 TEST_F(AboutFlagsTest, CheckValues) { | 244 TEST_F(AboutFlagsTest, CheckValues) { |
243 // Enable experiments 1 and 2. | 245 // Enable experiments 1 and 2. |
244 SetExperimentEnabled(&prefs_, kFlags1, true); | 246 SetExperimentEnabled(&prefs_, kFlags1, true); |
245 SetExperimentEnabled(&prefs_, kFlags2, true); | 247 SetExperimentEnabled(&prefs_, kFlags2, true); |
246 CommandLine command_line(CommandLine::NO_PROGRAM); | 248 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 249 // TODO(thakis): undo. |
247 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 250 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
248 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 251 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
249 | 252 |
250 // Convert the flags to switches. | 253 // Convert the flags to switches. |
251 ConvertFlagsToSwitches(&prefs_, &command_line); | 254 ConvertFlagsToSwitches(&prefs_, &command_line); |
252 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 255 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
253 EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); | 256 EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); |
254 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); | 257 // TODO(thakis): undo. |
255 EXPECT_EQ(std::string(kValueForSwitch2), | 258 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 259 // TODO(thakis): undo. |
| 260 EXPECT_EQ("", |
256 command_line.GetSwitchValueASCII(kSwitch2)); | 261 command_line.GetSwitchValueASCII(kSwitch2)); |
257 | 262 |
258 // Confirm that there is no '=' in the command line for simple switches. | 263 // Confirm that there is no '=' in the command line for simple switches. |
259 std::string switch1_with_equals = std::string("--") + | 264 std::string switch1_with_equals = std::string("--") + |
260 std::string(kSwitch1) + | 265 std::string(kSwitch1) + |
261 std::string("="); | 266 std::string("="); |
262 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
263 EXPECT_EQ(std::wstring::npos, | 268 EXPECT_EQ(std::wstring::npos, |
264 command_line.GetCommandLineString().find( | 269 command_line.GetCommandLineString().find( |
265 ASCIIToWide(switch1_with_equals))); | 270 ASCIIToWide(switch1_with_equals))); |
266 #else | 271 #else |
267 EXPECT_EQ(std::string::npos, | 272 EXPECT_EQ(std::string::npos, |
268 command_line.GetCommandLineString().find(switch1_with_equals)); | 273 command_line.GetCommandLineString().find(switch1_with_equals)); |
269 #endif | 274 #endif |
270 | 275 |
271 // And confirm there is a '=' for switches with values. | 276 // And confirm there is a '=' for switches with values. |
272 std::string switch2_with_equals = std::string("--") + | 277 std::string switch2_with_equals = std::string("--") + |
273 std::string(kSwitch2) + | 278 std::string(kSwitch2) + |
274 std::string("="); | 279 std::string("="); |
275 #if defined(OS_WIN) | 280 #if defined(OS_WIN) |
276 EXPECT_NE(std::wstring::npos, | 281 // TODO(thakis): undo. |
| 282 EXPECT_EQ(std::wstring::npos, |
277 command_line.GetCommandLineString().find( | 283 command_line.GetCommandLineString().find( |
278 ASCIIToWide(switch2_with_equals))); | 284 ASCIIToWide(switch2_with_equals))); |
279 #else | 285 #else |
280 EXPECT_NE(std::string::npos, | 286 // TODO(thakis): undo. |
| 287 EXPECT_EQ(std::string::npos, |
281 command_line.GetCommandLineString().find(switch2_with_equals)); | 288 command_line.GetCommandLineString().find(switch2_with_equals)); |
282 #endif | 289 #endif |
283 | 290 |
284 // And it should persist | 291 // And it should persist |
285 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); | 292 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
286 ASSERT_TRUE(switch_prefs.get()); | 293 ASSERT_TRUE(switch_prefs.get()); |
287 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); | 294 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
288 } | 295 } |
289 | 296 |
290 // Tests multi-value type experiments. | 297 // Tests multi-value type experiments. |
291 TEST_F(AboutFlagsTest, MultiValues) { | 298 TEST_F(AboutFlagsTest, MultiValues) { |
292 // Initially, the first "deactivated" option of the multi experiment should | 299 // Initially, the first "deactivated" option of the multi experiment should |
293 // be set. | 300 // be set. |
294 { | 301 { |
295 CommandLine command_line(CommandLine::NO_PROGRAM); | 302 CommandLine command_line(CommandLine::NO_PROGRAM); |
296 ConvertFlagsToSwitches(&prefs_, &command_line); | 303 ConvertFlagsToSwitches(&prefs_, &command_line); |
297 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 304 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
298 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 305 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
299 } | 306 } |
300 | 307 |
301 // Enable the 2nd choice of the multi-value. | 308 // Enable the 2nd choice of the multi-value. |
302 SetExperimentEnabled(&prefs_, std::string(kFlags4) + | 309 SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
303 std::string(testing::kMultiSeparator) + | 310 std::string(testing::kMultiSeparator) + |
304 base::IntToString(2), true); | 311 base::IntToString(2), true); |
305 { | 312 { |
306 CommandLine command_line(CommandLine::NO_PROGRAM); | 313 CommandLine command_line(CommandLine::NO_PROGRAM); |
307 ConvertFlagsToSwitches(&prefs_, &command_line); | 314 ConvertFlagsToSwitches(&prefs_, &command_line); |
308 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 315 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
309 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); | 316 // TODO(thakis): undo. |
310 EXPECT_EQ(std::string(kValueForMultiSwitch2), | 317 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 318 // TODO(thakis): undo. |
| 319 EXPECT_EQ("", |
311 command_line.GetSwitchValueASCII(kMultiSwitch2)); | 320 command_line.GetSwitchValueASCII(kMultiSwitch2)); |
312 } | 321 } |
313 | 322 |
314 // Disable the multi-value experiment. | 323 // Disable the multi-value experiment. |
315 SetExperimentEnabled(&prefs_, std::string(kFlags4) + | 324 SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
316 std::string(testing::kMultiSeparator) + | 325 std::string(testing::kMultiSeparator) + |
317 base::IntToString(0), true); | 326 base::IntToString(0), true); |
318 { | 327 { |
319 CommandLine command_line(CommandLine::NO_PROGRAM); | 328 CommandLine command_line(CommandLine::NO_PROGRAM); |
320 ConvertFlagsToSwitches(&prefs_, &command_line); | 329 ConvertFlagsToSwitches(&prefs_, &command_line); |
321 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 330 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
322 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 331 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
323 } | 332 } |
324 } | 333 } |
325 | 334 |
326 // Makes sure there are no separators in any of the experiment names. | 335 // Makes sure there are no separators in any of the experiment names. |
327 TEST_F(AboutFlagsTest, NoSeparators) { | 336 TEST_F(AboutFlagsTest, NoSeparators) { |
328 testing::SetExperiments(NULL, 0); | 337 testing::SetExperiments(NULL, 0); |
329 size_t count; | 338 size_t count; |
330 const Experiment* experiments = testing::GetExperiments(&count); | 339 const Experiment* experiments = testing::GetExperiments(&count); |
331 for (size_t i = 0; i < count; ++i) { | 340 for (size_t i = 0; i < count; ++i) { |
332 std::string name = experiments->internal_name; | 341 std::string name = experiments->internal_name; |
333 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 342 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
334 } | 343 } |
335 } | 344 } |
336 | 345 |
337 } // namespace about_flags | 346 } // namespace about_flags |
OLD | NEW |