| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/passwords/manage_passwords_bubble_model.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "components/password_manager/core/common/password_manager_pref_names.h" | 28 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 29 #include "components/password_manager/core/common/password_manager_ui.h" | 29 #include "components/password_manager/core/common/password_manager_ui.h" |
| 30 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
| 31 #include "components/variations/variations_associated_data.h" | 31 #include "components/variations/variations_associated_data.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
| 34 #include "content/public/test/web_contents_tester.h" | 34 #include "content/public/test/web_contents_tester.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 37 |
| 38 using password_bubble_experiment::kBrandingExperimentName; | |
| 39 using password_bubble_experiment::kChromeSignInPasswordPromoExperimentName; | 38 using password_bubble_experiment::kChromeSignInPasswordPromoExperimentName; |
| 40 using password_bubble_experiment::kChromeSignInPasswordPromoThresholdParam; | 39 using password_bubble_experiment::kChromeSignInPasswordPromoThresholdParam; |
| 41 using password_bubble_experiment::kSmartLockBrandingGroupName; | |
| 42 using password_bubble_experiment::kSmartLockBrandingSavePromptOnlyGroupName; | |
| 43 using ::testing::AnyNumber; | 40 using ::testing::AnyNumber; |
| 44 using ::testing::Return; | 41 using ::testing::Return; |
| 45 using ::testing::ReturnRef; | 42 using ::testing::ReturnRef; |
| 46 using ::testing::_; | 43 using ::testing::_; |
| 47 | 44 |
| 48 namespace { | 45 namespace { |
| 49 | 46 |
| 50 const char kFakeGroup[] = "FakeGroup"; | 47 const char kFakeGroup[] = "FakeGroup"; |
| 51 const char kSignInPromoCountTilNoThanksMetric[] = | 48 const char kSignInPromoCountTilNoThanksMetric[] = |
| 52 "PasswordManager.SignInPromoCountTilNoThanks"; | 49 "PasswordManager.SignInPromoCountTilNoThanks"; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 310 |
| 314 TEST_F(ManagePasswordsBubbleModelTest, ClickUpdate) { | 311 TEST_F(ManagePasswordsBubbleModelTest, ClickUpdate) { |
| 315 PretendUpdatePasswordWaiting(); | 312 PretendUpdatePasswordWaiting(); |
| 316 | 313 |
| 317 autofill::PasswordForm form; | 314 autofill::PasswordForm form; |
| 318 EXPECT_CALL(*controller(), UpdatePassword(form)); | 315 EXPECT_CALL(*controller(), UpdatePassword(form)); |
| 319 model()->OnUpdateClicked(form); | 316 model()->OnUpdateClicked(form); |
| 320 DestroyModel(); | 317 DestroyModel(); |
| 321 } | 318 } |
| 322 | 319 |
| 323 TEST_F(ManagePasswordsBubbleModelTest, ShowSmartLockWarmWelcome) { | |
| 324 TestSyncService* sync_service = static_cast<TestSyncService*>( | |
| 325 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 326 profile(), &TestingSyncFactoryFunction)); | |
| 327 sync_service->set_smartlock_enabled(true); | |
| 328 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
| 329 kSmartLockBrandingGroupName); | |
| 330 | |
| 331 PretendPasswordWaiting(); | |
| 332 | |
| 333 EXPECT_TRUE(model()->ShouldShowGoogleSmartLockWelcome()); | |
| 334 EXPECT_CALL(*GetStore(), AddSiteStatsImpl(_)); | |
| 335 DestroyModel(); | |
| 336 PretendPasswordWaiting(); | |
| 337 | |
| 338 EXPECT_FALSE(model()->ShouldShowGoogleSmartLockWelcome()); | |
| 339 EXPECT_TRUE(prefs()->GetBoolean( | |
| 340 password_manager::prefs::kWasSavePrompFirstRunExperienceShown)); | |
| 341 } | |
| 342 | |
| 343 TEST_F(ManagePasswordsBubbleModelTest, OmitSmartLockWarmWelcome) { | |
| 344 TestSyncService* sync_service = static_cast<TestSyncService*>( | |
| 345 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 346 profile(), &TestingSyncFactoryFunction)); | |
| 347 sync_service->set_smartlock_enabled(false); | |
| 348 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
| 349 kSmartLockBrandingGroupName); | |
| 350 | |
| 351 PretendPasswordWaiting(); | |
| 352 | |
| 353 EXPECT_FALSE(model()->ShouldShowGoogleSmartLockWelcome()); | |
| 354 EXPECT_CALL(*GetStore(), AddSiteStatsImpl(_)); | |
| 355 DestroyModel(); | |
| 356 PretendPasswordWaiting(); | |
| 357 | |
| 358 EXPECT_FALSE(model()->ShouldShowGoogleSmartLockWelcome()); | |
| 359 EXPECT_FALSE(prefs()->GetBoolean( | |
| 360 password_manager::prefs::kWasSavePrompFirstRunExperienceShown)); | |
| 361 } | |
| 362 | |
| 363 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) { | 320 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) { |
| 364 PretendPasswordWaiting(); | 321 PretendPasswordWaiting(); |
| 365 | 322 |
| 366 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); | 323 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); |
| 367 model()->OnBrandLinkClicked(); | 324 model()->OnBrandLinkClicked(); |
| 368 } | 325 } |
| 369 | 326 |
| 370 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) { | 327 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) { |
| 371 base::HistogramTester histogram_tester; | 328 base::HistogramTester histogram_tester; |
| 372 PretendPasswordWaiting(); | 329 PretendPasswordWaiting(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 histogram_tester.ExpectUniqueSample(kSignInPromoDismissalCountMetric, 1, 1); | 421 histogram_tester.ExpectUniqueSample(kSignInPromoDismissalCountMetric, 1, 1); |
| 465 EXPECT_FALSE(prefs()->GetBoolean( | 422 EXPECT_FALSE(prefs()->GetBoolean( |
| 466 password_manager::prefs::kWasSignInPasswordPromoClicked)); | 423 password_manager::prefs::kWasSignInPasswordPromoClicked)); |
| 467 } | 424 } |
| 468 | 425 |
| 469 namespace { | 426 namespace { |
| 470 | 427 |
| 471 enum class SmartLockStatus { ENABLE, DISABLE }; | 428 enum class SmartLockStatus { ENABLE, DISABLE }; |
| 472 | 429 |
| 473 struct TitleTestCase { | 430 struct TitleTestCase { |
| 474 const char* experiment_group; | |
| 475 SmartLockStatus smartlock_status; | 431 SmartLockStatus smartlock_status; |
| 476 const char* expected_title; | 432 const char* expected_title; |
| 477 }; | 433 }; |
| 478 | 434 |
| 479 } // namespace | 435 } // namespace |
| 480 | 436 |
| 481 class ManagePasswordsBubbleModelTitleTest | 437 class ManagePasswordsBubbleModelTitleTest |
| 482 : public ManagePasswordsBubbleModelTest, | 438 : public ManagePasswordsBubbleModelTest, |
| 483 public ::testing::WithParamInterface<TitleTestCase> {}; | 439 public ::testing::WithParamInterface<TitleTestCase> {}; |
| 484 | 440 |
| 485 TEST_P(ManagePasswordsBubbleModelTitleTest, BrandedTitleOnSaving) { | 441 TEST_P(ManagePasswordsBubbleModelTitleTest, BrandedTitleOnSaving) { |
| 486 TitleTestCase test_case = GetParam(); | 442 TitleTestCase test_case = GetParam(); |
| 487 TestSyncService* sync_service = static_cast<TestSyncService*>( | 443 TestSyncService* sync_service = static_cast<TestSyncService*>( |
| 488 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 444 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 489 profile(), &TestingSyncFactoryFunction)); | 445 profile(), &TestingSyncFactoryFunction)); |
| 490 sync_service->set_smartlock_enabled(test_case.smartlock_status == | 446 sync_service->set_smartlock_enabled(test_case.smartlock_status == |
| 491 SmartLockStatus::ENABLE); | 447 SmartLockStatus::ENABLE); |
| 492 if (test_case.experiment_group) { | |
| 493 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
| 494 test_case.experiment_group); | |
| 495 } | |
| 496 | 448 |
| 497 PretendPasswordWaiting(); | 449 PretendPasswordWaiting(); |
| 498 EXPECT_THAT(base::UTF16ToUTF8(model()->title()), | 450 EXPECT_THAT(base::UTF16ToUTF8(model()->title()), |
| 499 testing::HasSubstr(test_case.expected_title)); | 451 testing::HasSubstr(test_case.expected_title)); |
| 500 } | 452 } |
| 501 | 453 |
| 502 namespace { | 454 namespace { |
| 503 | 455 |
| 504 // Below, "Chrom" is the common prefix of Chromium and Google Chrome. Ideally, | 456 // Below, "Chrom" is the common prefix of Chromium and Google Chrome. Ideally, |
| 505 // we would use the localised strings, but ResourceBundle does not get | 457 // we would use the localised strings, but ResourceBundle does not get |
| 506 // initialised for this unittest. | 458 // initialised for this unittest. |
| 507 const TitleTestCase kTitleTestCases[] = { | 459 const TitleTestCase kTitleTestCases[] = { |
| 508 {kSmartLockBrandingGroupName, SmartLockStatus::ENABLE, "Google Smart Lock"}, | 460 {SmartLockStatus::ENABLE, "Google Smart Lock"}, |
| 509 {kSmartLockBrandingSavePromptOnlyGroupName, SmartLockStatus::ENABLE, | 461 {SmartLockStatus::DISABLE, "Chrom"}, |
| 510 "Google Smart Lock"}, | |
| 511 {nullptr, SmartLockStatus::ENABLE, "Chrom"}, | |
| 512 {"Default", SmartLockStatus::ENABLE, "Chrom"}, | |
| 513 {kSmartLockBrandingGroupName, SmartLockStatus::DISABLE, "Chrom"}, | |
| 514 {kSmartLockBrandingSavePromptOnlyGroupName, SmartLockStatus::DISABLE, | |
| 515 "Chrom"}, | |
| 516 {"Default", SmartLockStatus::DISABLE, "Chrom"}, | |
| 517 {nullptr, SmartLockStatus::DISABLE, "Chrom"}, | |
| 518 }; | 462 }; |
| 519 | 463 |
| 520 } // namespace | 464 } // namespace |
| 521 | 465 |
| 522 INSTANTIATE_TEST_CASE_P(Default, | 466 INSTANTIATE_TEST_CASE_P(Default, |
| 523 ManagePasswordsBubbleModelTitleTest, | 467 ManagePasswordsBubbleModelTitleTest, |
| 524 ::testing::ValuesIn(kTitleTestCases)); | 468 ::testing::ValuesIn(kTitleTestCases)); |
| 525 | 469 |
| 526 namespace { | |
| 527 | |
| 528 enum class ManageLinkTarget { EXTERNAL_PASSWORD_MANAGER, SETTINGS_PAGE }; | |
| 529 | |
| 530 struct ManageLinkTestCase { | |
| 531 const char* experiment_group; | |
| 532 SmartLockStatus smartlock_status; | |
| 533 ManageLinkTarget expected_target; | |
| 534 }; | |
| 535 | |
| 536 } // namespace | |
| 537 | |
| 538 class ManagePasswordsBubbleModelManageLinkTest | 470 class ManagePasswordsBubbleModelManageLinkTest |
| 539 : public ManagePasswordsBubbleModelTest, | 471 : public ManagePasswordsBubbleModelTest, |
| 540 public ::testing::WithParamInterface<ManageLinkTestCase> {}; | 472 public ::testing::WithParamInterface<SmartLockStatus> {}; |
| 541 | 473 |
| 542 TEST_P(ManagePasswordsBubbleModelManageLinkTest, OnManageLinkClicked) { | 474 TEST_P(ManagePasswordsBubbleModelManageLinkTest, OnManageLinkClicked) { |
| 543 ManageLinkTestCase test_case = GetParam(); | 475 SmartLockStatus smartlock_status = GetParam(); |
| 544 TestSyncService* sync_service = static_cast<TestSyncService*>( | 476 TestSyncService* sync_service = static_cast<TestSyncService*>( |
| 545 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 477 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 546 profile(), &TestingSyncFactoryFunction)); | 478 profile(), &TestingSyncFactoryFunction)); |
| 547 sync_service->set_smartlock_enabled(test_case.smartlock_status == | 479 sync_service->set_smartlock_enabled(smartlock_status == |
| 548 SmartLockStatus::ENABLE); | 480 SmartLockStatus::ENABLE); |
| 549 if (test_case.experiment_group) { | |
| 550 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
| 551 test_case.experiment_group); | |
| 552 } | |
| 553 | 481 |
| 554 PretendManagingPasswords(); | 482 PretendManagingPasswords(); |
| 555 | 483 |
| 556 switch (test_case.expected_target) { | 484 EXPECT_CALL(*controller(), NavigateToPasswordManagerSettingsPage()); |
| 557 case ManageLinkTarget::EXTERNAL_PASSWORD_MANAGER: | |
| 558 EXPECT_CALL(*controller(), NavigateToExternalPasswordManager()); | |
| 559 break; | |
| 560 case ManageLinkTarget::SETTINGS_PAGE: | |
| 561 EXPECT_CALL(*controller(), NavigateToPasswordManagerSettingsPage()); | |
| 562 break; | |
| 563 } | |
| 564 | 485 |
| 565 model()->OnManageLinkClicked(); | 486 model()->OnManageLinkClicked(); |
| 566 } | 487 } |
| 567 | 488 |
| 568 namespace { | 489 namespace { |
| 569 | 490 |
| 570 const ManageLinkTestCase kManageLinkTestCases[] = { | 491 const SmartLockStatus kManageLinkTestStatuses[] = { |
| 571 {kSmartLockBrandingGroupName, SmartLockStatus::ENABLE, | 492 SmartLockStatus::ENABLE, SmartLockStatus::DISABLE, |
| 572 ManageLinkTarget::EXTERNAL_PASSWORD_MANAGER}, | |
| 573 {kSmartLockBrandingSavePromptOnlyGroupName, SmartLockStatus::ENABLE, | |
| 574 ManageLinkTarget::SETTINGS_PAGE}, | |
| 575 {nullptr, SmartLockStatus::ENABLE, ManageLinkTarget::SETTINGS_PAGE}, | |
| 576 {"Default", SmartLockStatus::ENABLE, ManageLinkTarget::SETTINGS_PAGE}, | |
| 577 {kSmartLockBrandingGroupName, SmartLockStatus::DISABLE, | |
| 578 ManageLinkTarget::SETTINGS_PAGE}, | |
| 579 {kSmartLockBrandingSavePromptOnlyGroupName, SmartLockStatus::DISABLE, | |
| 580 ManageLinkTarget::SETTINGS_PAGE}, | |
| 581 {nullptr, SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, | |
| 582 {"Default", SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, | |
| 583 }; | 493 }; |
| 584 | 494 |
| 585 } // namespace | 495 } // namespace |
| 586 | 496 |
| 587 INSTANTIATE_TEST_CASE_P(Default, | 497 INSTANTIATE_TEST_CASE_P(Default, |
| 588 ManagePasswordsBubbleModelManageLinkTest, | 498 ManagePasswordsBubbleModelManageLinkTest, |
| 589 ::testing::ValuesIn(kManageLinkTestCases)); | 499 ::testing::ValuesIn(kManageLinkTestStatuses)); |
| OLD | NEW |