| 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_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 514 |
| 515 EXPECT_TRUE(called); | 515 EXPECT_TRUE(called); |
| 516 | 516 |
| 517 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 517 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 518 EXPECT_EQ(1U, passwords.size()); | 518 EXPECT_EQ(1U, passwords.size()); |
| 519 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 519 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 520 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), | 520 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), |
| 521 passwords[form_.signon_realm][0].password_value); | 521 passwords[form_.signon_realm][0].password_value); |
| 522 } | 522 } |
| 523 | 523 |
| 524 TEST_F(CredentialManagerImplTest, |
| 525 CredentialManagerStorePSLMatchDoesNotTriggerBubble) { |
| 526 autofill::PasswordForm psl_form = subdomain_form_; |
| 527 psl_form.username_value = form_.username_value; |
| 528 psl_form.password_value = form_.password_value; |
| 529 store_->AddLogin(psl_form); |
| 530 |
| 531 // Calling 'Store' with a new credential that is a PSL match for an existing |
| 532 // credential with identical username and password should result in a silent |
| 533 // save without prompting the user. |
| 534 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 535 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)) |
| 536 .Times(testing::Exactly(0)); |
| 537 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 538 bool called = false; |
| 539 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 540 RunAllPendingTasks(); |
| 541 EXPECT_TRUE(called); |
| 542 |
| 543 // Check that both credentials are present in the password store. |
| 544 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 545 EXPECT_EQ(2U, passwords.size()); |
| 546 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 547 EXPECT_EQ(1U, passwords[psl_form.signon_realm].size()); |
| 548 } |
| 549 |
| 550 TEST_F(CredentialManagerImplTest, |
| 551 CredentialManagerStorePSLMatchWithDifferentUsernameTriggersBubble) { |
| 552 base::string16 delta = base::ASCIIToUTF16("_totally_different"); |
| 553 autofill::PasswordForm psl_form = subdomain_form_; |
| 554 psl_form.username_value = form_.username_value + delta; |
| 555 psl_form.password_value = form_.password_value; |
| 556 store_->AddLogin(psl_form); |
| 557 |
| 558 // Calling 'Store' with a new credential that is a PSL match for an existing |
| 559 // credential but has a different username should prompt the user and not |
| 560 // result in a silent save. |
| 561 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 562 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)) |
| 563 .Times(testing::Exactly(1)); |
| 564 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 565 bool called = false; |
| 566 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 567 RunAllPendingTasks(); |
| 568 EXPECT_TRUE(called); |
| 569 |
| 570 // Check that only the initial credential is present in the password store |
| 571 // and the new one is still pending. |
| 572 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 573 EXPECT_EQ(1U, passwords.size()); |
| 574 EXPECT_EQ(1U, passwords[psl_form.signon_realm].size()); |
| 575 |
| 576 const auto& pending_cred = client_->pending_manager()->pending_credentials(); |
| 577 EXPECT_EQ(info.id, pending_cred.username_value); |
| 578 EXPECT_EQ(info.password, pending_cred.password_value); |
| 579 } |
| 580 |
| 581 TEST_F(CredentialManagerImplTest, |
| 582 CredentialManagerStorePSLMatchWithDifferentPasswordTriggersBubble) { |
| 583 base::string16 delta = base::ASCIIToUTF16("_totally_different"); |
| 584 autofill::PasswordForm psl_form = subdomain_form_; |
| 585 psl_form.username_value = form_.username_value; |
| 586 psl_form.password_value = form_.password_value + delta; |
| 587 store_->AddLogin(psl_form); |
| 588 |
| 589 // Calling 'Store' with a new credential that is a PSL match for an existing |
| 590 // credential but has a different password should prompt the user and not |
| 591 // result in a silent save. |
| 592 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 593 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)) |
| 594 .Times(testing::Exactly(1)); |
| 595 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 596 bool called = false; |
| 597 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 598 RunAllPendingTasks(); |
| 599 EXPECT_TRUE(called); |
| 600 |
| 601 // Check that only the initial credential is present in the password store |
| 602 // and the new one is still pending. |
| 603 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 604 EXPECT_EQ(1U, passwords.size()); |
| 605 EXPECT_EQ(1U, passwords[psl_form.signon_realm].size()); |
| 606 |
| 607 const auto& pending_cred = client_->pending_manager()->pending_credentials(); |
| 608 EXPECT_EQ(info.id, pending_cred.username_value); |
| 609 EXPECT_EQ(info.password, pending_cred.password_value); |
| 610 } |
| 611 |
| 524 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { | 612 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { |
| 525 form_.skip_zero_click = true; | 613 form_.skip_zero_click = true; |
| 526 store_->AddLogin(form_); | 614 store_->AddLogin(form_); |
| 527 RunAllPendingTasks(); | 615 RunAllPendingTasks(); |
| 528 | 616 |
| 529 // Calling 'Store' with a credential that matches |form_| should update | 617 // Calling 'Store' with a credential that matches |form_| should update |
| 530 // the credential without prompting the user. | 618 // the credential without prompting the user. |
| 531 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 619 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 532 bool called = false; | 620 bool called = false; |
| 533 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); | 621 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1547 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1460 CallStore(info, base::Bind(&RespondCallback, &called)); | 1548 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1461 // Allow the PasswordFormManager to talk to the password store | 1549 // Allow the PasswordFormManager to talk to the password store |
| 1462 RunAllPendingTasks(); | 1550 RunAllPendingTasks(); |
| 1463 | 1551 |
| 1464 ASSERT_TRUE(client_->pending_manager()); | 1552 ASSERT_TRUE(client_->pending_manager()); |
| 1465 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1553 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1466 } | 1554 } |
| 1467 | 1555 |
| 1468 } // namespace password_manager | 1556 } // namespace password_manager |
| OLD | NEW |