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