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

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

Powered by Google App Engine
This is Rietveld 408576698