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