| 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 <vector> | 10 #include <vector> |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 490 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(CredentialManagerDispatcherTest, | 493 TEST_F(CredentialManagerDispatcherTest, |
| 494 CredentialManagerOnRequireUserMediationWithAffiliation) { | 494 CredentialManagerOnRequireUserMediationWithAffiliation) { |
| 495 store_->AddLogin(form_); | 495 store_->AddLogin(form_); |
| 496 store_->AddLogin(cross_origin_form_); | 496 store_->AddLogin(cross_origin_form_); |
| 497 store_->AddLogin(affiliated_form1_); | 497 store_->AddLogin(affiliated_form1_); |
| 498 store_->AddLogin(affiliated_form2_); | 498 store_->AddLogin(affiliated_form2_); |
| 499 | 499 |
| 500 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 500 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 501 store_->SetAffiliatedMatchHelper(make_scoped_ptr(mock_helper)); | 501 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 502 | 502 |
| 503 std::vector<GURL> federations; | 503 std::vector<GURL> federations; |
| 504 std::vector<std::string> affiliated_realms; | 504 std::vector<std::string> affiliated_realms; |
| 505 affiliated_realms.push_back(kTestAndroidRealm1); | 505 affiliated_realms.push_back(kTestAndroidRealm1); |
| 506 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 506 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 507 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 507 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 508 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 508 RunAllPendingTasks(); | 509 RunAllPendingTasks(); |
| 509 | 510 |
| 510 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 511 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 511 EXPECT_EQ(4U, passwords.size()); | 512 EXPECT_EQ(4U, passwords.size()); |
| 512 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 513 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 513 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 514 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 514 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); | 515 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); |
| 515 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); | 516 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); |
| 516 | 517 |
| 517 dispatcher()->OnRequireUserMediation(kRequestId); | 518 dispatcher()->OnRequireUserMediation(kRequestId); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 668 |
| 668 std::vector<GURL> federations; | 669 std::vector<GURL> federations; |
| 669 federations.push_back(GURL("https://not-example.com/")); | 670 federations.push_back(GURL("https://not-example.com/")); |
| 670 | 671 |
| 671 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); | 672 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); |
| 672 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 673 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 673 | 674 |
| 674 ExpectZeroClickSignInFailure(); | 675 ExpectZeroClickSignInFailure(); |
| 675 } | 676 } |
| 676 | 677 |
| 678 TEST_F(CredentialManagerDispatcherTest, |
| 679 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { |
| 680 store_->AddLogin(affiliated_form1_); |
| 681 client_->set_first_run_seen(true); |
| 682 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 683 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 684 |
| 685 std::vector<GURL> federations; |
| 686 std::vector<std::string> affiliated_realms; |
| 687 affiliated_realms.push_back(kTestAndroidRealm1); |
| 688 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 689 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 690 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 691 |
| 692 // We pass in 'true' for the 'include_passwords' argument to ensure that |
| 693 // password-type credentials are included as potential matches. |
| 694 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 695 |
| 696 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 697 } |
| 698 |
| 699 TEST_F(CredentialManagerDispatcherTest, |
| 700 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { |
| 701 store_->AddLogin(affiliated_form1_); |
| 702 client_->set_first_run_seen(true); |
| 703 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 704 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 705 |
| 706 std::vector<GURL> federations; |
| 707 std::vector<std::string> affiliated_realms; |
| 708 affiliated_realms.push_back(kTestAndroidRealm1); |
| 709 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 710 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 711 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 712 |
| 713 // We pass in 'false' for the 'include_passwords' argument to ensure that |
| 714 // password-type credentials are excluded as potential matches. |
| 715 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); |
| 716 |
| 717 ExpectZeroClickSignInFailure(); |
| 718 } |
| 719 |
| 720 TEST_F(CredentialManagerDispatcherTest, |
| 721 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { |
| 722 affiliated_form1_.federation_url = GURL("https://example.com/"); |
| 723 store_->AddLogin(affiliated_form1_); |
| 724 client_->set_first_run_seen(true); |
| 725 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 726 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 727 |
| 728 std::vector<GURL> federations; |
| 729 federations.push_back(GURL("https://example.com/")); |
| 730 |
| 731 std::vector<std::string> affiliated_realms; |
| 732 affiliated_realms.push_back(kTestAndroidRealm1); |
| 733 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 734 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 735 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 736 |
| 737 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 738 |
| 739 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 740 } |
| 741 |
| 742 TEST_F(CredentialManagerDispatcherTest, |
| 743 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { |
| 744 affiliated_form1_.federation_url = GURL("https://example.com/"); |
| 745 store_->AddLogin(affiliated_form1_); |
| 746 client_->set_first_run_seen(true); |
| 747 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 748 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 749 |
| 750 std::vector<GURL> federations; |
| 751 federations.push_back(GURL("https://not-example.com/")); |
| 752 |
| 753 std::vector<std::string> affiliated_realms; |
| 754 affiliated_realms.push_back(kTestAndroidRealm1); |
| 755 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 756 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 757 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 758 |
| 759 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 760 |
| 761 ExpectZeroClickSignInFailure(); |
| 762 } |
| 763 |
| 677 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { | 764 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { |
| 678 client_->set_first_run_seen(false); | 765 client_->set_first_run_seen(false); |
| 679 | 766 |
| 680 store_->AddLogin(form_); | 767 store_->AddLogin(form_); |
| 681 | 768 |
| 682 std::vector<GURL> federations; | 769 std::vector<GURL> federations; |
| 683 EXPECT_CALL(*client_, | 770 EXPECT_CALL(*client_, |
| 684 NotifyUserAutoSigninBlockedOnFirstRunPtr(testing::Pointee(form_))) | 771 NotifyUserAutoSigninBlockedOnFirstRunPtr(testing::Pointee(form_))) |
| 685 .Times(1); | 772 .Times(1); |
| 686 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 773 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type); | 1012 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type); |
| 926 } | 1013 } |
| 927 | 1014 |
| 928 TEST_F(CredentialManagerDispatcherTest, | 1015 TEST_F(CredentialManagerDispatcherTest, |
| 929 ZeroClickWithAffiliatedFormInPasswordStore) { | 1016 ZeroClickWithAffiliatedFormInPasswordStore) { |
| 930 // Insert the affiliated form into the store, and mock out the association | 1017 // Insert the affiliated form into the store, and mock out the association |
| 931 // with the current origin. As it's the only form matching the origin, it | 1018 // with the current origin. As it's the only form matching the origin, it |
| 932 // ought to be returned automagically. | 1019 // ought to be returned automagically. |
| 933 store_->AddLogin(affiliated_form1_); | 1020 store_->AddLogin(affiliated_form1_); |
| 934 | 1021 |
| 935 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 1022 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 936 store_->SetAffiliatedMatchHelper(make_scoped_ptr(mock_helper)); | 1023 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 937 | 1024 |
| 938 std::vector<GURL> federations; | 1025 std::vector<GURL> federations; |
| 939 std::vector<std::string> affiliated_realms; | 1026 std::vector<std::string> affiliated_realms; |
| 940 affiliated_realms.push_back(kTestAndroidRealm1); | 1027 affiliated_realms.push_back(kTestAndroidRealm1); |
| 941 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 1028 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 942 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1029 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1030 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 943 | 1031 |
| 944 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1032 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 945 | 1033 |
| 946 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 1034 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 947 } | 1035 } |
| 948 | 1036 |
| 949 TEST_F(CredentialManagerDispatcherTest, | 1037 TEST_F(CredentialManagerDispatcherTest, |
| 950 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { | 1038 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { |
| 951 // Insert two affiliated forms into the store, and mock out the association | 1039 // Insert two affiliated forms into the store, and mock out the association |
| 952 // with the current origin. Multiple forms === no zero-click sign in. | 1040 // with the current origin. Multiple forms === no zero-click sign in. |
| 953 store_->AddLogin(affiliated_form1_); | 1041 store_->AddLogin(affiliated_form1_); |
| 954 store_->AddLogin(affiliated_form2_); | 1042 store_->AddLogin(affiliated_form2_); |
| 955 | 1043 |
| 956 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 1044 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 957 store_->SetAffiliatedMatchHelper(make_scoped_ptr(mock_helper)); | 1045 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 958 | 1046 |
| 959 std::vector<GURL> federations; | 1047 std::vector<GURL> federations; |
| 960 std::vector<std::string> affiliated_realms; | 1048 std::vector<std::string> affiliated_realms; |
| 961 affiliated_realms.push_back(kTestAndroidRealm1); | 1049 affiliated_realms.push_back(kTestAndroidRealm1); |
| 962 affiliated_realms.push_back(kTestAndroidRealm2); | 1050 affiliated_realms.push_back(kTestAndroidRealm2); |
| 963 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 1051 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 964 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1052 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1053 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 965 | 1054 |
| 966 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1055 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 967 | 1056 |
| 968 ExpectZeroClickSignInFailure(); | 1057 ExpectZeroClickSignInFailure(); |
| 969 } | 1058 } |
| 970 | 1059 |
| 971 TEST_F(CredentialManagerDispatcherTest, | 1060 TEST_F(CredentialManagerDispatcherTest, |
| 972 ZeroClickWithUnaffiliatedFormsInPasswordStore) { | 1061 ZeroClickWithUnaffiliatedFormsInPasswordStore) { |
| 973 // Insert the affiliated form into the store, but don't mock out the | 1062 // Insert the affiliated form into the store, but don't mock out the |
| 974 // association with the current origin. No association === no zero-click sign | 1063 // association with the current origin. No association === no zero-click sign |
| 975 // in. | 1064 // in. |
| 976 store_->AddLogin(affiliated_form1_); | 1065 store_->AddLogin(affiliated_form1_); |
| 977 | 1066 |
| 978 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 1067 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 979 store_->SetAffiliatedMatchHelper(make_scoped_ptr(mock_helper)); | 1068 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 980 | 1069 |
| 981 std::vector<GURL> federations; | 1070 std::vector<GURL> federations; |
| 982 std::vector<std::string> affiliated_realms; | 1071 std::vector<std::string> affiliated_realms; |
| 983 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 1072 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 984 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1073 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1074 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 985 | 1075 |
| 986 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1076 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 987 | 1077 |
| 988 ExpectZeroClickSignInFailure(); | 1078 ExpectZeroClickSignInFailure(); |
| 989 } | 1079 } |
| 990 | 1080 |
| 991 TEST_F(CredentialManagerDispatcherTest, | 1081 TEST_F(CredentialManagerDispatcherTest, |
| 992 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { | 1082 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { |
| 993 // Insert the affiliated form into the store, along with a real form for the | 1083 // Insert the affiliated form into the store, along with a real form for the |
| 994 // origin, and don't mock out the association with the current origin. No | 1084 // origin, and don't mock out the association with the current origin. No |
| 995 // association + existing form === zero-click sign in. | 1085 // association + existing form === zero-click sign in. |
| 996 store_->AddLogin(form_); | 1086 store_->AddLogin(form_); |
| 997 store_->AddLogin(affiliated_form1_); | 1087 store_->AddLogin(affiliated_form1_); |
| 998 | 1088 |
| 999 MockAffiliatedMatchHelper* mock_helper = new MockAffiliatedMatchHelper; | 1089 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); |
| 1000 store_->SetAffiliatedMatchHelper(make_scoped_ptr(mock_helper)); | 1090 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1001 | 1091 |
| 1002 std::vector<GURL> federations; | 1092 std::vector<GURL> federations; |
| 1003 std::vector<std::string> affiliated_realms; | 1093 std::vector<std::string> affiliated_realms; |
| 1004 mock_helper->ExpectCallToGetAffiliatedAndroidRealms( | 1094 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1005 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1095 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1096 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1006 | 1097 |
| 1007 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1098 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 1008 | 1099 |
| 1009 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 1100 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 1010 } | 1101 } |
| 1011 | 1102 |
| 1012 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 1103 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { |
| 1013 autofill::PasswordForm synthesized = | 1104 autofill::PasswordForm synthesized = |
| 1014 dispatcher_->GetSynthesizedFormForOrigin(); | 1105 dispatcher_->GetSynthesizedFormForOrigin(); |
| 1015 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 1106 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
| 1016 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 1107 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
| 1017 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 1108 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
| 1018 EXPECT_TRUE(synthesized.ssl_valid); | 1109 EXPECT_TRUE(synthesized.ssl_valid); |
| 1019 } | 1110 } |
| 1020 | 1111 |
| 1021 } // namespace password_manager | 1112 } // namespace password_manager |
| OLD | NEW |