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 "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" | |
Ilya Sherman
2014/07/22 20:37:05
FWIW, the Autofill code uses #include "third_party
| |
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 | |
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 }; | |
384 | |
113 class AboutFlagsTest : public ::testing::Test { | 385 class AboutFlagsTest : public ::testing::Test { |
114 protected: | 386 protected: |
115 AboutFlagsTest() : flags_storage_(&prefs_) { | 387 AboutFlagsTest() : flags_storage_(&prefs_) { |
116 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); | 388 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); |
117 testing::ClearState(); | 389 testing::ClearState(); |
390 | |
391 const SwitchesHistogramIDs& switch_histogram_id = GetSwitchesHistogramIds(); | |
392 for (SwitchesHistogramIDs::const_iterator i = switch_histogram_id.begin(); | |
393 i != switch_histogram_id.end(); | |
394 ++i) { | |
395 const int id = i->second; | |
396 if (static_cast<int>(histogram_id_to_switch_.size()) > id) { | |
397 EXPECT_FALSE(histogram_id_to_switch_[id]) | |
398 << "Duplicate switch histogram ID: " << id << ": '" | |
399 << *(histogram_id_to_switch_[id]) << "' conflicts with '" | |
400 << i->first << "'"; | |
401 } else { | |
402 histogram_id_to_switch_.resize(id + 1); | |
403 } | |
404 histogram_id_to_switch_[id] = new std::string(i->first); | |
405 } | |
118 } | 406 } |
119 | 407 |
120 virtual void SetUp() OVERRIDE { | 408 virtual void SetUp() OVERRIDE { |
121 for (size_t i = 0; i < arraysize(kExperiments); ++i) | 409 for (size_t i = 0; i < arraysize(kExperiments); ++i) |
122 kExperiments[i].supported_platforms = GetCurrentPlatform(); | 410 kExperiments[i].supported_platforms = GetCurrentPlatform(); |
123 | 411 |
124 int os_other_than_current = 1; | 412 int os_other_than_current = 1; |
125 while (os_other_than_current == GetCurrentPlatform()) | 413 while (os_other_than_current == GetCurrentPlatform()) |
126 os_other_than_current <<= 1; | 414 os_other_than_current <<= 1; |
127 kExperiments[2].supported_platforms = os_other_than_current; | 415 kExperiments[2].supported_platforms = os_other_than_current; |
128 | 416 |
129 testing::SetExperiments(kExperiments, arraysize(kExperiments)); | 417 testing::SetExperiments(kExperiments, arraysize(kExperiments)); |
130 } | 418 } |
131 | 419 |
132 virtual void TearDown() OVERRIDE { | 420 virtual void TearDown() OVERRIDE { |
133 testing::SetExperiments(NULL, 0); | 421 testing::SetExperiments(NULL, 0); |
134 } | 422 } |
135 | 423 |
136 TestingPrefServiceSimple prefs_; | 424 TestingPrefServiceSimple prefs_; |
137 PrefServiceFlagsStorage flags_storage_; | 425 PrefServiceFlagsStorage flags_storage_; |
426 ScopedVector<std::string> histogram_id_to_switch_; | |
138 }; | 427 }; |
139 | 428 |
140 | |
141 TEST_F(AboutFlagsTest, NoChangeNoRestart) { | 429 TEST_F(AboutFlagsTest, NoChangeNoRestart) { |
142 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 430 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
143 SetExperimentEnabled(&flags_storage_, kFlags1, false); | 431 SetExperimentEnabled(&flags_storage_, kFlags1, false); |
144 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 432 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
145 } | 433 } |
146 | 434 |
147 TEST_F(AboutFlagsTest, ChangeNeedsRestart) { | 435 TEST_F(AboutFlagsTest, ChangeNeedsRestart) { |
148 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 436 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
149 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 437 SetExperimentEnabled(&flags_storage_, kFlags1, true); |
150 EXPECT_TRUE(IsRestartNeededToCommitChanges()); | 438 EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 | 514 |
227 CommandLine command_line2(CommandLine::NO_PROGRAM); | 515 CommandLine command_line2(CommandLine::NO_PROGRAM); |
228 | 516 |
229 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels); | 517 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels); |
230 | 518 |
231 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); | 519 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); |
232 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); | 520 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); |
233 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); | 521 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); |
234 } | 522 } |
235 | 523 |
524 CommandLine::StringType CreateSwitch(const std::string& value) { | |
525 #if defined(OS_WIN) | |
526 return ASCIIToUTF16(value); | |
527 #else | |
528 return value; | |
529 #endif | |
530 } | |
531 | |
236 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { | 532 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { |
237 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 533 SetExperimentEnabled(&flags_storage_, kFlags1, true); |
238 | 534 |
535 // double dash | |
536 const std::string kDD("--"); | |
537 | |
239 CommandLine command_line(CommandLine::NO_PROGRAM); | 538 CommandLine command_line(CommandLine::NO_PROGRAM); |
240 command_line.AppendSwitch("foo"); | 539 command_line.AppendSwitch("foo"); |
241 | 540 |
242 CommandLine new_command_line(CommandLine::NO_PROGRAM); | 541 CommandLine new_command_line(CommandLine::NO_PROGRAM); |
243 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); | 542 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); |
244 | 543 |
245 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, | 544 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( |
246 command_line)); | 545 new_command_line, command_line, NULL)); |
546 { | |
547 std::set<CommandLine::StringType> difference; | |
548 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( | |
549 new_command_line, command_line, &difference)); | |
550 EXPECT_EQ(1U, difference.size()); | |
551 EXPECT_EQ(1U, difference.count(CreateSwitch(kDD + kSwitch1))); | |
552 } | |
247 | 553 |
248 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 554 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
249 | 555 |
250 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, | 556 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( |
251 command_line)); | 557 new_command_line, command_line, NULL)); |
558 { | |
559 std::set<CommandLine::StringType> difference; | |
560 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( | |
561 new_command_line, command_line, &difference)); | |
562 EXPECT_TRUE(difference.empty()); | |
563 } | |
252 | 564 |
253 // Now both have flags but different. | 565 // Now both have flags but different. |
254 SetExperimentEnabled(&flags_storage_, kFlags1, false); | 566 SetExperimentEnabled(&flags_storage_, kFlags1, false); |
255 SetExperimentEnabled(&flags_storage_, kFlags2, true); | 567 SetExperimentEnabled(&flags_storage_, kFlags2, true); |
256 | 568 |
257 CommandLine another_command_line(CommandLine::NO_PROGRAM); | 569 CommandLine another_command_line(CommandLine::NO_PROGRAM); |
258 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); | 570 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); |
259 | 571 |
260 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, | 572 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( |
261 another_command_line)); | 573 new_command_line, another_command_line, NULL)); |
574 { | |
575 std::set<CommandLine::StringType> difference; | |
576 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( | |
577 new_command_line, another_command_line, &difference)); | |
578 EXPECT_EQ(2U, difference.size()); | |
579 EXPECT_EQ(1U, difference.count(CreateSwitch(kDD + kSwitch1))); | |
580 EXPECT_EQ(1U, | |
581 difference.count( | |
582 CreateSwitch(kDD + kSwitch2 + "=" + kValueForSwitch2))); | |
583 } | |
262 } | 584 } |
263 | 585 |
264 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { | 586 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
265 std::map<std::string, CommandLine::StringType> switch_list; | 587 std::map<std::string, CommandLine::StringType> switch_list; |
266 switch_list[kSwitch1] = CommandLine::StringType(); | 588 switch_list[kSwitch1] = CommandLine::StringType(); |
267 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); | 589 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); |
268 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); | 590 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); |
269 switch_list["foo"] = CommandLine::StringType(); | 591 switch_list["foo"] = CommandLine::StringType(); |
270 | 592 |
271 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 593 SetExperimentEnabled(&flags_storage_, kFlags1, true); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 TEST_F(AboutFlagsTest, NoSeparators) { | 779 TEST_F(AboutFlagsTest, NoSeparators) { |
458 testing::SetExperiments(NULL, 0); | 780 testing::SetExperiments(NULL, 0); |
459 size_t count; | 781 size_t count; |
460 const Experiment* experiments = testing::GetExperiments(&count); | 782 const Experiment* experiments = testing::GetExperiments(&count); |
461 for (size_t i = 0; i < count; ++i) { | 783 for (size_t i = 0; i < count; ++i) { |
462 std::string name = experiments->internal_name; | 784 std::string name = experiments->internal_name; |
463 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 785 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
464 } | 786 } |
465 } | 787 } |
466 | 788 |
789 TEST_F(AboutFlagsTest, SwitchHistogramTableValid) { | |
790 if (histogram_id_to_switch_[0]) | |
791 EXPECT_STREQ("", histogram_id_to_switch_[0]->c_str()); | |
792 EXPECT_FALSE(histogram_id_to_switch_[1]); /* BAD_FLAG_FORMAT, */ | |
793 EXPECT_FALSE(histogram_id_to_switch_[2]); /* RESERVED2 */ | |
794 EXPECT_FALSE(histogram_id_to_switch_[3]); /* RESERVED3 */ | |
795 EXPECT_FALSE(histogram_id_to_switch_[4]); /* RESERVED4 */ | |
796 for (size_t i = 5; i < histogram_id_to_switch_.size(); ++i) { | |
797 if (histogram_id_to_switch_[i]) { | |
798 EXPECT_LT(i, arraysize(HistogramSwitchesOrdered)) | |
799 << "Switch index " << i << " (switch name '" | |
800 << histogram_id_to_switch_[i]->c_str() | |
801 << "') is found in about_flags, but missing from the test."; | |
802 } else { | |
803 EXPECT_LT(i, arraysize(HistogramSwitchesOrdered)) | |
804 << "Switch index " << i | |
805 << " is found in about_flags, but missing from the test."; | |
806 } | |
807 if (i >= arraysize(HistogramSwitchesOrdered)) | |
808 continue; | |
809 if (histogram_id_to_switch_[i]) | |
810 EXPECT_STREQ(HistogramSwitchesOrdered[i], | |
811 histogram_id_to_switch_[i]->c_str()) | |
812 << "Switch index " << i << " is wrong."; | |
813 } | |
814 } | |
815 | |
816 // Returns empty map on error. | |
817 std::map<int, std::string> ReadLoginCustomFlags(XmlReader& reader) { | |
818 size_t entries_index = 0; | |
819 | |
820 std::map<int, std::string> result; | |
821 bool success = true; | |
822 | |
823 while (true) { | |
824 const std::string node_name = reader.NodeName(); | |
825 if (node_name == "enum" && reader.IsClosingElement()) | |
826 break; | |
827 | |
828 if (node_name == "int") { | |
829 ++entries_index; | |
830 std::string value_str; | |
831 std::string label; | |
832 if (!reader.NodeAttribute("value", &value_str)) { | |
833 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index " | |
834 << entries_index << "): No 'value' attribute."; | |
835 success = false; | |
836 } | |
837 if (!reader.NodeAttribute("label", &label)) { | |
838 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index " | |
839 << entries_index << "): No 'label' attribute."; | |
840 success = false; | |
841 } | |
842 int value; | |
843 if (!base::StringToInt(value_str, &value)) { | |
844 LOG(ERROR) << "Bad LoginCustomFlags enum entry (at index " | |
845 << entries_index << "): No 'label' attribute."; | |
846 success = false; | |
847 } | |
848 if (success) { | |
849 result[value] = label; | |
850 } | |
851 } | |
852 reader.Next(); | |
853 } | |
854 return (success ? result : std::map<int, std::string>()); | |
855 } | |
856 | |
857 // Returns empty map on error. | |
858 std::map<int, std::string> ReadHistogramsXml() { | |
859 XmlReader histograms_xml; | |
860 std::map<int, std::string> login_custom_flags; | |
861 EXPECT_TRUE( | |
862 histograms_xml.LoadFile("tools/metrics/histograms/histograms.xml")); | |
Ilya Sherman
2014/07/08 04:22:11
It seems more appropriate to use a presubmit check
Alexander Alekseev
2014/07/08 20:45:36
This has been discussed here (and in private talk)
Ilya Sherman
2014/07/09 00:10:50
This list needs to be updated every time a new com
Alexander Alekseev
2014/07/11 18:13:27
You mean "every time a new commandline switch is a
Ilya Sherman
2014/07/12 00:25:10
Correct, but new flags are expected to be added to
Alexander Alekseev
2014/07/21 15:22:27
I think that presubmit checks verify the submitted
Ilya Sherman
2014/07/21 22:12:59
Sorry, I think we're talking past each other. My
Alexander Alekseev
2014/07/22 14:25:05
As far as I understand, you do not like the idea o
| |
863 | |
864 while (true) { | |
865 const std::string node_name = histograms_xml.NodeName(); | |
866 if (node_name == "enum") { | |
867 std::string name; | |
868 if (histograms_xml.NodeAttribute("name", &name) && | |
869 name == "LoginCustomFlags") { | |
870 EXPECT_TRUE(login_custom_flags.empty()) | |
871 << "Duplicate enum LoginCustomFlags found in histograms.xml"; | |
872 if (!login_custom_flags.empty()) | |
873 return std::map<int, std::string>(); | |
874 | |
875 if (histograms_xml.Read()) { | |
876 login_custom_flags = ReadLoginCustomFlags(histograms_xml); | |
877 EXPECT_FALSE(login_custom_flags.empty()); | |
878 if (login_custom_flags.empty()) | |
879 return std::map<int, std::string>(); | |
880 } | |
881 } | |
882 } | |
883 if (histograms_xml.Read()) | |
884 continue; | |
885 | |
886 if (histograms_xml.Next()) | |
887 continue; | |
888 | |
889 while (histograms_xml.Depth() && !histograms_xml.SkipToElement()) { | |
890 } | |
891 | |
892 if (!histograms_xml.Depth()) | |
893 break; | |
894 } | |
895 EXPECT_FALSE(login_custom_flags.empty()) | |
896 << "enum LoginCustomFlags is not found in histograms.xml"; | |
897 return login_custom_flags; | |
898 } | |
899 | |
900 TEST_F(AboutFlagsTest, CheckHistograms) { | |
901 std::map<int, std::string> login_custom_flags = ReadHistogramsXml(); | |
902 | |
903 for (size_t i = 5; i < arraysize(HistogramSwitchesOrdered); ++i) { | |
904 EXPECT_TRUE(login_custom_flags.count(i)) | |
905 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" | |
906 << HistogramSwitchesOrdered[i] << "'"; | |
907 | |
908 if (login_custom_flags.count(i)) { | |
909 EXPECT_STREQ(HistogramSwitchesOrdered[i], login_custom_flags[i].c_str()) | |
910 << "Bad histograms.xml enum LoginCustomFlags entry with value='" << i | |
911 << "'."; | |
912 } | |
913 } | |
914 // If maximum index in histograms.xml is greater than in test. | |
915 if (static_cast<size_t>(login_custom_flags.rbegin()->first) >= | |
916 arraysize(HistogramSwitchesOrdered)) { | |
917 for (std::map<int, std::string>::reverse_iterator ri = | |
918 login_custom_flags.rbegin(); | |
919 ri != login_custom_flags.rend(); | |
920 ++ri) { | |
921 if (static_cast<size_t>(ri->first) < arraysize(HistogramSwitchesOrdered)) | |
922 break; | |
923 EXPECT_LT(static_cast<size_t>(ri->first), | |
924 arraysize(HistogramSwitchesOrdered)) | |
925 << "Test has no data for histograms.xml enum LoginCustomFlags entry " | |
926 "with value='" << ri->first << "' label='" << ri->second << "'"; | |
927 } | |
928 } | |
929 } | |
930 | |
467 } // namespace about_flags | 931 } // namespace about_flags |
OLD | NEW |