Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2830303002: Fix sending autofill votes for sign-in forms. (Closed)
Patch Set: Comments added Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 327 }
328 328
329 // Verify that the last queried forms equal |expected_forms|. 329 // Verify that the last queried forms equal |expected_forms|.
330 void VerifyLastQueriedForms(const std::vector<FormData>& expected_forms) { 330 void VerifyLastQueriedForms(const std::vector<FormData>& expected_forms) {
331 ASSERT_EQ(expected_forms.size(), last_queried_forms_.size()); 331 ASSERT_EQ(expected_forms.size(), last_queried_forms_.size());
332 for (size_t i = 0; i < expected_forms.size(); ++i) { 332 for (size_t i = 0; i < expected_forms.size(); ++i) {
333 EXPECT_EQ(*last_queried_forms_[i], expected_forms[i]); 333 EXPECT_EQ(*last_queried_forms_[i], expected_forms[i]);
334 } 334 }
335 } 335 }
336 336
337 MOCK_METHOD5(StartUploadRequest,
338 bool(const FormStructure&,
339 bool,
340 const ServerFieldTypeSet&,
341 const std::string&,
342 bool));
343
337 private: 344 private:
338 std::vector<FormStructure*> last_queried_forms_; 345 std::vector<FormStructure*> last_queried_forms_;
339 346
340 DISALLOW_COPY_AND_ASSIGN(TestAutofillDownloadManager); 347 DISALLOW_COPY_AND_ASSIGN(TestAutofillDownloadManager);
341 }; 348 };
342 349
343 void ExpectFilledField(const char* expected_label, 350 void ExpectFilledField(const char* expected_label,
344 const char* expected_name, 351 const char* expected_name,
345 const char* expected_value, 352 const char* expected_value,
346 const char* expected_form_control_type, 353 const char* expected_form_control_type,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 class TestAutofillManager : public AutofillManager { 538 class TestAutofillManager : public AutofillManager {
532 public: 539 public:
533 TestAutofillManager(AutofillDriver* driver, 540 TestAutofillManager(AutofillDriver* driver,
534 AutofillClient* client, 541 AutofillClient* client,
535 TestPersonalDataManager* personal_data) 542 TestPersonalDataManager* personal_data)
536 : AutofillManager(driver, client, personal_data), 543 : AutofillManager(driver, client, personal_data),
537 personal_data_(personal_data), 544 personal_data_(personal_data),
538 autofill_enabled_(true), 545 autofill_enabled_(true),
539 credit_card_upload_enabled_(false), 546 credit_card_upload_enabled_(false),
540 credit_card_was_uploaded_(false), 547 credit_card_was_uploaded_(false),
541 expected_observed_submission_(true) { 548 expected_observed_submission_(true),
549 call_parent_upload_form_data_(false) {
542 set_payments_client( 550 set_payments_client(
543 new TestPaymentsClient(driver->GetURLRequestContext(), this)); 551 new TestPaymentsClient(driver->GetURLRequestContext(), this));
544 } 552 }
545 ~TestAutofillManager() override {} 553 ~TestAutofillManager() override {}
546 554
547 bool IsAutofillEnabled() const override { return autofill_enabled_; } 555 bool IsAutofillEnabled() const override { return autofill_enabled_; }
548 556
549 void set_autofill_enabled(bool autofill_enabled) { 557 void set_autofill_enabled(bool autofill_enabled) {
550 autofill_enabled_ = autofill_enabled; 558 autofill_enabled_ = autofill_enabled;
551 } 559 }
(...skipping 10 matching lines...) Expand all
562 570
563 void set_expected_submitted_field_types( 571 void set_expected_submitted_field_types(
564 const std::vector<ServerFieldTypeSet>& expected_types) { 572 const std::vector<ServerFieldTypeSet>& expected_types) {
565 expected_submitted_field_types_ = expected_types; 573 expected_submitted_field_types_ = expected_types;
566 } 574 }
567 575
568 void set_expected_observed_submission(bool expected) { 576 void set_expected_observed_submission(bool expected) {
569 expected_observed_submission_ = expected; 577 expected_observed_submission_ = expected;
570 } 578 }
571 579
580 void set_call_parent_upload_form_data(bool value) {
581 call_parent_upload_form_data_ = value;
582 }
583
572 void UploadFormDataAsyncCallback(const FormStructure* submitted_form, 584 void UploadFormDataAsyncCallback(const FormStructure* submitted_form,
573 const base::TimeTicks& load_time, 585 const base::TimeTicks& load_time,
574 const base::TimeTicks& interaction_time, 586 const base::TimeTicks& interaction_time,
575 const base::TimeTicks& submission_time, 587 const base::TimeTicks& submission_time,
576 bool observed_submission) override { 588 bool observed_submission) override {
577 run_loop_->Quit(); 589 run_loop_->Quit();
578 590
579 EXPECT_EQ(expected_observed_submission_, observed_submission); 591 EXPECT_EQ(expected_observed_submission_, observed_submission);
580 592
581 // If we have expected field types set, make sure they match. 593 // If we have expected field types set, make sure they match.
(...skipping 26 matching lines...) Expand all
608 // Resets the run loop so that it can wait for an asynchronous form 620 // Resets the run loop so that it can wait for an asynchronous form
609 // submission to complete. 621 // submission to complete.
610 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } 622 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); }
611 623
612 // Wait for the asynchronous calls within StartUploadProcess() to complete. 624 // Wait for the asynchronous calls within StartUploadProcess() to complete.
613 void WaitForAsyncUploadProcess() { run_loop_->Run(); } 625 void WaitForAsyncUploadProcess() { run_loop_->Run(); }
614 626
615 void UploadFormData(const FormStructure& submitted_form, 627 void UploadFormData(const FormStructure& submitted_form,
616 bool observed_submission) override { 628 bool observed_submission) override {
617 submitted_form_signature_ = submitted_form.FormSignatureAsStr(); 629 submitted_form_signature_ = submitted_form.FormSignatureAsStr();
630
631 if (call_parent_upload_form_data_)
632 AutofillManager::UploadFormData(submitted_form, observed_submission);
618 } 633 }
619 634
620 const std::string GetSubmittedFormSignature() { 635 const std::string GetSubmittedFormSignature() {
621 return submitted_form_signature_; 636 return submitted_form_signature_;
622 } 637 }
623 638
624 AutofillProfile* GetProfileWithGUID(const char* guid) { 639 AutofillProfile* GetProfileWithGUID(const char* guid) {
625 return personal_data_->GetProfileWithGUID(guid); 640 return personal_data_->GetProfileWithGUID(guid);
626 } 641 }
627 642
(...skipping 29 matching lines...) Expand all
657 credit_card_was_uploaded_ = true; 672 credit_card_was_uploaded_ = true;
658 }; 673 };
659 674
660 // Weak reference. 675 // Weak reference.
661 TestPersonalDataManager* personal_data_; 676 TestPersonalDataManager* personal_data_;
662 677
663 bool autofill_enabled_; 678 bool autofill_enabled_;
664 bool credit_card_upload_enabled_; 679 bool credit_card_upload_enabled_;
665 bool credit_card_was_uploaded_; 680 bool credit_card_was_uploaded_;
666 bool expected_observed_submission_; 681 bool expected_observed_submission_;
682 bool call_parent_upload_form_data_;
667 683
668 std::unique_ptr<base::RunLoop> run_loop_; 684 std::unique_ptr<base::RunLoop> run_loop_;
669 685
670 std::string submitted_form_signature_; 686 std::string submitted_form_signature_;
671 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; 687 std::vector<ServerFieldTypeSet> expected_submitted_field_types_;
672 688
673 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 689 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
674 }; 690 };
675 691
676 class TestAutofillExternalDelegate : public AutofillExternalDelegate { 692 class TestAutofillExternalDelegate : public AutofillExternalDelegate {
(...skipping 5387 matching lines...) Expand 10 before | Expand all | Expand 10 after
6064 test::CreateTestFormField("Password", "pw", "secret", "password", &field); 6080 test::CreateTestFormField("Password", "pw", "secret", "password", &field);
6065 form.fields.push_back(field); 6081 form.fields.push_back(field);
6066 types.clear(); 6082 types.clear();
6067 types.insert(PASSWORD); 6083 types.insert(PASSWORD);
6068 expected_types.push_back(types); 6084 expected_types.push_back(types);
6069 6085
6070 // We will expect these types in the upload and no observed submission. (the 6086 // We will expect these types in the upload and no observed submission. (the
6071 // callback initiated by WaitForAsyncUploadProcess checks these expectations.) 6087 // callback initiated by WaitForAsyncUploadProcess checks these expectations.)
6072 autofill_manager_->set_expected_submitted_field_types(expected_types); 6088 autofill_manager_->set_expected_submitted_field_types(expected_types);
6073 autofill_manager_->set_expected_observed_submission(true); 6089 autofill_manager_->set_expected_observed_submission(true);
6090 autofill_manager_->set_call_parent_upload_form_data(true);
6074 autofill_manager_->ResetRunLoop(); 6091 autofill_manager_->ResetRunLoop();
6075 6092
6076 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); 6093 std::unique_ptr<FormStructure> form_structure(new FormStructure(form));
6077 form_structure->set_is_signin_upload(true); 6094 form_structure->set_is_signin_upload(true);
6078 form_structure->field(1)->set_possible_types({autofill::PASSWORD}); 6095 form_structure->field(1)->set_possible_types({autofill::PASSWORD});
6079 6096
6080 std::string signature = form_structure->FormSignatureAsStr(); 6097 std::string signature = form_structure->FormSignatureAsStr();
6098
6099 ServerFieldTypeSet uploaded_available_types;
6100 EXPECT_CALL(*download_manager_,
6101 StartUploadRequest(_, false, _, std::string(), true))
6102 .WillOnce(DoAll(SaveArg<2>(&uploaded_available_types), Return(true)));
6081 autofill_manager_->StartUploadProcess(std::move(form_structure), 6103 autofill_manager_->StartUploadProcess(std::move(form_structure),
6082 base::TimeTicks::Now(), true); 6104 base::TimeTicks::Now(), true);
6083 6105
6084 // Wait for upload to complete (will check expected types as well). 6106 // Wait for upload to complete (will check expected types as well).
6085 autofill_manager_->WaitForAsyncUploadProcess(); 6107 autofill_manager_->WaitForAsyncUploadProcess();
6086 6108
6087 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); 6109 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature());
6110 EXPECT_NE(uploaded_available_types.end(),
6111 uploaded_available_types.find(autofill::PASSWORD));
6088 } 6112 }
6089 6113
6090 } // namespace autofill 6114 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/form_structure.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698