| 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 "chrome/browser/about_flags.h" | 5 #include "chrome/browser/about_flags.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 #if defined(OS_WIN) | 181 #if defined(OS_WIN) |
| 182 return base::UTF16ToUTF8(path); | 182 return base::UTF16ToUTF8(path); |
| 183 #else | 183 #else |
| 184 return path; | 184 return path; |
| 185 #endif | 185 #endif |
| 186 } | 186 } |
| 187 | 187 |
| 188 std::set<std::string> GetAllSwitchesForTesting() { | 188 std::set<std::string> GetAllSwitchesForTesting() { |
| 189 std::set<std::string> result; | 189 std::set<std::string> result; |
| 190 | 190 |
| 191 size_t num_experiments = 0; | 191 size_t num_entries = 0; |
| 192 const Experiment* experiments = | 192 const Entry* entries = testing::GetEntries(&num_entries); |
| 193 testing::GetExperiments(&num_experiments); | |
| 194 | 193 |
| 195 for (size_t i = 0; i < num_experiments; ++i) { | 194 for (size_t i = 0; i < num_entries; ++i) { |
| 196 const Experiment& experiment = experiments[i]; | 195 const Entry& entry = entries[i]; |
| 197 if (experiment.type == Experiment::SINGLE_VALUE) { | 196 if (entry.type == Entry::SINGLE_VALUE) { |
| 198 result.insert(experiment.command_line_switch); | 197 result.insert(entry.command_line_switch); |
| 199 } else if (experiment.type == Experiment::MULTI_VALUE) { | 198 } else if (entry.type == Entry::MULTI_VALUE) { |
| 200 for (int j = 0; j < experiment.num_choices; ++j) { | 199 for (int j = 0; j < entry.num_choices; ++j) { |
| 201 result.insert(experiment.choices[j].command_line_switch); | 200 result.insert(entry.choices[j].command_line_switch); |
| 202 } | 201 } |
| 203 } else { | 202 } else { |
| 204 DCHECK_EQ(experiment.type, Experiment::ENABLE_DISABLE_VALUE); | 203 DCHECK_EQ(entry.type, Entry::ENABLE_DISABLE_VALUE); |
| 205 result.insert(experiment.command_line_switch); | 204 result.insert(entry.command_line_switch); |
| 206 result.insert(experiment.disable_command_line_switch); | 205 result.insert(entry.disable_command_line_switch); |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 return result; | 208 return result; |
| 210 } | 209 } |
| 211 | 210 |
| 212 } // anonymous namespace | 211 } // anonymous namespace |
| 213 | 212 |
| 214 const Experiment::Choice kMultiChoices[] = { | 213 const Entry::Choice kMultiChoices[] = { |
| 215 { IDS_PRODUCT_NAME, "", "" }, | 214 { IDS_PRODUCT_NAME, "", "" }, |
| 216 { IDS_PRODUCT_NAME, kMultiSwitch1, "" }, | 215 { IDS_PRODUCT_NAME, kMultiSwitch1, "" }, |
| 217 { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 }, | 216 { IDS_PRODUCT_NAME, kMultiSwitch2, kValueForMultiSwitch2 }, |
| 218 }; | 217 }; |
| 219 | 218 |
| 220 // The experiments that are set for these tests. The 3rd experiment is not | 219 // The entries that are set for these tests. The 3rd entry is not supported on |
| 221 // supported on the current platform, all others are. | 220 // the current platform, all others are. |
| 222 static Experiment kExperiments[] = { | 221 static Entry kEntries[] = { |
| 223 { | 222 { |
| 224 kFlags1, | 223 kFlags1, |
| 225 IDS_PRODUCT_NAME, | 224 IDS_PRODUCT_NAME, |
| 226 IDS_PRODUCT_NAME, | 225 IDS_PRODUCT_NAME, |
| 227 0, // Ends up being mapped to the current platform. | 226 0, // Ends up being mapped to the current platform. |
| 228 Experiment::SINGLE_VALUE, | 227 Entry::SINGLE_VALUE, |
| 229 kSwitch1, | 228 kSwitch1, |
| 230 "", | 229 "", |
| 231 NULL, | 230 NULL, |
| 232 NULL, | 231 NULL, |
| 233 NULL, | 232 NULL, |
| 234 0 | 233 0 |
| 235 }, | 234 }, |
| 236 { | 235 { |
| 237 kFlags2, | 236 kFlags2, |
| 238 IDS_PRODUCT_NAME, | 237 IDS_PRODUCT_NAME, |
| 239 IDS_PRODUCT_NAME, | 238 IDS_PRODUCT_NAME, |
| 240 0, // Ends up being mapped to the current platform. | 239 0, // Ends up being mapped to the current platform. |
| 241 Experiment::SINGLE_VALUE, | 240 Entry::SINGLE_VALUE, |
| 242 kSwitch2, | 241 kSwitch2, |
| 243 kValueForSwitch2, | 242 kValueForSwitch2, |
| 244 NULL, | 243 NULL, |
| 245 NULL, | 244 NULL, |
| 246 NULL, | 245 NULL, |
| 247 0 | 246 0 |
| 248 }, | 247 }, |
| 249 { | 248 { |
| 250 kFlags3, | 249 kFlags3, |
| 251 IDS_PRODUCT_NAME, | 250 IDS_PRODUCT_NAME, |
| 252 IDS_PRODUCT_NAME, | 251 IDS_PRODUCT_NAME, |
| 253 0, // This ends up enabling for an OS other than the current. | 252 0, // This ends up enabling for an OS other than the current. |
| 254 Experiment::SINGLE_VALUE, | 253 Entry::SINGLE_VALUE, |
| 255 kSwitch3, | 254 kSwitch3, |
| 256 "", | 255 "", |
| 257 NULL, | 256 NULL, |
| 258 NULL, | 257 NULL, |
| 259 NULL, | 258 NULL, |
| 260 0 | 259 0 |
| 261 }, | 260 }, |
| 262 { | 261 { |
| 263 kFlags4, | 262 kFlags4, |
| 264 IDS_PRODUCT_NAME, | 263 IDS_PRODUCT_NAME, |
| 265 IDS_PRODUCT_NAME, | 264 IDS_PRODUCT_NAME, |
| 266 0, // Ends up being mapped to the current platform. | 265 0, // Ends up being mapped to the current platform. |
| 267 Experiment::MULTI_VALUE, | 266 Entry::MULTI_VALUE, |
| 268 "", | 267 "", |
| 269 "", | 268 "", |
| 270 "", | 269 "", |
| 271 "", | 270 "", |
| 272 kMultiChoices, | 271 kMultiChoices, |
| 273 arraysize(kMultiChoices) | 272 arraysize(kMultiChoices) |
| 274 }, | 273 }, |
| 275 { | 274 { |
| 276 kFlags5, | 275 kFlags5, |
| 277 IDS_PRODUCT_NAME, | 276 IDS_PRODUCT_NAME, |
| 278 IDS_PRODUCT_NAME, | 277 IDS_PRODUCT_NAME, |
| 279 0, // Ends up being mapped to the current platform. | 278 0, // Ends up being mapped to the current platform. |
| 280 Experiment::ENABLE_DISABLE_VALUE, | 279 Entry::ENABLE_DISABLE_VALUE, |
| 281 kSwitch1, | 280 kSwitch1, |
| 282 kEnableDisableValue1, | 281 kEnableDisableValue1, |
| 283 kSwitch2, | 282 kSwitch2, |
| 284 kEnableDisableValue2, | 283 kEnableDisableValue2, |
| 285 NULL, | 284 NULL, |
| 286 3 | 285 3 |
| 287 }, | 286 }, |
| 288 }; | 287 }; |
| 289 | 288 |
| 290 class AboutFlagsTest : public ::testing::Test { | 289 class AboutFlagsTest : public ::testing::Test { |
| 291 protected: | 290 protected: |
| 292 AboutFlagsTest() : flags_storage_(&prefs_) { | 291 AboutFlagsTest() : flags_storage_(&prefs_) { |
| 293 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); | 292 prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments); |
| 294 testing::ClearState(); | 293 testing::ClearState(); |
| 295 } | 294 } |
| 296 | 295 |
| 297 void SetUp() override { | 296 void SetUp() override { |
| 298 for (size_t i = 0; i < arraysize(kExperiments); ++i) | 297 for (size_t i = 0; i < arraysize(kEntries); ++i) |
| 299 kExperiments[i].supported_platforms = GetCurrentPlatform(); | 298 kEntries[i].supported_platforms = GetCurrentPlatform(); |
| 300 | 299 |
| 301 int os_other_than_current = 1; | 300 int os_other_than_current = 1; |
| 302 while (os_other_than_current == GetCurrentPlatform()) | 301 while (os_other_than_current == GetCurrentPlatform()) |
| 303 os_other_than_current <<= 1; | 302 os_other_than_current <<= 1; |
| 304 kExperiments[2].supported_platforms = os_other_than_current; | 303 kEntries[2].supported_platforms = os_other_than_current; |
| 305 | 304 |
| 306 testing::SetExperiments(kExperiments, arraysize(kExperiments)); | 305 testing::SetEntries(kEntries, arraysize(kEntries)); |
| 307 } | 306 } |
| 308 | 307 |
| 309 void TearDown() override { testing::SetExperiments(NULL, 0); } | 308 void TearDown() override { testing::SetEntries(NULL, 0); } |
| 310 | 309 |
| 311 TestingPrefServiceSimple prefs_; | 310 TestingPrefServiceSimple prefs_; |
| 312 PrefServiceFlagsStorage flags_storage_; | 311 PrefServiceFlagsStorage flags_storage_; |
| 313 }; | 312 }; |
| 314 | 313 |
| 315 | 314 |
| 316 TEST_F(AboutFlagsTest, NoChangeNoRestart) { | 315 TEST_F(AboutFlagsTest, NoChangeNoRestart) { |
| 317 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 316 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 318 SetExperimentEnabled(&flags_storage_, kFlags1, false); | 317 SetEntryEnabled(&flags_storage_, kFlags1, false); |
| 319 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 318 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 320 } | 319 } |
| 321 | 320 |
| 322 TEST_F(AboutFlagsTest, ChangeNeedsRestart) { | 321 TEST_F(AboutFlagsTest, ChangeNeedsRestart) { |
| 323 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 322 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 324 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 323 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 325 EXPECT_TRUE(IsRestartNeededToCommitChanges()); | 324 EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
| 326 } | 325 } |
| 327 | 326 |
| 328 TEST_F(AboutFlagsTest, MultiFlagChangeNeedsRestart) { | 327 TEST_F(AboutFlagsTest, MultiFlagChangeNeedsRestart) { |
| 329 const Experiment& experiment = kExperiments[3]; | 328 const Entry& entry = kEntries[3]; |
| 330 ASSERT_EQ(kFlags4, experiment.internal_name); | 329 ASSERT_EQ(kFlags4, entry.internal_name); |
| 331 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 330 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 332 // Enable the 2nd choice of the multi-value. | 331 // Enable the 2nd choice of the multi-value. |
| 333 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true); | 332 SetEntryEnabled(&flags_storage_, entry.NameForChoice(2), true); |
| 334 EXPECT_TRUE(IsRestartNeededToCommitChanges()); | 333 EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
| 335 testing::ClearState(); | 334 testing::ClearState(); |
| 336 EXPECT_FALSE(IsRestartNeededToCommitChanges()); | 335 EXPECT_FALSE(IsRestartNeededToCommitChanges()); |
| 337 // Enable the default choice now. | 336 // Enable the default choice now. |
| 338 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true); | 337 SetEntryEnabled(&flags_storage_, entry.NameForChoice(0), true); |
| 339 EXPECT_TRUE(IsRestartNeededToCommitChanges()); | 338 EXPECT_TRUE(IsRestartNeededToCommitChanges()); |
| 340 } | 339 } |
| 341 | 340 |
| 342 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) { | 341 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) { |
| 343 // Add two experiments, check they're there. | 342 // Add two entries, check they're there. |
| 344 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 343 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 345 SetExperimentEnabled(&flags_storage_, kFlags2, true); | 344 SetEntryEnabled(&flags_storage_, kFlags2, true); |
| 346 | 345 |
| 347 const base::ListValue* experiments_list = prefs_.GetList( | 346 const base::ListValue* entry_list = prefs_.GetList( |
| 348 prefs::kEnabledLabsExperiments); | 347 prefs::kEnabledLabsExperiments); |
| 349 ASSERT_TRUE(experiments_list != NULL); | 348 ASSERT_TRUE(entry_list != NULL); |
| 350 | 349 |
| 351 ASSERT_EQ(2u, experiments_list->GetSize()); | 350 ASSERT_EQ(2u, entry_list->GetSize()); |
| 352 | 351 |
| 353 std::string s0; | 352 std::string s0; |
| 354 ASSERT_TRUE(experiments_list->GetString(0, &s0)); | 353 ASSERT_TRUE(entry_list->GetString(0, &s0)); |
| 355 std::string s1; | 354 std::string s1; |
| 356 ASSERT_TRUE(experiments_list->GetString(1, &s1)); | 355 ASSERT_TRUE(entry_list->GetString(1, &s1)); |
| 357 | 356 |
| 358 EXPECT_TRUE(s0 == kFlags1 || s1 == kFlags1); | 357 EXPECT_TRUE(s0 == kFlags1 || s1 == kFlags1); |
| 359 EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2); | 358 EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2); |
| 360 | 359 |
| 361 // Remove one experiment, check the other's still around. | 360 // Remove one entry, check the other's still around. |
| 362 SetExperimentEnabled(&flags_storage_, kFlags2, false); | 361 SetEntryEnabled(&flags_storage_, kFlags2, false); |
| 363 | 362 |
| 364 experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); | 363 entry_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
| 365 ASSERT_TRUE(experiments_list != NULL); | 364 ASSERT_TRUE(entry_list != NULL); |
| 366 ASSERT_EQ(1u, experiments_list->GetSize()); | 365 ASSERT_EQ(1u, entry_list->GetSize()); |
| 367 ASSERT_TRUE(experiments_list->GetString(0, &s0)); | 366 ASSERT_TRUE(entry_list->GetString(0, &s0)); |
| 368 EXPECT_TRUE(s0 == kFlags1); | 367 EXPECT_TRUE(s0 == kFlags1); |
| 369 } | 368 } |
| 370 | 369 |
| 371 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) { | 370 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) { |
| 372 // Add two experiments, check the pref exists. | 371 // Add two entries, check the pref exists. |
| 373 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 372 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 374 SetExperimentEnabled(&flags_storage_, kFlags2, true); | 373 SetEntryEnabled(&flags_storage_, kFlags2, true); |
| 375 const base::ListValue* experiments_list = prefs_.GetList( | 374 const base::ListValue* entry_list = prefs_.GetList( |
| 376 prefs::kEnabledLabsExperiments); | 375 prefs::kEnabledLabsExperiments); |
| 377 ASSERT_TRUE(experiments_list != NULL); | 376 ASSERT_TRUE(entry_list != NULL); |
| 378 | 377 |
| 379 // Remove both, the pref should have been removed completely. | 378 // Remove both, the pref should have been removed completely. |
| 380 SetExperimentEnabled(&flags_storage_, kFlags1, false); | 379 SetEntryEnabled(&flags_storage_, kFlags1, false); |
| 381 SetExperimentEnabled(&flags_storage_, kFlags2, false); | 380 SetEntryEnabled(&flags_storage_, kFlags2, false); |
| 382 experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments); | 381 entry_list = prefs_.GetList(prefs::kEnabledLabsExperiments); |
| 383 EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0); | 382 EXPECT_TRUE(entry_list == NULL || entry_list->GetSize() == 0); |
| 384 } | 383 } |
| 385 | 384 |
| 386 TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { | 385 TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { |
| 387 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 386 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 388 | 387 |
| 389 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 388 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 390 command_line.AppendSwitch("foo"); | 389 command_line.AppendSwitch("foo"); |
| 391 | 390 |
| 392 EXPECT_TRUE(command_line.HasSwitch("foo")); | 391 EXPECT_TRUE(command_line.HasSwitch("foo")); |
| 393 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 392 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 394 | 393 |
| 395 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 394 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 396 | 395 |
| 397 EXPECT_TRUE(command_line.HasSwitch("foo")); | 396 EXPECT_TRUE(command_line.HasSwitch("foo")); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 410 | 409 |
| 411 base::CommandLine::StringType CreateSwitch(const std::string& value) { | 410 base::CommandLine::StringType CreateSwitch(const std::string& value) { |
| 412 #if defined(OS_WIN) | 411 #if defined(OS_WIN) |
| 413 return base::ASCIIToUTF16(value); | 412 return base::ASCIIToUTF16(value); |
| 414 #else | 413 #else |
| 415 return value; | 414 return value; |
| 416 #endif | 415 #endif |
| 417 } | 416 } |
| 418 | 417 |
| 419 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { | 418 TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { |
| 420 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 419 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 421 | 420 |
| 422 const std::string kDoubleDash("--"); | 421 const std::string kDoubleDash("--"); |
| 423 | 422 |
| 424 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 423 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 425 command_line.AppendSwitch("foo"); | 424 command_line.AppendSwitch("foo"); |
| 426 | 425 |
| 427 base::CommandLine new_command_line(base::CommandLine::NO_PROGRAM); | 426 base::CommandLine new_command_line(base::CommandLine::NO_PROGRAM); |
| 428 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); | 427 ConvertFlagsToSwitches(&flags_storage_, &new_command_line, kAddSentinels); |
| 429 | 428 |
| 430 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( | 429 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 442 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( | 441 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( |
| 443 new_command_line, command_line, NULL)); | 442 new_command_line, command_line, NULL)); |
| 444 { | 443 { |
| 445 std::set<base::CommandLine::StringType> difference; | 444 std::set<base::CommandLine::StringType> difference; |
| 446 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( | 445 EXPECT_TRUE(AreSwitchesIdenticalToCurrentCommandLine( |
| 447 new_command_line, command_line, &difference)); | 446 new_command_line, command_line, &difference)); |
| 448 EXPECT_TRUE(difference.empty()); | 447 EXPECT_TRUE(difference.empty()); |
| 449 } | 448 } |
| 450 | 449 |
| 451 // Now both have flags but different. | 450 // Now both have flags but different. |
| 452 SetExperimentEnabled(&flags_storage_, kFlags1, false); | 451 SetEntryEnabled(&flags_storage_, kFlags1, false); |
| 453 SetExperimentEnabled(&flags_storage_, kFlags2, true); | 452 SetEntryEnabled(&flags_storage_, kFlags2, true); |
| 454 | 453 |
| 455 base::CommandLine another_command_line(base::CommandLine::NO_PROGRAM); | 454 base::CommandLine another_command_line(base::CommandLine::NO_PROGRAM); |
| 456 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); | 455 ConvertFlagsToSwitches(&flags_storage_, &another_command_line, kAddSentinels); |
| 457 | 456 |
| 458 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( | 457 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( |
| 459 new_command_line, another_command_line, NULL)); | 458 new_command_line, another_command_line, NULL)); |
| 460 { | 459 { |
| 461 std::set<base::CommandLine::StringType> difference; | 460 std::set<base::CommandLine::StringType> difference; |
| 462 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( | 461 EXPECT_FALSE(AreSwitchesIdenticalToCurrentCommandLine( |
| 463 new_command_line, another_command_line, &difference)); | 462 new_command_line, another_command_line, &difference)); |
| 464 EXPECT_EQ(2U, difference.size()); | 463 EXPECT_EQ(2U, difference.size()); |
| 465 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1))); | 464 EXPECT_EQ(1U, difference.count(CreateSwitch(kDoubleDash + kSwitch1))); |
| 466 EXPECT_EQ(1U, | 465 EXPECT_EQ(1U, |
| 467 difference.count(CreateSwitch(kDoubleDash + kSwitch2 + "=" + | 466 difference.count(CreateSwitch(kDoubleDash + kSwitch2 + "=" + |
| 468 kValueForSwitch2))); | 467 kValueForSwitch2))); |
| 469 } | 468 } |
| 470 } | 469 } |
| 471 | 470 |
| 472 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { | 471 TEST_F(AboutFlagsTest, RemoveFlagSwitches) { |
| 473 std::map<std::string, base::CommandLine::StringType> switch_list; | 472 std::map<std::string, base::CommandLine::StringType> switch_list; |
| 474 switch_list[kSwitch1] = base::CommandLine::StringType(); | 473 switch_list[kSwitch1] = base::CommandLine::StringType(); |
| 475 switch_list[switches::kFlagSwitchesBegin] = base::CommandLine::StringType(); | 474 switch_list[switches::kFlagSwitchesBegin] = base::CommandLine::StringType(); |
| 476 switch_list[switches::kFlagSwitchesEnd] = base::CommandLine::StringType(); | 475 switch_list[switches::kFlagSwitchesEnd] = base::CommandLine::StringType(); |
| 477 switch_list["foo"] = base::CommandLine::StringType(); | 476 switch_list["foo"] = base::CommandLine::StringType(); |
| 478 | 477 |
| 479 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 478 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 480 | 479 |
| 481 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. | 480 // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called. |
| 482 RemoveFlagsSwitches(&switch_list); | 481 RemoveFlagsSwitches(&switch_list); |
| 483 ASSERT_EQ(4u, switch_list.size()); | 482 ASSERT_EQ(4u, switch_list.size()); |
| 484 EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end()); | 483 EXPECT_TRUE(switch_list.find(kSwitch1) != switch_list.end()); |
| 485 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) != | 484 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesBegin) != |
| 486 switch_list.end()); | 485 switch_list.end()); |
| 487 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) != | 486 EXPECT_TRUE(switch_list.find(switches::kFlagSwitchesEnd) != |
| 488 switch_list.end()); | 487 switch_list.end()); |
| 489 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); | 488 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 490 | 489 |
| 491 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. | 490 // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again. |
| 492 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 491 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 493 command_line.AppendSwitch("foo"); | 492 command_line.AppendSwitch("foo"); |
| 494 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 493 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 495 RemoveFlagsSwitches(&switch_list); | 494 RemoveFlagsSwitches(&switch_list); |
| 496 | 495 |
| 497 // Now the about:flags-related switch should have been removed. | 496 // Now the about:flags-related switch should have been removed. |
| 498 ASSERT_EQ(1u, switch_list.size()); | 497 ASSERT_EQ(1u, switch_list.size()); |
| 499 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); | 498 EXPECT_TRUE(switch_list.find("foo") != switch_list.end()); |
| 500 } | 499 } |
| 501 | 500 |
| 502 // Tests enabling experiments that aren't supported on the current platform. | 501 // Tests enabling experiments that aren't supported on the current platform. |
| 503 TEST_F(AboutFlagsTest, PersistAndPrune) { | 502 TEST_F(AboutFlagsTest, PersistAndPrune) { |
| 504 // Enable experiments 1 and 3. | 503 // Enable experiments 1 and 3. |
| 505 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 504 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 506 SetExperimentEnabled(&flags_storage_, kFlags3, true); | 505 SetEntryEnabled(&flags_storage_, kFlags3, true); |
| 507 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 506 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 508 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 507 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 509 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 508 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 510 | 509 |
| 511 // Convert the flags to switches. Experiment 3 shouldn't be among the switches | 510 // Convert the flags to switches. Entry 3 shouldn't be among the switches |
| 512 // as it is not applicable to the current platform. | 511 // as it is not applicable to the current platform. |
| 513 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 512 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 514 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 513 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 515 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); | 514 EXPECT_FALSE(command_line.HasSwitch(kSwitch3)); |
| 516 | 515 |
| 517 // Experiment 3 should show still be persisted in preferences though. | 516 // Entry 3 should show still be persisted in preferences though. |
| 518 const base::ListValue* experiments_list = | 517 const base::ListValue* entry_list = |
| 519 prefs_.GetList(prefs::kEnabledLabsExperiments); | 518 prefs_.GetList(prefs::kEnabledLabsExperiments); |
| 520 ASSERT_TRUE(experiments_list); | 519 ASSERT_TRUE(entry_list); |
| 521 EXPECT_EQ(2U, experiments_list->GetSize()); | 520 EXPECT_EQ(2U, entry_list->GetSize()); |
| 522 std::string s0; | 521 std::string s0; |
| 523 ASSERT_TRUE(experiments_list->GetString(0, &s0)); | 522 ASSERT_TRUE(entry_list->GetString(0, &s0)); |
| 524 EXPECT_EQ(kFlags1, s0); | 523 EXPECT_EQ(kFlags1, s0); |
| 525 std::string s1; | 524 std::string s1; |
| 526 ASSERT_TRUE(experiments_list->GetString(1, &s1)); | 525 ASSERT_TRUE(entry_list->GetString(1, &s1)); |
| 527 EXPECT_EQ(kFlags3, s1); | 526 EXPECT_EQ(kFlags3, s1); |
| 528 } | 527 } |
| 529 | 528 |
| 530 // Tests that switches which should have values get them in the command | 529 // Tests that switches which should have values get them in the command |
| 531 // line. | 530 // line. |
| 532 TEST_F(AboutFlagsTest, CheckValues) { | 531 TEST_F(AboutFlagsTest, CheckValues) { |
| 533 // Enable experiments 1 and 2. | 532 // Enable experiments 1 and 2. |
| 534 SetExperimentEnabled(&flags_storage_, kFlags1, true); | 533 SetEntryEnabled(&flags_storage_, kFlags1, true); |
| 535 SetExperimentEnabled(&flags_storage_, kFlags2, true); | 534 SetEntryEnabled(&flags_storage_, kFlags2, true); |
| 536 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 535 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 537 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 536 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 538 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 537 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 539 | 538 |
| 540 // Convert the flags to switches. | 539 // Convert the flags to switches. |
| 541 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 540 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 542 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 541 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 543 EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1)); | 542 EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1)); |
| 544 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); | 543 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 545 EXPECT_EQ(std::string(kValueForSwitch2), | 544 EXPECT_EQ(std::string(kValueForSwitch2), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 565 #if defined(OS_WIN) | 564 #if defined(OS_WIN) |
| 566 EXPECT_NE(base::string16::npos, | 565 EXPECT_NE(base::string16::npos, |
| 567 command_line.GetCommandLineString().find( | 566 command_line.GetCommandLineString().find( |
| 568 base::ASCIIToUTF16(switch2_with_equals))); | 567 base::ASCIIToUTF16(switch2_with_equals))); |
| 569 #else | 568 #else |
| 570 EXPECT_NE(std::string::npos, | 569 EXPECT_NE(std::string::npos, |
| 571 command_line.GetCommandLineString().find(switch2_with_equals)); | 570 command_line.GetCommandLineString().find(switch2_with_equals)); |
| 572 #endif | 571 #endif |
| 573 | 572 |
| 574 // And it should persist. | 573 // And it should persist. |
| 575 const base::ListValue* experiments_list = | 574 const base::ListValue* entry_list = |
| 576 prefs_.GetList(prefs::kEnabledLabsExperiments); | 575 prefs_.GetList(prefs::kEnabledLabsExperiments); |
| 577 ASSERT_TRUE(experiments_list); | 576 ASSERT_TRUE(entry_list); |
| 578 EXPECT_EQ(2U, experiments_list->GetSize()); | 577 EXPECT_EQ(2U, entry_list->GetSize()); |
| 579 std::string s0; | 578 std::string s0; |
| 580 ASSERT_TRUE(experiments_list->GetString(0, &s0)); | 579 ASSERT_TRUE(entry_list->GetString(0, &s0)); |
| 581 EXPECT_EQ(kFlags1, s0); | 580 EXPECT_EQ(kFlags1, s0); |
| 582 std::string s1; | 581 std::string s1; |
| 583 ASSERT_TRUE(experiments_list->GetString(1, &s1)); | 582 ASSERT_TRUE(entry_list->GetString(1, &s1)); |
| 584 EXPECT_EQ(kFlags2, s1); | 583 EXPECT_EQ(kFlags2, s1); |
| 585 } | 584 } |
| 586 | 585 |
| 587 // Tests multi-value type experiments. | 586 // Tests multi-value type experiments. |
| 588 TEST_F(AboutFlagsTest, MultiValues) { | 587 TEST_F(AboutFlagsTest, MultiValues) { |
| 589 const Experiment& experiment = kExperiments[3]; | 588 const Entry& entry = kEntries[3]; |
| 590 ASSERT_EQ(kFlags4, experiment.internal_name); | 589 ASSERT_EQ(kFlags4, entry.internal_name); |
| 591 | 590 |
| 592 // Initially, the first "deactivated" option of the multi experiment should | 591 // Initially, the first "deactivated" option of the multi experiment should |
| 593 // be set. | 592 // be set. |
| 594 { | 593 { |
| 595 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 594 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 596 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 595 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 597 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 596 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 598 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 597 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 599 } | 598 } |
| 600 | 599 |
| 601 // Enable the 2nd choice of the multi-value. | 600 // Enable the 2nd choice of the multi-value. |
| 602 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true); | 601 SetEntryEnabled(&flags_storage_, entry.NameForChoice(2), true); |
| 603 { | 602 { |
| 604 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 603 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 605 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 604 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 606 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 605 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 607 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); | 606 EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2)); |
| 608 EXPECT_EQ(std::string(kValueForMultiSwitch2), | 607 EXPECT_EQ(std::string(kValueForMultiSwitch2), |
| 609 command_line.GetSwitchValueASCII(kMultiSwitch2)); | 608 command_line.GetSwitchValueASCII(kMultiSwitch2)); |
| 610 } | 609 } |
| 611 | 610 |
| 612 // Disable the multi-value experiment. | 611 // Disable the multi-value entry. |
| 613 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true); | 612 SetEntryEnabled(&flags_storage_, entry.NameForChoice(0), true); |
| 614 { | 613 { |
| 615 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 614 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 616 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 615 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 617 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 616 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 618 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 617 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 619 } | 618 } |
| 620 } | 619 } |
| 621 | 620 |
| 622 TEST_F(AboutFlagsTest, EnableDisableValues) { | 621 TEST_F(AboutFlagsTest, EnableDisableValues) { |
| 623 const Experiment& experiment = kExperiments[4]; | 622 const Entry& entry = kEntries[4]; |
| 624 ASSERT_EQ(kFlags5, experiment.internal_name); | 623 ASSERT_EQ(kFlags5, entry.internal_name); |
| 625 | 624 |
| 626 // Nothing selected. | 625 // Nothing selected. |
| 627 { | 626 { |
| 628 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 627 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 629 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 628 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 630 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 629 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 631 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 630 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 632 } | 631 } |
| 633 | 632 |
| 634 // "Enable" option selected. | 633 // "Enable" option selected. |
| 635 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true); | 634 SetEntryEnabled(&flags_storage_, entry.NameForChoice(1), true); |
| 636 { | 635 { |
| 637 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 636 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 638 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 637 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 639 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); | 638 EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); |
| 640 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); | 639 EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); |
| 641 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1)); | 640 EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1)); |
| 642 } | 641 } |
| 643 | 642 |
| 644 // "Disable" option selected. | 643 // "Disable" option selected. |
| 645 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true); | 644 SetEntryEnabled(&flags_storage_, entry.NameForChoice(2), true); |
| 646 { | 645 { |
| 647 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 646 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 648 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 647 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 649 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); | 648 EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); |
| 650 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); | 649 EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); |
| 651 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2)); | 650 EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2)); |
| 652 } | 651 } |
| 653 | 652 |
| 654 // "Default" option selected, same as nothing selected. | 653 // "Default" option selected, same as nothing selected. |
| 655 SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true); | 654 SetEntryEnabled(&flags_storage_, entry.NameForChoice(0), true); |
| 656 { | 655 { |
| 657 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 656 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 658 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); | 657 ConvertFlagsToSwitches(&flags_storage_, &command_line, kAddSentinels); |
| 659 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); | 658 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1)); |
| 660 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); | 659 EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2)); |
| 661 } | 660 } |
| 662 } | 661 } |
| 663 | 662 |
| 664 // Makes sure there are no separators in any of the experiment names. | 663 // Makes sure there are no separators in any of the experiment names. |
| 665 TEST_F(AboutFlagsTest, NoSeparators) { | 664 TEST_F(AboutFlagsTest, NoSeparators) { |
| 666 testing::SetExperiments(NULL, 0); | 665 testing::SetEntries(NULL, 0); |
| 667 size_t count; | 666 size_t count; |
| 668 const Experiment* experiments = testing::GetExperiments(&count); | 667 const Entry* entries = testing::GetEntries(&count); |
| 669 for (size_t i = 0; i < count; ++i) { | 668 for (size_t i = 0; i < count; ++i) { |
| 670 std::string name = experiments->internal_name; | 669 std::string name = entries[i].internal_name; |
| 671 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; | 670 EXPECT_EQ(std::string::npos, name.find(testing::kMultiSeparator)) << i; |
| 672 } | 671 } |
| 673 } | 672 } |
| 674 | 673 |
| 675 class AboutFlagsHistogramTest : public ::testing::Test { | 674 class AboutFlagsHistogramTest : public ::testing::Test { |
| 676 protected: | 675 protected: |
| 677 // This is a helper function to check that all IDs in enum LoginCustomFlags in | 676 // This is a helper function to check that all IDs in enum LoginCustomFlags in |
| 678 // histograms.xml are unique. | 677 // histograms.xml are unique. |
| 679 void SetSwitchToHistogramIdMapping(const std::string& switch_name, | 678 void SetSwitchToHistogramIdMapping(const std::string& switch_name, |
| 680 const Sample switch_histogram_id, | 679 const Sample switch_histogram_id, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && | 760 EXPECT_TRUE(enum_entry != histograms_xml_switches_ids.end() && |
| 762 enum_entry->first == flag) | 761 enum_entry->first == flag) |
| 763 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" | 762 << "histograms.xml enum LoginCustomFlags doesn't contain switch '" |
| 764 << flag << "' (value=" << uma_id | 763 << flag << "' (value=" << uma_id |
| 765 << " expected). Consider adding entry:\n" | 764 << " expected). Consider adding entry:\n" |
| 766 << " " << GetHistogramEnumEntryText(flag, uma_id); | 765 << " " << GetHistogramEnumEntryText(flag, uma_id); |
| 767 } | 766 } |
| 768 } | 767 } |
| 769 | 768 |
| 770 } // namespace about_flags | 769 } // namespace about_flags |
| OLD | NEW |