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

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

Issue 344883002: Collect UMA statistics on which chrome://flags lead to chrome restart on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/prefs/pref_registry_simple.h" 5 #include "base/prefs/pref_registry_simple.h"
6 #include "base/prefs/testing_pref_service.h" 6 #include "base/prefs/testing_pref_service.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/about_flags.h" 10 #include "chrome/browser/about_flags.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 CommandLine command_line2(CommandLine::NO_PROGRAM); 227 CommandLine command_line2(CommandLine::NO_PROGRAM);
228 228
229 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels); 229 ConvertFlagsToSwitches(&flags_storage_, &command_line2, kNoSentinels);
230 230
231 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1)); 231 EXPECT_TRUE(command_line2.HasSwitch(kSwitch1));
232 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin)); 232 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesBegin));
233 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd)); 233 EXPECT_FALSE(command_line2.HasSwitch(switches::kFlagSwitchesEnd));
234 } 234 }
235 235
236 CommandLine::StringType CreateSwitch(const std::string& value) {
237 #if defined(OS_WIN)
238 return ASCIIToUTF16(value);
239 #else
240 return value;
241 #endif
242 }
243
236 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { 244 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) {
237 SetExperimentEnabled(&flags_storage_, kFlags1, true); 245 SetExperimentEnabled(&flags_storage_, kFlags1, true);
238 246
247 const std::string kDoubleDash("--");
248
239 CommandLine command_line(CommandLine::NO_PROGRAM); 249 CommandLine command_line(CommandLine::NO_PROGRAM);
240 command_line.AppendSwitch("foo"); 250 command_line.AppendSwitch("foo");
241 251
242 CommandLine new_command_line(CommandLine::NO_PROGRAM); 252 CommandLine new_command_line(CommandLine::NO_PROGRAM);
243 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); 253 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels);
244 254
245 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 255 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
246 command_line)); 256 new_command_line, command_line, NULL));
257 {
258 std::set<CommandLine::StringType> difference;
259 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
260 new_command_line, command_line, &difference));
261 EXPECT_EQ(1U, difference.size());
262 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1)));
263 }
247 264
248 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); 265 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels);
249 266
250 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 267 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
251 command_line)); 268 new_command_line, command_line, NULL));
269 {
270 std::set<CommandLine::StringType> difference;
271 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine(
272 new_command_line, command_line, &difference));
273 EXPECT_TRUE(difference.empty());
274 }
252 275
253 // Now both have flags but different. 276 // Now both have flags but different.
254 SetExperimentEnabled(&flags_storage_, kFlags1, false); 277 SetExperimentEnabled(&flags_storage_, kFlags1, false);
255 SetExperimentEnabled(&flags_storage_, kFlags2, true); 278 SetExperimentEnabled(&flags_storage_, kFlags2, true);
256 279
257 CommandLine another_command_line(CommandLine::NO_PROGRAM); 280 CommandLine another_command_line(CommandLine::NO_PROGRAM);
258 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); 281 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels);
259 282
260 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(new_command_line, 283 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
261 another_command_line)); 284 new_command_line, another_command_line, NULL));
285 {
286 std::set<CommandLine::StringType> difference;
287 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine(
288 new_command_line, another_command_line, &difference));
289 EXPECT_EQ(2U, difference.size());
290 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1)));
291 EXPECT_EQ(1U,
292 difference.count(CreateSwitch(kDoubleDash + kSwitch2 + "=" +
293 kValueForSwitch2)));
294 }
262 } 295 }
263 296
264 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { 297 TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
265 std::map<std::string, CommandLine::StringType> switch_list; 298 std::map<std::string, CommandLine::StringType> switch_list;
266 switch_list[kSwitch1] = CommandLine::StringType(); 299 switch_list[kSwitch1] = CommandLine::StringType();
267 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); 300 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType();
268 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); 301 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType();
269 switch_list["foo"] = CommandLine::StringType(); 302 switch_list["foo"] = CommandLine::StringType();
270 303
271 SetExperimentEnabled(&flags_storage_, kFlags1, true); 304 SetExperimentEnabled(&flags_storage_, kFlags1, true);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 testing::SetExperiments(NULL, 0); 491 testing::SetExperiments(NULL, 0);
459 size_t count; 492 size_t count;
460 const Experiment* experiments = testing::GetExperiments(&count); 493 const Experiment* experiments = testing::GetExperiments(&count);
461 for (size_t i = 0; i < count; ++i) { 494 for (size_t i = 0; i < count; ++i) {
462 std::string name = experiments->internal_name; 495 std::string name = experiments->internal_name;
463 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; 496 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i;
464 } 497 }
465 } 498 }
466 499
467 } // namespace about_flags 500 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698