| 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 "components/password_manager/content/browser/credential_manager_dispatc
her.h" | 5 #include "components/password_manager/content/browser/credential_manager_dispatc
her.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 class MockPasswordManagerClient : public StubPasswordManagerClient { | 54 class MockPasswordManagerClient : public StubPasswordManagerClient { |
| 55 public: | 55 public: |
| 56 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); | 56 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); |
| 57 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 57 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 58 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 58 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 59 MOCK_METHOD1(NotifyUserAutoSigninPtr, | 59 MOCK_METHOD1(NotifyUserAutoSigninPtr, |
| 60 bool(const std::vector<autofill::PasswordForm*>& local_forms)); | 60 bool(const std::vector<autofill::PasswordForm*>& local_forms)); |
| 61 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, | 61 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, |
| 62 bool(autofill::PasswordForm* form)); | 62 bool(autofill::PasswordForm* form)); |
| 63 MOCK_METHOD0(NotifyStorePasswordCalled, void()); |
| 63 MOCK_METHOD2(PromptUserToSavePasswordPtr, | 64 MOCK_METHOD2(PromptUserToSavePasswordPtr, |
| 64 void(PasswordFormManager*, CredentialSourceType type)); | 65 void(PasswordFormManager*, CredentialSourceType type)); |
| 65 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, | 66 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, |
| 66 bool(const std::vector<autofill::PasswordForm*>& local_forms, | 67 bool(const std::vector<autofill::PasswordForm*>& local_forms, |
| 67 const std::vector<autofill::PasswordForm*>& federated_forms, | 68 const std::vector<autofill::PasswordForm*>& federated_forms, |
| 68 const GURL& origin, | 69 const GURL& origin, |
| 69 const CredentialsCallback& callback)); | 70 const CredentialsCallback& callback)); |
| 70 | 71 |
| 71 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { | 72 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { |
| 72 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, | 73 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 client_->set_zero_click_enabled(false); | 333 client_->set_zero_click_enabled(false); |
| 333 client_->set_first_run_seen(false); | 334 client_->set_first_run_seen(false); |
| 334 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); | 335 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); |
| 335 } | 336 } |
| 336 | 337 |
| 337 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { | 338 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { |
| 338 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 339 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 339 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 340 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 340 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 341 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 341 .Times(testing::Exactly(1)); | 342 .Times(testing::Exactly(1)); |
| 343 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 342 | 344 |
| 343 dispatcher()->OnStore(kRequestId, info); | 345 dispatcher()->OnStore(kRequestId, info); |
| 344 | 346 |
| 345 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | 347 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; |
| 346 const IPC::Message* message = | 348 const IPC::Message* message = |
| 347 process()->sink().GetFirstMessageMatching(kMsgID); | 349 process()->sink().GetFirstMessageMatching(kMsgID); |
| 348 EXPECT_TRUE(message); | 350 EXPECT_TRUE(message); |
| 349 process()->sink().ClearMessages(); | 351 process()->sink().ClearMessages(); |
| 350 | 352 |
| 351 // Allow the PasswordFormManager to talk to the password store, determine | 353 // Allow the PasswordFormManager to talk to the password store, determine |
| (...skipping 14 matching lines...) Expand all Loading... |
| 366 | 368 |
| 367 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) { | 369 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) { |
| 368 // Populate the PasswordStore with a form. | 370 // Populate the PasswordStore with a form. |
| 369 store_->AddLogin(form_); | 371 store_->AddLogin(form_); |
| 370 RunAllPendingTasks(); | 372 RunAllPendingTasks(); |
| 371 | 373 |
| 372 // Calling 'OnStore' with a credential that matches |form_| should update | 374 // Calling 'OnStore' with a credential that matches |form_| should update |
| 373 // the password without prompting the user. | 375 // the password without prompting the user. |
| 374 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 376 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 375 info.password = base::ASCIIToUTF16("Totally new password."); | 377 info.password = base::ASCIIToUTF16("Totally new password."); |
| 378 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); |
| 379 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 376 dispatcher()->OnStore(kRequestId, info); | 380 dispatcher()->OnStore(kRequestId, info); |
| 377 | 381 |
| 378 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | |
| 379 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | |
| 380 .Times(testing::Exactly(0)); | |
| 381 | |
| 382 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | 382 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; |
| 383 const IPC::Message* message = | 383 const IPC::Message* message = |
| 384 process()->sink().GetFirstMessageMatching(kMsgID); | 384 process()->sink().GetFirstMessageMatching(kMsgID); |
| 385 EXPECT_TRUE(message); | 385 EXPECT_TRUE(message); |
| 386 process()->sink().ClearMessages(); | 386 process()->sink().ClearMessages(); |
| 387 | 387 |
| 388 // Allow the PasswordFormManager to talk to the password store, determine | 388 // Allow the PasswordFormManager to talk to the password store, determine |
| 389 // the form is a match for an existing form, and update the PasswordStore. | 389 // the form is a match for an existing form, and update the PasswordStore. |
| 390 RunAllPendingTasks(); | 390 RunAllPendingTasks(); |
| 391 | 391 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 402 // form that's set to skip zero click. | 402 // form that's set to skip zero click. |
| 403 client_->set_zero_click_enabled(true); | 403 client_->set_zero_click_enabled(true); |
| 404 client_->set_first_run_seen(true); | 404 client_->set_first_run_seen(true); |
| 405 form_.skip_zero_click = true; | 405 form_.skip_zero_click = true; |
| 406 store_->AddLogin(form_); | 406 store_->AddLogin(form_); |
| 407 RunAllPendingTasks(); | 407 RunAllPendingTasks(); |
| 408 | 408 |
| 409 // Calling 'OnStore' with a credential that matches |form_| should update | 409 // Calling 'OnStore' with a credential that matches |form_| should update |
| 410 // the credential without prompting the user. | 410 // the credential without prompting the user. |
| 411 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 411 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 412 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 412 dispatcher()->OnStore(kRequestId, info); | 413 dispatcher()->OnStore(kRequestId, info); |
| 413 process()->sink().ClearMessages(); | 414 process()->sink().ClearMessages(); |
| 414 | 415 |
| 415 // Allow the PasswordFormManager to talk to the password store, determine | 416 // Allow the PasswordFormManager to talk to the password store, determine |
| 416 // the form is a match for an existing form, and update the PasswordStore. | 417 // the form is a match for an existing form, and update the PasswordStore. |
| 417 RunAllPendingTasks(); | 418 RunAllPendingTasks(); |
| 418 | 419 |
| 419 // Verify that the update toggled the skip_zero_click flag off. | 420 // Verify that the update toggled the skip_zero_click flag off. |
| 420 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 421 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 421 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 422 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 422 } | 423 } |
| 423 | 424 |
| 424 TEST_F(CredentialManagerDispatcherTest, | 425 TEST_F(CredentialManagerDispatcherTest, |
| 425 CredentialManagerFederatedStoreOverwriteZeroClick) { | 426 CredentialManagerFederatedStoreOverwriteZeroClick) { |
| 426 // Set the global zero click flag on, and populate the PasswordStore with a | 427 // Set the global zero click flag on, and populate the PasswordStore with a |
| 427 // form that's set to skip zero click. | 428 // form that's set to skip zero click. |
| 428 client_->set_zero_click_enabled(true); | 429 client_->set_zero_click_enabled(true); |
| 429 client_->set_first_run_seen(true); | 430 client_->set_first_run_seen(true); |
| 430 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 431 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 431 form_.skip_zero_click = true; | 432 form_.skip_zero_click = true; |
| 432 form_.signon_realm = "federation://example.com/example.com"; | 433 form_.signon_realm = "federation://example.com/example.com"; |
| 433 store_->AddLogin(form_); | 434 store_->AddLogin(form_); |
| 434 RunAllPendingTasks(); | 435 RunAllPendingTasks(); |
| 435 | 436 |
| 436 // Calling 'OnStore' with a credential that matches |form_| should update | 437 // Calling 'OnStore' with a credential that matches |form_| should update |
| 437 // the credential without prompting the user. | 438 // the credential without prompting the user. |
| 438 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); | 439 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 440 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 439 dispatcher()->OnStore(kRequestId, info); | 441 dispatcher()->OnStore(kRequestId, info); |
| 440 process()->sink().ClearMessages(); | 442 process()->sink().ClearMessages(); |
| 441 | 443 |
| 442 // Allow the PasswordFormManager to talk to the password store, determine | 444 // Allow the PasswordFormManager to talk to the password store, determine |
| 443 // the form is a match for an existing form, and update the PasswordStore. | 445 // the form is a match for an existing form, and update the PasswordStore. |
| 444 RunAllPendingTasks(); | 446 RunAllPendingTasks(); |
| 445 | 447 |
| 446 // Verify that the update toggled the skip_zero_click flag off. | 448 // Verify that the update toggled the skip_zero_click flag off. |
| 447 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 449 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 448 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 450 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 484 } |
| 483 | 485 |
| 484 TEST_F(CredentialManagerDispatcherTest, | 486 TEST_F(CredentialManagerDispatcherTest, |
| 485 CredentialManagerSignInWithSavingDisabledForCurrentPage) { | 487 CredentialManagerSignInWithSavingDisabledForCurrentPage) { |
| 486 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 488 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 487 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 489 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 488 .WillRepeatedly(testing::Return(false)); | 490 .WillRepeatedly(testing::Return(false)); |
| 489 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 491 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 490 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 492 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 491 .Times(testing::Exactly(0)); | 493 .Times(testing::Exactly(0)); |
| 494 EXPECT_CALL(*client_, NotifyStorePasswordCalled()).Times(0); |
| 492 | 495 |
| 493 dispatcher()->OnStore(kRequestId, info); | 496 dispatcher()->OnStore(kRequestId, info); |
| 494 | 497 |
| 495 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | 498 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; |
| 496 const IPC::Message* message = | 499 const IPC::Message* message = |
| 497 process()->sink().GetFirstMessageMatching(kMsgID); | 500 process()->sink().GetFirstMessageMatching(kMsgID); |
| 498 EXPECT_TRUE(message); | 501 EXPECT_TRUE(message); |
| 499 process()->sink().ClearMessages(); | 502 process()->sink().ClearMessages(); |
| 500 | 503 |
| 501 RunAllPendingTasks(); | 504 RunAllPendingTasks(); |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 dispatcher()->OnStore(kRequestId, info); | 1301 dispatcher()->OnStore(kRequestId, info); |
| 1299 process()->sink().ClearMessages(); | 1302 process()->sink().ClearMessages(); |
| 1300 // Allow the PasswordFormManager to talk to the password store | 1303 // Allow the PasswordFormManager to talk to the password store |
| 1301 RunAllPendingTasks(); | 1304 RunAllPendingTasks(); |
| 1302 | 1305 |
| 1303 ASSERT_TRUE(client_->pending_manager()); | 1306 ASSERT_TRUE(client_->pending_manager()); |
| 1304 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1307 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1305 } | 1308 } |
| 1306 | 1309 |
| 1307 } // namespace password_manager | 1310 } // namespace password_manager |
| OLD | NEW |