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 constexpr char kFakeGroup[] = "FakeGroup"; |
51 const char kSignInPromoCountTilNoThanksMetric[] = | 48 constexpr char kSignInPromoCountTilNoThanksMetric[] = |
52 "PasswordManager.SignInPromoCountTilNoThanks"; | 49 "PasswordManager.SignInPromoCountTilNoThanks"; |
53 const char kSignInPromoCountTilSignInMetric[] = | 50 constexpr char kSignInPromoCountTilSignInMetric[] = |
54 "PasswordManager.SignInPromoCountTilSignIn"; | 51 "PasswordManager.SignInPromoCountTilSignIn"; |
55 const char kSignInPromoDismissalCountMetric[] = | 52 constexpr char kSignInPromoDismissalCountMetric[] = |
56 "PasswordManager.SignInPromoDismissalCount"; | 53 "PasswordManager.SignInPromoDismissalCount"; |
57 const char kSignInPromoDismissalReasonMetric[] = "PasswordManager.SignInPromo"; | 54 constexpr char kSignInPromoDismissalReasonMetric[] = |
58 const char kSiteOrigin[] = "http://example.com/login"; | 55 "PasswordManager.SignInPromo"; |
59 const char kUsername[] = "Admin"; | 56 constexpr char kSiteOrigin[] = "http://example.com/login"; |
60 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; | 57 constexpr char kUsername[] = "Admin"; |
| 58 constexpr char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; |
61 | 59 |
62 class TestSyncService : public browser_sync::ProfileSyncServiceMock { | 60 class TestSyncService : public browser_sync::ProfileSyncServiceMock { |
63 public: | 61 public: |
| 62 enum class SyncedTypes { ALL, NONE }; |
| 63 |
64 explicit TestSyncService(Profile* profile) | 64 explicit TestSyncService(Profile* profile) |
65 : browser_sync::ProfileSyncServiceMock( | 65 : browser_sync::ProfileSyncServiceMock( |
66 CreateProfileSyncServiceParamsForTest(profile)), | 66 CreateProfileSyncServiceParamsForTest(profile)), |
67 smartlock_enabled_(false) {} | 67 synced_types_(SyncedTypes::NONE) {} |
68 ~TestSyncService() override {} | 68 ~TestSyncService() override {} |
69 | 69 |
70 // FakeSyncService: | 70 // FakeSyncService: |
71 bool IsFirstSetupComplete() const override { return true; } | 71 bool IsFirstSetupComplete() const override { return true; } |
72 bool IsSyncAllowed() const override { return true; } | 72 bool IsSyncAllowed() const override { return true; } |
73 bool IsSyncActive() const override { return true; } | 73 bool IsSyncActive() const override { return true; } |
74 syncer::ModelTypeSet GetActiveDataTypes() const override { | 74 syncer::ModelTypeSet GetActiveDataTypes() const override { |
75 return smartlock_enabled_ ? syncer::ModelTypeSet::All() | 75 switch (synced_types_) { |
76 : syncer::ModelTypeSet(); | 76 case SyncedTypes::ALL: |
| 77 return syncer::ModelTypeSet::All(); |
| 78 case SyncedTypes::NONE: |
| 79 return syncer::ModelTypeSet(); |
| 80 } |
| 81 NOTREACHED(); |
| 82 return syncer::ModelTypeSet(); |
77 } | 83 } |
78 bool CanSyncStart() const override { return true; } | 84 bool CanSyncStart() const override { return true; } |
79 syncer::ModelTypeSet GetPreferredDataTypes() const override { | 85 syncer::ModelTypeSet GetPreferredDataTypes() const override { |
80 return GetActiveDataTypes(); | 86 return GetActiveDataTypes(); |
81 } | 87 } |
82 bool IsUsingSecondaryPassphrase() const override { return false; } | 88 bool IsUsingSecondaryPassphrase() const override { return false; } |
83 | 89 |
84 void set_smartlock_enabled(bool smartlock_enabled) { | 90 void set_synced_types(SyncedTypes synced_types) { |
85 smartlock_enabled_ = smartlock_enabled; | 91 synced_types_ = synced_types; |
86 } | 92 } |
87 | 93 |
88 private: | 94 private: |
89 bool smartlock_enabled_; | 95 SyncedTypes synced_types_; |
90 }; | 96 }; |
91 | 97 |
92 std::unique_ptr<KeyedService> TestingSyncFactoryFunction( | 98 std::unique_ptr<KeyedService> TestingSyncFactoryFunction( |
93 content::BrowserContext* context) { | 99 content::BrowserContext* context) { |
94 return base::MakeUnique<TestSyncService>(static_cast<Profile*>(context)); | 100 return base::MakeUnique<TestSyncService>(static_cast<Profile*>(context)); |
95 } | 101 } |
96 | 102 |
97 } // namespace | 103 } // namespace |
98 | 104 |
99 class ManagePasswordsBubbleModelTest : public ::testing::Test { | 105 class ManagePasswordsBubbleModelTest : public ::testing::Test { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 319 |
314 TEST_F(ManagePasswordsBubbleModelTest, ClickUpdate) { | 320 TEST_F(ManagePasswordsBubbleModelTest, ClickUpdate) { |
315 PretendUpdatePasswordWaiting(); | 321 PretendUpdatePasswordWaiting(); |
316 | 322 |
317 autofill::PasswordForm form; | 323 autofill::PasswordForm form; |
318 EXPECT_CALL(*controller(), UpdatePassword(form)); | 324 EXPECT_CALL(*controller(), UpdatePassword(form)); |
319 model()->OnUpdateClicked(form); | 325 model()->OnUpdateClicked(form); |
320 DestroyModel(); | 326 DestroyModel(); |
321 } | 327 } |
322 | 328 |
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) { | 329 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) { |
364 PretendPasswordWaiting(); | 330 PretendPasswordWaiting(); |
365 | 331 |
366 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); | 332 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); |
367 model()->OnBrandLinkClicked(); | 333 model()->OnBrandLinkClicked(); |
368 } | 334 } |
369 | 335 |
370 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) { | 336 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) { |
371 base::HistogramTester histogram_tester; | 337 base::HistogramTester histogram_tester; |
372 PretendPasswordWaiting(); | 338 PretendPasswordWaiting(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 password_manager::metrics_util::CHROME_SIGNIN_DISMISSED, 1); | 427 password_manager::metrics_util::CHROME_SIGNIN_DISMISSED, 1); |
462 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0); | 428 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0); |
463 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0); | 429 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0); |
464 histogram_tester.ExpectUniqueSample(kSignInPromoDismissalCountMetric, 1, 1); | 430 histogram_tester.ExpectUniqueSample(kSignInPromoDismissalCountMetric, 1, 1); |
465 EXPECT_FALSE(prefs()->GetBoolean( | 431 EXPECT_FALSE(prefs()->GetBoolean( |
466 password_manager::prefs::kWasSignInPasswordPromoClicked)); | 432 password_manager::prefs::kWasSignInPasswordPromoClicked)); |
467 } | 433 } |
468 | 434 |
469 namespace { | 435 namespace { |
470 | 436 |
471 enum class SmartLockStatus { ENABLE, DISABLE }; | |
472 | |
473 struct TitleTestCase { | 437 struct TitleTestCase { |
474 const char* experiment_group; | 438 TestSyncService::SyncedTypes synced_types; |
475 SmartLockStatus smartlock_status; | |
476 const char* expected_title; | 439 const char* expected_title; |
477 }; | 440 }; |
478 | 441 |
479 } // namespace | 442 } // namespace |
480 | 443 |
481 class ManagePasswordsBubbleModelTitleTest | 444 class ManagePasswordsBubbleModelTitleTest |
482 : public ManagePasswordsBubbleModelTest, | 445 : public ManagePasswordsBubbleModelTest, |
483 public ::testing::WithParamInterface<TitleTestCase> {}; | 446 public ::testing::WithParamInterface<TitleTestCase> {}; |
484 | 447 |
485 TEST_P(ManagePasswordsBubbleModelTitleTest, BrandedTitleOnSaving) { | 448 TEST_P(ManagePasswordsBubbleModelTitleTest, BrandedTitleOnSaving) { |
486 TitleTestCase test_case = GetParam(); | 449 TitleTestCase test_case = GetParam(); |
487 TestSyncService* sync_service = static_cast<TestSyncService*>( | 450 TestSyncService* sync_service = static_cast<TestSyncService*>( |
488 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 451 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
489 profile(), &TestingSyncFactoryFunction)); | 452 profile(), &TestingSyncFactoryFunction)); |
490 sync_service->set_smartlock_enabled(test_case.smartlock_status == | 453 sync_service->set_synced_types(test_case.synced_types); |
491 SmartLockStatus::ENABLE); | |
492 if (test_case.experiment_group) { | |
493 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
494 test_case.experiment_group); | |
495 } | |
496 | 454 |
497 PretendPasswordWaiting(); | 455 PretendPasswordWaiting(); |
498 EXPECT_THAT(base::UTF16ToUTF8(model()->title()), | 456 EXPECT_THAT(base::UTF16ToUTF8(model()->title()), |
499 testing::HasSubstr(test_case.expected_title)); | 457 testing::HasSubstr(test_case.expected_title)); |
500 } | 458 } |
501 | 459 |
502 namespace { | 460 namespace { |
503 | 461 |
504 // Below, "Chrom" is the common prefix of Chromium and Google Chrome. Ideally, | 462 // Below, "Chrom" is the common prefix of Chromium and Google Chrome. Ideally, |
505 // we would use the localised strings, but ResourceBundle does not get | 463 // we would use the localised strings, but ResourceBundle does not get |
506 // initialised for this unittest. | 464 // initialised for this unittest. |
507 const TitleTestCase kTitleTestCases[] = { | 465 constexpr TitleTestCase kTitleTestCases[] = { |
508 {kSmartLockBrandingGroupName, SmartLockStatus::ENABLE, "Google Smart Lock"}, | 466 {TestSyncService::SyncedTypes::ALL, "Google Smart Lock"}, |
509 {kSmartLockBrandingSavePromptOnlyGroupName, SmartLockStatus::ENABLE, | 467 {TestSyncService::SyncedTypes::NONE, "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 }; | 468 }; |
519 | 469 |
520 } // namespace | 470 } // namespace |
521 | 471 |
522 INSTANTIATE_TEST_CASE_P(Default, | 472 INSTANTIATE_TEST_CASE_P(Default, |
523 ManagePasswordsBubbleModelTitleTest, | 473 ManagePasswordsBubbleModelTitleTest, |
524 ::testing::ValuesIn(kTitleTestCases)); | 474 ::testing::ValuesIn(kTitleTestCases)); |
525 | 475 |
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 | 476 class ManagePasswordsBubbleModelManageLinkTest |
539 : public ManagePasswordsBubbleModelTest, | 477 : public ManagePasswordsBubbleModelTest, |
540 public ::testing::WithParamInterface<ManageLinkTestCase> {}; | 478 public ::testing::WithParamInterface<TestSyncService::SyncedTypes> {}; |
541 | 479 |
542 TEST_P(ManagePasswordsBubbleModelManageLinkTest, OnManageLinkClicked) { | 480 TEST_P(ManagePasswordsBubbleModelManageLinkTest, OnManageLinkClicked) { |
543 ManageLinkTestCase test_case = GetParam(); | |
544 TestSyncService* sync_service = static_cast<TestSyncService*>( | 481 TestSyncService* sync_service = static_cast<TestSyncService*>( |
545 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 482 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
546 profile(), &TestingSyncFactoryFunction)); | 483 profile(), &TestingSyncFactoryFunction)); |
547 sync_service->set_smartlock_enabled(test_case.smartlock_status == | 484 sync_service->set_synced_types(GetParam()); |
548 SmartLockStatus::ENABLE); | |
549 if (test_case.experiment_group) { | |
550 base::FieldTrialList::CreateFieldTrial(kBrandingExperimentName, | |
551 test_case.experiment_group); | |
552 } | |
553 | 485 |
554 PretendManagingPasswords(); | 486 PretendManagingPasswords(); |
555 | 487 |
556 switch (test_case.expected_target) { | 488 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 | 489 |
565 model()->OnManageLinkClicked(); | 490 model()->OnManageLinkClicked(); |
566 } | 491 } |
567 | 492 |
568 namespace { | |
569 | |
570 const ManageLinkTestCase kManageLinkTestCases[] = { | |
571 {kSmartLockBrandingGroupName, SmartLockStatus::ENABLE, | |
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 }; | |
584 | |
585 } // namespace | |
586 | |
587 INSTANTIATE_TEST_CASE_P(Default, | 493 INSTANTIATE_TEST_CASE_P(Default, |
588 ManagePasswordsBubbleModelManageLinkTest, | 494 ManagePasswordsBubbleModelManageLinkTest, |
589 ::testing::ValuesIn(kManageLinkTestCases)); | 495 ::testing::Values(TestSyncService::SyncedTypes::ALL, |
| 496 TestSyncService::SyncedTypes::NONE)); |
OLD | NEW |