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 <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 }; | 99 }; |
100 | 100 |
101 MATCHER_P(CheckUsername, username_value, "Username incorrect") { | 101 MATCHER_P(CheckUsername, username_value, "Username incorrect") { |
102 return arg.username_value == username_value; | 102 return arg.username_value == username_value; |
103 } | 103 } |
104 | 104 |
105 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") { | 105 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") { |
106 return arg && arg->username_value == username_value; | 106 return arg && arg->username_value == username_value; |
107 } | 107 } |
108 | 108 |
109 MATCHER_P2(CheckUploadedAutofillTypesAndSignature, | 109 MATCHER_P3(CheckUploadedAutofillTypesAndSignature, |
110 form_signature, | 110 form_signature, |
111 expected_types, | 111 expected_types, |
| 112 expect_generation_vote, |
112 "Unexpected autofill types or form signature") { | 113 "Unexpected autofill types or form signature") { |
113 if (form_signature != arg.FormSignatureAsStr()) { | 114 if (form_signature != arg.FormSignatureAsStr()) { |
114 // Unexpected form's signature. | 115 // Unexpected form's signature. |
115 ADD_FAILURE() << "Expected form signature is " << form_signature | 116 ADD_FAILURE() << "Expected form signature is " << form_signature |
116 << ", but found " << arg.FormSignatureAsStr(); | 117 << ", but found " << arg.FormSignatureAsStr(); |
117 return false; | 118 return false; |
118 } | 119 } |
| 120 bool found_generation_vote = false; |
119 for (const auto& field : arg) { | 121 for (const auto& field : arg) { |
120 if (field->possible_types().size() > 1) { | 122 if (field->possible_types().size() > 1) { |
121 ADD_FAILURE() << field->name << " field has several possible types"; | 123 ADD_FAILURE() << field->name << " field has several possible types"; |
122 return false; | 124 return false; |
123 } | 125 } |
124 | 126 |
| 127 found_generation_vote |= |
| 128 field->generation_type() != |
| 129 autofill::AutofillUploadContents::Field::NO_GENERATION; |
| 130 |
125 autofill::ServerFieldType expected_vote = | 131 autofill::ServerFieldType expected_vote = |
126 expected_types.find(field->name) == expected_types.end() | 132 expected_types.find(field->name) == expected_types.end() |
127 ? autofill::NO_SERVER_DATA | 133 ? autofill::NO_SERVER_DATA |
128 : expected_types.find(field->name)->second; | 134 : expected_types.find(field->name)->second; |
129 autofill::ServerFieldType actual_vote = | 135 autofill::ServerFieldType actual_vote = |
130 field->possible_types().empty() ? autofill::NO_SERVER_DATA | 136 field->possible_types().empty() ? autofill::NO_SERVER_DATA |
131 : *field->possible_types().begin(); | 137 : *field->possible_types().begin(); |
132 if (expected_vote != actual_vote) { | 138 if (expected_vote != actual_vote) { |
133 ADD_FAILURE() << field->name << " field: expected vote " << expected_vote | 139 ADD_FAILURE() << field->name << " field: expected vote " << expected_vote |
134 << ", but found " << actual_vote; | 140 << ", but found " << actual_vote; |
135 return false; | 141 return false; |
136 } | 142 } |
137 } | 143 } |
| 144 EXPECT_EQ(expect_generation_vote, found_generation_vote); |
138 return true; | 145 return true; |
139 } | 146 } |
140 | 147 |
141 MATCHER_P2(CheckUploadedGenerationTypesAndSignature, | 148 MATCHER_P2(CheckUploadedGenerationTypesAndSignature, |
142 form_signature, | 149 form_signature, |
143 expected_generation_types, | 150 expected_generation_types, |
144 "Unexpected generation types or form signature") { | 151 "Unexpected generation types or form signature") { |
145 if (form_signature != arg.FormSignatureAsStr()) { | 152 if (form_signature != arg.FormSignatureAsStr()) { |
146 // Unexpected form's signature. | 153 // Unexpected form's signature. |
147 ADD_FAILURE() << "Expected form signature is " << form_signature | 154 ADD_FAILURE() << "Expected form signature is " << form_signature |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 411 |
405 // When we're voting for an account creation form, we should also vote | 412 // When we're voting for an account creation form, we should also vote |
406 // for its username field. | 413 // for its username field. |
407 if (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD) { | 414 if (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD) { |
408 expected_types[match.username_element] = autofill::USERNAME; | 415 expected_types[match.username_element] = autofill::USERNAME; |
409 expected_available_field_types.insert(autofill::USERNAME); | 416 expected_available_field_types.insert(autofill::USERNAME); |
410 } else { | 417 } else { |
411 expected_types[match.username_element] = autofill::UNKNOWN_TYPE; | 418 expected_types[match.username_element] = autofill::UNKNOWN_TYPE; |
412 } | 419 } |
413 | 420 |
| 421 bool expect_generation_vote = false; |
414 if (field_type) { | 422 if (field_type) { |
| 423 // Show the password generation popup to check that the generation vote |
| 424 // would be ignored. |
| 425 form_manager.set_generation_element(saved_match()->password_element); |
| 426 form_manager.set_generation_popup_was_shown(true); |
| 427 expect_generation_vote = |
| 428 *field_type != autofill::ACCOUNT_CREATION_PASSWORD; |
| 429 |
415 expected_available_field_types.insert(*field_type); | 430 expected_available_field_types.insert(*field_type); |
416 expected_types[saved_match()->password_element] = *field_type; | 431 expected_types[saved_match()->password_element] = *field_type; |
417 } else { | |
418 expected_available_field_types.insert( | |
419 autofill::NOT_ACCOUNT_CREATION_PASSWORD); | |
420 expected_types[saved_match()->password_element] = | |
421 autofill::NOT_ACCOUNT_CREATION_PASSWORD; | |
422 } | 432 } |
423 | 433 |
424 if (field_type) { | 434 if (field_type) { |
425 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 435 EXPECT_CALL( |
426 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( | 436 *client()->mock_driver()->mock_autofill_download_manager(), |
427 pending_structure.FormSignatureAsStr(), | 437 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
428 expected_types), | 438 pending_structure.FormSignatureAsStr(), |
429 false, expected_available_field_types, | 439 expected_types, expect_generation_vote), |
430 expected_login_signature, true)); | 440 false, expected_available_field_types, |
| 441 expected_login_signature, true)); |
431 } else { | 442 } else { |
432 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 443 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
433 StartUploadRequest(_, _, _, _, _)) | 444 StartUploadRequest(_, _, _, _, _)) |
434 .Times(0); | 445 .Times(0); |
435 } | 446 } |
436 form_manager.ProvisionallySave( | 447 form_manager.ProvisionallySave( |
437 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 448 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
438 form_manager.Save(); | 449 form_manager.Save(); |
439 Mock::VerifyAndClearExpectations( | 450 Mock::VerifyAndClearExpectations( |
440 client()->mock_driver()->mock_autofill_download_manager()); | 451 client()->mock_driver()->mock_autofill_download_manager()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 autofill::FormStructure(observed_form()->form_data) | 528 autofill::FormStructure(observed_form()->form_data) |
518 .FormSignatureAsStr(); | 529 .FormSignatureAsStr(); |
519 | 530 |
520 std::string expected_login_signature; | 531 std::string expected_login_signature; |
521 if (field_type == autofill::NEW_PASSWORD) { | 532 if (field_type == autofill::NEW_PASSWORD) { |
522 autofill::FormStructure pending_structure(saved_match()->form_data); | 533 autofill::FormStructure pending_structure(saved_match()->form_data); |
523 expected_login_signature = pending_structure.FormSignatureAsStr(); | 534 expected_login_signature = pending_structure.FormSignatureAsStr(); |
524 } | 535 } |
525 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 536 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
526 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( | 537 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
527 observed_form_signature, expected_types), | 538 observed_form_signature, expected_types, |
| 539 false /* expect_generation_vote */), |
528 false, expected_available_field_types, | 540 false, expected_available_field_types, |
529 expected_login_signature, true)); | 541 expected_login_signature, true)); |
530 | 542 |
531 switch (field_type) { | 543 switch (field_type) { |
532 case autofill::NEW_PASSWORD: | 544 case autofill::NEW_PASSWORD: |
533 form_manager.Update(*saved_match()); | 545 form_manager.Update(*saved_match()); |
534 break; | 546 break; |
535 case autofill::PROBABLY_NEW_PASSWORD: | 547 case autofill::PROBABLY_NEW_PASSWORD: |
536 form_manager.OnNoInteraction(true /* it is an update */); | 548 form_manager.OnNoInteraction(true /* it is an update */); |
537 break; | 549 break; |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 expected_available_field_types.insert(autofill::NEW_PASSWORD); | 2577 expected_available_field_types.insert(autofill::NEW_PASSWORD); |
2566 | 2578 |
2567 std::string observed_form_signature = | 2579 std::string observed_form_signature = |
2568 autofill::FormStructure(observed_form()->form_data).FormSignatureAsStr(); | 2580 autofill::FormStructure(observed_form()->form_data).FormSignatureAsStr(); |
2569 | 2581 |
2570 std::string expected_login_signature = | 2582 std::string expected_login_signature = |
2571 autofill::FormStructure(saved_match()->form_data).FormSignatureAsStr(); | 2583 autofill::FormStructure(saved_match()->form_data).FormSignatureAsStr(); |
2572 | 2584 |
2573 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 2585 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
2574 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( | 2586 StartUploadRequest(CheckUploadedAutofillTypesAndSignature( |
2575 observed_form_signature, expected_types), | 2587 observed_form_signature, expected_types, |
| 2588 false /* expect_generation_vote */), |
2576 false, expected_available_field_types, | 2589 false, expected_available_field_types, |
2577 expected_login_signature, true)); | 2590 expected_login_signature, true)); |
2578 | 2591 |
2579 form_manager.Update(*saved_match()); | 2592 form_manager.Update(*saved_match()); |
2580 } | 2593 } |
2581 | 2594 |
2582 // Checks uploading a vote about the usage of the password generation popup. | 2595 // Checks uploading a vote about the usage of the password generation popup. |
2583 TEST_F(PasswordFormManagerTest, GeneratedVoteUpload) { | 2596 TEST_F(PasswordFormManagerTest, GeneratedVoteUpload) { |
2584 bool kFalseTrue[] = {false, true}; | 2597 bool kFalseTrue[] = {false, true}; |
2585 SavePromptInteraction kSavePromptInterations[] = {SAVE, NEVER, | 2598 SavePromptInteraction kSavePromptInterations[] = {SAVE, NEVER, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2769 expected_types[ASCIIToUTF16("full_name")] = autofill::UNKNOWN_TYPE; | 2782 expected_types[ASCIIToUTF16("full_name")] = autofill::UNKNOWN_TYPE; |
2770 expected_types[saved_match()->username_element] = autofill::UNKNOWN_TYPE; | 2783 expected_types[saved_match()->username_element] = autofill::UNKNOWN_TYPE; |
2771 expected_available_field_types.insert( | 2784 expected_available_field_types.insert( |
2772 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD); | 2785 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD); |
2773 expected_types[saved_match()->password_element] = | 2786 expected_types[saved_match()->password_element] = |
2774 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD; | 2787 autofill::PROBABLY_ACCOUNT_CREATION_PASSWORD; |
2775 | 2788 |
2776 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), | 2789 EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(), |
2777 StartUploadRequest( | 2790 StartUploadRequest( |
2778 CheckUploadedAutofillTypesAndSignature( | 2791 CheckUploadedAutofillTypesAndSignature( |
2779 pending_structure.FormSignatureAsStr(), expected_types), | 2792 pending_structure.FormSignatureAsStr(), expected_types, |
| 2793 false /* expect_generation_vote */), |
2780 false, expected_available_field_types, std::string(), true)); | 2794 false, expected_available_field_types, std::string(), true)); |
2781 | 2795 |
2782 form_manager.ProvisionallySave( | 2796 form_manager.ProvisionallySave( |
2783 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 2797 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
2784 form_manager.Save(); | 2798 form_manager.Save(); |
2785 } | 2799 } |
2786 | 2800 |
2787 TEST_F(PasswordFormManagerFillOnAccountSelectTest, ProcessFrame) { | 2801 TEST_F(PasswordFormManagerFillOnAccountSelectTest, ProcessFrame) { |
2788 EXPECT_CALL(*client()->mock_driver(), | 2802 EXPECT_CALL(*client()->mock_driver(), |
2789 ShowInitialPasswordAccountSuggestions(_)); | 2803 ShowInitialPasswordAccountSuggestions(_)); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2953 updated, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 2967 updated, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
2954 credentials_to_update.clear(); | 2968 credentials_to_update.clear(); |
2955 EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr)) | 2969 EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr)) |
2956 .WillOnce(SaveArgPointee<2>(&credentials_to_update)); | 2970 .WillOnce(SaveArgPointee<2>(&credentials_to_update)); |
2957 form_manager()->Save(); | 2971 form_manager()->Save(); |
2958 | 2972 |
2959 EXPECT_THAT(credentials_to_update, IsEmpty()); | 2973 EXPECT_THAT(credentials_to_update, IsEmpty()); |
2960 } | 2974 } |
2961 | 2975 |
2962 } // namespace password_manager | 2976 } // namespace password_manager |
OLD | NEW |