| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 CommandLine command_line(CommandLine::NO_PROGRAM); | 177 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 178 command_line.AppendSwitch("foo"); | 178 command_line.AppendSwitch("foo"); |
| 179 | 179 |
| 180 EXPECT_TRUE(command_line.HasSwitch("foo")); | 180 EXPECT_TRUE(command_line.HasSwitch("foo")); |
| 181 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 181 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 182 | 182 |
| 183 ConvertFlagsToSwitches(&prefs_, &command_line); | 183 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 184 | 184 |
| 185 EXPECT_TRUE(command_line.HasSwitch("foo")); | 185 EXPECT_TRUE(command_line.HasSwitch("foo")); |
| 186 // TODO(thakis): Undo | 186 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 187 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | |
| 188 } | 187 } |
| 189 | 188 |
| 190 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { | 189 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
| 191 std::map<std::string, CommandLine::StringType> switch_list; | 190 std::map<std::string, CommandLine::StringType> switch_list; |
| 192 switch_list[kSwitch1] = CommandLine::StringType(); | 191 switch_list[kSwitch1] = CommandLine::StringType(); |
| 193 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); | 192 switch_list[switches::kFlagSwitchesBegin] = CommandLine::StringType(); |
| 194 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); | 193 switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType(); |
| 195 switch_list["foo"] = CommandLine::StringType(); | 194 switch_list["foo"] = CommandLine::StringType(); |
| 196 | 195 |
| 197 SetExperimentEnabled(&prefs_, kFlags1, true); | 196 SetExperimentEnabled(&prefs_, kFlags1, true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 222 // Enable experiments 1 and 3. | 221 // Enable experiments 1 and 3. |
| 223 SetExperimentEnabled(&prefs_, kFlags1, true); | 222 SetExperimentEnabled(&prefs_, kFlags1, true); |
| 224 SetExperimentEnabled(&prefs_, kFlags3, true); | 223 SetExperimentEnabled(&prefs_, kFlags3, true); |
| 225 CommandLine command_line(CommandLine::NO_PROGRAM); | 224 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 226 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 225 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 227 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 226 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 228 | 227 |
| 229 // Convert the flags to switches. Experiment 3 shouldn't be among the switches | 228 // Convert the flags to switches. Experiment 3 shouldn't be among the switches |
| 230 // as it is not applicable to the current platform. | 229 // as it is not applicable to the current platform. |
| 231 ConvertFlagsToSwitches(&prefs_, &command_line); | 230 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 232 // TODO(thakis): undo. | 231 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 233 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | |
| 234 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 232 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 235 | 233 |
| 236 // Experiment 3 should show still be persisted in preferences though. | 234 // Experiment 3 should show still be persisted in preferences though. |
| 237 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); | 235 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 238 ASSERT_TRUE(switch_prefs.get()); | 236 ASSERT_TRUE(switch_prefs.get()); |
| 239 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); | 237 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
| 240 } | 238 } |
| 241 | 239 |
| 242 // Tests that switches which should have values get them in the command | 240 // Tests that switches which should have values get them in the command |
| 243 // line. | 241 // line. |
| 244 TEST_F(AboutFlagsTest, CheckValues) { | 242 TEST_F(AboutFlagsTest, CheckValues) { |
| 245 // Enable experiments 1 and 2. | 243 // Enable experiments 1 and 2. |
| 246 SetExperimentEnabled(&prefs_, kFlags1, true); | 244 SetExperimentEnabled(&prefs_, kFlags1, true); |
| 247 SetExperimentEnabled(&prefs_, kFlags2, true); | 245 SetExperimentEnabled(&prefs_, kFlags2, true); |
| 248 CommandLine command_line(CommandLine::NO_PROGRAM); | 246 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 249 // TODO(thakis): undo. | |
| 250 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 247 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 251 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 248 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 252 | 249 |
| 253 // Convert the flags to switches. | 250 // Convert the flags to switches. |
| 254 ConvertFlagsToSwitches(&prefs_, &command_line); | 251 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 255 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 252 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 256 EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); | 253 EXPECT_EQ(std::string(""), command_line.GetSwitchValueASCII(kSwitch1)); |
| 257 // TODO(thakis): undo. | 254 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 258 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 255 EXPECT_EQ(std::string(kValueForSwitch2), |
| 259 // TODO(thakis): undo. | |
| 260 EXPECT_EQ("", | |
| 261 command_line.GetSwitchValueASCII(kSwitch2)); | 256 command_line.GetSwitchValueASCII(kSwitch2)); |
| 262 | 257 |
| 263 // 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. |
| 264 std::string switch1_with_equals = std::string("--") + | 259 std::string switch1_with_equals = std::string("--") + |
| 265 std::string(kSwitch1) + | 260 std::string(kSwitch1) + |
| 266 std::string("="); | 261 std::string("="); |
| 267 #if defined(OS_WIN) | 262 #if defined(OS_WIN) |
| 268 EXPECT_EQ(std::wstring::npos, | 263 EXPECT_EQ(std::wstring::npos, |
| 269 command_line.GetCommandLineString().find( | 264 command_line.GetCommandLineString().find( |
| 270 ASCIIToWide(switch1_with_equals))); | 265 ASCIIToWide(switch1_with_equals))); |
| 271 #else | 266 #else |
| 272 EXPECT_EQ(std::string::npos, | 267 EXPECT_EQ(std::string::npos, |
| 273 command_line.GetCommandLineString().find(switch1_with_equals)); | 268 command_line.GetCommandLineString().find(switch1_with_equals)); |
| 274 #endif | 269 #endif |
| 275 | 270 |
| 276 // And confirm there is a '=' for switches with values. | 271 // And confirm there is a '=' for switches with values. |
| 277 std::string switch2_with_equals = std::string("--") + | 272 std::string switch2_with_equals = std::string("--") + |
| 278 std::string(kSwitch2) + | 273 std::string(kSwitch2) + |
| 279 std::string("="); | 274 std::string("="); |
| 280 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 281 // TODO(thakis): undo. | 276 EXPECT_NE(std::wstring::npos, |
| 282 EXPECT_EQ(std::wstring::npos, | |
| 283 command_line.GetCommandLineString().find( | 277 command_line.GetCommandLineString().find( |
| 284 ASCIIToWide(switch2_with_equals))); | 278 ASCIIToWide(switch2_with_equals))); |
| 285 #else | 279 #else |
| 286 // TODO(thakis): undo. | 280 EXPECT_NE(std::string::npos, |
| 287 EXPECT_EQ(std::string::npos, | |
| 288 command_line.GetCommandLineString().find(switch2_with_equals)); | 281 command_line.GetCommandLineString().find(switch2_with_equals)); |
| 289 #endif | 282 #endif |
| 290 | 283 |
| 291 // And it should persist | 284 // And it should persist |
| 292 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); | 285 scoped_ptr<ListValue> switch_prefs(GetFlagsExperimentsData(&prefs_)); |
| 293 ASSERT_TRUE(switch_prefs.get()); | 286 ASSERT_TRUE(switch_prefs.get()); |
| 294 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); | 287 EXPECT_EQ(arraysize(kExperiments) - 1, switch_prefs->GetSize()); |
| 295 } | 288 } |
| 296 | 289 |
| 297 // Tests multi-value type experiments. | 290 // Tests multi-value type experiments. |
| 298 TEST_F(AboutFlagsTest, MultiValues) { | 291 TEST_F(AboutFlagsTest, MultiValues) { |
| 299 // Initially, the first "deactivated" option of the multi experiment should | 292 // Initially, the first "deactivated" option of the multi experiment should |
| 300 // be set. | 293 // be set. |
| 301 { | 294 { |
| 302 CommandLine command_line(CommandLine::NO_PROGRAM); | 295 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 303 ConvertFlagsToSwitches(&prefs_, &command_line); | 296 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 304 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 297 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 305 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 298 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 306 } | 299 } |
| 307 | 300 |
| 308 // Enable the 2nd choice of the multi-value. | 301 // Enable the 2nd choice of the multi-value. |
| 309 SetExperimentEnabled(&prefs_, std::string(kFlags4) + | 302 SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
| 310 std::string(testing::kMultiSeparator) + | 303 std::string(testing::kMultiSeparator) + |
| 311 base::IntToString(2), true); | 304 base::IntToString(2), true); |
| 312 { | 305 { |
| 313 CommandLine command_line(CommandLine::NO_PROGRAM); | 306 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 314 ConvertFlagsToSwitches(&prefs_, &command_line); | 307 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 315 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 308 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 316 // TODO(thakis): undo. | 309 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); |
| 317 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 310 EXPECT_EQ(std::string(kValueForMultiSwitch2), |
| 318 // TODO(thakis): undo. | |
| 319 EXPECT_EQ("", | |
| 320 command_line.GetSwitchValueASCII(kMultiSwitch2)); | 311 command_line.GetSwitchValueASCII(kMultiSwitch2)); |
| 321 } | 312 } |
| 322 | 313 |
| 323 // Disable the multi-value experiment. | 314 // Disable the multi-value experiment. |
| 324 SetExperimentEnabled(&prefs_, std::string(kFlags4) + | 315 SetExperimentEnabled(&prefs_, std::string(kFlags4) + |
| 325 std::string(testing::kMultiSeparator) + | 316 std::string(testing::kMultiSeparator) + |
| 326 base::IntToString(0), true); | 317 base::IntToString(0), true); |
| 327 { | 318 { |
| 328 CommandLine command_line(CommandLine::NO_PROGRAM); | 319 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 329 ConvertFlagsToSwitches(&prefs_, &command_line); | 320 ConvertFlagsToSwitches(&prefs_, &command_line); |
| 330 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 321 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 331 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 322 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 332 } | 323 } |
| 333 } | 324 } |
| 334 | 325 |
| 335 // Makes sure there are no separators in any of the experiment names. | 326 // Makes sure there are no separators in any of the experiment names. |
| 336 TEST_F(AboutFlagsTest, NoSeparators) { | 327 TEST_F(AboutFlagsTest, NoSeparators) { |
| 337 testing::SetExperiments(NULL, 0); | 328 testing::SetExperiments(NULL, 0); |
| 338 size_t count; | 329 size_t count; |
| 339 const Experiment* experiments = testing::GetExperiments(&count); | 330 const Experiment* experiments = testing::GetExperiments(&count); |
| 340 for (size_t i = 0; i < count; ++i) { | 331 for (size_t i = 0; i < count; ++i) { |
| 341 std::string name = experiments->internal_name; | 332 std::string name = experiments->internal_name; |
| 342 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 333 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
| 343 } | 334 } |
| 344 } | 335 } |
| 345 | 336 |
| 346 } // namespace about_flags | 337 } // namespace about_flags |
| OLD | NEW |