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

Side by Side Diff: chrome/browser/about_flags_unittest.cc

Issue 344883002: Collect UMA statistics on which chrome://flags lead to chrome restart on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed about_flags_switches_histogram_id.h -> about_flags_switches_histogram_ids.h . Created 6 years, 5 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
OLDNEW
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 "base/memory/scoped_vector.h"
5 #include "base/prefs/pref_registry_simple.h" 6 #include "base/prefs/pref_registry_simple.h"
6 #include "base/prefs/testing_pref_service.h" 7 #include "base/prefs/testing_pref_service.h"
7 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/browser/about_flags.h" 11 #include "chrome/browser/about_flags.h"
11 #include "chrome/browser/pref_service_flags_storage.h" 12 #include "chrome/browser/pref_service_flags_storage.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "grit/chromium_strings.h" 15 #include "grit/chromium_strings.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/libxml/chromium/libxml_utils.h"
16 18
17 const char kFlags1[] = "flag1"; 19 const char kFlags1[] = "flag1";
18 const char kFlags2[] = "flag2"; 20 const char kFlags2[] = "flag2";
19 const char kFlags3[] = "flag3"; 21 const char kFlags3[] = "flag3";
20 const char kFlags4[] = "flag4"; 22 const char kFlags4[] = "flag4";
21 const char kFlags5[] = "flag5"; 23 const char kFlags5[] = "flag5";
22 24
23 const char kSwitch1[] = "switch"; 25 const char kSwitch1[] = "switch";
24 const char kSwitch2[] = "switch2"; 26 const char kSwitch2[] = "switch2";
25 const char kSwitch3[] = "switch3"; 27 const char kSwitch3[] = "switch3";
26 const char kValueForSwitch2[] = "value_for_switch2"; 28 const char kValueForSwitch2[] = "value_for_switch2";
27 29
28 const char kMultiSwitch1[] = "multi_switch1"; 30 const char kMultiSwitch1[] = "multi_switch1";
29 const char kMultiSwitch2[] = "multi_switch2"; 31 const char kMultiSwitch2[] = "multi_switch2";
30 const char kValueForMultiSwitch2[] = "value_for_multi_switch2"; 32 const char kValueForMultiSwitch2[] = "value_for_multi_switch2";
31 33
32 const char kEnableDisableValue1[] = "value1"; 34 const char kEnableDisableValue1[] = "value1";
33 const char kEnableDisableValue2[] = "value2"; 35 const char kEnableDisableValue2[] = "value2";
34 36
35 namespace about_flags { 37 namespace about_flags {
36 38
39 enum TestSwitchesHistogramIDs {
40 ID_UNKNOWN_FLAG = UMA_HISTOGRAM_ID_UNKNOWN_FLAG,
41 ID_BAD_FLAG_FORMAT = UMA_HISTOGRAM_ID_BAD_FLAG_FORMAT,
42 ID_kMultiSwitch1,
43 ID_kMultiSwitch2,
44 ID_kSwitch1,
45 ID_kSwitch2,
46 ID_kSwitch3,
47 };
48
49 #define ID(x) static_cast<const about_flags::SwitchesUmaHistogramId>(x)
50
37 const Experiment::Choice kMultiChoices[] = { 51 const Experiment::Choice kMultiChoices[] = {
38 { IDS_PRODUCT_NAME, "", "" }, 52 { IDS_PRODUCT_NAME, "", "", ID(ID_UNKNOWN_FLAG) },
39 { IDS_PRODUCT_NAME, kMultiSwitch1, "" }, 53 { IDS_PRODUCT_NAME, kMultiSwitch1, "", ID(ID_kMultiSwitch1) },
40 { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 }, 54 { IDS_PRODUCT_NAME,
55 kMultiSwitch2, kValueForMultiSwitch2, ID(ID_kMultiSwitch2) },
41 }; 56 };
42 57
58 #undef ID
59
43 // The experiments that are set for these tests. The 3rd experiment is not 60 // The experiments that are set for these tests. The 3rd experiment is not
44 // supported on the current platform, all others are. 61 // supported on the current platform, all others are.
45 static Experiment kExperiments[] = { 62 static Experiment kExperiments[] = {
46 { 63 {
47 kFlags1, 64 kFlags1,
48 IDS_PRODUCT_NAME, 65 IDS_PRODUCT_NAME,
49 IDS_PRODUCT_NAME, 66 IDS_PRODUCT_NAME,
50 0, // Ends up being mapped to the current platform. 67 0, // Ends up being mapped to the current platform.
51 Experiment::SINGLE_VALUE, 68 Experiment::SINGLE_VALUE,
52 kSwitch1, 69 kSwitch1,
53 "", 70 "",
71 ID_kSwitch1,
54 NULL, 72 NULL,
55 NULL, 73 NULL,
74 0,
56 NULL, 75 NULL,
57 0 76 0
58 }, 77 },
59 { 78 {
60 kFlags2, 79 kFlags2,
61 IDS_PRODUCT_NAME, 80 IDS_PRODUCT_NAME,
62 IDS_PRODUCT_NAME, 81 IDS_PRODUCT_NAME,
63 0, // Ends up being mapped to the current platform. 82 0, // Ends up being mapped to the current platform.
64 Experiment::SINGLE_VALUE, 83 Experiment::SINGLE_VALUE,
65 kSwitch2, 84 kSwitch2,
66 kValueForSwitch2, 85 kValueForSwitch2,
86 ID_kSwitch2,
67 NULL, 87 NULL,
68 NULL, 88 NULL,
89 0,
69 NULL, 90 NULL,
70 0 91 0
71 }, 92 },
72 { 93 {
73 kFlags3, 94 kFlags3,
74 IDS_PRODUCT_NAME, 95 IDS_PRODUCT_NAME,
75 IDS_PRODUCT_NAME, 96 IDS_PRODUCT_NAME,
76 0, // This ends up enabling for an OS other than the current. 97 0, // This ends up enabling for an OS other than the current.
77 Experiment::SINGLE_VALUE, 98 Experiment::SINGLE_VALUE,
78 kSwitch3, 99 kSwitch3,
79 "", 100 "",
101 ID_kSwitch3,
80 NULL, 102 NULL,
81 NULL, 103 NULL,
104 0,
82 NULL, 105 NULL,
83 0 106 0
84 }, 107 },
85 { 108 {
86 kFlags4, 109 kFlags4,
87 IDS_PRODUCT_NAME, 110 IDS_PRODUCT_NAME,
88 IDS_PRODUCT_NAME, 111 IDS_PRODUCT_NAME,
89 0, // Ends up being mapped to the current platform. 112 0, // Ends up being mapped to the current platform.
90 Experiment::MULTI_VALUE, 113 Experiment::MULTI_VALUE,
91 "", 114 "",
92 "", 115 "",
116 0,
93 "", 117 "",
94 "", 118 "",
119 0,
95 kMultiChoices, 120 kMultiChoices,
96 arraysize(kMultiChoices) 121 arraysize(kMultiChoices)
97 }, 122 },
98 { 123 {
99 kFlags5, 124 kFlags5,
100 IDS_PRODUCT_NAME, 125 IDS_PRODUCT_NAME,
101 IDS_PRODUCT_NAME, 126 IDS_PRODUCT_NAME,
102 0, // Ends up being mapped to the current platform. 127 0, // Ends up being mapped to the current platform.
103 Experiment::ENABLE_DISABLE_VALUE, 128 Experiment::ENABLE_DISABLE_VALUE,
104 kSwitch1, 129 kSwitch1,
105 kEnableDisableValue1, 130 kEnableDisableValue1,
131 ID_kSwitch1,
106 kSwitch2, 132 kSwitch2,
107 kEnableDisableValue2, 133 kEnableDisableValue2,
134 ID_kSwitch2,
108 NULL, 135 NULL,
109 3 136 3
110 }, 137 },
111 }; 138 };
112 139
140 /*
141 This table contains histogram IDs for switches. Switch ID must never change!
142 */
143 const char* const HistogramSwitchesOrdered[] = {
144 NULL, /* No flag */
145 NULL, /* Bad flag format */
146 NULL, /* reserved */
147 NULL, /* reserved */
148 NULL, /* reserved */
149 "disable-webrtc-hw-encoding",
150 "disable-minimize-on-second-launcher-item-click",
151 "disable-virtual-keyboard-overscroll",
152 "disable-virtual-keyboard-overscroll",
153 "enable-pinch-virtual-viewport",
154 "prefetch-search-results",
155 "enable-experimental-app-list",
156 "enable-devtools-experiments",
157 "enable-centered-app-list",
158 "enable-accelerated-overflow-scroll",
159 "enable-tcp-fastopen",
160 "enable-zero-suggest-personalized",
161 "enable-experimental-web-platform-features",
162 "use-simple-cache-backend",
163 "disable-search-button-in-omnibox",
164 "file-manager-enable-new-audio-player",
165 "disable-prefixed-encrypted-media",
166 "disable-origin-chip",
167 "disable-touch-adjustment",
168 "disable-offline-auto-reload",
169 "enable-fixed-position-compositing",
170 "enable-nacl",
171 "disable-saml-signin",
172 "disable-views-rect-based-targeting",
173 "enable-linkable-ephemeral-apps",
174 "enable-zero-copy",
175 "enable-session-crashed-bubble",
176 "enable-spelling-auto-correct",
177 "disable-suggestions-service",
178 "disable-app-list-app-info",
179 "allow-insecure-websocket-from-https-origin",
180 "enable-input-view",
181 "enable-web-midi",
182 "disable-app-list-voice-search",
183 "disable-offline-load-stale-cache",
184 "manual-enhanced-bookmarks",
185 "num-raster-threads",
186 "disable-cast",
187 "enable-instant-search-clicks",
188 "enable-zero-suggest-ether-noserp",
189 "enable-overlay-scrollbar",
190 "enable-spdy4",
191 "disable-boot-animation",
192 "disable-password-generation",
193 "disable-software-rasterizer",
194 "enable-avfoundation",
195 "disable-spdy-proxy-dev-auth-origin",
196 "disable-new-profile-management",
197 "mediadrm-enable-non-compositing",
198 "disable-text-input-focus-manager",
199 "enable-smooth-scrolling",
200 "enable-password-generation",
201 "disable-device-discovery",
202 "scroll-end-effect",
203 "enable-delegated-renderer",
204 "ash-enable-touch-view-testing",
205 "touch-events",
206 "disable-new-ntp",
207 "disable-permissions-bubbles",
208 "enable-network-portal-notification",
209 "disable-media-source",
210 "enable-encrypted-media",
211 "enable-apps-file-associations",
212 "enable-search-button-in-omnibox-for-str",
213 "disable-sync-app-list",
214 "file-manager-enable-new-gallery",
215 "enable-fast-unload",
216 "disable-fast-text-autosizing",
217 "tab-capture-upscale-quality",
218 "disable-threaded-compositing",
219 "enable-accelerated-fixed-root-background",
220 "enable-lcd-text",
221 "nacl-debug-mask",
222 "disable-transition-compositing",
223 "enable-embeddedsearch-api",
224 "enable-settings-window",
225 "force-device-scale-factor",
226 "disable-password-manager-reauthentication",
227 "disable-pinch-virtual-viewport",
228 "disable-webgl",
229 "save-page-as-mhtml",
230 "disable-zero-suggest",
231 "show-composited-layer-borders",
232 "enable-zero-suggest-most-visited",
233 "enable-answers-in-suggest",
234 "malware-interstitial-v3",
235 "enable-virtual-keyboard",
236 "disable-quic",
237 "default-tile-width",
238 "enable-automatic-password-saving",
239 "enable-search-button-in-omnibox-always",
240 "disable-input-view",
241 "enable-one-copy",
242 "overscroll-history-navigation",
243 "enable-quic-https",
244 "js-flags",
245 "enable-nacl-debug",
246 "enable-viewport-meta",
247 "enable-experimental-input-view-features",
248 "disable-gpu-rasterization",
249 "enable-print-preview-register-promos",
250 "enable-simplified-fullscreen",
251 "enable-accessibility-tab-switcher",
252 "enable-quic",
253 "enable-origin-chip-on-srp",
254 "fast-user-switching",
255 "enable-touch-editing",
256 "wallet-service-use-sandbox",
257 "enable-carrier-switching",
258 "disable-contextual-search",
259 "enable-zero-suggest-ether-serp",
260 "enable-cloud-devices",
261 "disable-quic-https",
262 "enable-touch-drag-drop",
263 "enable-permissions-bubbles",
264 "enable-first-run-ui-transitions",
265 "disable-device-discovery-notifications",
266 "enable-threaded-compositing",
267 "enable-easy-unlock",
268 "enable-origin-chip-always",
269 "enable-pinch",
270 "enable-bleeding-edge-rendering-fast-paths",
271 "disable-lcd-text",
272 "enable-streamlined-hosted-apps",
273 "disable-webrtc",
274 "enable-save-password-bubble",
275 "enable-apps-show-on-first-paint",
276 "enable-new-ntp",
277 "enable-text-input-focus-manager",
278 "enable-service-worker-sync",
279 "enable-harfbuzz-rendertext",
280 "enable-download-resumption",
281 "new-profile-management",
282 "disable-touch-editing",
283 "google-profile-info",
284 "enable-impl-side-painting",
285 "enable-distance-field-text",
286 "enable-deferred-image-decoding",
287 "manual-enhanced-bookmarks-optout",
288 "enable-search-button-in-omnibox-for-str-or-iip",
289 "enable-offline-auto-reload",
290 "enable-experimental-canvas-features",
291 "enable-app-install-alerts",
292 "enable-cloud-print-xps",
293 "max-tiles-for-interest-area",
294 "enable-app-list",
295 "disable-accelerated-video-decode",
296 "out-of-process-pdf",
297 "disable-session-crashed-bubble",
298 "enable-swipe-selection",
299 "disable-fixed-position-compositing",
300 "enable-web-based-signin",
301 "ssl-interstitial-v2-gray",
302 "enable-sync-app-list",
303 "disable-compositor-touch-hit-testing",
304 "disable-accelerated-fixed-root-background",
305 "enhanced-bookmarks-experiment",
306 "disable-pnacl",
307 "extension-content-verification",
308 "disable-touch-drag-drop",
309 "default-tile-height",
310 "disable-sync-synced-notifications",
311 "new-avatar-menu",
312 "allow-nacl-socket-api",
313 "enable-experimental-extension-apis",
314 "enable-app-window-controls",
315 "silent-debugger-extension-api",
316 "enable-suggestions-service",
317 "enable-contextual-search",
318 "enable-fast-text-autosizing",
319 "ash-touch-hud",
320 "disable-accelerated-overflow-scroll",
321 "disable-async-dns",
322 "disable-webaudio",
323 "disable-delegated-renderer",
324 "disable-save-password-bubble",
325 "enable-offline-load-stale-cache",
326 "disable-display-color-calibration",
327 "debug-packed-apps",
328 "enable-gpu-rasterization",
329 "disable-impl-side-painting",
330 "disable-distance-field-text",
331 "performance-monitor-gathering",
332 "disable-pinch",
333 "enable-syncfs-directory-operation",
334 "disable-ntp-other-sessions-menu",
335 "enable-spelling-feedback-field-trial",
336 "ssl-interstitial-v1",
337 "disable-gesture-requirement-for-media-playback",
338 "touch-scrolling-mode",
339 "enable-touchpad-three-finger-click",
340 "disable-quickoffice-component-app",
341 "enable-transition-compositing",
342 "disable-account-consistency",
343 "enable-request-tablet-site",
344 "tab-capture-downscale-quality",
345 "enable-service-worker",
346 "ash-debug-shortcuts",
347 "enable-sync-synced-notifications",
348 "ignore-gpu-blacklist",
349 "ssl-interstitial-v2-colorful",
350 "do-not-ignore-autocomplete-off",
351 "disable-accelerated-2d-canvas",
352 "enable-gesture-tap-highlight",
353 "reset-app-list-install-state",
354 "enable-scroll-prediction",
355 "enable-ephemeral-apps",
356 "enable-webgl-draft-extensions",
357 "disable-network-portal-notification",
358 "enable-device-discovery-notifications",
359 "disable-layer-squashing",
360 "disable-gesture-tap-highlight",
361 "enable-offline-auto-reload-visible-only",
362 "enable-spdy-proxy-dev-auth-origin",
363 "enable-translate-new-ux",
364 "no-pings",
365 "enable-scripts-require-action",
366 "disable-webrtc-hw-decoding",
367 "enable-virtual-keyboard-overscroll",
368 "disable-direct-write",
369 "extensions-on-chrome-urls",
370 "malware-interstitial-v2",
371 "enable-account-consistency",
372 "disable-offline-auto-reload-visible-only",
373 "disable-settings-window",
374 "disable-embedded-shared-worker",
375 "show-autofill-type-predictions",
376 "enable-async-dns",
377 "enable-prominent-url-app-flow",
378 "enable-high-dpi-fixed-position-compositing",
379 "force-gpu-rasterization",
380 "disable-device-enumeration",
381 "show-fps-counter",
382 "apps-keep-chrome-alive",
383 "enable-filemanager-mtp",
384 "enable-panels",
385 "disable-overlay-scrollbar",
386 "disable-zero-copy",
387 "disable-click-delay",
388 };
389
113 class AboutFlagsTest : public ::testing::Test { 390 class AboutFlagsTest : public ::testing::Test {
114 protected: 391 protected:
115 AboutFlagsTest() : flags_storage_(&prefs_) { 392 AboutFlagsTest() : flags_storage_(&prefs_) {
116 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); 393 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
117 testing::ClearState(); 394 testing::ClearState();
395
396 const SwitchesHistogramIDs& switch_histogram_id = GetSwitchesHistogramIds();
397 for (SwitchesHistogramIDs::const_iterator i = switch_histogram_id.begin();
398 i != switch_histogram_id.end();
399 ++i) {
400 const int id = i->second;
401 if (static_cast<int>(histogram_id_to_switch_.size()) > id) {
402 EXPECT_FALSE(histogram_id_to_switch_[id])
403 << "Duplicate switch histogram ID: " << id << ": '"
404 << *(histogram_id_to_switch_[id]) << "' conflicts with '"
405 << i->first << "'";
406 } else {
407 histogram_id_to_switch_.resize(id + 1);
408 }
409 histogram_id_to_switch_[id] = new std::string(i->first);
410 }
118 } 411 }
119 412
120 virtual void SetUp() OVERRIDE { 413 virtual void SetUp() OVERRIDE {
121 for (size_t i = 0; i < arraysize(kExperiments); ++i) 414 for (size_t i = 0; i < arraysize(kExperiments); ++i)
122 kExperiments[i].supported_platforms = GetCurrentPlatform(); 415 kExperiments[i].supported_platforms = GetCurrentPlatform();
123 416
124 int os_other_than_current = 1; 417 int os_other_than_current = 1;
125 while (os_other_than_current == GetCurrentPlatform()) 418 while (os_other_than_current == GetCurrentPlatform())
126 os_other_than_current <<= 1; 419 os_other_than_current <<= 1;
127 kExperiments[2].supported_platforms = os_other_than_current; 420 kExperiments[2].supported_platforms = os_other_than_current;
128 421
129 testing::SetExperiments(kExperiments, arraysize(kExperiments)); 422 testing::SetExperiments(kExperiments, arraysize(kExperiments));
130 } 423 }
131 424
132 virtual void TearDown() OVERRIDE { 425 virtual void TearDown() OVERRIDE {
133 testing::SetExperiments(NULL, 0); 426 testing::SetExperiments(NULL, 0);
134 } 427 }
135 428
136 TestingPrefServiceSimple prefs_; 429 TestingPrefServiceSimple prefs_;
137 PrefServiceFlagsStorage flags_storage_; 430 PrefServiceFlagsStorage flags_storage_;
431 ScopedVector<std::string> histogram_id_to_switch_;
138 }; 432 };
139 433
140
141 TEST_F(AboutFlagsTest, NoChangeNoRestart) { 434 TEST_F(AboutFlagsTest, NoChangeNoRestart) {
142 EXPECT_FALSE(IsRestartNeededToCommitChanges()); 435 EXPECT_FALSE(IsRestartNeededToCommitChanges());
143 SetExperimentEnabled(&flags_storage_, kFlags1, false); 436 SetExperimentEnabled(&flags_storage_, kFlags1, false);
144 EXPECT_FALSE(IsRestartNeededToCommitChanges()); 437 EXPECT_FALSE(IsRestartNeededToCommitChanges());
145 } 438 }
146 439
147 TEST_F(AboutFlagsTest, ChangeNeedsRestart) { 440 TEST_F(AboutFlagsTest, ChangeNeedsRestart) {
148 EXPECT_FALSE(IsRestartNeededToCommitChanges()); 441 EXPECT_FALSE(IsRestartNeededToCommitChanges());
149 SetExperimentEnabled(&flags_storage_, kFlags1, true); 442 SetExperimentEnabled(&flags_storage_, kFlags1, true);
150 EXPECT_TRUE(IsRestartNeededToCommitChanges()); 443 EXPECT_TRUE(IsRestartNeededToCommitChanges());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 519
227 CommandLine command_line2(CommandLine::NO_PROGRAM); 520 CommandLine command_line2(CommandLine::NO_PROGRAM);
228 521
229 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels); 522 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels);
230 523
231 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); 524 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
232 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); 525 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
233 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); 526 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
234 } 527 }
235 528
529 CommandLine::StringType CreateSwitch(const std::string& value) {
530 #if defined(OS_WIN)
531 return ASCIIToUTF16(value);
532 #else
533 return value;
534 #endif
535 }
536
236 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { 537 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) {
237 SetExperimentEnabled(&flags_storage_, kFlags1, true); 538 SetExperimentEnabled(&flags_storage_, kFlags1, true);
238 539
540 // double dash
541 const std::string kDD("--");
542
239 CommandLine command_line(CommandLine::NO_PROGRAM); 543 CommandLine command_line(CommandLine::NO_PROGRAM);
240 command_line.AppendSwitch("foo"); 544 command_line.AppendSwitch("foo");
241 545
242 CommandLine new_command_line(CommandLine::NO_PROGRAM); 546 CommandLine new_command_line(CommandLine::NO_PROGRAM);
243 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); 547 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels);
244 548
245 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 549 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
246 command_line)); 550 new_command_line, command_line, NULL));
551 {
552 std::set<CommandLine::StringType> difference;
553 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
554 new_command_line, command_line, &difference));
555 EXPECT_EQ(1U, difference.size());
556 EXPECT_EQ(1U, difference.count(CreateSwitch(kDD + kSwitch1)));
557 }
247 558
248 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); 559 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
249 560
250 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 561 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
251 command_line)); 562 new_command_line, command_line, NULL));
563 {
564 std::set<CommandLine::StringType> difference;
565 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
566 new_command_line, command_line, &difference));
567 EXPECT_TRUE(difference.empty());
568 }
252 569
253 // Now both have flags but different. 570 // Now both have flags but different.
254 SetExperimentEnabled(&flags_storage_, kFlags1, false); 571 SetExperimentEnabled(&flags_storage_, kFlags1, false);
255 SetExperimentEnabled(&flags_storage_, kFlags2, true); 572 SetExperimentEnabled(&flags_storage_, kFlags2, true);
256 573
257 CommandLine another_command_line(CommandLine::NO_PROGRAM); 574 CommandLine another_command_line(CommandLine::NO_PROGRAM);
258 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); 575 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels);
259 576
260 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 577 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
261 another_command_line)); 578 new_command_line, another_command_line, NULL));
579 {
580 std::set<CommandLine::StringType> difference;
581 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
582 new_command_line, another_command_line, &difference));
583 EXPECT_EQ(2U, difference.size());
584 EXPECT_EQ(1U, difference.count(CreateSwitch(kDD + kSwitch1)));
585 EXPECT_EQ(1U,
586 difference.count(
587 CreateSwitch(kDD + kSwitch2 + "=" + kValueForSwitch2)));
588 }
262 } 589 }
263 590
264 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { 591 TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
265 std::map<std::string, CommandLine::StringType> switch_list; 592 std::map<std::string, CommandLine::StringType> switch_list;
266 switch_list[kSwitch1] = CommandLine::StringType(); 593 switch_list[kSwitch1] = CommandLine::StringType();
267 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); 594 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType();
268 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); 595 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType();
269 switch_list["foo"] = CommandLine::StringType(); 596 switch_list["foo"] = CommandLine::StringType();
270 597
271 SetExperimentEnabled(&flags_storage_, kFlags1, true); 598 SetExperimentEnabled(&flags_storage_, kFlags1, true);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 TEST_F(AboutFlagsTest, NoSeparators) { 784 TEST_F(AboutFlagsTest, NoSeparators) {
458 testing::SetExperiments(NULL, 0); 785 testing::SetExperiments(NULL, 0);
459 size_t count; 786 size_t count;
460 const Experiment* experiments = testing::GetExperiments(&count); 787 const Experiment* experiments = testing::GetExperiments(&count);
461 for (size_t i = 0; i < count; ++i) { 788 for (size_t i = 0; i < count; ++i) {
462 std::string name = experiments->internal_name; 789 std::string name = experiments->internal_name;
463 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; 790 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i;
464 } 791 }
465 } 792 }
466 793
794 TEST_F(AboutFlagsTest, SwitchHistogramTableValid) {
795 if (histogram_id_to_switch_[0])
796 EXPECT_STREQ("", histogram_id_to_switch_[0]->c_str());
797 EXPECT_FALSE(histogram_id_to_switch_[1]); /* BAD_FLAG_FORMAT, */
798 EXPECT_FALSE(histogram_id_to_switch_[2]); /* RESERVED2 */
799 EXPECT_FALSE(histogram_id_to_switch_[3]); /* RESERVED3 */
800 EXPECT_FALSE(histogram_id_to_switch_[4]); /* RESERVED4 */
801 for (size_t i = 5; i < histogram_id_to_switch_.size(); ++i) {
802 if (histogram_id_to_switch_[i]) {
803 EXPECT_LT(i, arraysize(HistogramSwitchesOrdered))
804 << "Switch index " << i << " (switch name '"
805 << histogram_id_to_switch_[i]->c_str()
806 << "') is found in about_flags, but missing from the test.";
807 } else {
808 EXPECT_LT(i, arraysize(HistogramSwitchesOrdered))
809 << "Switch index " << i
810 << " is found in about_flags, but missing from the test.";
811 }
812 if (i >= arraysize(HistogramSwitchesOrdered))
813 continue;
814 if (histogram_id_to_switch_[i])
815 EXPECT_STREQ(HistogramSwitchesOrdered[i],
816 histogram_id_to_switch_[i]->c_str())
817 << "Switch index " << i << " is wrong.";
818 }
819 }
820
821 // Returns empty map on error.
822 std::map<int, std::string> ReadLoginCustomFlags(XmlReader& reader) {
823 size_t entries_index = 0;
824
825 std::map<int, std::string> result;
826 bool success = true;
827
828 while (true) {
829 const std::string node_name = reader.NodeName();
830 if (node_name == "enum" && reader.IsClosingElement())
831 break;
832
833 if (node_name == "int") {
834 ++entries_index;
835 std::string value_str;
836 std::string label;
837 if (!reader.NodeAttribute("value", &value_str)) {
838 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index "
839 << entries_index << "): No 'value' attribute.";
840 success = false;
841 }
842 if (!reader.NodeAttribute("label", &label)) {
843 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index "
844 << entries_index << "): No 'label' attribute.";
845 success = false;
846 }
847 int value;
848 if (!base::StringToInt(value_str, &value)) {
849 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index "
850 << entries_index << "): No 'label' attribute.";
851 success = false;
852 }
853 if (success) {
854 result[value] = label;
855 }
856 }
857 reader.Next();
858 }
859 return (success ? result : std::map<int, std::string>());
860 }
861
862 // Returns empty map on error.
863 std::map<int, std::string> ReadHistogramsXml() {
864 XmlReader histograms_xml;
865 std::map<int, std::string> login_custom_flags;
866 EXPECT_TRUE(
867 histograms_xml.LoadFile("tools/metrics/histograms/histograms.xml"));
868
869 while (true) {
870 const std::string node_name = histograms_xml.NodeName();
871 if (node_name == "enum") {
872 std::string name;
873 if (histograms_xml.NodeAttribute("name", &name) &&
874 name == "LoginCustomFlags") {
875 EXPECT_TRUE(login_custom_flags.empty())
876 << "Duplicate enum LoginCustomFlags found in histograms.xml";
877 if (!login_custom_flags.empty())
878 return std::map<int, std::string>();
879
880 if (histograms_xml.Read()) {
881 login_custom_flags = ReadLoginCustomFlags(histograms_xml);
882 EXPECT_FALSE(login_custom_flags.empty());
883 if (login_custom_flags.empty())
884 return std::map<int, std::string>();
885 }
886 }
887 }
888 if (histograms_xml.Read())
889 continue;
890
891 if (histograms_xml.Next())
892 continue;
893
894 while (histograms_xml.Depth() && !histograms_xml.SkipToElement()) {
895 }
896
897 if (!histograms_xml.Depth())
898 break;
899 }
900 EXPECT_FALSE(login_custom_flags.empty())
901 << "enum LoginCustomFlags is not found in histograms.xml";
902 return login_custom_flags;
903 }
904
905 TEST_F(AboutFlagsTest, CheckHistograms) {
906 std::map<int, std::string> login_custom_flags = ReadHistogramsXml();
907
908 for (size_t i = 5; i < arraysize(HistogramSwitchesOrdered); ++i) {
909 EXPECT_TRUE(login_custom_flags.count(i))
910 << "histograms.xml enum LoginCustomFlags doesn't contain switch '"
911 << HistogramSwitchesOrdered[i] << "'";
912
913 if (login_custom_flags.count(i)) {
914 EXPECT_STREQ(HistogramSwitchesOrdered[i], login_custom_flags[i].c_str())
915 << "Bad histograms.xml enum LoginCustomFlags entry with value='" << i
916 << "'.";
917 }
918 }
919 // If maximum index in histograms.xml is greater than in test.
920 if (static_cast<size_t>(login_custom_flags.rbegin()->first) >=
921 arraysize(HistogramSwitchesOrdered)) {
922 for (std::map<int, std::string>::reverse_iterator ri =
923 login_custom_flags.rbegin();
924 ri != login_custom_flags.rend();
925 ++ri) {
926 if (static_cast<size_t>(ri->first) < arraysize(HistogramSwitchesOrdered))
927 break;
928 EXPECT_LT(static_cast<size_t>(ri->first),
929 arraysize(HistogramSwitchesOrdered))
930 << "Test has no data for histograms.xml enum LoginCustomFlags entry "
931 "with value='" << ri->first << "' label='" << ri->second << "'";
932 }
933 }
934 }
935
467 } // namespace about_flags 936 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698