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/string_number_conversions.h" | 5 #include "base/string_number_conversions.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/about_flags.h" | 8 #include "chrome/browser/about_flags.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Enable experiments 1 and 2. | 243 // Enable experiments 1 and 2. |
244 SetExperimentEnabled(&prefs_, kFlags1, true); | 244 SetExperimentEnabled(&prefs_, kFlags1, true); |
245 SetExperimentEnabled(&prefs_, kFlags2, true); | 245 SetExperimentEnabled(&prefs_, kFlags2, true); |
246 CommandLine command_line(CommandLine::NO_PROGRAM); | 246 CommandLine command_line(CommandLine::NO_PROGRAM); |
247 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 247 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
248 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 248 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
249 | 249 |
250 // Convert the flags to switches. | 250 // Convert the flags to switches. |
251 ConvertFlagsToSwitches(&prefs_, &command_line); | 251 ConvertFlagsToSwitches(&prefs_, &command_line); |
252 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 252 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
253 EXPECT_EQ(std::string(""), | 253 EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); |
254 command_line.GetSwitchValueASCII(kSwitch1)); | |
255 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); | 254 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
256 EXPECT_EQ(std::string(kValueForSwitch2), | 255 EXPECT_EQ(std::string(kValueForSwitch2), |
257 command_line.GetSwitchValueASCII(kSwitch2)); | 256 command_line.GetSwitchValueASCII(kSwitch2)); |
258 | 257 |
259 // Confirm that there is no '=' in the command line for simple switches. | 258 // Confirm that there is no '=' in the command line for simple switches. |
260 std::string switch1_with_equals = std::string("--") + | 259 std::string switch1_with_equals = std::string("--") + |
261 std::string(kSwitch1) + | 260 std::string(kSwitch1) + |
262 std::string("="); | 261 std::string("="); |
263 #if defined(OS_WIN) | 262 #if defined(OS_WIN) |
264 EXPECT_EQ(std::wstring::npos, | 263 EXPECT_EQ(std::wstring::npos, |
265 command_line.command_line_string().find( | 264 command_line.GetCommandLineString().find( |
266 ASCIIToWide(switch1_with_equals))); | 265 ASCIIToWide(switch1_with_equals))); |
267 #else | 266 #else |
268 EXPECT_EQ(std::string::npos, | 267 EXPECT_EQ(std::string::npos, |
269 command_line.command_line_string().find(switch1_with_equals)); | 268 command_line.GetCommandLineString().find(switch1_with_equals)); |
270 #endif | 269 #endif |
271 | 270 |
272 // And confirm there is a '=' for switches with values. | 271 // And confirm there is a '=' for switches with values. |
273 std::string switch2_with_equals = std::string("--") + | 272 std::string switch2_with_equals = std::string("--") + |
274 std::string(kSwitch2) + | 273 std::string(kSwitch2) + |
275 std::string("="); | 274 std::string("="); |
276 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
277 EXPECT_NE(std::wstring::npos, | 276 EXPECT_NE(std::wstring::npos, |
278 command_line.command_line_string().find( | 277 command_line.GetCommandLineString().find( |
279 ASCIIToWide(switch2_with_equals))); | 278 ASCIIToWide(switch2_with_equals))); |
280 #else | 279 #else |
281 EXPECT_NE(std::string::npos, | 280 EXPECT_NE(std::string::npos, |
282 command_line.command_line_string().find(switch2_with_equals)); | 281 command_line.GetCommandLineString().find(switch2_with_equals)); |
283 #endif | 282 #endif |
284 | 283 |
285 // And it should persist | 284 // And it should persist |
286 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); | 285 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
287 ASSERT_TRUE(switch_prefs.get()); | 286 ASSERT_TRUE(switch_prefs.get()); |
288 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); | 287 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
289 } | 288 } |
290 | 289 |
291 // Tests multi-value type experiments. | 290 // Tests multi-value type experiments. |
292 TEST_F(AboutFlagsTest, MultiValues) { | 291 TEST_F(AboutFlagsTest, MultiValues) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 testing::SetExperiments(NULL, 0); | 328 testing::SetExperiments(NULL, 0); |
330 size_t count; | 329 size_t count; |
331 const Experiment* experiments = testing::GetExperiments(&count); | 330 const Experiment* experiments = testing::GetExperiments(&count); |
332 for (size_t i = 0; i < count; ++i) { | 331 for (size_t i = 0; i < count; ++i) { |
333 std::string name = experiments->internal_name; | 332 std::string name = experiments->internal_name; |
334 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 333 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
335 } | 334 } |
336 } | 335 } |
337 | 336 |
338 } // namespace about_flags | 337 } // namespace about_flags |
OLD | NEW |