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

Side by Side Diff: components/flags_ui/flags_state_unittest.cc

Issue 2231753002: components: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more call site Created 4 years, 4 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
« no previous file with comments | « components/flags_ui/flags_state.cc ('k') | components/guest_view/browser/guest_view_manager.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/flags_ui/flags_state.h" 5 #include "components/flags_ui/flags_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 switch_list[kSwitch1] = base::CommandLine::StringType(); 402 switch_list[kSwitch1] = base::CommandLine::StringType();
403 switch_list[switches::kFlagSwitchesBegin] = base::CommandLine::StringType(); 403 switch_list[switches::kFlagSwitchesBegin] = base::CommandLine::StringType();
404 switch_list[switches::kFlagSwitchesEnd] = base::CommandLine::StringType(); 404 switch_list[switches::kFlagSwitchesEnd] = base::CommandLine::StringType();
405 switch_list["foo"] = base::CommandLine::StringType(); 405 switch_list["foo"] = base::CommandLine::StringType();
406 406
407 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); 407 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true);
408 408
409 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. 409 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called.
410 flags_state_->RemoveFlagsSwitches(&switch_list); 410 flags_state_->RemoveFlagsSwitches(&switch_list);
411 ASSERT_EQ(4u, switch_list.size()); 411 ASSERT_EQ(4u, switch_list.size());
412 EXPECT_TRUE(ContainsKey(switch_list, kSwitch1)); 412 EXPECT_TRUE(base::ContainsKey(switch_list, kSwitch1));
413 EXPECT_TRUE(ContainsKey(switch_list, switches::kFlagSwitchesBegin)); 413 EXPECT_TRUE(base::ContainsKey(switch_list, switches::kFlagSwitchesBegin));
414 EXPECT_TRUE(ContainsKey(switch_list, switches::kFlagSwitchesEnd)); 414 EXPECT_TRUE(base::ContainsKey(switch_list, switches::kFlagSwitchesEnd));
415 EXPECT_TRUE(ContainsKey(switch_list, "foo")); 415 EXPECT_TRUE(base::ContainsKey(switch_list, "foo"));
416 416
417 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. 417 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again.
418 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 418 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
419 command_line.AppendSwitch("foo"); 419 command_line.AppendSwitch("foo");
420 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 420 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
421 kAddSentinels, kEnableFeatures, 421 kAddSentinels, kEnableFeatures,
422 kDisableFeatures); 422 kDisableFeatures);
423 flags_state_->RemoveFlagsSwitches(&switch_list); 423 flags_state_->RemoveFlagsSwitches(&switch_list);
424 424
425 // Now the about:flags-related switch should have been removed. 425 // Now the about:flags-related switch should have been removed.
426 ASSERT_EQ(1u, switch_list.size()); 426 ASSERT_EQ(1u, switch_list.size());
427 EXPECT_TRUE(ContainsKey(switch_list, "foo")); 427 EXPECT_TRUE(base::ContainsKey(switch_list, "foo"));
428 } 428 }
429 429
430 TEST_F(FlagsStateTest, RemoveFlagSwitches_Features) { 430 TEST_F(FlagsStateTest, RemoveFlagSwitches_Features) {
431 struct { 431 struct {
432 int enabled_choice; // 0: default, 1: enabled, 2: disabled. 432 int enabled_choice; // 0: default, 1: enabled, 2: disabled.
433 const char* existing_enable_features; 433 const char* existing_enable_features;
434 const char* existing_disable_features; 434 const char* existing_disable_features;
435 const char* expected_enable_features; 435 const char* expected_enable_features;
436 const char* expected_disable_features; 436 const char* expected_disable_features;
437 } cases[] = { 437 } cases[] = {
(...skipping 30 matching lines...) Expand all
468 468
469 const std::string entry_name = base::StringPrintf( 469 const std::string entry_name = base::StringPrintf(
470 "%s%s%d", kFlags7, testing::kMultiSeparator, cases[i].enabled_choice); 470 "%s%s%d", kFlags7, testing::kMultiSeparator, cases[i].enabled_choice);
471 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry_name, true); 471 flags_state_->SetFeatureEntryEnabled(&flags_storage_, entry_name, true);
472 472
473 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line, 473 flags_state_->ConvertFlagsToSwitches(&flags_storage_, &command_line,
474 kAddSentinels, kEnableFeatures, 474 kAddSentinels, kEnableFeatures,
475 kDisableFeatures); 475 kDisableFeatures);
476 auto switch_list = command_line.GetSwitches(); 476 auto switch_list = command_line.GetSwitches();
477 EXPECT_EQ(cases[i].expected_enable_features != nullptr, 477 EXPECT_EQ(cases[i].expected_enable_features != nullptr,
478 ContainsKey(switch_list, kEnableFeatures)); 478 base::ContainsKey(switch_list, kEnableFeatures));
479 if (cases[i].expected_enable_features) 479 if (cases[i].expected_enable_features)
480 EXPECT_EQ(CreateSwitch(cases[i].expected_enable_features), 480 EXPECT_EQ(CreateSwitch(cases[i].expected_enable_features),
481 switch_list[kEnableFeatures]); 481 switch_list[kEnableFeatures]);
482 482
483 EXPECT_EQ(cases[i].expected_disable_features != nullptr, 483 EXPECT_EQ(cases[i].expected_disable_features != nullptr,
484 ContainsKey(switch_list, kDisableFeatures)); 484 base::ContainsKey(switch_list, kDisableFeatures));
485 if (cases[i].expected_disable_features) 485 if (cases[i].expected_disable_features)
486 EXPECT_EQ(CreateSwitch(cases[i].expected_disable_features), 486 EXPECT_EQ(CreateSwitch(cases[i].expected_disable_features),
487 switch_list[kDisableFeatures]); 487 switch_list[kDisableFeatures]);
488 488
489 // RemoveFlagsSwitches() should result in the original values for these 489 // RemoveFlagsSwitches() should result in the original values for these
490 // switches. 490 // switches.
491 switch_list = command_line.GetSwitches(); 491 switch_list = command_line.GetSwitches();
492 flags_state_->RemoveFlagsSwitches(&switch_list); 492 flags_state_->RemoveFlagsSwitches(&switch_list);
493 EXPECT_EQ(cases[i].existing_enable_features != nullptr, 493 EXPECT_EQ(cases[i].existing_enable_features != nullptr,
494 ContainsKey(switch_list, kEnableFeatures)); 494 base::ContainsKey(switch_list, kEnableFeatures));
495 if (cases[i].existing_enable_features) 495 if (cases[i].existing_enable_features)
496 EXPECT_EQ(CreateSwitch(cases[i].existing_enable_features), 496 EXPECT_EQ(CreateSwitch(cases[i].existing_enable_features),
497 switch_list[kEnableFeatures]); 497 switch_list[kEnableFeatures]);
498 EXPECT_EQ(cases[i].existing_disable_features != nullptr, 498 EXPECT_EQ(cases[i].existing_disable_features != nullptr,
499 ContainsKey(switch_list, kEnableFeatures)); 499 base::ContainsKey(switch_list, kEnableFeatures));
500 if (cases[i].existing_disable_features) 500 if (cases[i].existing_disable_features)
501 EXPECT_EQ(CreateSwitch(cases[i].existing_disable_features), 501 EXPECT_EQ(CreateSwitch(cases[i].existing_disable_features),
502 switch_list[kDisableFeatures]); 502 switch_list[kDisableFeatures]);
503 } 503 }
504 } 504 }
505 505
506 // Tests enabling entries that aren't supported on the current platform. 506 // Tests enabling entries that aren't supported on the current platform.
507 TEST_F(FlagsStateTest, PersistAndPrune) { 507 TEST_F(FlagsStateTest, PersistAndPrune) {
508 // Enable entries 1 and 3. 508 // Enable entries 1 and 3.
509 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true); 509 flags_state_->SetFeatureEntryEnabled(&flags_storage_, kFlags1, true);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 &supported_entries, &unsupported_entries, 781 &supported_entries, &unsupported_entries,
782 base::Bind(&SkipFeatureEntry)); 782 base::Bind(&SkipFeatureEntry));
783 // All |kEntries| except for |kFlags3| should be supported. 783 // All |kEntries| except for |kFlags3| should be supported.
784 EXPECT_EQ(7u, supported_entries.GetSize()); 784 EXPECT_EQ(7u, supported_entries.GetSize());
785 EXPECT_EQ(1u, unsupported_entries.GetSize()); 785 EXPECT_EQ(1u, unsupported_entries.GetSize());
786 EXPECT_EQ(arraysize(kEntries), 786 EXPECT_EQ(arraysize(kEntries),
787 supported_entries.GetSize() + unsupported_entries.GetSize()); 787 supported_entries.GetSize() + unsupported_entries.GetSize());
788 } 788 }
789 789
790 } // namespace flags_ui 790 } // namespace flags_ui
OLDNEW
« no previous file with comments | « components/flags_ui/flags_state.cc ('k') | components/guest_view/browser/guest_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698