blob: d892e2b0d76298bbc23c20471b0852e2f225d4cd [file] [log] [blame]
[email protected]1bc78422011-03-31 08:41:381// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]e2ddbc92010-10-15 20:02:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
asvitkine26e40322015-05-21 21:28:305#include "chrome/browser/about_flags.h"
6
[email protected]4b66a7d2014-08-15 17:13:317#include <stdint.h>
asvitkinebff63b22014-11-25 01:03:528#include <utility>
[email protected]4b66a7d2014-08-15 17:13:319
10#include "base/files/file_path.h"
11#include "base/memory/scoped_vector.h"
12#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5713#include "base/prefs/pref_registry_simple.h"
[email protected]e5ba874f2013-02-14 17:20:1914#include "base/prefs/testing_pref_service.h"
[email protected]3ea1b182013-02-08 22:38:4115#include "base/strings/string_number_conversions.h"
[email protected]4b66a7d2014-08-15 17:13:3116#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/utf_string_conversions.h"
[email protected]a314ee5a2010-10-26 21:23:2818#include "base/values.h"
[email protected]e6d1c4f2013-06-12 17:37:4019#include "chrome/browser/pref_service_flags_storage.h"
[email protected]e2ddbc92010-10-15 20:02:0720#include "chrome/common/chrome_switches.h"
21#include "chrome/common/pref_names.h"
[email protected]af39f002014-08-22 10:18:1822#include "chrome/grit/chromium_strings.h"
[email protected]e2ddbc92010-10-15 20:02:0723#include "testing/gtest/include/gtest/gtest.h"
[email protected]4b66a7d2014-08-15 17:13:3124#include "third_party/libxml/chromium/libxml_utils.h"
25
asvitkine26e40322015-05-21 21:28:3026namespace about_flags {
27
[email protected]4b66a7d2014-08-15 17:13:3128namespace {
[email protected]e2ddbc92010-10-15 20:02:0729
[email protected]a314ee5a2010-10-26 21:23:2830const char kFlags1[] = "flag1";
31const char kFlags2[] = "flag2";
32const char kFlags3[] = "flag3";
[email protected]8a6ff28d2010-12-02 16:35:1933const char kFlags4[] = "flag4";
[email protected]83e9fa702013-02-25 19:30:4434const char kFlags5[] = "flag5";
flackr0a5eb1562015-06-12 18:50:1435const char kFlags6[] = "flag6";
[email protected]e2ddbc92010-10-15 20:02:0736
[email protected]a314ee5a2010-10-26 21:23:2837const char kSwitch1[] = "switch";
38const char kSwitch2[] = "switch2";
39const char kSwitch3[] = "switch3";
flackr0a5eb1562015-06-12 18:50:1440const char kSwitch6[] = "switch6";
[email protected]a82744532011-02-11 16:15:5341const char kValueForSwitch2[] = "value_for_switch2";
[email protected]e2ddbc92010-10-15 20:02:0742
[email protected]8a6ff28d2010-12-02 16:35:1943const char kMultiSwitch1[] = "multi_switch1";
44const char kMultiSwitch2[] = "multi_switch2";
[email protected]a82744532011-02-11 16:15:5345const char kValueForMultiSwitch2[] = "value_for_multi_switch2";
[email protected]8a6ff28d2010-12-02 16:35:1946
[email protected]83e9fa702013-02-25 19:30:4447const char kEnableDisableValue1[] = "value1";
48const char kEnableDisableValue2[] = "value2";
49
alemate0107c3272014-09-03 04:30:0450typedef base::HistogramBase::Sample Sample;
51typedef std::map<std::string, Sample> SwitchToIdMap;
[email protected]4b66a7d2014-08-15 17:13:3152
53// This is a helper function to the ReadEnumFromHistogramsXml().
54// Extracts single enum (with integer values) from histograms.xml.
55// Expects |reader| to point at given enum.
56// Returns map { value => label }.
57// Returns empty map on error.
alemate0107c3272014-09-03 04:30:0458std::map<Sample, std::string> ParseEnumFromHistogramsXml(
[email protected]4b66a7d2014-08-15 17:13:3159 const std::string& enum_name,
60 XmlReader* reader) {
61 int entries_index = -1;
62
alemate0107c3272014-09-03 04:30:0463 std::map<Sample, std::string> result;
[email protected]4b66a7d2014-08-15 17:13:3164 bool success = true;
65
66 while (true) {
67 const std::string node_name = reader->NodeName();
68 if (node_name == "enum" && reader->IsClosingElement())
69 break;
70
71 if (node_name == "int") {
72 ++entries_index;
73 std::string value_str;
74 std::string label;
75 const bool has_value = reader->NodeAttribute("value", &value_str);
76 const bool has_label = reader->NodeAttribute("label", &label);
77 if (!has_value) {
78 ADD_FAILURE() << "Bad " << enum_name << " enum entry (at index "
79 << entries_index << ", label='" << label
80 << "'): No 'value' attribute.";
81 success = false;
82 }
83 if (!has_label) {
84 ADD_FAILURE() << "Bad " << enum_name << " enum entry (at index "
85 << entries_index << ", value_str='" << value_str
86 << "'): No 'label' attribute.";
87 success = false;
88 }
89
alemate0107c3272014-09-03 04:30:0490 Sample value;
91 if (has_value && !base::StringToInt(value_str, &value)) {
[email protected]4b66a7d2014-08-15 17:13:3192 ADD_FAILURE() << "Bad " << enum_name << " enum entry (at index "
93 << entries_index << ", label='" << label
94 << "', value_str='" << value_str
95 << "'): 'value' attribute is not integer.";
96 success = false;
97 }
98 if (result.count(value)) {
99 ADD_FAILURE() << "Bad " << enum_name << " enum entry (at index "
100 << entries_index << ", label='" << label
101 << "', value_str='" << value_str
102 << "'): duplicate value '" << value_str
103 << "' found in enum. The previous one has label='"
104 << result[value] << "'.";
105 success = false;
106 }
107 if (success) {
108 result[value] = label;
109 }
110 }
111 // All enum entries are on the same level, so it is enough to iterate
112 // until possible.
113 reader->Next();
114 }
alemate0107c3272014-09-03 04:30:04115 return (success ? result : std::map<Sample, std::string>());
[email protected]4b66a7d2014-08-15 17:13:31116}
117
118// Find and read given enum (with integer values) from histograms.xml.
119// |enum_name| - enum name.
120// |histograms_xml| - must be loaded histograms.xml file.
121//
122// Returns map { value => label } so that:
123// <int value="9" label="enable-pinch-virtual-viewport"/>
124// becomes:
125// { 9 => "enable-pinch-virtual-viewport" }
126// Returns empty map on error.
alemate0107c3272014-09-03 04:30:04127std::map<Sample, std::string> ReadEnumFromHistogramsXml(
[email protected]4b66a7d2014-08-15 17:13:31128 const std::string& enum_name,
129 XmlReader* histograms_xml) {
alemate0107c3272014-09-03 04:30:04130 std::map<Sample, std::string> login_custom_flags;
[email protected]4b66a7d2014-08-15 17:13:31131
132 // Implement simple depth first search.
133 while (true) {
134 const std::string node_name = histograms_xml->NodeName();
135 if (node_name == "enum") {
136 std::string name;
137 if (histograms_xml->NodeAttribute("name", &name) && name == enum_name) {
138 if (!login_custom_flags.empty()) {
139 EXPECT_TRUE(login_custom_flags.empty())
140 << "Duplicate enum '" << enum_name << "' found in histograms.xml";
alemate0107c3272014-09-03 04:30:04141 return std::map<Sample, std::string>();
[email protected]4b66a7d2014-08-15 17:13:31142 }
143
144 const bool got_into_enum = histograms_xml->Read();
145 if (got_into_enum) {
146 login_custom_flags =
147 ParseEnumFromHistogramsXml(enum_name, histograms_xml);
148 EXPECT_FALSE(login_custom_flags.empty())
149 << "Bad enum '" << enum_name
150 << "' found in histograms.xml (format error).";
151 } else {
152 EXPECT_TRUE(got_into_enum)
153 << "Bad enum '" << enum_name
154 << "' (looks empty) found in histograms.xml.";
155 }
156 if (login_custom_flags.empty())
alemate0107c3272014-09-03 04:30:04157 return std::map<Sample, std::string>();
[email protected]4b66a7d2014-08-15 17:13:31158 }
159 }
160 // Go deeper if possible (stops at the closing tag of the deepest node).
161 if (histograms_xml->Read())
162 continue;
163
164 // Try next node on the same level (skips closing tag).
165 if (histograms_xml->Next())
166 continue;
167
168 // Go up until next node on the same level exists.
169 while (histograms_xml->Depth() && !histograms_xml->SkipToElement()) {
170 }
171
172 // Reached top. histograms.xml consists of the single top level node
173 // 'histogram-configuration', so this is the end.
174 if (!histograms_xml->Depth())
175 break;
176 }
177 EXPECT_FALSE(login_custom_flags.empty())
178 << "Enum '" << enum_name << "' is not found in histograms.xml.";
179 return login_custom_flags;
180}
181
182std::string FilePathStringTypeToString(const base::FilePath::StringType& path) {
183#if defined(OS_WIN)
184 return base::UTF16ToUTF8(path);
185#else
186 return path;
187#endif
188}
189
190std::set<std::string> GetAllSwitchesForTesting() {
191 std::set<std::string> result;
192
193 size_t num_experiments = 0;
asvitkine26e40322015-05-21 21:28:30194 const Experiment* experiments =
195 testing::GetExperiments(&num_experiments);
[email protected]4b66a7d2014-08-15 17:13:31196
197 for (size_t i = 0; i < num_experiments; ++i) {
asvitkine26e40322015-05-21 21:28:30198 const Experiment& experiment = experiments[i];
flackr0a5eb1562015-06-12 18:50:14199 if (experiment.type == Experiment::SINGLE_VALUE ||
200 experiment.type == Experiment::SINGLE_DISABLE_VALUE) {
[email protected]4b66a7d2014-08-15 17:13:31201 result.insert(experiment.command_line_switch);
asvitkine26e40322015-05-21 21:28:30202 } else if (experiment.type == Experiment::MULTI_VALUE) {
[email protected]4b66a7d2014-08-15 17:13:31203 for (int j = 0; j < experiment.num_choices; ++j) {
204 result.insert(experiment.choices[j].command_line_switch);
205 }
206 } else {
asvitkine26e40322015-05-21 21:28:30207 DCHECK_EQ(experiment.type, Experiment::ENABLE_DISABLE_VALUE);
[email protected]4b66a7d2014-08-15 17:13:31208 result.insert(experiment.command_line_switch);
209 result.insert(experiment.disable_command_line_switch);
210 }
211 }
212 return result;
213}
214
215} // anonymous namespace
216
[email protected]8a6ff28d2010-12-02 16:35:19217const Experiment::Choice kMultiChoices[] = {
[email protected]a82744532011-02-11 16:15:53218 { IDS_PRODUCT_NAME, "", "" },
219 { IDS_PRODUCT_NAME, kMultiSwitch1, "" },
220 { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 },
[email protected]8a6ff28d2010-12-02 16:35:19221};
222
223// The experiments that are set for these tests. The 3rd experiment is not
224// supported on the current platform, all others are.
[email protected]a314ee5a2010-10-26 21:23:28225static Experiment kExperiments[] = {
226 {
227 kFlags1,
228 IDS_PRODUCT_NAME,
229 IDS_PRODUCT_NAME,
230 0, // Ends up being mapped to the current platform.
[email protected]8a6ff28d2010-12-02 16:35:19231 Experiment::SINGLE_VALUE,
232 kSwitch1,
[email protected]a82744532011-02-11 16:15:53233 "",
[email protected]8a6ff28d2010-12-02 16:35:19234 NULL,
[email protected]83e9fa702013-02-25 19:30:44235 NULL,
236 NULL,
[email protected]8a6ff28d2010-12-02 16:35:19237 0
[email protected]a314ee5a2010-10-26 21:23:28238 },
239 {
240 kFlags2,
241 IDS_PRODUCT_NAME,
242 IDS_PRODUCT_NAME,
243 0, // Ends up being mapped to the current platform.
[email protected]8a6ff28d2010-12-02 16:35:19244 Experiment::SINGLE_VALUE,
245 kSwitch2,
[email protected]a82744532011-02-11 16:15:53246 kValueForSwitch2,
[email protected]8a6ff28d2010-12-02 16:35:19247 NULL,
[email protected]83e9fa702013-02-25 19:30:44248 NULL,
249 NULL,
[email protected]8a6ff28d2010-12-02 16:35:19250 0
[email protected]a314ee5a2010-10-26 21:23:28251 },
252 {
253 kFlags3,
254 IDS_PRODUCT_NAME,
255 IDS_PRODUCT_NAME,
256 0, // This ends up enabling for an OS other than the current.
[email protected]8a6ff28d2010-12-02 16:35:19257 Experiment::SINGLE_VALUE,
258 kSwitch3,
[email protected]a82744532011-02-11 16:15:53259 "",
[email protected]8a6ff28d2010-12-02 16:35:19260 NULL,
[email protected]83e9fa702013-02-25 19:30:44261 NULL,
262 NULL,
[email protected]8a6ff28d2010-12-02 16:35:19263 0
264 },
265 {
266 kFlags4,
267 IDS_PRODUCT_NAME,
268 IDS_PRODUCT_NAME,
269 0, // Ends up being mapped to the current platform.
270 Experiment::MULTI_VALUE,
271 "",
[email protected]a82744532011-02-11 16:15:53272 "",
[email protected]83e9fa702013-02-25 19:30:44273 "",
274 "",
[email protected]8a6ff28d2010-12-02 16:35:19275 kMultiChoices,
276 arraysize(kMultiChoices)
[email protected]a314ee5a2010-10-26 21:23:28277 },
[email protected]83e9fa702013-02-25 19:30:44278 {
279 kFlags5,
280 IDS_PRODUCT_NAME,
281 IDS_PRODUCT_NAME,
282 0, // Ends up being mapped to the current platform.
283 Experiment::ENABLE_DISABLE_VALUE,
284 kSwitch1,
285 kEnableDisableValue1,
286 kSwitch2,
287 kEnableDisableValue2,
288 NULL,
289 3
290 },
flackr0a5eb1562015-06-12 18:50:14291 {
292 kFlags6,
293 IDS_PRODUCT_NAME,
294 IDS_PRODUCT_NAME,
295 0,
296 Experiment::SINGLE_DISABLE_VALUE,
297 kSwitch6,
298 "",
299 NULL,
300 NULL,
301 NULL,
302 0
303 },
[email protected]a314ee5a2010-10-26 21:23:28304};
305
[email protected]e2ddbc92010-10-15 20:02:07306class AboutFlagsTest : public ::testing::Test {
307 protected:
[email protected]e6d1c4f2013-06-12 17:37:40308 AboutFlagsTest() : flags_storage_(&prefs_) {
[email protected]b1de2c72013-02-06 02:45:47309 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
[email protected]e2ddbc92010-10-15 20:02:07310 testing::ClearState();
311 }
312
dchenge1bc7982014-10-30 00:32:40313 void SetUp() override {
[email protected]a314ee5a2010-10-26 21:23:28314 for (size_t i = 0; i < arraysize(kExperiments); ++i)
315 kExperiments[i].supported_platforms = GetCurrentPlatform();
316
317 int os_other_than_current = 1;
318 while (os_other_than_current == GetCurrentPlatform())
319 os_other_than_current <<= 1;
320 kExperiments[2].supported_platforms = os_other_than_current;
321
322 testing::SetExperiments(kExperiments, arraysize(kExperiments));
323 }
324
dchenge1bc7982014-10-30 00:32:40325 void TearDown() override { testing::SetExperiments(NULL, 0); }
[email protected]a314ee5a2010-10-26 21:23:28326
[email protected]5b199522012-12-22 17:24:44327 TestingPrefServiceSimple prefs_;
[email protected]e6d1c4f2013-06-12 17:37:40328 PrefServiceFlagsStorage flags_storage_;
[email protected]e2ddbc92010-10-15 20:02:07329};
330
[email protected]147492b2013-03-19 23:52:08331
332TEST_F(AboutFlagsTest, NoChangeNoRestart) {
333 EXPECT_FALSE(IsRestartNeededToCommitChanges());
[email protected]e6d1c4f2013-06-12 17:37:40334 SetExperimentEnabled(&flags_storage_, kFlags1, false);
[email protected]147492b2013-03-19 23:52:08335 EXPECT_FALSE(IsRestartNeededToCommitChanges());
flackr0a5eb1562015-06-12 18:50:14336
337 // kFlags6 is enabled by default, so enabling should not require a restart.
338 SetExperimentEnabled(&flags_storage_, kFlags6, true);
339 EXPECT_FALSE(IsRestartNeededToCommitChanges());
[email protected]147492b2013-03-19 23:52:08340}
341
[email protected]e2ddbc92010-10-15 20:02:07342TEST_F(AboutFlagsTest, ChangeNeedsRestart) {
[email protected]e2ddbc92010-10-15 20:02:07343 EXPECT_FALSE(IsRestartNeededToCommitChanges());
[email protected]e6d1c4f2013-06-12 17:37:40344 SetExperimentEnabled(&flags_storage_, kFlags1, true);
[email protected]e2ddbc92010-10-15 20:02:07345 EXPECT_TRUE(IsRestartNeededToCommitChanges());
346}
347
flackr0a5eb1562015-06-12 18:50:14348// Tests that disabling a default enabled experiment requires a restart.
349TEST_F(AboutFlagsTest, DisableChangeNeedsRestart) {
350 EXPECT_FALSE(IsRestartNeededToCommitChanges());
351 SetExperimentEnabled(&flags_storage_, kFlags6, false);
352 EXPECT_TRUE(IsRestartNeededToCommitChanges());
353}
354
[email protected]147492b2013-03-19 23:52:08355TEST_F(AboutFlagsTest, MultiFlagChangeNeedsRestart) {
356 const Experiment& experiment = kExperiments[3];
357 ASSERT_EQ(kFlags4, experiment.internal_name);
358 EXPECT_FALSE(IsRestartNeededToCommitChanges());
359 // Enable the 2nd choice of the multi-value.
[email protected]e6d1c4f2013-06-12 17:37:40360 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
[email protected]147492b2013-03-19 23:52:08361 EXPECT_TRUE(IsRestartNeededToCommitChanges());
362 testing::ClearState();
363 EXPECT_FALSE(IsRestartNeededToCommitChanges());
364 // Enable the default choice now.
[email protected]e6d1c4f2013-06-12 17:37:40365 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
[email protected]147492b2013-03-19 23:52:08366 EXPECT_TRUE(IsRestartNeededToCommitChanges());
367}
368
[email protected]e2ddbc92010-10-15 20:02:07369TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) {
[email protected]e2ddbc92010-10-15 20:02:07370 // Add two experiments, check they're there.
[email protected]e6d1c4f2013-06-12 17:37:40371 SetExperimentEnabled(&flags_storage_, kFlags1, true);
372 SetExperimentEnabled(&flags_storage_, kFlags2, true);
[email protected]e2ddbc92010-10-15 20:02:07373
[email protected]5bcdd99d2013-12-23 18:28:30374 const base::ListValue* experiments_list = prefs_.GetList(
[email protected]e2ddbc92010-10-15 20:02:07375 prefs::kEnabledLabsExperiments);
376 ASSERT_TRUE(experiments_list != NULL);
377
378 ASSERT_EQ(2u, experiments_list->GetSize());
379
380 std::string s0;
381 ASSERT_TRUE(experiments_list->GetString(0, &s0));
382 std::string s1;
383 ASSERT_TRUE(experiments_list->GetString(1, &s1));
384
385 EXPECT_TRUE(s0 == kFlags1 || s1 == kFlags1);
386 EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2);
387
388 // Remove one experiment, check the other's still around.
[email protected]e6d1c4f2013-06-12 17:37:40389 SetExperimentEnabled(&flags_storage_, kFlags2, false);
[email protected]e2ddbc92010-10-15 20:02:07390
[email protected]1bc78422011-03-31 08:41:38391 experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
[email protected]e2ddbc92010-10-15 20:02:07392 ASSERT_TRUE(experiments_list != NULL);
393 ASSERT_EQ(1u, experiments_list->GetSize());
394 ASSERT_TRUE(experiments_list->GetString(0, &s0));
395 EXPECT_TRUE(s0 == kFlags1);
396}
397
398TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) {
[email protected]e2ddbc92010-10-15 20:02:07399 // Add two experiments, check the pref exists.
[email protected]e6d1c4f2013-06-12 17:37:40400 SetExperimentEnabled(&flags_storage_, kFlags1, true);
401 SetExperimentEnabled(&flags_storage_, kFlags2, true);
[email protected]5bcdd99d2013-12-23 18:28:30402 const base::ListValue* experiments_list = prefs_.GetList(
[email protected]e2ddbc92010-10-15 20:02:07403 prefs::kEnabledLabsExperiments);
404 ASSERT_TRUE(experiments_list != NULL);
405
406 // Remove both, the pref should have been removed completely.
[email protected]e6d1c4f2013-06-12 17:37:40407 SetExperimentEnabled(&flags_storage_, kFlags1, false);
408 SetExperimentEnabled(&flags_storage_, kFlags2, false);
[email protected]1bc78422011-03-31 08:41:38409 experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
[email protected]e2ddbc92010-10-15 20:02:07410 EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0);
411}
412
413TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) {
[email protected]e6d1c4f2013-06-12 17:37:40414 SetExperimentEnabled(&flags_storage_, kFlags1, true);
[email protected]e2ddbc92010-10-15 20:02:07415
avi3ef9ec9e2014-12-22 22:50:17416 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]e2ddbc92010-10-15 20:02:07417 command_line.AppendSwitch("foo");
418
419 EXPECT_TRUE(command_line.HasSwitch("foo"));
[email protected]a314ee5a2010-10-26 21:23:28420 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
[email protected]e2ddbc92010-10-15 20:02:07421
[email protected]578f2092013-09-16 17:16:21422 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]e2ddbc92010-10-15 20:02:07423
424 EXPECT_TRUE(command_line.HasSwitch("foo"));
[email protected]cd7fa99f2011-09-07 01:24:55425 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
[email protected]578f2092013-09-16 17:16:21426 EXPECT_TRUE(command_line.HasSwitch(switches::kFlagSwitchesBegin));
427 EXPECT_TRUE(command_line.HasSwitch(switches::kFlagSwitchesEnd));
428
avi3ef9ec9e2014-12-22 22:50:17429 base::CommandLine command_line2(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21430
431 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels);
432
433 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
434 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
435 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
[email protected]e2ddbc92010-10-15 20:02:07436}
437
avi3ef9ec9e2014-12-22 22:50:17438base::CommandLine::StringType CreateSwitch(const std::string& value) {
[email protected]4b66a7d2014-08-15 17:13:31439#if defined(OS_WIN)
440 return base::ASCIIToUTF16(value);
441#else
442 return value;
443#endif
444}
445
[email protected]6d98abf2013-06-17 23:35:51446TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) {
447 SetExperimentEnabled(&flags_storage_, kFlags1, true);
448
[email protected]4b66a7d2014-08-15 17:13:31449 const std::string kDoubleDash("--");
450
avi3ef9ec9e2014-12-22 22:50:17451 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]6d98abf2013-06-17 23:35:51452 command_line.AppendSwitch("foo");
453
avi3ef9ec9e2014-12-22 22:50:17454 base::CommandLine new_command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21455 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels);
[email protected]6d98abf2013-06-17 23:35:51456
[email protected]4b66a7d2014-08-15 17:13:31457 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
458 new_command_line, command_line, NULL));
459 {
avi3ef9ec9e2014-12-22 22:50:17460 std::set<base::CommandLine::StringType> difference;
[email protected]4b66a7d2014-08-15 17:13:31461 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
462 new_command_line, command_line, &difference));
463 EXPECT_EQ(1U, difference.size());
464 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1)));
465 }
[email protected]6d98abf2013-06-17 23:35:51466
[email protected]578f2092013-09-16 17:16:21467 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]6d98abf2013-06-17 23:35:51468
[email protected]4b66a7d2014-08-15 17:13:31469 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
470 new_command_line, command_line, NULL));
471 {
avi3ef9ec9e2014-12-22 22:50:17472 std::set<base::CommandLine::StringType> difference;
[email protected]4b66a7d2014-08-15 17:13:31473 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
474 new_command_line, command_line, &difference));
475 EXPECT_TRUE(difference.empty());
476 }
[email protected]6d98abf2013-06-17 23:35:51477
478 // Now both have flags but different.
479 SetExperimentEnabled(&flags_storage_, kFlags1, false);
480 SetExperimentEnabled(&flags_storage_, kFlags2, true);
481
avi3ef9ec9e2014-12-22 22:50:17482 base::CommandLine another_command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21483 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels);
[email protected]6d98abf2013-06-17 23:35:51484
[email protected]4b66a7d2014-08-15 17:13:31485 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
486 new_command_line, another_command_line, NULL));
487 {
avi3ef9ec9e2014-12-22 22:50:17488 std::set<base::CommandLine::StringType> difference;
[email protected]4b66a7d2014-08-15 17:13:31489 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
490 new_command_line, another_command_line, &difference));
491 EXPECT_EQ(2U, difference.size());
492 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1)));
493 EXPECT_EQ(1U,
494 difference.count(CreateSwitch(kDoubleDash + kSwitch2 + "=" +
495 kValueForSwitch2)));
496 }
[email protected]6d98abf2013-06-17 23:35:51497}
498
[email protected]e2ddbc92010-10-15 20:02:07499TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
avi3ef9ec9e2014-12-22 22:50:17500 std::map<std::string, base::CommandLine::StringType> switch_list;
501 switch_list[kSwitch1] = base::CommandLine::StringType();
502 switch_list[switches::kFlagSwitchesBegin] = base::CommandLine::StringType();
503 switch_list[switches::kFlagSwitchesEnd] = base::CommandLine::StringType();
504 switch_list["foo"] = base::CommandLine::StringType();
[email protected]e2ddbc92010-10-15 20:02:07505
[email protected]e6d1c4f2013-06-12 17:37:40506 SetExperimentEnabled(&flags_storage_, kFlags1, true);
[email protected]e2ddbc92010-10-15 20:02:07507
508 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called.
509 RemoveFlagsSwitches(&switch_list);
510 ASSERT_EQ(4u, switch_list.size());
[email protected]a314ee5a2010-10-26 21:23:28511 EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end());
[email protected]e2ddbc92010-10-15 20:02:07512 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) !=
513 switch_list.end());
514 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) !=
515 switch_list.end());
516 EXPECT_TRUE(switch_list.find("foo") != switch_list.end());
517
518 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again.
avi3ef9ec9e2014-12-22 22:50:17519 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]e2ddbc92010-10-15 20:02:07520 command_line.AppendSwitch("foo");
[email protected]578f2092013-09-16 17:16:21521 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]e2ddbc92010-10-15 20:02:07522 RemoveFlagsSwitches(&switch_list);
523
524 // Now the about:flags-related switch should have been removed.
525 ASSERT_EQ(1u, switch_list.size());
526 EXPECT_TRUE(switch_list.find("foo") != switch_list.end());
527}
528
[email protected]a314ee5a2010-10-26 21:23:28529// Tests enabling experiments that aren't supported on the current platform.
530TEST_F(AboutFlagsTest, PersistAndPrune) {
[email protected]8a6ff28d2010-12-02 16:35:19531 // Enable experiments 1 and 3.
[email protected]e6d1c4f2013-06-12 17:37:40532 SetExperimentEnabled(&flags_storage_, kFlags1, true);
533 SetExperimentEnabled(&flags_storage_, kFlags3, true);
avi3ef9ec9e2014-12-22 22:50:17534 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]a314ee5a2010-10-26 21:23:28535 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
536 EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
537
538 // Convert the flags to switches. Experiment 3 shouldn't be among the switches
539 // as it is not applicable to the current platform.
[email protected]578f2092013-09-16 17:16:21540 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]cd7fa99f2011-09-07 01:24:55541 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
[email protected]a314ee5a2010-10-26 21:23:28542 EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
543
544 // Experiment 3 should show still be persisted in preferences though.
[email protected]5bcdd99d2013-12-23 18:28:30545 const base::ListValue* experiments_list =
[email protected]ee28495a2013-05-20 04:10:52546 prefs_.GetList(prefs::kEnabledLabsExperiments);
547 ASSERT_TRUE(experiments_list);
548 EXPECT_EQ(2U, experiments_list->GetSize());
549 std::string s0;
550 ASSERT_TRUE(experiments_list->GetString(0, &s0));
551 EXPECT_EQ(kFlags1, s0);
552 std::string s1;
553 ASSERT_TRUE(experiments_list->GetString(1, &s1));
554 EXPECT_EQ(kFlags3, s1);
[email protected]8a6ff28d2010-12-02 16:35:19555}
556
[email protected]a82744532011-02-11 16:15:53557// Tests that switches which should have values get them in the command
558// line.
559TEST_F(AboutFlagsTest, CheckValues) {
560 // Enable experiments 1 and 2.
[email protected]e6d1c4f2013-06-12 17:37:40561 SetExperimentEnabled(&flags_storage_, kFlags1, true);
562 SetExperimentEnabled(&flags_storage_, kFlags2, true);
avi3ef9ec9e2014-12-22 22:50:17563 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]a82744532011-02-11 16:15:53564 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
565 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
566
567 // Convert the flags to switches.
[email protected]578f2092013-09-16 17:16:21568 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]cd7fa99f2011-09-07 01:24:55569 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
[email protected]007b3f82013-04-09 08:46:45570 EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1));
[email protected]cd7fa99f2011-09-07 01:24:55571 EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
572 EXPECT_EQ(std::string(kValueForSwitch2),
[email protected]a82744532011-02-11 16:15:53573 command_line.GetSwitchValueASCII(kSwitch2));
574
575 // Confirm that there is no '=' in the command line for simple switches.
576 std::string switch1_with_equals = std::string("--") +
577 std::string(kSwitch1) +
578 std::string("=");
579#if defined(OS_WIN)
thestig11bf74d2014-11-24 20:14:42580 EXPECT_EQ(base::string16::npos,
[email protected]61a4c6f2011-07-20 04:54:52581 command_line.GetCommandLineString().find(
thestig11bf74d2014-11-24 20:14:42582 base::ASCIIToUTF16(switch1_with_equals)));
[email protected]a82744532011-02-11 16:15:53583#else
584 EXPECT_EQ(std::string::npos,
[email protected]61a4c6f2011-07-20 04:54:52585 command_line.GetCommandLineString().find(switch1_with_equals));
[email protected]a82744532011-02-11 16:15:53586#endif
587
588 // And confirm there is a '=' for switches with values.
589 std::string switch2_with_equals = std::string("--") +
590 std::string(kSwitch2) +
591 std::string("=");
[email protected]5b199522012-12-22 17:24:44592#if defined(OS_WIN)
thestig11bf74d2014-11-24 20:14:42593 EXPECT_NE(base::string16::npos,
[email protected]61a4c6f2011-07-20 04:54:52594 command_line.GetCommandLineString().find(
thestig11bf74d2014-11-24 20:14:42595 base::ASCIIToUTF16(switch2_with_equals)));
[email protected]a82744532011-02-11 16:15:53596#else
[email protected]cd7fa99f2011-09-07 01:24:55597 EXPECT_NE(std::string::npos,
[email protected]61a4c6f2011-07-20 04:54:52598 command_line.GetCommandLineString().find(switch2_with_equals));
[email protected]a82744532011-02-11 16:15:53599#endif
600
[email protected]ee28495a2013-05-20 04:10:52601 // And it should persist.
[email protected]5bcdd99d2013-12-23 18:28:30602 const base::ListValue* experiments_list =
[email protected]ee28495a2013-05-20 04:10:52603 prefs_.GetList(prefs::kEnabledLabsExperiments);
604 ASSERT_TRUE(experiments_list);
605 EXPECT_EQ(2U, experiments_list->GetSize());
606 std::string s0;
607 ASSERT_TRUE(experiments_list->GetString(0, &s0));
608 EXPECT_EQ(kFlags1, s0);
609 std::string s1;
610 ASSERT_TRUE(experiments_list->GetString(1, &s1));
611 EXPECT_EQ(kFlags2, s1);
[email protected]a82744532011-02-11 16:15:53612}
613
[email protected]28e35af2011-02-09 12:56:22614// Tests multi-value type experiments.
[email protected]8a6ff28d2010-12-02 16:35:19615TEST_F(AboutFlagsTest, MultiValues) {
[email protected]83e9fa702013-02-25 19:30:44616 const Experiment& experiment = kExperiments[3];
617 ASSERT_EQ(kFlags4, experiment.internal_name);
618
[email protected]28e35af2011-02-09 12:56:22619 // Initially, the first "deactivated" option of the multi experiment should
620 // be set.
[email protected]8a6ff28d2010-12-02 16:35:19621 {
avi3ef9ec9e2014-12-22 22:50:17622 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21623 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]28e35af2011-02-09 12:56:22624 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
[email protected]8a6ff28d2010-12-02 16:35:19625 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
626 }
627
[email protected]28e35af2011-02-09 12:56:22628 // Enable the 2nd choice of the multi-value.
[email protected]e6d1c4f2013-06-12 17:37:40629 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
[email protected]8a6ff28d2010-12-02 16:35:19630 {
avi3ef9ec9e2014-12-22 22:50:17631 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21632 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]8a6ff28d2010-12-02 16:35:19633 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
[email protected]cd7fa99f2011-09-07 01:24:55634 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2));
635 EXPECT_EQ(std::string(kValueForMultiSwitch2),
[email protected]a82744532011-02-11 16:15:53636 command_line.GetSwitchValueASCII(kMultiSwitch2));
[email protected]8a6ff28d2010-12-02 16:35:19637 }
638
639 // Disable the multi-value experiment.
[email protected]e6d1c4f2013-06-12 17:37:40640 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
[email protected]83e9fa702013-02-25 19:30:44641 {
avi3ef9ec9e2014-12-22 22:50:17642 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21643 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]83e9fa702013-02-25 19:30:44644 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
645 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
646 }
647}
648
flackr0a5eb1562015-06-12 18:50:14649// Tests that disable flags are added when an experiment is disabled.
650TEST_F(AboutFlagsTest, DisableFlagCommandLine) {
651 // Nothing selected.
652 {
653 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
654 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
655 EXPECT_FALSE(command_line.HasSwitch(kSwitch6));
656 }
657
658 // Disable the experiment 6.
659 SetExperimentEnabled(&flags_storage_, kFlags6, false);
660 {
661 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
662 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
663 EXPECT_TRUE(command_line.HasSwitch(kSwitch6));
664 }
665
666 // Enable experiment 6.
667 SetExperimentEnabled(&flags_storage_, kFlags6, true);
668 {
669 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
670 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
671 EXPECT_FALSE(command_line.HasSwitch(kSwitch6));
672 }
673}
674
[email protected]83e9fa702013-02-25 19:30:44675TEST_F(AboutFlagsTest, EnableDisableValues) {
676 const Experiment& experiment = kExperiments[4];
677 ASSERT_EQ(kFlags5, experiment.internal_name);
678
679 // Nothing selected.
680 {
avi3ef9ec9e2014-12-22 22:50:17681 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21682 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]83e9fa702013-02-25 19:30:44683 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
684 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
685 }
686
687 // "Enable" option selected.
[email protected]e6d1c4f2013-06-12 17:37:40688 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true);
[email protected]83e9fa702013-02-25 19:30:44689 {
avi3ef9ec9e2014-12-22 22:50:17690 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21691 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]83e9fa702013-02-25 19:30:44692 EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
693 EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
694 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
695 }
696
697 // "Disable" option selected.
[email protected]e6d1c4f2013-06-12 17:37:40698 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
[email protected]83e9fa702013-02-25 19:30:44699 {
avi3ef9ec9e2014-12-22 22:50:17700 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21701 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]83e9fa702013-02-25 19:30:44702 EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
703 EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
704 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
705 }
706
707 // "Default" option selected, same as nothing selected.
[email protected]e6d1c4f2013-06-12 17:37:40708 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
[email protected]8a6ff28d2010-12-02 16:35:19709 {
avi3ef9ec9e2014-12-22 22:50:17710 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]578f2092013-09-16 17:16:21711 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
[email protected]8a6ff28d2010-12-02 16:35:19712 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
713 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
714 }
715}
716
717// Makes sure there are no separators in any of the experiment names.
718TEST_F(AboutFlagsTest, NoSeparators) {
719 testing::SetExperiments(NULL, 0);
720 size_t count;
721 const Experiment* experiments = testing::GetExperiments(&count);
722 for (size_t i = 0; i < count; ++i) {
723 std::string name = experiments->internal_name;
724 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i;
725 }
[email protected]a314ee5a2010-10-26 21:23:28726}
727
[email protected]4b66a7d2014-08-15 17:13:31728class AboutFlagsHistogramTest : public ::testing::Test {
729 protected:
730 // This is a helper function to check that all IDs in enum LoginCustomFlags in
731 // histograms.xml are unique.
732 void SetSwitchToHistogramIdMapping(const std::string& switch_name,
alemate0107c3272014-09-03 04:30:04733 const Sample switch_histogram_id,
734 std::map<std::string, Sample>* out_map) {
735 const std::pair<std::map<std::string, Sample>::iterator, bool> status =
[email protected]4b66a7d2014-08-15 17:13:31736 out_map->insert(std::make_pair(switch_name, switch_histogram_id));
737 if (!status.second) {
738 EXPECT_TRUE(status.first->second == switch_histogram_id)
739 << "Duplicate switch '" << switch_name
740 << "' found in enum 'LoginCustomFlags' in histograms.xml.";
741 }
742 }
743
744 // This method generates a hint for the user for what string should be added
745 // to the enum LoginCustomFlags to make in consistent.
746 std::string GetHistogramEnumEntryText(const std::string& switch_name,
alemate0107c3272014-09-03 04:30:04747 Sample value) {
[email protected]4b66a7d2014-08-15 17:13:31748 return base::StringPrintf(
alemate0107c3272014-09-03 04:30:04749 "<int value=\"%d\" label=\"%s\"/>", value, switch_name.c_str());
[email protected]4b66a7d2014-08-15 17:13:31750 }
751};
752
753TEST_F(AboutFlagsHistogramTest, CheckHistograms) {
754 base::FilePath histograms_xml_file_path;
755 ASSERT_TRUE(
756 PathService::Get(base::DIR_SOURCE_ROOT, &histograms_xml_file_path));
757 histograms_xml_file_path = histograms_xml_file_path.AppendASCII("tools")
758 .AppendASCII("metrics")
759 .AppendASCII("histograms")
760 .AppendASCII("histograms.xml");
761
762 XmlReader histograms_xml;
763 ASSERT_TRUE(histograms_xml.LoadFile(
764 FilePathStringTypeToString(histograms_xml_file_path.value())));
alemate0107c3272014-09-03 04:30:04765 std::map<Sample, std::string> login_custom_flags =
[email protected]4b66a7d2014-08-15 17:13:31766 ReadEnumFromHistogramsXml("LoginCustomFlags", &histograms_xml);
767 ASSERT_TRUE(login_custom_flags.size())
768 << "Error reading enum 'LoginCustomFlags' from histograms.xml.";
769
770 // Build reverse map {switch_name => id} from login_custom_flags.
771 SwitchToIdMap histograms_xml_switches_ids;
772
asvitkinebff63b22014-11-25 01:03:52773 EXPECT_TRUE(login_custom_flags.count(testing::kBadSwitchFormatHistogramId))
[email protected]4b66a7d2014-08-15 17:13:31774 << "Entry for UMA ID of incorrect command-line flag is not found in "
775 "histograms.xml enum LoginCustomFlags. "
776 "Consider adding entry:\n"
777 << " " << GetHistogramEnumEntryText("BAD_FLAG_FORMAT", 0);
778 // Check that all LoginCustomFlags entries have correct values.
asvitkinebff63b22014-11-25 01:03:52779 for (const auto& entry : login_custom_flags) {
780 if (entry.first == testing::kBadSwitchFormatHistogramId) {
781 // Add error value with empty name.
782 SetSwitchToHistogramIdMapping(std::string(), entry.first,
783 &histograms_xml_switches_ids);
[email protected]4b66a7d2014-08-15 17:13:31784 continue;
785 }
asvitkinebff63b22014-11-25 01:03:52786 const Sample uma_id = GetSwitchUMAId(entry.second);
787 EXPECT_EQ(uma_id, entry.first)
[email protected]4b66a7d2014-08-15 17:13:31788 << "histograms.xml enum LoginCustomFlags "
asvitkinebff63b22014-11-25 01:03:52789 "entry '" << entry.second << "' has incorrect value=" << entry.first
[email protected]4b66a7d2014-08-15 17:13:31790 << ", but " << uma_id << " is expected. Consider changing entry to:\n"
asvitkinebff63b22014-11-25 01:03:52791 << " " << GetHistogramEnumEntryText(entry.second, uma_id);
792 SetSwitchToHistogramIdMapping(entry.second, entry.first,
793 &histograms_xml_switches_ids);
[email protected]4b66a7d2014-08-15 17:13:31794 }
795
796 // Check that all flags in about_flags.cc have entries in login_custom_flags.
797 std::set<std::string> all_switches = GetAllSwitchesForTesting();
asvitkinebff63b22014-11-25 01:03:52798 for (const std::string& flag : all_switches) {
[email protected]4b66a7d2014-08-15 17:13:31799 // Skip empty placeholders.
asvitkinebff63b22014-11-25 01:03:52800 if (flag.empty())
[email protected]4b66a7d2014-08-15 17:13:31801 continue;
asvitkinebff63b22014-11-25 01:03:52802 const Sample uma_id = GetSwitchUMAId(flag);
803 EXPECT_NE(testing::kBadSwitchFormatHistogramId, uma_id)
804 << "Command-line switch '" << flag
[email protected]4b66a7d2014-08-15 17:13:31805 << "' from about_flags.cc has UMA ID equal to reserved value "
asvitkinebff63b22014-11-25 01:03:52806 "kBadSwitchFormatHistogramId="
807 << testing::kBadSwitchFormatHistogramId
[email protected]4b66a7d2014-08-15 17:13:31808 << ". Please modify switch name.";
809 SwitchToIdMap::iterator enum_entry =
asvitkinebff63b22014-11-25 01:03:52810 histograms_xml_switches_ids.lower_bound(flag);
[email protected]4b66a7d2014-08-15 17:13:31811
812 // Ignore case here when switch ID is incorrect - it has already been
813 // reported in the previous loop.
814 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() &&
asvitkinebff63b22014-11-25 01:03:52815 enum_entry->first == flag)
[email protected]4b66a7d2014-08-15 17:13:31816 << "histograms.xml enum LoginCustomFlags doesn't contain switch '"
asvitkinebff63b22014-11-25 01:03:52817 << flag << "' (value=" << uma_id
[email protected]4b66a7d2014-08-15 17:13:31818 << " expected). Consider adding entry:\n"
asvitkinebff63b22014-11-25 01:03:52819 << " " << GetHistogramEnumEntryText(flag, uma_id);
[email protected]4b66a7d2014-08-15 17:13:31820 }
821}
822
[email protected]e2ddbc92010-10-15 20:02:07823} // namespace about_flags