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

Side by Side Diff: chrome/browser/about_flags_unittest.cc

Issue 23983031: Owner flags storage should not save the flags names but the actual switches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/prefs/pref_registry_simple.h" 5 #include "base/prefs/pref_registry_simple.h"
6 #include "base/prefs/testing_pref_service.h" 6 #include "base/prefs/testing_pref_service.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/about_flags.h" 10 #include "chrome/browser/about_flags.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { 211 TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) {
212 SetExperimentEnabled(&flags_storage_, kFlags1, true); 212 SetExperimentEnabled(&flags_storage_, kFlags1, true);
213 213
214 CommandLine command_line(CommandLine::NO_PROGRAM); 214 CommandLine command_line(CommandLine::NO_PROGRAM);
215 command_line.AppendSwitch("foo"); 215 command_line.AppendSwitch("foo");
216 216
217 EXPECT_TRUE(command_line.HasSwitch("foo")); 217 EXPECT_TRUE(command_line.HasSwitch("foo"));
218 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 218 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
219 219
220 ConvertFlagsToSwitches(&flags_storage_, &command_line); 220 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
221 221
222 EXPECT_TRUE(command_line.HasSwitch("foo")); 222 EXPECT_TRUE(command_line.HasSwitch("foo"));
223 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); 223 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
224 EXPECT_TRUE(command_line.HasSwitch(switches::kFlagSwitchesBegin));
225 EXPECT_TRUE(command_line.HasSwitch(switches::kFlagSwitchesEnd));
226
227 CommandLine command_line2(CommandLine::NO_PROGRAM);
228
229 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels);
230
231 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
232 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
233 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
224 } 234 }
225 235
226 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { 236 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) {
227 SetExperimentEnabled(&flags_storage_, kFlags1, true); 237 SetExperimentEnabled(&flags_storage_, kFlags1, true);
228 238
229 CommandLine command_line(CommandLine::NO_PROGRAM); 239 CommandLine command_line(CommandLine::NO_PROGRAM);
230 command_line.AppendSwitch("foo"); 240 command_line.AppendSwitch("foo");
231 241
232 CommandLine new_command_line(CommandLine::NO_PROGRAM); 242 CommandLine new_command_line(CommandLine::NO_PROGRAM);
233 ConvertFlagsToSwitches(&flags_storage_, &new_command_line); 243 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels);
234 244
235 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 245 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line,
236 command_line)); 246 command_line));
237 247
238 ConvertFlagsToSwitches(&flags_storage_, &command_line); 248 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
239 249
240 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 250 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line,
241 command_line)); 251 command_line));
242 252
243 // Now both have flags but different. 253 // Now both have flags but different.
244 SetExperimentEnabled(&flags_storage_, kFlags1, false); 254 SetExperimentEnabled(&flags_storage_, kFlags1, false);
245 SetExperimentEnabled(&flags_storage_, kFlags2, true); 255 SetExperimentEnabled(&flags_storage_, kFlags2, true);
246 256
247 CommandLine another_command_line(CommandLine::NO_PROGRAM); 257 CommandLine another_command_line(CommandLine::NO_PROGRAM);
248 ConvertFlagsToSwitches(&flags_storage_, &another_command_line); 258 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels);
249 259
250 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 260 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line,
251 another_command_line)); 261 another_command_line));
252 } 262 }
253 263
254 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { 264 TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
255 std::map<std::string, CommandLine::StringType> switch_list; 265 std::map<std::string, CommandLine::StringType> switch_list;
256 switch_list[kSwitch1] = CommandLine::StringType(); 266 switch_list[kSwitch1] = CommandLine::StringType();
257 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); 267 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType();
258 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); 268 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType();
259 switch_list["foo"] = CommandLine::StringType(); 269 switch_list["foo"] = CommandLine::StringType();
260 270
261 SetExperimentEnabled(&flags_storage_, kFlags1, true); 271 SetExperimentEnabled(&flags_storage_, kFlags1, true);
262 272
263 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. 273 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called.
264 RemoveFlagsSwitches(&switch_list); 274 RemoveFlagsSwitches(&switch_list);
265 ASSERT_EQ(4u, switch_list.size()); 275 ASSERT_EQ(4u, switch_list.size());
266 EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end()); 276 EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end());
267 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) != 277 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) !=
268 switch_list.end()); 278 switch_list.end());
269 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) != 279 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) !=
270 switch_list.end()); 280 switch_list.end());
271 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); 281 EXPECT_TRUE(switch_list.find("foo") != switch_list.end());
272 282
273 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. 283 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again.
274 CommandLine command_line(CommandLine::NO_PROGRAM); 284 CommandLine command_line(CommandLine::NO_PROGRAM);
275 command_line.AppendSwitch("foo"); 285 command_line.AppendSwitch("foo");
276 ConvertFlagsToSwitches(&flags_storage_, &command_line); 286 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
277 RemoveFlagsSwitches(&switch_list); 287 RemoveFlagsSwitches(&switch_list);
278 288
279 // Now the about:flags-related switch should have been removed. 289 // Now the about:flags-related switch should have been removed.
280 ASSERT_EQ(1u, switch_list.size()); 290 ASSERT_EQ(1u, switch_list.size());
281 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); 291 EXPECT_TRUE(switch_list.find("foo") != switch_list.end());
282 } 292 }
283 293
284 // Tests enabling experiments that aren't supported on the current platform. 294 // Tests enabling experiments that aren't supported on the current platform.
285 TEST_F(AboutFlagsTest, PersistAndPrune) { 295 TEST_F(AboutFlagsTest, PersistAndPrune) {
286 // Enable experiments 1 and 3. 296 // Enable experiments 1 and 3.
287 SetExperimentEnabled(&flags_storage_, kFlags1, true); 297 SetExperimentEnabled(&flags_storage_, kFlags1, true);
288 SetExperimentEnabled(&flags_storage_, kFlags3, true); 298 SetExperimentEnabled(&flags_storage_, kFlags3, true);
289 CommandLine command_line(CommandLine::NO_PROGRAM); 299 CommandLine command_line(CommandLine::NO_PROGRAM);
290 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 300 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
291 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); 301 EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
292 302
293 // Convert the flags to switches. Experiment 3 shouldn't be among the switches 303 // Convert the flags to switches. Experiment 3 shouldn't be among the switches
294 // as it is not applicable to the current platform. 304 // as it is not applicable to the current platform.
295 ConvertFlagsToSwitches(&flags_storage_, &command_line); 305 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
296 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); 306 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
297 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); 307 EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
298 308
299 // Experiment 3 should show still be persisted in preferences though. 309 // Experiment 3 should show still be persisted in preferences though.
300 const ListValue* experiments_list = 310 const ListValue* experiments_list =
301 prefs_.GetList(prefs::kEnabledLabsExperiments); 311 prefs_.GetList(prefs::kEnabledLabsExperiments);
302 ASSERT_TRUE(experiments_list); 312 ASSERT_TRUE(experiments_list);
303 EXPECT_EQ(2U, experiments_list->GetSize()); 313 EXPECT_EQ(2U, experiments_list->GetSize());
304 std::string s0; 314 std::string s0;
305 ASSERT_TRUE(experiments_list->GetString(0, &s0)); 315 ASSERT_TRUE(experiments_list->GetString(0, &s0));
306 EXPECT_EQ(kFlags1, s0); 316 EXPECT_EQ(kFlags1, s0);
307 std::string s1; 317 std::string s1;
308 ASSERT_TRUE(experiments_list->GetString(1, &s1)); 318 ASSERT_TRUE(experiments_list->GetString(1, &s1));
309 EXPECT_EQ(kFlags3, s1); 319 EXPECT_EQ(kFlags3, s1);
310 } 320 }
311 321
312 // Tests that switches which should have values get them in the command 322 // Tests that switches which should have values get them in the command
313 // line. 323 // line.
314 TEST_F(AboutFlagsTest, CheckValues) { 324 TEST_F(AboutFlagsTest, CheckValues) {
315 // Enable experiments 1 and 2. 325 // Enable experiments 1 and 2.
316 SetExperimentEnabled(&flags_storage_, kFlags1, true); 326 SetExperimentEnabled(&flags_storage_, kFlags1, true);
317 SetExperimentEnabled(&flags_storage_, kFlags2, true); 327 SetExperimentEnabled(&flags_storage_, kFlags2, true);
318 CommandLine command_line(CommandLine::NO_PROGRAM); 328 CommandLine command_line(CommandLine::NO_PROGRAM);
319 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 329 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
320 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); 330 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
321 331
322 // Convert the flags to switches. 332 // Convert the flags to switches.
323 ConvertFlagsToSwitches(&flags_storage_, &command_line); 333 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
324 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); 334 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
325 EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1)); 335 EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1));
326 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); 336 EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
327 EXPECT_EQ(std::string(kValueForSwitch2), 337 EXPECT_EQ(std::string(kValueForSwitch2),
328 command_line.GetSwitchValueASCII(kSwitch2)); 338 command_line.GetSwitchValueASCII(kSwitch2));
329 339
330 // Confirm that there is no '=' in the command line for simple switches. 340 // Confirm that there is no '=' in the command line for simple switches.
331 std::string switch1_with_equals = std::string("--") + 341 std::string switch1_with_equals = std::string("--") +
332 std::string(kSwitch1) + 342 std::string(kSwitch1) +
333 std::string("="); 343 std::string("=");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 378
369 // Tests multi-value type experiments. 379 // Tests multi-value type experiments.
370 TEST_F(AboutFlagsTest, MultiValues) { 380 TEST_F(AboutFlagsTest, MultiValues) {
371 const Experiment& experiment = kExperiments[3]; 381 const Experiment& experiment = kExperiments[3];
372 ASSERT_EQ(kFlags4, experiment.internal_name); 382 ASSERT_EQ(kFlags4, experiment.internal_name);
373 383
374 // Initially, the first "deactivated" option of the multi experiment should 384 // Initially, the first "deactivated" option of the multi experiment should
375 // be set. 385 // be set.
376 { 386 {
377 CommandLine command_line(CommandLine::NO_PROGRAM); 387 CommandLine command_line(CommandLine::NO_PROGRAM);
378 ConvertFlagsToSwitches(&flags_storage_, &command_line); 388 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
379 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 389 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
380 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 390 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
381 } 391 }
382 392
383 // Enable the 2nd choice of the multi-value. 393 // Enable the 2nd choice of the multi-value.
384 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true); 394 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
385 { 395 {
386 CommandLine command_line(CommandLine::NO_PROGRAM); 396 CommandLine command_line(CommandLine::NO_PROGRAM);
387 ConvertFlagsToSwitches(&flags_storage_, &command_line); 397 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
388 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 398 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
389 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); 399 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2));
390 EXPECT_EQ(std::string(kValueForMultiSwitch2), 400 EXPECT_EQ(std::string(kValueForMultiSwitch2),
391 command_line.GetSwitchValueASCII(kMultiSwitch2)); 401 command_line.GetSwitchValueASCII(kMultiSwitch2));
392 } 402 }
393 403
394 // Disable the multi-value experiment. 404 // Disable the multi-value experiment.
395 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true); 405 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
396 { 406 {
397 CommandLine command_line(CommandLine::NO_PROGRAM); 407 CommandLine command_line(CommandLine::NO_PROGRAM);
398 ConvertFlagsToSwitches(&flags_storage_, &command_line); 408 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
399 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 409 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
400 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 410 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
401 } 411 }
402 } 412 }
403 413
404 TEST_F(AboutFlagsTest, EnableDisableValues) { 414 TEST_F(AboutFlagsTest, EnableDisableValues) {
405 const Experiment& experiment = kExperiments[4]; 415 const Experiment& experiment = kExperiments[4];
406 ASSERT_EQ(kFlags5, experiment.internal_name); 416 ASSERT_EQ(kFlags5, experiment.internal_name);
407 417
408 // Nothing selected. 418 // Nothing selected.
409 { 419 {
410 CommandLine command_line(CommandLine::NO_PROGRAM); 420 CommandLine command_line(CommandLine::NO_PROGRAM);
411 ConvertFlagsToSwitches(&flags_storage_, &command_line); 421 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
412 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 422 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
413 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); 423 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
414 } 424 }
415 425
416 // "Enable" option selected. 426 // "Enable" option selected.
417 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true); 427 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true);
418 { 428 {
419 CommandLine command_line(CommandLine::NO_PROGRAM); 429 CommandLine command_line(CommandLine::NO_PROGRAM);
420 ConvertFlagsToSwitches(&flags_storage_, &command_line); 430 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
421 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); 431 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
422 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); 432 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
423 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1)); 433 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
424 } 434 }
425 435
426 // "Disable" option selected. 436 // "Disable" option selected.
427 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true); 437 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
428 { 438 {
429 CommandLine command_line(CommandLine::NO_PROGRAM); 439 CommandLine command_line(CommandLine::NO_PROGRAM);
430 ConvertFlagsToSwitches(&flags_storage_, &command_line); 440 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
431 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); 441 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
432 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); 442 EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
433 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2)); 443 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
434 } 444 }
435 445
436 // "Default" option selected, same as nothing selected. 446 // "Default" option selected, same as nothing selected.
437 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true); 447 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
438 { 448 {
439 CommandLine command_line(CommandLine::NO_PROGRAM); 449 CommandLine command_line(CommandLine::NO_PROGRAM);
440 ConvertFlagsToSwitches(&flags_storage_, &command_line); 450 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
441 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); 451 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
442 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); 452 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
443 } 453 }
444 } 454 }
445 455
446 // Makes sure there are no separators in any of the experiment names. 456 // Makes sure there are no separators in any of the experiment names.
447 TEST_F(AboutFlagsTest, NoSeparators) { 457 TEST_F(AboutFlagsTest, NoSeparators) {
448 testing::SetExperiments(NULL, 0); 458 testing::SetExperiments(NULL, 0);
449 size_t count; 459 size_t count;
450 const Experiment* experiments = testing::GetExperiments(&count); 460 const Experiment* experiments = testing::GetExperiments(&count);
451 for (size_t i = 0; i < count; ++i) { 461 for (size_t i = 0; i < count; ++i) {
452 std::string name = experiments->internal_name; 462 std::string name = experiments->internal_name;
453 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; 463 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i;
454 } 464 }
455 } 465 }
456 466
457 } // namespace about_flags 467 } // namespace about_flags
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698