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

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

Issue 2653733006: Remove the Finch experiment for the sign-in promo in the password bubble. (Closed)
Patch Set: fix mac/2 Created 3 years, 11 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"
11 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram_samples.h" 11 #include "base/metrics/histogram_samples.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
15 #include "base/test/simple_test_clock.h" 14 #include "base/test/simple_test_clock.h"
16 #include "chrome/browser/password_manager/password_store_factory.h" 15 #include "chrome/browser/password_manager/password_store_factory.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/sync/profile_sync_test_util.h" 17 #include "chrome/browser/sync/profile_sync_test_util.h"
19 #include "chrome/browser/ui/passwords/passwords_model_delegate_mock.h" 18 #include "chrome/browser/ui/passwords/passwords_model_delegate_mock.h"
20 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
21 #include "components/browser_sync/profile_sync_service_mock.h" 20 #include "components/browser_sync/profile_sync_service_mock.h"
22 #include "components/password_manager/core/browser/mock_password_store.h" 21 #include "components/password_manager/core/browser/mock_password_store.h"
23 #include "components/password_manager/core/browser/password_bubble_experiment.h"
24 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 22 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
25 #include "components/password_manager/core/browser/password_manager_test_utils.h " 23 #include "components/password_manager/core/browser/password_manager_test_utils.h "
26 #include "components/password_manager/core/browser/statistics_table.h" 24 #include "components/password_manager/core/browser/statistics_table.h"
27 #include "components/password_manager/core/common/credential_manager_types.h" 25 #include "components/password_manager/core/common/credential_manager_types.h"
28 #include "components/password_manager/core/common/password_manager_pref_names.h" 26 #include "components/password_manager/core/common/password_manager_pref_names.h"
29 #include "components/password_manager/core/common/password_manager_ui.h" 27 #include "components/password_manager/core/common/password_manager_ui.h"
30 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
31 #include "components/variations/variations_associated_data.h"
32 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "content/public/test/web_contents_tester.h" 31 #include "content/public/test/web_contents_tester.h"
35 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
37 34
38 using password_bubble_experiment::kChromeSignInPasswordPromoExperimentName;
39 using password_bubble_experiment::kChromeSignInPasswordPromoThresholdParam;
40 using ::testing::AnyNumber; 35 using ::testing::AnyNumber;
41 using ::testing::Return; 36 using ::testing::Return;
42 using ::testing::ReturnRef; 37 using ::testing::ReturnRef;
43 using ::testing::_; 38 using ::testing::_;
44 39
45 namespace { 40 namespace {
46 41
47 constexpr char kFakeGroup[] = "FakeGroup";
48 constexpr char kSignInPromoCountTilNoThanksMetric[] = 42 constexpr char kSignInPromoCountTilNoThanksMetric[] =
49 "PasswordManager.SignInPromoCountTilNoThanks"; 43 "PasswordManager.SignInPromoCountTilNoThanks";
50 constexpr char kSignInPromoCountTilSignInMetric[] = 44 constexpr char kSignInPromoCountTilSignInMetric[] =
51 "PasswordManager.SignInPromoCountTilSignIn"; 45 "PasswordManager.SignInPromoCountTilSignIn";
52 constexpr char kSignInPromoDismissalCountMetric[] = 46 constexpr char kSignInPromoDismissalCountMetric[] =
53 "PasswordManager.SignInPromoDismissalCount"; 47 "PasswordManager.SignInPromoDismissalCount";
54 constexpr char kSignInPromoDismissalReasonMetric[] = 48 constexpr char kSignInPromoDismissalReasonMetric[] =
55 "PasswordManager.SignInPromo"; 49 "PasswordManager.SignInPromo";
56 constexpr char kSiteOrigin[] = "http://example.com/login"; 50 constexpr char kSiteOrigin[] = "http://example.com/login";
57 constexpr char kUsername[] = "Admin"; 51 constexpr char kUsername[] = "Admin";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 91
98 std::unique_ptr<KeyedService> TestingSyncFactoryFunction( 92 std::unique_ptr<KeyedService> TestingSyncFactoryFunction(
99 content::BrowserContext* context) { 93 content::BrowserContext* context) {
100 return base::MakeUnique<TestSyncService>(static_cast<Profile*>(context)); 94 return base::MakeUnique<TestSyncService>(static_cast<Profile*>(context));
101 } 95 }
102 96
103 } // namespace 97 } // namespace
104 98
105 class ManagePasswordsBubbleModelTest : public ::testing::Test { 99 class ManagePasswordsBubbleModelTest : public ::testing::Test {
106 public: 100 public:
107 ManagePasswordsBubbleModelTest() : field_trials_(nullptr) {} 101 ManagePasswordsBubbleModelTest() = default;
108 ~ManagePasswordsBubbleModelTest() override = default; 102 ~ManagePasswordsBubbleModelTest() override = default;
109 103
110 void SetUp() override { 104 void SetUp() override {
111 test_web_contents_.reset( 105 test_web_contents_.reset(
112 content::WebContentsTester::CreateTestWebContents(&profile_, nullptr)); 106 content::WebContentsTester::CreateTestWebContents(&profile_, nullptr));
113 mock_delegate_.reset(new testing::StrictMock<PasswordsModelDelegateMock>); 107 mock_delegate_.reset(new testing::StrictMock<PasswordsModelDelegateMock>);
114 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( 108 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
115 profile(), 109 profile(),
116 password_manager::BuildPasswordStore< 110 password_manager::BuildPasswordStore<
117 content::BrowserContext, 111 content::BrowserContext,
118 testing::StrictMock<password_manager::MockPasswordStore>>); 112 testing::StrictMock<password_manager::MockPasswordStore>>);
119 #if !defined(OS_MACOSX) 113 #if !defined(OS_MACOSX)
120 // TODO(crbug.com/668155): Remove conditional compilation when 114 // TODO(crbug.com/668155): Remove conditional compilation when
121 // PasswordReuseDetector initialization will be implemented for Mac. 115 // PasswordReuseDetector initialization will be implemented for Mac.
122 // The call of FillAutofillableLogins is caused by a posted task for an 116 // The call of FillAutofillableLogins is caused by a posted task for an
123 // initialization of PasswordReuseDetector in the call of 117 // initialization of PasswordReuseDetector in the call of
124 // BuildPasswordStore() in the previous code. There is no thread race since 118 // BuildPasswordStore() in the previous code. There is no thread race since
125 // unit tests run in one thread, and any post task will be executed after 119 // unit tests run in one thread, and any post task will be executed after
126 // finishing the current function. 120 // finishing the current function.
127 EXPECT_CALL(*GetStore(), FillAutofillableLogins(_)); 121 EXPECT_CALL(*GetStore(), FillAutofillableLogins(_));
128 #endif 122 #endif
129 } 123 }
130 124
131 void TearDown() override { 125 void TearDown() override {
132 // Reset the delegate first. It can happen if the user closes the tab. 126 // Reset the delegate first. It can happen if the user closes the tab.
133 mock_delegate_.reset(); 127 mock_delegate_.reset();
134 model_.reset(); 128 model_.reset();
135 variations::testing::ClearAllVariationIDs();
136 variations::testing::ClearAllVariationParams();
137 } 129 }
138 130
139 PrefService* prefs() { return profile_.GetPrefs(); } 131 PrefService* prefs() { return profile_.GetPrefs(); }
140 132
141 TestingProfile* profile() { return &profile_; } 133 TestingProfile* profile() { return &profile_; }
142 134
143 password_manager::MockPasswordStore* GetStore() { 135 password_manager::MockPasswordStore* GetStore() {
144 return static_cast<password_manager::MockPasswordStore*>( 136 return static_cast<password_manager::MockPasswordStore*>(
145 PasswordStoreFactory::GetInstance() 137 PasswordStoreFactory::GetInstance()
146 ->GetForProfile(profile(), ServiceAccessType::EXPLICIT_ACCESS) 138 ->GetForProfile(profile(), ServiceAccessType::EXPLICIT_ACCESS)
(...skipping 17 matching lines...) Expand all
164 void DestroyModelExpectReason( 156 void DestroyModelExpectReason(
165 password_manager::metrics_util::UIDismissalReason dismissal_reason); 157 password_manager::metrics_util::UIDismissalReason dismissal_reason);
166 158
167 static password_manager::InteractionsStats GetTestStats(); 159 static password_manager::InteractionsStats GetTestStats();
168 static autofill::PasswordForm GetPendingPassword(); 160 static autofill::PasswordForm GetPendingPassword();
169 161
170 private: 162 private:
171 content::TestBrowserThreadBundle thread_bundle_; 163 content::TestBrowserThreadBundle thread_bundle_;
172 TestingProfile profile_; 164 TestingProfile profile_;
173 std::unique_ptr<content::WebContents> test_web_contents_; 165 std::unique_ptr<content::WebContents> test_web_contents_;
174 base::FieldTrialList field_trials_;
175 std::unique_ptr<ManagePasswordsBubbleModel> model_; 166 std::unique_ptr<ManagePasswordsBubbleModel> model_;
176 std::unique_ptr<PasswordsModelDelegateMock> mock_delegate_; 167 std::unique_ptr<PasswordsModelDelegateMock> mock_delegate_;
177 }; 168 };
178 169
179 void ManagePasswordsBubbleModelTest::SetUpWithState( 170 void ManagePasswordsBubbleModelTest::SetUpWithState(
180 password_manager::ui::State state, 171 password_manager::ui::State state,
181 ManagePasswordsBubbleModel::DisplayReason reason) { 172 ManagePasswordsBubbleModel::DisplayReason reason) {
182 GURL origin(kSiteOrigin); 173 GURL origin(kSiteOrigin);
183 EXPECT_CALL(*controller(), GetOrigin()).WillOnce(ReturnRef(origin)); 174 EXPECT_CALL(*controller(), GetOrigin()).WillOnce(ReturnRef(origin));
184 EXPECT_CALL(*controller(), GetState()).WillOnce(Return(state)); 175 EXPECT_CALL(*controller(), GetState()).WillOnce(Return(state));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 329 }
339 330
340 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) { 331 TEST_F(ManagePasswordsBubbleModelTest, OnBrandLinkClicked) {
341 PretendPasswordWaiting(); 332 PretendPasswordWaiting();
342 333
343 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage()); 334 EXPECT_CALL(*controller(), NavigateToSmartLockHelpPage());
344 model()->OnBrandLinkClicked(); 335 model()->OnBrandLinkClicked();
345 } 336 }
346 337
347 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) { 338 TEST_F(ManagePasswordsBubbleModelTest, SuppressSignInPromo) {
339 prefs()->SetBoolean(password_manager::prefs::kWasSignInPasswordPromoClicked,
340 true);
348 base::HistogramTester histogram_tester; 341 base::HistogramTester histogram_tester;
349 PretendPasswordWaiting(); 342 PretendPasswordWaiting();
350 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin())); 343 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
351 EXPECT_CALL(*controller(), SavePassword()); 344 EXPECT_CALL(*controller(), SavePassword());
352 model()->OnSaveClicked(); 345 model()->OnSaveClicked();
353 346
354 EXPECT_FALSE(model()->ReplaceToShowPromotionIfNeeded()); 347 EXPECT_FALSE(model()->ReplaceToShowPromotionIfNeeded());
355 DestroyModel(); 348 DestroyModel();
356 histogram_tester.ExpectTotalCount(kSignInPromoDismissalReasonMetric, 0); 349 histogram_tester.ExpectTotalCount(kSignInPromoDismissalReasonMetric, 0);
357 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0); 350 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0);
358 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0); 351 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0);
359 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0); 352 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0);
360 } 353 }
361 354
362 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoOK) { 355 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoOK) {
363 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
364 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
365 variations::AssociateVariationParams(
366 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
367 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
368 base::HistogramTester histogram_tester; 356 base::HistogramTester histogram_tester;
369 PretendPasswordWaiting(); 357 PretendPasswordWaiting();
370 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin())); 358 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
371 EXPECT_CALL(*controller(), SavePassword()); 359 EXPECT_CALL(*controller(), SavePassword());
372 model()->OnSaveClicked(); 360 model()->OnSaveClicked();
373 361
374 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded()); 362 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded());
375 EXPECT_CALL(*controller(), NavigateToChromeSignIn()); 363 EXPECT_CALL(*controller(), NavigateToChromeSignIn());
376 model()->OnSignInToChromeClicked(); 364 model()->OnSignInToChromeClicked();
377 DestroyModel(); 365 DestroyModel();
378 histogram_tester.ExpectUniqueSample( 366 histogram_tester.ExpectUniqueSample(
379 kUIDismissalReasonMetric, 367 kUIDismissalReasonMetric,
380 password_manager::metrics_util::CLICKED_SAVE, 1); 368 password_manager::metrics_util::CLICKED_SAVE, 1);
381 histogram_tester.ExpectUniqueSample( 369 histogram_tester.ExpectUniqueSample(
382 kSignInPromoDismissalReasonMetric, 370 kSignInPromoDismissalReasonMetric,
383 password_manager::metrics_util::CHROME_SIGNIN_OK, 1); 371 password_manager::metrics_util::CHROME_SIGNIN_OK, 1);
384 histogram_tester.ExpectUniqueSample(kSignInPromoCountTilSignInMetric, 1, 1); 372 histogram_tester.ExpectUniqueSample(kSignInPromoCountTilSignInMetric, 1, 1);
385 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0); 373 histogram_tester.ExpectTotalCount(kSignInPromoCountTilNoThanksMetric, 0);
386 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0); 374 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0);
387 EXPECT_TRUE(prefs()->GetBoolean( 375 EXPECT_TRUE(prefs()->GetBoolean(
388 password_manager::prefs::kWasSignInPasswordPromoClicked)); 376 password_manager::prefs::kWasSignInPasswordPromoClicked));
389 } 377 }
390 378
391 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoCancel) { 379 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoCancel) {
392 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
393 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
394 variations::AssociateVariationParams(
395 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
396 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
397 base::HistogramTester histogram_tester; 380 base::HistogramTester histogram_tester;
398 PretendPasswordWaiting(); 381 PretendPasswordWaiting();
399 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin())); 382 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
400 EXPECT_CALL(*controller(), SavePassword()); 383 EXPECT_CALL(*controller(), SavePassword());
401 model()->OnSaveClicked(); 384 model()->OnSaveClicked();
402 385
403 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded()); 386 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded());
404 model()->OnSkipSignInClicked(); 387 model()->OnSkipSignInClicked();
405 DestroyModel(); 388 DestroyModel();
406 histogram_tester.ExpectUniqueSample( 389 histogram_tester.ExpectUniqueSample(
407 kUIDismissalReasonMetric, 390 kUIDismissalReasonMetric,
408 password_manager::metrics_util::CLICKED_SAVE, 1); 391 password_manager::metrics_util::CLICKED_SAVE, 1);
409 histogram_tester.ExpectUniqueSample( 392 histogram_tester.ExpectUniqueSample(
410 kSignInPromoDismissalReasonMetric, 393 kSignInPromoDismissalReasonMetric,
411 password_manager::metrics_util::CHROME_SIGNIN_CANCEL, 1); 394 password_manager::metrics_util::CHROME_SIGNIN_CANCEL, 1);
412 histogram_tester.ExpectUniqueSample(kSignInPromoCountTilNoThanksMetric, 1, 1); 395 histogram_tester.ExpectUniqueSample(kSignInPromoCountTilNoThanksMetric, 1, 1);
413 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0); 396 histogram_tester.ExpectTotalCount(kSignInPromoCountTilSignInMetric, 0);
414 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0); 397 histogram_tester.ExpectTotalCount(kSignInPromoDismissalCountMetric, 0);
415 EXPECT_TRUE(prefs()->GetBoolean( 398 EXPECT_TRUE(prefs()->GetBoolean(
416 password_manager::prefs::kWasSignInPasswordPromoClicked)); 399 password_manager::prefs::kWasSignInPasswordPromoClicked));
417 } 400 }
418 401
419 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoDismiss) { 402 TEST_F(ManagePasswordsBubbleModelTest, SignInPromoDismiss) {
420 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
421 kChromeSignInPasswordPromoExperimentName, kFakeGroup));
422 variations::AssociateVariationParams(
423 kChromeSignInPasswordPromoExperimentName, kFakeGroup,
424 {{kChromeSignInPasswordPromoThresholdParam, "3"}});
425 base::HistogramTester histogram_tester; 403 base::HistogramTester histogram_tester;
426 PretendPasswordWaiting(); 404 PretendPasswordWaiting();
427 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin())); 405 EXPECT_CALL(*GetStore(), RemoveSiteStatsImpl(GURL(kSiteOrigin).GetOrigin()));
428 EXPECT_CALL(*controller(), SavePassword()); 406 EXPECT_CALL(*controller(), SavePassword());
429 model()->OnSaveClicked(); 407 model()->OnSaveClicked();
430 408
431 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded()); 409 EXPECT_TRUE(model()->ReplaceToShowPromotionIfNeeded());
432 DestroyModel(); 410 DestroyModel();
433 histogram_tester.ExpectUniqueSample( 411 histogram_tester.ExpectUniqueSample(
434 kUIDismissalReasonMetric, 412 kUIDismissalReasonMetric,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 476
499 EXPECT_CALL(*controller(), NavigateToPasswordManagerSettingsPage()); 477 EXPECT_CALL(*controller(), NavigateToPasswordManagerSettingsPage());
500 478
501 model()->OnManageLinkClicked(); 479 model()->OnManageLinkClicked();
502 } 480 }
503 481
504 INSTANTIATE_TEST_CASE_P(Default, 482 INSTANTIATE_TEST_CASE_P(Default,
505 ManagePasswordsBubbleModelManageLinkTest, 483 ManagePasswordsBubbleModelManageLinkTest,
506 ::testing::Values(TestSyncService::SyncedTypes::ALL, 484 ::testing::Values(TestSyncService::SyncedTypes::ALL,
507 TestSyncService::SyncedTypes::NONE)); 485 TestSyncService::SyncedTypes::NONE));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698