OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/browser/password_form_manager.h" | 5 #include "components/password_manager/core/browser/password_form_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") { | 114 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") { |
115 return arg && arg->username_value == username_value; | 115 return arg && arg->username_value == username_value; |
116 } | 116 } |
117 | 117 |
118 MATCHER_P2(CheckUploadedAutofillTypesAndSignature, | 118 MATCHER_P2(CheckUploadedAutofillTypesAndSignature, |
119 form_signature, | 119 form_signature, |
120 expected_types, | 120 expected_types, |
121 "Unexpected autofill types or form signature") { | 121 "Unexpected autofill types or form signature") { |
122 if (form_signature != arg.FormSignature()) { | 122 if (form_signature != arg.FormSignatureAsStr()) { |
123 // An unexpected form is uploaded. | 123 // An unexpected form is uploaded. |
124 return false; | 124 return false; |
125 } | 125 } |
126 for (const autofill::AutofillField* field : arg) { | 126 for (const autofill::AutofillField* field : arg) { |
127 if (expected_types.find(field->name) == expected_types.end()) { | 127 if (expected_types.find(field->name) == expected_types.end()) { |
128 if (!field->possible_types().empty()) { | 128 if (!field->possible_types().empty()) { |
129 // Unexpected types are uploaded. | 129 // Unexpected types are uploaded. |
130 return false; | 130 return false; |
131 } | 131 } |
132 } else { | 132 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
149 } | 149 } |
150 } | 150 } |
151 } | 151 } |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 MATCHER_P2(CheckUploadedGenerationTypesAndSignature, | 155 MATCHER_P2(CheckUploadedGenerationTypesAndSignature, |
156 form_signature, | 156 form_signature, |
157 expected_generation_types, | 157 expected_generation_types, |
158 "Unexpected generation types or form signature") { | 158 "Unexpected generation types or form signature") { |
159 if (form_signature != arg.FormSignature()) { | 159 if (form_signature != arg.FormSignatureAsStr()) { |
160 // Unexpected form's signature. | 160 // Unexpected form's signature. |
161 ADD_FAILURE() << "Expected form signature is " << form_signature | 161 ADD_FAILURE() << "Expected form signature is " << form_signature |
162 << ", but found " << arg.FormSignature(); | 162 << ", but found " << arg.FormSignatureAsStr(); |
163 return false; | 163 return false; |
164 } | 164 } |
165 for (const autofill::AutofillField* field : arg) { | 165 for (const autofill::AutofillField* field : arg) { |
166 if (expected_generation_types.find(field->name) == | 166 if (expected_generation_types.find(field->name) == |
167 expected_generation_types.end()) { | 167 expected_generation_types.end()) { |
168 if (field->generation_type() != | 168 if (field->generation_type() != |
169 autofill::AutofillUploadContents::Field::NO_GENERATION) { | 169 autofill::AutofillUploadContents::Field::NO_GENERATION) { |
170 // Unexpected generation type. | 170 // Unexpected generation type. |
171 ADD_FAILURE() << "Expected no generation type for the field " | 171 ADD_FAILURE() << "Expected no generation type for the field " |
172 << field->name << ", but found " | 172 << field->name << ", but found " |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 // for its username field. | 492 // for its username field. |
493 base::string16 username_vote = | 493 base::string16 username_vote = |
494 (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD) | 494 (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD) |
495 ? result[0]->username_element | 495 ? result[0]->username_element |
496 : base::string16(); | 496 : base::string16(); |
497 | 497 |
498 form_manager.OnGetPasswordStoreResults(std::move(result)); | 498 form_manager.OnGetPasswordStoreResults(std::move(result)); |
499 std::string expected_login_signature; | 499 std::string expected_login_signature; |
500 autofill::FormStructure observed_structure(observed_form_data); | 500 autofill::FormStructure observed_structure(observed_form_data); |
501 autofill::FormStructure pending_structure(saved_match()->form_data); | 501 autofill::FormStructure pending_structure(saved_match()->form_data); |
502 if (observed_structure.FormSignature() != | 502 if (observed_structure.FormSignatureAsStr() != |
503 pending_structure.FormSignature() && | 503 pending_structure.FormSignatureAsStr() && |
504 times_used == 0) { | 504 times_used == 0) { |
505 expected_login_signature = observed_structure.FormSignature(); | 505 expected_login_signature = observed_structure.FormSignatureAsStr(); |
506 } | 506 } |
507 autofill::ServerFieldTypeSet expected_available_field_types; | 507 autofill::ServerFieldTypeSet expected_available_field_types; |
508 expected_available_field_types.insert(autofill::USERNAME); | 508 expected_available_field_types.insert(autofill::USERNAME); |
509 std::map<base::string16, autofill::ServerFieldType> expected_types; | 509 std::map<base::string16, autofill::ServerFieldType> expected_types; |
510 expected_types[ASCIIToUTF16("full_name")] = autofill::UNKNOWN_TYPE; | 510 expected_types[ASCIIToUTF16("full_name")] = autofill::UNKNOWN_TYPE; |
511 expected_types[saved_match()->username_element] = | 511 expected_types[saved_match()->username_element] = |
512 username_vote.empty() ? autofill::UNKNOWN_TYPE : autofill::USERNAME; | 512 username_vote.empty() ? autofill::UNKNOWN_TYPE : autofill::USERNAME; |
513 if (field_type) { | 513 if (field_type) { |
514 expected_available_field_types.insert(*field_type); | 514 expected_available_field_types.insert(*field_type); |
515 expected_types[saved_match()->password_element] = *field_type; | 515 expected_types[saved_match()->password_element] = *field_type; |
516 } else { | 516 } else { |
517 expected_available_field_types.insert( | 517 expected_available_field_types.insert( |
518 autofill::NOT_ACCOUNT_CREATION_PASSWORD); | 518 autofill::NOT_ACCOUNT_CREATION_PASSWORD); |
519 expected_types[saved_match()->password_element] = | 519 expected_types[saved_match()->password_element] = |
520 autofill::NOT_ACCOUNT_CREATION_PASSWORD; | 520 autofill::NOT_ACCOUNT_CREATION_PASSWORD; |
521 } | 521 } |
522 | 522 |
523 if (field_type) { | 523 if (field_type) { |
524 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 524 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
525 StartUploadRequest( | 525 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
526 CheckUploadedAutofillTypesAndSignature( | 526 pending_structure.FormSignatureAsStr(), |
527 pending_structure.FormSignature(), expected_types), | 527 expected_types), |
528 false, expected_available_field_types, | 528 false, expected_available_field_types, |
529 expected_login_signature, true)); | 529 expected_login_signature, true)); |
530 } else { | 530 } else { |
531 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 531 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
532 StartUploadRequest(_, _, _, _, _)) | 532 StartUploadRequest(_, _, _, _, _)) |
533 .Times(0); | 533 .Times(0); |
534 } | 534 } |
535 form_manager.ProvisionallySave( | 535 form_manager.ProvisionallySave( |
536 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 536 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
537 form_manager.Save(); | 537 form_manager.Save(); |
538 } | 538 } |
539 | 539 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 expected_types[observed_form_.username_element] = autofill::USERNAME; | 585 expected_types[observed_form_.username_element] = autofill::USERNAME; |
586 expected_types[observed_form_.password_element] = autofill::PASSWORD; | 586 expected_types[observed_form_.password_element] = autofill::PASSWORD; |
587 expected_types[observed_form_.new_password_element] = field_type; | 587 expected_types[observed_form_.new_password_element] = field_type; |
588 | 588 |
589 autofill::ServerFieldTypeSet expected_available_field_types; | 589 autofill::ServerFieldTypeSet expected_available_field_types; |
590 expected_available_field_types.insert(autofill::USERNAME); | 590 expected_available_field_types.insert(autofill::USERNAME); |
591 expected_available_field_types.insert(autofill::PASSWORD); | 591 expected_available_field_types.insert(autofill::PASSWORD); |
592 expected_available_field_types.insert(field_type); | 592 expected_available_field_types.insert(field_type); |
593 | 593 |
594 std::string observed_form_signature = | 594 std::string observed_form_signature = |
595 autofill::FormStructure(observed_form()->form_data).FormSignature(); | 595 autofill::FormStructure(observed_form()->form_data) |
| 596 .FormSignatureAsStr(); |
596 | 597 |
597 std::string expected_login_signature; | 598 std::string expected_login_signature; |
598 if (field_type == autofill::NEW_PASSWORD) { | 599 if (field_type == autofill::NEW_PASSWORD) { |
599 autofill::FormStructure pending_structure(saved_match()->form_data); | 600 autofill::FormStructure pending_structure(saved_match()->form_data); |
600 expected_login_signature = pending_structure.FormSignature(); | 601 expected_login_signature = pending_structure.FormSignatureAsStr(); |
601 } | 602 } |
602 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 603 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
603 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( | 604 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
604 observed_form_signature, expected_types), | 605 observed_form_signature, expected_types), |
605 false, expected_available_field_types, | 606 false, expected_available_field_types, |
606 expected_login_signature, true)); | 607 expected_login_signature, true)); |
607 | 608 |
608 switch (field_type) { | 609 switch (field_type) { |
609 case autofill::NEW_PASSWORD: | 610 case autofill::NEW_PASSWORD: |
610 form_manager.Update(*saved_match()); | 611 form_manager.Update(*saved_match()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 autofill::AutofillUploadContents::Field::PasswordGenerationType> | 709 autofill::AutofillUploadContents::Field::PasswordGenerationType> |
709 expected_generation_types; | 710 expected_generation_types; |
710 expected_generation_types[generation_element] = expected_generation_type; | 711 expected_generation_types[generation_element] = expected_generation_type; |
711 | 712 |
712 autofill::FormStructure form_structure(submitted_form.form_data); | 713 autofill::FormStructure form_structure(submitted_form.form_data); |
713 | 714 |
714 EXPECT_CALL( | 715 EXPECT_CALL( |
715 *client()->mock_driver()->mock_autofill_download_manager(), | 716 *client()->mock_driver()->mock_autofill_download_manager(), |
716 StartUploadRequest( | 717 StartUploadRequest( |
717 CheckUploadedGenerationTypesAndSignature( | 718 CheckUploadedGenerationTypesAndSignature( |
718 form_structure.FormSignature(), expected_generation_types), | 719 form_structure.FormSignatureAsStr(), expected_generation_types), |
719 false, expected_available_field_types, std::string(), true)); | 720 false, expected_available_field_types, std::string(), true)); |
720 | 721 |
721 form_manager.ProvisionallySave( | 722 form_manager.ProvisionallySave( |
722 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 723 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
723 form_manager.Save(); | 724 form_manager.Save(); |
724 } | 725 } |
725 | 726 |
726 PasswordForm* observed_form() { return &observed_form_; } | 727 PasswordForm* observed_form() { return &observed_form_; } |
727 PasswordForm* saved_match() { return &saved_match_; } | 728 PasswordForm* saved_match() { return &saved_match_; } |
728 PasswordForm* psl_saved_match() { return &psl_saved_match_; } | 729 PasswordForm* psl_saved_match() { return &psl_saved_match_; } |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2759 std::map<base::string16, autofill::ServerFieldType> expected_types; | 2760 std::map<base::string16, autofill::ServerFieldType> expected_types; |
2760 expected_types[observed_form()->password_element] = autofill::PASSWORD; | 2761 expected_types[observed_form()->password_element] = autofill::PASSWORD; |
2761 expected_types[observed_form()->new_password_element] = | 2762 expected_types[observed_form()->new_password_element] = |
2762 autofill::NEW_PASSWORD; | 2763 autofill::NEW_PASSWORD; |
2763 | 2764 |
2764 autofill::ServerFieldTypeSet expected_available_field_types; | 2765 autofill::ServerFieldTypeSet expected_available_field_types; |
2765 expected_available_field_types.insert(autofill::PASSWORD); | 2766 expected_available_field_types.insert(autofill::PASSWORD); |
2766 expected_available_field_types.insert(autofill::NEW_PASSWORD); | 2767 expected_available_field_types.insert(autofill::NEW_PASSWORD); |
2767 | 2768 |
2768 std::string observed_form_signature = | 2769 std::string observed_form_signature = |
2769 autofill::FormStructure(observed_form()->form_data).FormSignature(); | 2770 autofill::FormStructure(observed_form()->form_data).FormSignatureAsStr(); |
2770 | 2771 |
2771 std::string expected_login_signature = | 2772 std::string expected_login_signature = |
2772 autofill::FormStructure(saved_match()->form_data).FormSignature(); | 2773 autofill::FormStructure(saved_match()->form_data).FormSignatureAsStr(); |
2773 | 2774 |
2774 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 2775 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
2775 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( | 2776 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
2776 observed_form_signature, expected_types), | 2777 observed_form_signature, expected_types), |
2777 false, expected_available_field_types, | 2778 false, expected_available_field_types, |
2778 expected_login_signature, true)); | 2779 expected_login_signature, true)); |
2779 | 2780 |
2780 form_manager.Update(*saved_match()); | 2781 form_manager.Update(*saved_match()); |
2781 } | 2782 } |
2782 | 2783 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2981 expected_available_field_types.insert(autofill::USERNAME); | 2982 expected_available_field_types.insert(autofill::USERNAME); |
2982 expected_types[saved_match()->username_element] = autofill::USERNAME; | 2983 expected_types[saved_match()->username_element] = autofill::USERNAME; |
2983 expected_available_field_types.insert( | 2984 expected_available_field_types.insert( |
2984 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD); | 2985 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD); |
2985 expected_types[saved_match()->password_element] = | 2986 expected_types[saved_match()->password_element] = |
2986 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD; | 2987 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD; |
2987 | 2988 |
2988 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 2989 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
2989 StartUploadRequest( | 2990 StartUploadRequest( |
2990 CheckUploadedAutofillTypesAndSignature( | 2991 CheckUploadedAutofillTypesAndSignature( |
2991 pending_structure.FormSignature(), expected_types), | 2992 pending_structure.FormSignatureAsStr(), expected_types), |
2992 false, expected_available_field_types, std::string(), true)); | 2993 false, expected_available_field_types, std::string(), true)); |
2993 | 2994 |
2994 form_manager.ProvisionallySave( | 2995 form_manager.ProvisionallySave( |
2995 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 2996 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
2996 form_manager.Save(); | 2997 form_manager.Save(); |
2997 } | 2998 } |
2998 | 2999 |
2999 TEST_F(PasswordFormManagerFillOnAccountSelectTest, ProcessFrame) { | 3000 TEST_F(PasswordFormManagerFillOnAccountSelectTest, ProcessFrame) { |
3000 EXPECT_CALL(*client()->mock_driver(), | 3001 EXPECT_CALL(*client()->mock_driver(), |
3001 ShowInitialPasswordAccountSuggestions(_)); | 3002 ShowInitialPasswordAccountSuggestions(_)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 ->ProcessMatches(all_matches, 0u); | 3073 ->ProcessMatches(all_matches, 0u); |
3073 | 3074 |
3074 EXPECT_EQ(1u, form_manager.best_matches().size()); | 3075 EXPECT_EQ(1u, form_manager.best_matches().size()); |
3075 EXPECT_EQ(kCorrectScheme, | 3076 EXPECT_EQ(kCorrectScheme, |
3076 form_manager.best_matches().begin()->second->scheme); | 3077 form_manager.best_matches().begin()->second->scheme); |
3077 } | 3078 } |
3078 } | 3079 } |
3079 } | 3080 } |
3080 | 3081 |
3081 } // namespace password_manager | 3082 } // namespace password_manager |
OLD | NEW |