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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 161 |
162 std::string FilePathStringTypeToString(const base::FilePath::StringType& path) { | 162 std::string FilePathStringTypeToString(const base::FilePath::StringType& path) { |
163 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
164 return base::UTF16ToUTF8(path); | 164 return base::UTF16ToUTF8(path); |
165 #else | 165 #else |
166 return path; | 166 return path; |
167 #endif | 167 #endif |
168 } | 168 } |
169 | 169 |
170 // Get all associated switches corresponding to defined about_flags.cc entries. | 170 // Get all associated switches corresponding to defined about_flags.cc entries. |
171 // Does not include information about FEATURE_VALUE or | 171 std::set<std::string> GetAllSwitchesAndFeaturesForTesting() { |
172 // FEATURE_WITH_VARIATIOSN_VALUE entries. | |
173 std::set<std::string> GetAllSwitchesForTesting() { | |
174 std::set<std::string> result; | 172 std::set<std::string> result; |
175 | 173 |
176 size_t num_entries = 0; | 174 size_t num_entries = 0; |
177 const flags_ui::FeatureEntry* entries = | 175 const flags_ui::FeatureEntry* entries = |
178 testing::GetFeatureEntries(&num_entries); | 176 testing::GetFeatureEntries(&num_entries); |
179 | 177 |
180 for (size_t i = 0; i < num_entries; ++i) { | 178 for (size_t i = 0; i < num_entries; ++i) { |
181 const flags_ui::FeatureEntry& entry = entries[i]; | 179 const flags_ui::FeatureEntry& entry = entries[i]; |
182 switch (entry.type) { | 180 switch (entry.type) { |
183 case flags_ui::FeatureEntry::SINGLE_VALUE: | 181 case flags_ui::FeatureEntry::SINGLE_VALUE: |
184 case flags_ui::FeatureEntry::SINGLE_DISABLE_VALUE: | 182 case flags_ui::FeatureEntry::SINGLE_DISABLE_VALUE: |
185 result.insert(entry.command_line_switch); | 183 result.insert(entry.command_line_switch); |
186 break; | 184 break; |
187 case flags_ui::FeatureEntry::MULTI_VALUE: | 185 case flags_ui::FeatureEntry::MULTI_VALUE: |
188 for (int j = 0; j < entry.num_options; ++j) { | 186 for (int j = 0; j < entry.num_options; ++j) { |
189 result.insert(entry.ChoiceForOption(j).command_line_switch); | 187 result.insert(entry.ChoiceForOption(j).command_line_switch); |
190 } | 188 } |
191 break; | 189 break; |
192 case flags_ui::FeatureEntry::ENABLE_DISABLE_VALUE: | 190 case flags_ui::FeatureEntry::ENABLE_DISABLE_VALUE: |
193 result.insert(entry.command_line_switch); | 191 result.insert(entry.command_line_switch); |
194 result.insert(entry.disable_command_line_switch); | 192 result.insert(entry.disable_command_line_switch); |
195 break; | 193 break; |
196 case flags_ui::FeatureEntry::FEATURE_VALUE: | 194 case flags_ui::FeatureEntry::FEATURE_VALUE: |
197 case flags_ui::FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE: | 195 case flags_ui::FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE: |
| 196 result.insert(std::string(entry.feature->name) + ":enabled"); |
| 197 result.insert(std::string(entry.feature->name) + ":disabled"); |
198 break; | 198 break; |
199 } | 199 } |
200 } | 200 } |
201 return result; | 201 return result; |
202 } | 202 } |
203 | 203 |
204 } // anonymous namespace | 204 } // anonymous namespace |
205 | 205 |
206 // Makes sure there are no separators in any of the entry names. | 206 // Makes sure there are no separators in any of the entry names. |
207 TEST(AboutFlagsTest, NoSeparators) { | 207 TEST(AboutFlagsTest, NoSeparators) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 EXPECT_EQ(uma_id, entry.first) | 276 EXPECT_EQ(uma_id, entry.first) |
277 << "histograms.xml enum LoginCustomFlags " | 277 << "histograms.xml enum LoginCustomFlags " |
278 "entry '" << entry.second << "' has incorrect value=" << entry.first | 278 "entry '" << entry.second << "' has incorrect value=" << entry.first |
279 << ", but " << uma_id << " is expected. Consider changing entry to:\n" | 279 << ", but " << uma_id << " is expected. Consider changing entry to:\n" |
280 << " " << GetHistogramEnumEntryText(entry.second, uma_id); | 280 << " " << GetHistogramEnumEntryText(entry.second, uma_id); |
281 SetSwitchToHistogramIdMapping(entry.second, entry.first, | 281 SetSwitchToHistogramIdMapping(entry.second, entry.first, |
282 &histograms_xml_switches_ids); | 282 &histograms_xml_switches_ids); |
283 } | 283 } |
284 | 284 |
285 // Check that all flags in about_flags.cc have entries in login_custom_flags. | 285 // Check that all flags in about_flags.cc have entries in login_custom_flags. |
286 std::set<std::string> all_switches = GetAllSwitchesForTesting(); | 286 std::set<std::string> all_flags = GetAllSwitchesAndFeaturesForTesting(); |
287 for (const std::string& flag : all_switches) { | 287 for (const std::string& flag : all_flags) { |
288 // Skip empty placeholders. | 288 // Skip empty placeholders. |
289 if (flag.empty()) | 289 if (flag.empty()) |
290 continue; | 290 continue; |
291 const Sample uma_id = GetSwitchUMAId(flag); | 291 const Sample uma_id = GetSwitchUMAId(flag); |
292 EXPECT_NE(testing::kBadSwitchFormatHistogramId, uma_id) | 292 EXPECT_NE(testing::kBadSwitchFormatHistogramId, uma_id) |
293 << "Command-line switch '" << flag | 293 << "Command-line switch '" << flag |
294 << "' from about_flags.cc has UMA ID equal to reserved value " | 294 << "' from about_flags.cc has UMA ID equal to reserved value " |
295 "kBadSwitchFormatHistogramId=" | 295 "kBadSwitchFormatHistogramId=" |
296 << testing::kBadSwitchFormatHistogramId | 296 << testing::kBadSwitchFormatHistogramId |
297 << ". Please modify switch name."; | 297 << ". Please modify switch name."; |
298 SwitchToIdMap::iterator enum_entry = | 298 SwitchToIdMap::iterator enum_entry = |
299 histograms_xml_switches_ids.lower_bound(flag); | 299 histograms_xml_switches_ids.lower_bound(flag); |
300 | 300 |
301 // Ignore case here when switch ID is incorrect - it has already been | 301 // Ignore case here when switch ID is incorrect - it has already been |
302 // reported in the previous loop. | 302 // reported in the previous loop. |
303 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && | 303 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && |
304 enum_entry->first == flag) | 304 enum_entry->first == flag) |
305 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" | 305 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" |
306 << flag << "' (value=" << uma_id | 306 << flag << "' (value=" << uma_id |
307 << " expected). Consider adding entry:\n" | 307 << " expected). Consider adding entry:\n" |
308 << " " << GetHistogramEnumEntryText(flag, uma_id); | 308 << " " << GetHistogramEnumEntryText(flag, uma_id); |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 } // namespace about_flags | 312 } // namespace about_flags |
OLD | NEW |