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/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
11 #include "base/metrics/histogram_samples.h" | 12 #include "base/metrics/histogram_samples.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
14 #include "base/test/simple_test_clock.h" | 15 #include "base/test/simple_test_clock.h" |
15 #include "chrome/browser/password_manager/password_store_factory.h" | 16 #include "chrome/browser/password_manager/password_store_factory.h" |
16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 17 #include "chrome/browser/sync/profile_sync_service_factory.h" |
17 #include "chrome/browser/sync/profile_sync_test_util.h" | 18 #include "chrome/browser/sync/profile_sync_test_util.h" |
18 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" | 19 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 bool IsUsingSecondaryPassphrase() const override { return false; } | 69 bool IsUsingSecondaryPassphrase() const override { return false; } |
69 | 70 |
70 void set_smartlock_enabled(bool smartlock_enabled) { | 71 void set_smartlock_enabled(bool smartlock_enabled) { |
71 smartlock_enabled_ = smartlock_enabled; | 72 smartlock_enabled_ = smartlock_enabled; |
72 } | 73 } |
73 | 74 |
74 private: | 75 private: |
75 bool smartlock_enabled_; | 76 bool smartlock_enabled_; |
76 }; | 77 }; |
77 | 78 |
78 scoped_ptr<KeyedService> TestingSyncFactoryFunction( | 79 std::unique_ptr<KeyedService> TestingSyncFactoryFunction( |
79 content::BrowserContext* context) { | 80 content::BrowserContext* context) { |
80 return make_scoped_ptr(new TestSyncService(static_cast<Profile*>(context))); | 81 return base::WrapUnique(new TestSyncService(static_cast<Profile*>(context))); |
81 } | 82 } |
82 | 83 |
83 } // namespace | 84 } // namespace |
84 | 85 |
85 class ManagePasswordsBubbleModelTest : public ::testing::Test { | 86 class ManagePasswordsBubbleModelTest : public ::testing::Test { |
86 public: | 87 public: |
87 ManagePasswordsBubbleModelTest() : field_trials_(nullptr) {} | 88 ManagePasswordsBubbleModelTest() : field_trials_(nullptr) {} |
88 ~ManagePasswordsBubbleModelTest() override = default; | 89 ~ManagePasswordsBubbleModelTest() override = default; |
89 | 90 |
90 void SetUp() override { | 91 void SetUp() override { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void DestroyModel(); | 138 void DestroyModel(); |
138 void DestroyModelExpectReason( | 139 void DestroyModelExpectReason( |
139 password_manager::metrics_util::UIDismissalReason dismissal_reason); | 140 password_manager::metrics_util::UIDismissalReason dismissal_reason); |
140 | 141 |
141 static password_manager::InteractionsStats GetTestStats(); | 142 static password_manager::InteractionsStats GetTestStats(); |
142 static autofill::PasswordForm GetPendingPassword(); | 143 static autofill::PasswordForm GetPendingPassword(); |
143 | 144 |
144 private: | 145 private: |
145 content::TestBrowserThreadBundle thread_bundle_; | 146 content::TestBrowserThreadBundle thread_bundle_; |
146 TestingProfile profile_; | 147 TestingProfile profile_; |
147 scoped_ptr<content::WebContents> test_web_contents_; | 148 std::unique_ptr<content::WebContents> test_web_contents_; |
148 base::FieldTrialList field_trials_; | 149 base::FieldTrialList field_trials_; |
149 scoped_ptr<ManagePasswordsBubbleModel> model_; | 150 std::unique_ptr<ManagePasswordsBubbleModel> model_; |
150 }; | 151 }; |
151 | 152 |
152 void ManagePasswordsBubbleModelTest::SetUpWithState( | 153 void ManagePasswordsBubbleModelTest::SetUpWithState( |
153 password_manager::ui::State state, | 154 password_manager::ui::State state, |
154 ManagePasswordsBubbleModel::DisplayReason reason) { | 155 ManagePasswordsBubbleModel::DisplayReason reason) { |
155 ManagePasswordsUIControllerMock* mock = controller(); | 156 ManagePasswordsUIControllerMock* mock = controller(); |
156 GURL origin(kSiteOrigin); | 157 GURL origin(kSiteOrigin); |
157 EXPECT_CALL(*mock, GetOrigin()).WillOnce(ReturnRef(origin)); | 158 EXPECT_CALL(*mock, GetOrigin()).WillOnce(ReturnRef(origin)); |
158 EXPECT_CALL(*mock, GetState()).WillOnce(Return(state)); | 159 EXPECT_CALL(*mock, GetState()).WillOnce(Return(state)); |
159 EXPECT_CALL(*mock, OnBubbleShown()); | 160 EXPECT_CALL(*mock, OnBubbleShown()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 form.password_value = base::ASCIIToUTF16("12345"); | 238 form.password_value = base::ASCIIToUTF16("12345"); |
238 return form; | 239 return form; |
239 } | 240 } |
240 | 241 |
241 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) { | 242 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) { |
242 PretendPasswordWaiting(); | 243 PretendPasswordWaiting(); |
243 | 244 |
244 EXPECT_EQ(model()->dismissal_reason(), | 245 EXPECT_EQ(model()->dismissal_reason(), |
245 password_manager::metrics_util::NO_DIRECT_INTERACTION); | 246 password_manager::metrics_util::NO_DIRECT_INTERACTION); |
246 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, model()->state()); | 247 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, model()->state()); |
247 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 248 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
248 base::Time now = base::Time::Now(); | 249 base::Time now = base::Time::Now(); |
249 clock->SetNow(now); | 250 clock->SetNow(now); |
250 model()->set_clock(std::move(clock)); | 251 model()->set_clock(std::move(clock)); |
251 password_manager::InteractionsStats stats = GetTestStats(); | 252 password_manager::InteractionsStats stats = GetTestStats(); |
252 stats.dismissal_count++; | 253 stats.dismissal_count++; |
253 stats.update_time = now; | 254 stats.update_time = now; |
254 EXPECT_CALL(*GetStore(), AddSiteStatsImpl(stats)); | 255 EXPECT_CALL(*GetStore(), AddSiteStatsImpl(stats)); |
255 EXPECT_CALL(*controller(), SavePassword()).Times(0); | 256 EXPECT_CALL(*controller(), SavePassword()).Times(0); |
256 EXPECT_CALL(*controller(), NeverSavePassword()).Times(0); | 257 EXPECT_CALL(*controller(), NeverSavePassword()).Times(0); |
257 DestroyModelExpectReason( | 258 DestroyModelExpectReason( |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 ManageLinkTarget::SETTINGS_PAGE}, | 486 ManageLinkTarget::SETTINGS_PAGE}, |
486 {nullptr, SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, | 487 {nullptr, SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, |
487 {"Default", SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, | 488 {"Default", SmartLockStatus::DISABLE, ManageLinkTarget::SETTINGS_PAGE}, |
488 }; | 489 }; |
489 | 490 |
490 } // namespace | 491 } // namespace |
491 | 492 |
492 INSTANTIATE_TEST_CASE_P(Default, | 493 INSTANTIATE_TEST_CASE_P(Default, |
493 ManagePasswordsBubbleModelManageLinkTest, | 494 ManagePasswordsBubbleModelManageLinkTest, |
494 ::testing::ValuesIn(kManageLinkTestCases)); | 495 ::testing::ValuesIn(kManageLinkTestCases)); |
OLD | NEW |