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 "chrome/browser/about_flags.h" | 5 #include "chrome/browser/about_flags.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/grit/chromium_strings.h" | 21 #include "chrome/grit/chromium_strings.h" |
22 #include "components/flags_ui/flags_ui_pref_names.h" | 22 #include "components/flags_ui/flags_ui_pref_names.h" |
23 #include "components/flags_ui/pref_service_flags_storage.h" | 23 #include "components/flags_ui/pref_service_flags_storage.h" |
24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/libxml/chromium/libxml_utils.h" | 26 #include "third_party/libxml/chromium/libxml_utils.h" |
27 | 27 |
| 28 using flags_ui::FeatureEntry; |
| 29 |
28 namespace about_flags { | 30 namespace about_flags { |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 const char kFlags1[] = "flag1"; | 34 const char kFlags1[] = "flag1"; |
33 const char kFlags2[] = "flag2"; | 35 const char kFlags2[] = "flag2"; |
34 const char kFlags3[] = "flag3"; | 36 const char kFlags3[] = "flag3"; |
35 const char kFlags4[] = "flag4"; | 37 const char kFlags4[] = "flag4"; |
36 const char kFlags5[] = "flag5"; | 38 const char kFlags5[] = "flag5"; |
37 const char kFlags6[] = "flag6"; | 39 const char kFlags6[] = "flag6"; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 cases[i].existing_enable_features); | 519 cases[i].existing_enable_features); |
518 } | 520 } |
519 if (cases[i].existing_disable_features) { | 521 if (cases[i].existing_disable_features) { |
520 command_line.AppendSwitchASCII(switches::kDisableFeatures, | 522 command_line.AppendSwitchASCII(switches::kDisableFeatures, |
521 cases[i].existing_disable_features); | 523 cases[i].existing_disable_features); |
522 } | 524 } |
523 | 525 |
524 testing::ClearState(); | 526 testing::ClearState(); |
525 | 527 |
526 const std::string entry_name = base::StringPrintf( | 528 const std::string entry_name = base::StringPrintf( |
527 "%s%s%d", kFlags7, testing::kMultiSeparator, cases[i].enabled_choice); | 529 "%s%s%d", kFlags7, flags_ui::testing::kMultiSeparator, |
| 530 cases[i].enabled_choice); |
528 SetFeatureEntryEnabled(&flags_storage_, entry_name, true); | 531 SetFeatureEntryEnabled(&flags_storage_, entry_name, true); |
529 | 532 |
530 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 533 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
531 auto switch_list = command_line.GetSwitches(); | 534 auto switch_list = command_line.GetSwitches(); |
532 EXPECT_EQ(cases[i].expected_enable_features != nullptr, | 535 EXPECT_EQ(cases[i].expected_enable_features != nullptr, |
533 ContainsKey(switch_list, switches::kEnableFeatures)); | 536 ContainsKey(switch_list, switches::kEnableFeatures)); |
534 if (cases[i].expected_enable_features) | 537 if (cases[i].expected_enable_features) |
535 EXPECT_EQ(CreateSwitch(cases[i].expected_enable_features), | 538 EXPECT_EQ(CreateSwitch(cases[i].expected_enable_features), |
536 switch_list[switches::kEnableFeatures]); | 539 switch_list[switches::kEnableFeatures]); |
537 | 540 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 805 } |
803 } | 806 } |
804 | 807 |
805 // Makes sure there are no separators in any of the entry names. | 808 // Makes sure there are no separators in any of the entry names. |
806 TEST_F(AboutFlagsTest, NoSeparators) { | 809 TEST_F(AboutFlagsTest, NoSeparators) { |
807 testing::SetFeatureEntries(nullptr, 0); | 810 testing::SetFeatureEntries(nullptr, 0); |
808 size_t count; | 811 size_t count; |
809 const FeatureEntry* entries = testing::GetFeatureEntries(&count); | 812 const FeatureEntry* entries = testing::GetFeatureEntries(&count); |
810 for (size_t i = 0; i < count; ++i) { | 813 for (size_t i = 0; i < count; ++i) { |
811 std::string name = entries[i].internal_name; | 814 std::string name = entries[i].internal_name; |
812 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 815 EXPECT_EQ(std::string::npos, name.find(flags_ui::testing::kMultiSeparator)) |
| 816 << i; |
813 } | 817 } |
814 } | 818 } |
815 | 819 |
816 class AboutFlagsHistogramTest : public ::testing::Test { | 820 class AboutFlagsHistogramTest : public ::testing::Test { |
817 protected: | 821 protected: |
818 // This is a helper function to check that all IDs in enum LoginCustomFlags in | 822 // This is a helper function to check that all IDs in enum LoginCustomFlags in |
819 // histograms.xml are unique. | 823 // histograms.xml are unique. |
820 void SetSwitchToHistogramIdMapping(const std::string& switch_name, | 824 void SetSwitchToHistogramIdMapping(const std::string& switch_name, |
821 const Sample switch_histogram_id, | 825 const Sample switch_histogram_id, |
822 std::map<std::string, Sample>* out_map) { | 826 std::map<std::string, Sample>* out_map) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && | 906 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && |
903 enum_entry->first == flag) | 907 enum_entry->first == flag) |
904 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" | 908 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" |
905 << flag << "' (value=" << uma_id | 909 << flag << "' (value=" << uma_id |
906 << " expected). Consider adding entry:\n" | 910 << " expected). Consider adding entry:\n" |
907 << " " << GetHistogramEnumEntryText(flag, uma_id); | 911 << " " << GetHistogramEnumEntryText(flag, uma_id); |
908 } | 912 } |
909 } | 913 } |
910 | 914 |
911 } // namespace about_flags | 915 } // namespace about_flags |
OLD | NEW |