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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/stl_util.h" | |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
22 #include "components/flags_ui/feature_entry.h" | 23 #include "components/flags_ui/feature_entry.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/libxml/chromium/libxml_utils.h" | 25 #include "third_party/libxml/chromium/libxml_utils.h" |
25 | 26 |
26 namespace about_flags { | 27 namespace about_flags { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 std::string FilePathStringTypeToString(const base::FilePath::StringType& path) { | 163 std::string FilePathStringTypeToString(const base::FilePath::StringType& path) { |
163 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
164 return base::UTF16ToUTF8(path); | 165 return base::UTF16ToUTF8(path); |
165 #else | 166 #else |
166 return path; | 167 return path; |
167 #endif | 168 #endif |
168 } | 169 } |
169 | 170 |
170 // Get all associated switches corresponding to defined about_flags.cc entries. | 171 // Get all associated switches corresponding to defined about_flags.cc entries. |
171 // Does not include information about FEATURE_VALUE or | 172 // Does not include information about FEATURE_VALUE or |
172 // FEATURE_WITH_VARIATIOSN_VALUE entries. | 173 // FEATURE_WITH_VARIATIONS_VALUE entries. |
173 std::set<std::string> GetAllSwitchesForTesting() { | 174 std::set<std::string> GetAllSwitchesForTesting() { |
174 std::set<std::string> result; | 175 std::set<std::string> result; |
175 | 176 |
176 size_t num_entries = 0; | 177 size_t num_entries = 0; |
177 const flags_ui::FeatureEntry* entries = | 178 const flags_ui::FeatureEntry* entries = |
178 testing::GetFeatureEntries(&num_entries); | 179 testing::GetFeatureEntries(&num_entries); |
179 | 180 |
180 for (size_t i = 0; i < num_entries; ++i) { | 181 for (size_t i = 0; i < num_entries; ++i) { |
181 const flags_ui::FeatureEntry& entry = entries[i]; | 182 const flags_ui::FeatureEntry& entry = entries[i]; |
182 switch (entry.type) { | 183 switch (entry.type) { |
(...skipping 11 matching lines...) Expand all Loading... | |
194 result.insert(entry.disable_command_line_switch); | 195 result.insert(entry.disable_command_line_switch); |
195 break; | 196 break; |
196 case flags_ui::FeatureEntry::FEATURE_VALUE: | 197 case flags_ui::FeatureEntry::FEATURE_VALUE: |
197 case flags_ui::FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE: | 198 case flags_ui::FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE: |
198 break; | 199 break; |
199 } | 200 } |
200 } | 201 } |
201 return result; | 202 return result; |
202 } | 203 } |
203 | 204 |
205 // Get all associated features corresponding to defined about_flags.cc entries. | |
206 // Does not include information about FEATURE_WITH_VARIATIONS_VALUE entries. | |
207 std::set<std::string> GetAllFeaturesForTesting() { | |
208 std::set<std::string> result; | |
209 | |
210 size_t num_entries = 0; | |
211 const flags_ui::FeatureEntry* entries = | |
212 testing::GetFeatureEntries(&num_entries); | |
213 | |
214 for (size_t i = 0; i < num_entries; ++i) { | |
215 const flags_ui::FeatureEntry& entry = entries[i]; | |
216 | |
217 std::string enabled_feature; | |
218 std::string disabled_feature; | |
219 switch (entry.type) { | |
220 case flags_ui::FeatureEntry::FEATURE_VALUE: | |
221 enabled_feature.append(entry.feature->name); | |
222 enabled_feature.append(":enabled"); | |
223 disabled_feature.append(entry.feature->name); | |
224 disabled_feature.append(":disabled"); | |
Alexei Svitkine (slow)
2016/09/16 15:52:39
Just inline all of this into the .insert() call an
lawrencewu
2016/09/16 17:12:57
Done.
| |
225 result.insert(enabled_feature); | |
226 result.insert(disabled_feature); | |
227 break; | |
228 case flags_ui::FeatureEntry::SINGLE_VALUE: | |
229 case flags_ui::FeatureEntry::SINGLE_DISABLE_VALUE: | |
230 case flags_ui::FeatureEntry::MULTI_VALUE: | |
231 case flags_ui::FeatureEntry::ENABLE_DISABLE_VALUE: | |
232 case flags_ui::FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE: | |
233 break; | |
234 } | |
235 } | |
236 return result; | |
237 } | |
238 | |
204 } // anonymous namespace | 239 } // anonymous namespace |
205 | 240 |
206 // Makes sure there are no separators in any of the entry names. | 241 // Makes sure there are no separators in any of the entry names. |
207 TEST(AboutFlagsTest, NoSeparators) { | 242 TEST(AboutFlagsTest, NoSeparators) { |
208 size_t count; | 243 size_t count; |
209 const flags_ui::FeatureEntry* entries = testing::GetFeatureEntries(&count); | 244 const flags_ui::FeatureEntry* entries = testing::GetFeatureEntries(&count); |
210 for (size_t i = 0; i < count; ++i) { | 245 for (size_t i = 0; i < count; ++i) { |
211 std::string name = entries[i].internal_name; | 246 std::string name = entries[i].internal_name; |
212 EXPECT_EQ(std::string::npos, name.find(flags_ui::testing::kMultiSeparator)) | 247 EXPECT_EQ(std::string::npos, name.find(flags_ui::testing::kMultiSeparator)) |
213 << i; | 248 << i; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 << "histograms.xml enum LoginCustomFlags " | 312 << "histograms.xml enum LoginCustomFlags " |
278 "entry '" << entry.second << "' has incorrect value=" << entry.first | 313 "entry '" << entry.second << "' has incorrect value=" << entry.first |
279 << ", but " << uma_id << " is expected. Consider changing entry to:\n" | 314 << ", but " << uma_id << " is expected. Consider changing entry to:\n" |
280 << " " << GetHistogramEnumEntryText(entry.second, uma_id); | 315 << " " << GetHistogramEnumEntryText(entry.second, uma_id); |
281 SetSwitchToHistogramIdMapping(entry.second, entry.first, | 316 SetSwitchToHistogramIdMapping(entry.second, entry.first, |
282 &histograms_xml_switches_ids); | 317 &histograms_xml_switches_ids); |
283 } | 318 } |
284 | 319 |
285 // Check that all flags in about_flags.cc have entries in login_custom_flags. | 320 // Check that all flags in about_flags.cc have entries in login_custom_flags. |
286 std::set<std::string> all_switches = GetAllSwitchesForTesting(); | 321 std::set<std::string> all_switches = GetAllSwitchesForTesting(); |
287 for (const std::string& flag : all_switches) { | 322 std::set<std::string> all_features = GetAllFeaturesForTesting(); |
323 std::set<std::string> all_flags = base::STLSetUnion<std::set<std::string>>( | |
324 all_switches, | |
325 all_features); | |
Alexei Svitkine (slow)
2016/09/16 15:52:39
Given the test just wants this final merged list a
lawrencewu
2016/09/16 17:12:57
Done.
| |
326 for (const std::string& flag : all_flags) { | |
288 // Skip empty placeholders. | 327 // Skip empty placeholders. |
289 if (flag.empty()) | 328 if (flag.empty()) |
290 continue; | 329 continue; |
291 const Sample uma_id = GetSwitchUMAId(flag); | 330 const Sample uma_id = GetSwitchUMAId(flag); |
292 EXPECT_NE(testing::kBadSwitchFormatHistogramId, uma_id) | 331 EXPECT_NE(testing::kBadSwitchFormatHistogramId, uma_id) |
293 << "Command-line switch '" << flag | 332 << "Command-line switch '" << flag |
294 << "' from about_flags.cc has UMA ID equal to reserved value " | 333 << "' from about_flags.cc has UMA ID equal to reserved value " |
295 "kBadSwitchFormatHistogramId=" | 334 "kBadSwitchFormatHistogramId=" |
296 << testing::kBadSwitchFormatHistogramId | 335 << testing::kBadSwitchFormatHistogramId |
297 << ". Please modify switch name."; | 336 << ". Please modify switch name."; |
298 SwitchToIdMap::iterator enum_entry = | 337 SwitchToIdMap::iterator enum_entry = |
299 histograms_xml_switches_ids.lower_bound(flag); | 338 histograms_xml_switches_ids.lower_bound(flag); |
300 | 339 |
301 // Ignore case here when switch ID is incorrect - it has already been | 340 // Ignore case here when switch ID is incorrect - it has already been |
302 // reported in the previous loop. | 341 // reported in the previous loop. |
303 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && | 342 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && |
304 enum_entry->first == flag) | 343 enum_entry->first == flag) |
305 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" | 344 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" |
306 << flag << "' (value=" << uma_id | 345 << flag << "' (value=" << uma_id |
307 << " expected). Consider adding entry:\n" | 346 << " expected). Consider adding entry:\n" |
308 << " " << GetHistogramEnumEntryText(flag, uma_id); | 347 << " " << GetHistogramEnumEntryText(flag, uma_id); |
309 } | 348 } |
310 } | 349 } |
311 | 350 |
312 } // namespace about_flags | 351 } // namespace about_flags |
OLD | NEW |