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 <map> | 5 #include <map> |
6 #include <memory> | 6 #include <memory> |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 17 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
18 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" | 18 #include "chrome/browser/ui/passwords/manage_passwords_icon_view.h" |
19 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" | 19 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" |
20 #include "chrome/browser/ui/passwords/password_dialog_controller.h" | 20 #include "chrome/browser/ui/passwords/password_dialog_controller.h" |
21 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" | 21 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" |
22 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 22 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "components/autofill/core/common/password_form.h" | 25 #include "components/autofill/core/common/password_form.h" |
| 26 #include "components/password_manager/core/browser/fake_form_fetcher.h" |
26 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
27 #include "components/password_manager/core/browser/password_form_manager.h" | 28 #include "components/password_manager/core/browser/password_form_manager.h" |
28 #include "components/password_manager/core/browser/password_manager.h" | 29 #include "components/password_manager/core/browser/password_manager.h" |
29 #include "components/password_manager/core/browser/statistics_table.h" | 30 #include "components/password_manager/core/browser/statistics_table.h" |
30 #include "components/password_manager/core/browser/stub_form_saver.h" | 31 #include "components/password_manager/core/browser/stub_form_saver.h" |
31 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 32 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
32 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 33 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
33 #include "components/password_manager/core/common/password_manager_ui.h" | 34 #include "components/password_manager/core/common/password_manager_ui.h" |
34 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
35 #include "components/variations/variations_associated_data.h" | 36 #include "components/variations/variations_associated_data.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 variations::AssociateVariationParams(kSmartBubbleExperimentName, "A", params); | 154 variations::AssociateVariationParams(kSmartBubbleExperimentName, "A", params); |
154 ASSERT_TRUE( | 155 ASSERT_TRUE( |
155 base::FieldTrialList::CreateFieldTrial(kSmartBubbleExperimentName, "A")); | 156 base::FieldTrialList::CreateFieldTrial(kSmartBubbleExperimentName, "A")); |
156 } | 157 } |
157 | 158 |
158 } // namespace | 159 } // namespace |
159 | 160 |
160 class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness { | 161 class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness { |
161 public: | 162 public: |
162 ManagePasswordsUIControllerTest() | 163 ManagePasswordsUIControllerTest() |
163 : password_manager_(&client_), field_trial_list_(nullptr) {} | 164 : password_manager_(&client_), field_trial_list_(nullptr) { |
| 165 fetcher_.Fetch(); |
| 166 } |
164 | 167 |
165 void SetUp() override; | 168 void SetUp() override; |
166 | 169 |
| 170 password_manager::FakeFormFetcher& fetcher() { return fetcher_; } |
167 autofill::PasswordForm& test_local_form() { return test_local_form_; } | 171 autofill::PasswordForm& test_local_form() { return test_local_form_; } |
168 autofill::PasswordForm& test_federated_form() { return test_federated_form_; } | 172 autofill::PasswordForm& test_federated_form() { return test_federated_form_; } |
169 DialogPromptMock& dialog_prompt() { return dialog_prompt_; } | 173 DialogPromptMock& dialog_prompt() { return dialog_prompt_; } |
170 | 174 |
171 TestManagePasswordsUIController* controller() { | 175 TestManagePasswordsUIController* controller() { |
172 return static_cast<TestManagePasswordsUIController*>( | 176 return static_cast<TestManagePasswordsUIController*>( |
173 ManagePasswordsUIController::FromWebContents(web_contents())); | 177 ManagePasswordsUIController::FromWebContents(web_contents())); |
174 } | 178 } |
175 | 179 |
176 void ExpectIconStateIs(password_manager::ui::State state); | 180 void ExpectIconStateIs(password_manager::ui::State state); |
177 void ExpectIconAndControllerStateIs(password_manager::ui::State state); | 181 void ExpectIconAndControllerStateIs(password_manager::ui::State state); |
178 | 182 |
179 std::unique_ptr<password_manager::PasswordFormManager> | 183 std::unique_ptr<password_manager::PasswordFormManager> |
180 CreateFormManagerWithBestMatches( | 184 CreateFormManagerWithBestMatches( |
181 const autofill::PasswordForm& observed_form, | 185 const autofill::PasswordForm& observed_form, |
182 std::vector<std::unique_ptr<autofill::PasswordForm>> best_matches); | 186 const std::vector<const autofill::PasswordForm*>& best_matches); |
183 | 187 |
184 std::unique_ptr<password_manager::PasswordFormManager> CreateFormManager(); | 188 std::unique_ptr<password_manager::PasswordFormManager> CreateFormManager(); |
185 | 189 |
186 // Tests that the state is not changed when the password is autofilled. | 190 // Tests that the state is not changed when the password is autofilled. |
187 void TestNotChangingStateOnAutofill( | 191 void TestNotChangingStateOnAutofill( |
188 password_manager::ui::State state); | 192 password_manager::ui::State state); |
189 | 193 |
190 MOCK_METHOD1(CredentialCallback, void(const autofill::PasswordForm*)); | 194 MOCK_METHOD1(CredentialCallback, void(const autofill::PasswordForm*)); |
191 | 195 |
192 private: | 196 private: |
193 password_manager::StubPasswordManagerClient client_; | 197 password_manager::StubPasswordManagerClient client_; |
194 password_manager::StubPasswordManagerDriver driver_; | 198 password_manager::StubPasswordManagerDriver driver_; |
195 password_manager::PasswordManager password_manager_; | 199 password_manager::PasswordManager password_manager_; |
| 200 password_manager::FakeFormFetcher fetcher_; |
196 | 201 |
197 autofill::PasswordForm test_local_form_; | 202 autofill::PasswordForm test_local_form_; |
198 autofill::PasswordForm test_federated_form_; | 203 autofill::PasswordForm test_federated_form_; |
199 base::FieldTrialList field_trial_list_; | 204 base::FieldTrialList field_trial_list_; |
200 DialogPromptMock dialog_prompt_; | 205 DialogPromptMock dialog_prompt_; |
201 }; | 206 }; |
202 | 207 |
203 void ManagePasswordsUIControllerTest::SetUp() { | 208 void ManagePasswordsUIControllerTest::SetUp() { |
204 ChromeRenderViewHostTestHarness::SetUp(); | 209 ChromeRenderViewHostTestHarness::SetUp(); |
205 | 210 |
(...skipping 26 matching lines...) Expand all Loading... |
232 | 237 |
233 void ManagePasswordsUIControllerTest::ExpectIconAndControllerStateIs( | 238 void ManagePasswordsUIControllerTest::ExpectIconAndControllerStateIs( |
234 password_manager::ui::State state) { | 239 password_manager::ui::State state) { |
235 ExpectIconStateIs(state); | 240 ExpectIconStateIs(state); |
236 EXPECT_EQ(state, controller()->GetState()); | 241 EXPECT_EQ(state, controller()->GetState()); |
237 } | 242 } |
238 | 243 |
239 std::unique_ptr<password_manager::PasswordFormManager> | 244 std::unique_ptr<password_manager::PasswordFormManager> |
240 ManagePasswordsUIControllerTest::CreateFormManagerWithBestMatches( | 245 ManagePasswordsUIControllerTest::CreateFormManagerWithBestMatches( |
241 const autofill::PasswordForm& observed_form, | 246 const autofill::PasswordForm& observed_form, |
242 std::vector<std::unique_ptr<autofill::PasswordForm>> best_matches) { | 247 const std::vector<const autofill::PasswordForm*>& best_matches) { |
243 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 248 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
244 new password_manager::PasswordFormManager( | 249 new password_manager::PasswordFormManager( |
245 &password_manager_, &client_, driver_.AsWeakPtr(), observed_form, | 250 &password_manager_, &client_, driver_.AsWeakPtr(), observed_form, |
246 base::WrapUnique(new password_manager::StubFormSaver))); | 251 base::WrapUnique(new password_manager::StubFormSaver), &fetcher_)); |
247 test_form_manager->OnGetPasswordStoreResults(std::move(best_matches)); | 252 fetcher_.SetNonFederated(best_matches, 0u); |
248 return test_form_manager; | 253 return test_form_manager; |
249 } | 254 } |
250 | 255 |
251 std::unique_ptr<password_manager::PasswordFormManager> | 256 std::unique_ptr<password_manager::PasswordFormManager> |
252 ManagePasswordsUIControllerTest::CreateFormManager() { | 257 ManagePasswordsUIControllerTest::CreateFormManager() { |
253 std::vector<std::unique_ptr<autofill::PasswordForm>> stored_forms; | |
254 stored_forms.push_back( | |
255 base::MakeUnique<autofill::PasswordForm>(test_local_form())); | |
256 return CreateFormManagerWithBestMatches(test_local_form(), | 258 return CreateFormManagerWithBestMatches(test_local_form(), |
257 std::move(stored_forms)); | 259 {&test_local_form()}); |
258 } | 260 } |
259 | 261 |
260 void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill( | 262 void ManagePasswordsUIControllerTest::TestNotChangingStateOnAutofill( |
261 password_manager::ui::State state) { | 263 password_manager::ui::State state) { |
262 DCHECK(state == password_manager::ui::PENDING_PASSWORD_STATE || | 264 DCHECK(state == password_manager::ui::PENDING_PASSWORD_STATE || |
263 state == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE || | 265 state == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE || |
264 state == password_manager::ui::CONFIRMATION_STATE); | 266 state == password_manager::ui::CONFIRMATION_STATE); |
265 | 267 |
266 // Set the bubble state to |state|. | 268 // Set the bubble state to |state|. |
267 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 269 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_EQ(test_local_form().origin, controller()->GetOrigin()); | 331 EXPECT_EQ(test_local_form().origin, controller()->GetOrigin()); |
330 | 332 |
331 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); | 333 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); |
332 } | 334 } |
333 | 335 |
334 TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) { | 336 TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) { |
335 autofill::PasswordForm blacklisted; | 337 autofill::PasswordForm blacklisted; |
336 blacklisted.origin = test_local_form().origin; | 338 blacklisted.origin = test_local_form().origin; |
337 blacklisted.signon_realm = blacklisted.origin.spec(); | 339 blacklisted.signon_realm = blacklisted.origin.spec(); |
338 blacklisted.blacklisted_by_user = true; | 340 blacklisted.blacklisted_by_user = true; |
339 std::vector<std::unique_ptr<autofill::PasswordForm>> stored_forms; | |
340 stored_forms.push_back(base::MakeUnique<autofill::PasswordForm>(blacklisted)); | |
341 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager = | 341 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager = |
342 CreateFormManagerWithBestMatches(test_local_form(), | 342 CreateFormManagerWithBestMatches(test_local_form(), {&blacklisted}); |
343 std::move(stored_forms)); | |
344 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 343 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
345 controller()->OnPasswordSubmitted(std::move(test_form_manager)); | 344 controller()->OnPasswordSubmitted(std::move(test_form_manager)); |
346 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | 345 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, |
347 controller()->GetState()); | 346 controller()->GetState()); |
348 EXPECT_FALSE(controller()->opened_bubble()); | 347 EXPECT_FALSE(controller()->opened_bubble()); |
349 | 348 |
350 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); | 349 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); |
351 } | 350 } |
352 | 351 |
353 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) { | 352 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleSuppressed) { |
354 CreateSmartBubbleFieldTrial(); | 353 CreateSmartBubbleFieldTrial(); |
355 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 354 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
356 CreateFormManager()); | 355 CreateFormManager()); |
357 password_manager::InteractionsStats stats; | 356 password_manager::InteractionsStats stats; |
358 stats.origin_domain = test_local_form().origin.GetOrigin(); | 357 stats.origin_domain = test_local_form().origin.GetOrigin(); |
359 stats.username_value = test_local_form().username_value; | 358 stats.username_value = test_local_form().username_value; |
360 stats.dismissal_count = kGreatDissmisalCount; | 359 stats.dismissal_count = kGreatDissmisalCount; |
361 std::vector<std::unique_ptr<password_manager::InteractionsStats>> | 360 fetcher().set_stats({&stats}); |
362 interactions; | |
363 interactions.push_back( | |
364 base::MakeUnique<password_manager::InteractionsStats>(stats)); | |
365 test_form_manager->OnGetSiteStatistics(std::move(interactions)); | |
366 test_form_manager->ProvisionallySave( | 361 test_form_manager->ProvisionallySave( |
367 test_local_form(), | 362 test_local_form(), |
368 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 363 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
369 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 364 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
370 controller()->OnPasswordSubmitted(std::move(test_form_manager)); | 365 controller()->OnPasswordSubmitted(std::move(test_form_manager)); |
371 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | 366 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, |
372 controller()->GetState()); | 367 controller()->GetState()); |
373 EXPECT_FALSE(controller()->opened_bubble()); | 368 EXPECT_FALSE(controller()->opened_bubble()); |
374 ASSERT_TRUE(controller()->GetCurrentInteractionStats()); | 369 ASSERT_TRUE(controller()->GetCurrentInteractionStats()); |
375 EXPECT_EQ(stats, *controller()->GetCurrentInteractionStats()); | 370 EXPECT_EQ(stats, *controller()->GetCurrentInteractionStats()); |
376 | 371 |
377 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); | 372 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); |
378 variations::testing::ClearAllVariationParams(); | 373 variations::testing::ClearAllVariationParams(); |
379 } | 374 } |
380 | 375 |
381 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleNotSuppressed) { | 376 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedBubbleNotSuppressed) { |
382 CreateSmartBubbleFieldTrial(); | 377 CreateSmartBubbleFieldTrial(); |
383 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 378 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
384 CreateFormManager()); | 379 CreateFormManager()); |
385 password_manager::InteractionsStats stats; | 380 password_manager::InteractionsStats stats; |
386 stats.origin_domain = test_local_form().origin.GetOrigin(); | 381 stats.origin_domain = test_local_form().origin.GetOrigin(); |
387 stats.username_value = base::ASCIIToUTF16("not my username"); | 382 stats.username_value = base::ASCIIToUTF16("not my username"); |
388 stats.dismissal_count = kGreatDissmisalCount; | 383 stats.dismissal_count = kGreatDissmisalCount; |
389 std::vector<std::unique_ptr<password_manager::InteractionsStats>> | 384 fetcher().set_stats({&stats}); |
390 interactions; | |
391 interactions.push_back( | |
392 base::MakeUnique<password_manager::InteractionsStats>(stats)); | |
393 test_form_manager->OnGetSiteStatistics(std::move(interactions)); | |
394 test_form_manager->ProvisionallySave( | 385 test_form_manager->ProvisionallySave( |
395 test_local_form(), | 386 test_local_form(), |
396 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 387 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
397 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 388 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
398 controller()->OnPasswordSubmitted(std::move(test_form_manager)); | 389 controller()->OnPasswordSubmitted(std::move(test_form_manager)); |
399 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | 390 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, |
400 controller()->GetState()); | 391 controller()->GetState()); |
401 EXPECT_TRUE(controller()->opened_bubble()); | 392 EXPECT_TRUE(controller()->opened_bubble()); |
402 EXPECT_FALSE(controller()->GetCurrentInteractionStats()); | 393 EXPECT_FALSE(controller()->GetCurrentInteractionStats()); |
403 | 394 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // Open the bubble again. | 792 // Open the bubble again. |
802 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 793 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
803 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 794 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
804 controller()->OnAutoSignin(std::move(local_credentials), | 795 controller()->OnAutoSignin(std::move(local_credentials), |
805 test_local_form().origin); | 796 test_local_form().origin); |
806 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); | 797 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); |
807 // Check the delegate is destroyed. Thus, the first bubble has no way to mess | 798 // Check the delegate is destroyed. Thus, the first bubble has no way to mess |
808 // up with the controller's state. | 799 // up with the controller's state. |
809 EXPECT_FALSE(proxy_delegate); | 800 EXPECT_FALSE(proxy_delegate); |
810 } | 801 } |
OLD | NEW |