Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc

Issue 2036323002: Implement the UI logic behind the Sign In promo in the password bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "components/browser_sync/browser/profile_sync_service_mock.h" 21 #include "components/browser_sync/browser/profile_sync_service_mock.h"
22 #include "components/password_manager/core/browser/mock_password_store.h" 22 #include "components/password_manager/core/browser/mock_password_store.h"
23 #include "components/password_manager/core/browser/password_bubble_experiment.h" 23 #include "components/password_manager/core/browser/password_bubble_experiment.h"
24 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 24 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
25 #include "components/password_manager/core/browser/password_manager_test_utils.h " 25 #include "components/password_manager/core/browser/password_manager_test_utils.h "
26 #include "components/password_manager/core/browser/statistics_table.h" 26 #include "components/password_manager/core/browser/statistics_table.h"
27 #include "components/password_manager/core/common/credential_manager_types.h" 27 #include "components/password_manager/core/common/credential_manager_types.h"
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 "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "content/public/test/web_contents_tester.h" 33 #include "content/public/test/web_contents_tester.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 36
36 using password_bubble_experiment::kBrandingExperimentName; 37 using password_bubble_experiment::kBrandingExperimentName;
38 using password_bubble_experiment::kChromeSignInPasswordPromoExperimentName;
39 using password_bubble_experiment::kChromeSignInPasswordPromoThresholdParam;
37 using password_bubble_experiment::kSmartLockBrandingGroupName; 40 using password_bubble_experiment::kSmartLockBrandingGroupName;
38 using password_bubble_experiment::kSmartLockBrandingSavePromptOnlyGroupName; 41 using password_bubble_experiment::kSmartLockBrandingSavePromptOnlyGroupName;
39 using ::testing::AnyNumber; 42 using ::testing::AnyNumber;
40 using ::testing::Return; 43 using ::testing::Return;
41 using ::testing::ReturnRef; 44 using ::testing::ReturnRef;
42 using ::testing::_; 45 using ::testing::_;
43 46
44 namespace { 47 namespace {
45 48
49 const char kFakeGroup[] = "FakeGroup";
50 const char kSignInPromoDismissalReasonMetric[] = "PasswordManager.SignInPromo";
46 const char kSiteOrigin[] = "http://example.com/login"; 51 const char kSiteOrigin[] = "http://example.com/login";
47 const char kUsername[] = "Admin"; 52 const char kUsername[] = "Admin";
48 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; 53 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason";
49 54
50 class TestSyncService : public ProfileSyncServiceMock { 55 class TestSyncService : public ProfileSyncServiceMock {
51 public: 56 public:
52 explicit TestSyncService(Profile* profile) 57 explicit TestSyncService(Profile* profile)
53 : ProfileSyncServiceMock(CreateProfileSyncServiceParamsForTest(profile)), 58 : ProfileSyncServiceMock(CreateProfileSyncServiceParamsForTest(profile)),
54 smartlock_enabled_(false) {} 59 smartlock_enabled_(false) {}
55 ~TestSyncService() override {} 60 ~TestSyncService() override {}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 profile(), 104 profile(),
100 password_manager::BuildPasswordStore< 105 password_manager::BuildPasswordStore<
101 content::BrowserContext, 106 content::BrowserContext,
102 testing::StrictMock<password_manager::MockPasswordStore>>); 107 testing::StrictMock<password_manager::MockPasswordStore>>);
103 } 108 }
104 109
105 void TearDown() override { 110 void TearDown() override {
106 // Reset WebContents first. It can happen if the user closes the tab. 111 // Reset WebContents first. It can happen if the user closes the tab.
107 test_web_contents_.reset(); 112 test_web_contents_.reset();
108 model_.reset(); 113 model_.reset();
114 variations::testing::ClearAllVariationIDs();
115 variations::testing::ClearAllVariationParams();
109 } 116 }
110 117
111 PrefService* prefs() { return profile_.GetPrefs(); } 118 PrefService* prefs() { return profile_.GetPrefs(); }
112 119
113 TestingProfile* profile() { return &profile_; } 120 TestingProfile* profile() { return &profile_; }
114 121
115 password_manager::MockPasswordStore* GetStore() { 122 password_manager::MockPasswordStore* GetStore() {
116 return static_cast<password_manager::MockPasswordStore*>( 123 return static_cast<password_manager::MockPasswordStore*>(
117 PasswordStoreFactory::GetInstance() 124 PasswordStoreFactory::GetInstance()
118 ->GetForProfile(profile(), ServiceAccessType::EXPLICIT_ACCESS) 125 ->GetForProfile(profile(), ServiceAccessType::EXPLICIT_ACCESS)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 password_manager::prefs::kWasSavePrompFirstRunExperienceShown)); 360 password_manager::prefs::kWasSavePrompFirstRunExperienceShown));
354 } 361 }
355 362
356 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) { 363 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) {
357 PretendPasswordWaiting(); 364 PretendPasswordWaiting();
358 365
359 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); 366 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage());
360 model()->OnBrandLinkClicked(); 367 model()->OnBrandLinkClicked();
361 } 368 }
362 369
370 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) {
371 base::HistogramTester histogram_tester;
372 PretendPasswordWaiting();
373 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
374 EXPECT_CALL(*controller(), SavePassword());
375 model()->OnSaveClicked();
376
377 EXPECT_FALSE(model()->ReplaceToShowSignInPromoIfNeeded());
378 DestroyModel();
379 histogram_tester.ExpectTotalCount(kSignInPromoDismissalReasonMetric, 0);
380 }
381
382 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoOK) {
383 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
384 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
385 variations::AssociateVariationParams(
386 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
387 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
388 base::HistogramTester histogram_tester;
389 PretendPasswordWaiting();
390 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
391 EXPECT_CALL(*controller(), SavePassword());
392 model()->OnSaveClicked();
393
394 EXPECT_TRUE(model()->ReplaceToShowSignInPromoIfNeeded());
395 EXPECT_CALL(*controller(), NavigateToChromeSignIn());
396 model()->OnSignInToChromeClicked();
397 DestroyModel();
398 histogram_tester.ExpectUniqueSample(
399 kUIDismissalReasonMetric,
400 password_manager::metrics_util::CLICKED_SAVE, 1);
401 histogram_tester.ExpectUniqueSample(
402 kSignInPromoDismissalReasonMetric,
403 password_manager::metrics_util::CHROME_SIGNIN_OK, 1);
404 EXPECT_TRUE(prefs()->GetBoolean(
405 password_manager::prefs::kWasSignInPasswordPromoClicked));
406 }
407
408 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoCancel) {
409 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
410 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
411 variations::AssociateVariationParams(
412 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
413 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
414 base::HistogramTester histogram_tester;
415 PretendPasswordWaiting();
416 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
417 EXPECT_CALL(*controller(), SavePassword());
418 model()->OnSaveClicked();
419
420 EXPECT_TRUE(model()->ReplaceToShowSignInPromoIfNeeded());
421 model()->OnSkipSignInClicked();
422 DestroyModel();
423 histogram_tester.ExpectUniqueSample(
424 kUIDismissalReasonMetric,
425 password_manager::metrics_util::CLICKED_SAVE, 1);
426 histogram_tester.ExpectUniqueSample(
427 kSignInPromoDismissalReasonMetric,
428 password_manager::metrics_util::CHROME_SIGNIN_CANCEL, 1);
429 EXPECT_TRUE(prefs()->GetBoolean(
430 password_manager::prefs::kWasSignInPasswordPromoClicked));
431 }
432
433 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoDismiss) {
434 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
435 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
436 variations::AssociateVariationParams(
437 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
438 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
439 base::HistogramTester histogram_tester;
440 PretendPasswordWaiting();
441 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
442 EXPECT_CALL(*controller(), SavePassword());
443 model()->OnSaveClicked();
444
445 EXPECT_TRUE(model()->ReplaceToShowSignInPromoIfNeeded());
446 DestroyModel();
447 histogram_tester.ExpectUniqueSample(
448 kUIDismissalReasonMetric,
449 password_manager::metrics_util::CLICKED_SAVE, 1);
450 histogram_tester.ExpectUniqueSample(
451 kSignInPromoDismissalReasonMetric,
452 password_manager::metrics_util::CHROME_SIGNIN_DISMISSED, 1);
453 EXPECT_FALSE(prefs()->GetBoolean(
454 password_manager::prefs::kWasSignInPasswordPromoClicked));
455 }
456
363 namespace { 457 namespace {
364 458
365 enum class SmartLockStatus { ENABLE, DISABLE }; 459 enum class SmartLockStatus { ENABLE, DISABLE };
366 460
367 struct TitleTestCase { 461 struct TitleTestCase {
368 const char* experiment_group; 462 const char* experiment_group;
369 SmartLockStatus smartlock_status; 463 SmartLockStatus smartlock_status;
370 const char* expected_title; 464 const char* expected_title;
371 }; 465 };
372 466
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 ManageLinkTarget::SETTINGS_PAGE}, 568 ManageLinkTarget::SETTINGS_PAGE},
475 {nullptr, SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, 569 {nullptr, SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE},
476 {"Default", SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, 570 {"Default", SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE},
477 }; 571 };
478 572
479 } // namespace 573 } // namespace
480 574
481 INSTANTIATE_TEST_CASE_P(Default, 575 INSTANTIATE_TEST_CASE_P(Default,
482 ManagePasswordsBubbleModelManageLinkTest, 576 ManagePasswordsBubbleModelManageLinkTest,
483 ::testing::ValuesIn(kManageLinkTestCases)); 577 ::testing::ValuesIn(kManageLinkTestCases));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698