| OLD | NEW |
| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 using testing::AtLeast; | 74 using testing::AtLeast; |
| 75 using testing::Return; | 75 using testing::Return; |
| 76 using testing::SaveArg; | 76 using testing::SaveArg; |
| 77 | 77 |
| 78 namespace autofill { | 78 namespace autofill { |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 | 81 |
| 82 const int kDefaultPageID = 137; | 82 const int kDefaultPageID = 137; |
| 83 | 83 |
| 84 const std::string kUTF8MidlineEllipsis = | 84 const char kUTF8MidlineEllipsis[] = |
| 85 " " | 85 " " |
| 86 "\xE2\x80\xA2\xE2\x80\x86" | 86 "\xE2\x80\xA2\xE2\x80\x86" |
| 87 "\xE2\x80\xA2\xE2\x80\x86" | 87 "\xE2\x80\xA2\xE2\x80\x86" |
| 88 "\xE2\x80\xA2\xE2\x80\x86" | 88 "\xE2\x80\xA2\xE2\x80\x86" |
| 89 "\xE2\x80\xA2\xE2\x80\x86"; | 89 "\xE2\x80\xA2\xE2\x80\x86"; |
| 90 | 90 |
| 91 class MockAutofillClient : public TestAutofillClient { | 91 class MockAutofillClient : public TestAutofillClient { |
| 92 public: | 92 public: |
| 93 MockAutofillClient() {} | 93 MockAutofillClient() {} |
| 94 | 94 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); | 213 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); |
| 214 if (profile) { | 214 if (profile) { |
| 215 web_profiles_.erase( | 215 web_profiles_.erase( |
| 216 std::find_if(web_profiles_.begin(), web_profiles_.end(), | 216 std::find_if(web_profiles_.begin(), web_profiles_.end(), |
| 217 [profile](const std::unique_ptr<AutofillProfile>& ptr) { | 217 [profile](const std::unique_ptr<AutofillProfile>& ptr) { |
| 218 return ptr.get() == profile; | 218 return ptr.get() == profile; |
| 219 })); | 219 })); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ClearAutofillProfiles() { | 223 void ClearAutofillProfiles() { web_profiles_.clear(); } |
| 224 web_profiles_.clear(); | |
| 225 } | |
| 226 | 224 |
| 227 void ClearCreditCards() { | 225 void ClearCreditCards() { |
| 228 local_credit_cards_.clear(); | 226 local_credit_cards_.clear(); |
| 229 server_credit_cards_.clear(); | 227 server_credit_cards_.clear(); |
| 230 } | 228 } |
| 231 | 229 |
| 232 // Create Elvis card with whitespace in the credit card number. | 230 // Create Elvis card with whitespace in the credit card number. |
| 233 void CreateTestCreditCardWithWhitespace() { | 231 void CreateTestCreditCardWithWhitespace() { |
| 234 ClearCreditCards(); | 232 ClearCreditCards(); |
| 235 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 233 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 ExpectFilledField("First Name", "firstname", first, "text", | 418 ExpectFilledField("First Name", "firstname", first, "text", |
| 421 filled_form.fields[0]); | 419 filled_form.fields[0]); |
| 422 ExpectFilledField("Middle Name", "middlename", middle, "text", | 420 ExpectFilledField("Middle Name", "middlename", middle, "text", |
| 423 filled_form.fields[1]); | 421 filled_form.fields[1]); |
| 424 ExpectFilledField("Last Name", "lastname", last, "text", | 422 ExpectFilledField("Last Name", "lastname", last, "text", |
| 425 filled_form.fields[2]); | 423 filled_form.fields[2]); |
| 426 ExpectFilledField("Address Line 1", "addr1", address1, "text", | 424 ExpectFilledField("Address Line 1", "addr1", address1, "text", |
| 427 filled_form.fields[3]); | 425 filled_form.fields[3]); |
| 428 ExpectFilledField("Address Line 2", "addr2", address2, "text", | 426 ExpectFilledField("Address Line 2", "addr2", address2, "text", |
| 429 filled_form.fields[4]); | 427 filled_form.fields[4]); |
| 430 ExpectFilledField("City", "city", city, "text", | 428 ExpectFilledField("City", "city", city, "text", filled_form.fields[5]); |
| 431 filled_form.fields[5]); | 429 ExpectFilledField("State", "state", state, "text", filled_form.fields[6]); |
| 432 ExpectFilledField("State", "state", state, "text", | |
| 433 filled_form.fields[6]); | |
| 434 ExpectFilledField("Postal Code", "zipcode", postal_code, "text", | 430 ExpectFilledField("Postal Code", "zipcode", postal_code, "text", |
| 435 filled_form.fields[7]); | 431 filled_form.fields[7]); |
| 436 ExpectFilledField("Country", "country", country, "text", | 432 ExpectFilledField("Country", "country", country, "text", |
| 437 filled_form.fields[8]); | 433 filled_form.fields[8]); |
| 438 ExpectFilledField("Phone Number", "phonenumber", phone, "tel", | 434 ExpectFilledField("Phone Number", "phonenumber", phone, "tel", |
| 439 filled_form.fields[9]); | 435 filled_form.fields[9]); |
| 440 ExpectFilledField("Email", "email", email, "email", | 436 ExpectFilledField("Email", "email", email, "email", filled_form.fields[10]); |
| 441 filled_form.fields[10]); | |
| 442 } | 437 } |
| 443 | 438 |
| 444 if (has_credit_card_fields) { | 439 if (has_credit_card_fields) { |
| 445 size_t offset = has_address_fields? kAddressFormSize : 0; | 440 size_t offset = has_address_fields ? kAddressFormSize : 0; |
| 446 ExpectFilledField("Name on Card", "nameoncard", name_on_card, "text", | 441 ExpectFilledField("Name on Card", "nameoncard", name_on_card, "text", |
| 447 filled_form.fields[offset + 0]); | 442 filled_form.fields[offset + 0]); |
| 448 ExpectFilledField("Card Number", "cardnumber", card_number, "text", | 443 ExpectFilledField("Card Number", "cardnumber", card_number, "text", |
| 449 filled_form.fields[offset + 1]); | 444 filled_form.fields[offset + 1]); |
| 450 if (use_month_type) { | 445 if (use_month_type) { |
| 451 std::string exp_year = expiration_year; | 446 std::string exp_year = expiration_year; |
| 452 std::string exp_month = expiration_month; | 447 std::string exp_month = expiration_month; |
| 453 std::string date; | 448 std::string date; |
| 454 if (!exp_year.empty() && !exp_month.empty()) | 449 if (!exp_year.empty() && !exp_month.empty()) |
| 455 date = exp_year + "-" + exp_month; | 450 date = exp_year + "-" + exp_month; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", | 489 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", |
| 495 "", "", "", "", "", "", "Miku Hatsune", "4234567890654321", | 490 "", "", "", "", "", "", "Miku Hatsune", "4234567890654321", |
| 496 month, year, has_address_fields, true, true); | 491 month, year, has_address_fields, true, true); |
| 497 } | 492 } |
| 498 | 493 |
| 499 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { | 494 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { |
| 500 public: | 495 public: |
| 501 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) | 496 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) |
| 502 : AutocompleteHistoryManager(driver, client) {} | 497 : AutocompleteHistoryManager(driver, client) {} |
| 503 | 498 |
| 504 MOCK_METHOD4(OnGetAutocompleteSuggestions, void( | 499 MOCK_METHOD4(OnGetAutocompleteSuggestions, |
| 505 int query_id, | 500 void(int query_id, |
| 506 const base::string16& name, | 501 const base::string16& name, |
| 507 const base::string16& prefix, | 502 const base::string16& prefix, |
| 508 const std::string& form_control_type)); | 503 const std::string& form_control_type)); |
| 509 MOCK_METHOD1(OnWillSubmitForm, void(const FormData& form)); | 504 MOCK_METHOD1(OnWillSubmitForm, void(const FormData& form)); |
| 510 | 505 |
| 511 private: | 506 private: |
| 512 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); | 507 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); |
| 513 }; | 508 }; |
| 514 | 509 |
| 515 class MockAutofillDriver : public TestAutofillDriver { | 510 class MockAutofillDriver : public TestAutofillDriver { |
| 516 public: | 511 public: |
| 517 MockAutofillDriver() | 512 MockAutofillDriver() |
| 518 : is_incognito_(false), did_interact_with_credit_card_form_(false) {} | 513 : is_incognito_(false), did_interact_with_credit_card_form_(false) {} |
| 519 | 514 |
| 520 // Mock methods to enable testability. | 515 // Mock methods to enable testability. |
| 521 MOCK_METHOD3(SendFormDataToRenderer, void(int query_id, | 516 MOCK_METHOD3(SendFormDataToRenderer, |
| 522 RendererFormDataAction action, | 517 void(int query_id, |
| 523 const FormData& data)); | 518 RendererFormDataAction action, |
| 519 const FormData& data)); |
| 524 | 520 |
| 525 void SetIsIncognito(bool is_incognito) { | 521 void SetIsIncognito(bool is_incognito) { is_incognito_ = is_incognito; } |
| 526 is_incognito_ = is_incognito; | |
| 527 } | |
| 528 | 522 |
| 529 bool IsIncognito() const override { return is_incognito_; } | 523 bool IsIncognito() const override { return is_incognito_; } |
| 530 | 524 |
| 531 void DidInteractWithCreditCardForm() override { | 525 void DidInteractWithCreditCardForm() override { |
| 532 did_interact_with_credit_card_form_ = true; | 526 did_interact_with_credit_card_form_ = true; |
| 533 }; | 527 } |
| 534 | 528 |
| 535 void ClearDidInteractWithCreditCardForm() { | 529 void ClearDidInteractWithCreditCardForm() { |
| 536 did_interact_with_credit_card_form_ = false; | 530 did_interact_with_credit_card_form_ = false; |
| 537 }; | 531 } |
| 538 | 532 |
| 539 bool did_interact_with_credit_card_form() const { | 533 bool did_interact_with_credit_card_form() const { |
| 540 return did_interact_with_credit_card_form_; | 534 return did_interact_with_credit_card_form_; |
| 541 } | 535 } |
| 542 | 536 |
| 543 private: | 537 private: |
| 544 bool is_incognito_; | 538 bool is_incognito_; |
| 545 bool did_interact_with_credit_card_form_; | 539 bool did_interact_with_credit_card_form_; |
| 546 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 540 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
| 547 }; | 541 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 bool observed_submission) override { | 593 bool observed_submission) override { |
| 600 run_loop_->Quit(); | 594 run_loop_->Quit(); |
| 601 | 595 |
| 602 EXPECT_EQ(expected_observed_submission_, observed_submission); | 596 EXPECT_EQ(expected_observed_submission_, observed_submission); |
| 603 | 597 |
| 604 // If we have expected field types set, make sure they match. | 598 // If we have expected field types set, make sure they match. |
| 605 if (!expected_submitted_field_types_.empty()) { | 599 if (!expected_submitted_field_types_.empty()) { |
| 606 ASSERT_EQ(expected_submitted_field_types_.size(), | 600 ASSERT_EQ(expected_submitted_field_types_.size(), |
| 607 submitted_form->field_count()); | 601 submitted_form->field_count()); |
| 608 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) { | 602 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) { |
| 609 SCOPED_TRACE( | 603 SCOPED_TRACE(base::StringPrintf( |
| 610 base::StringPrintf( | 604 "Field %d with value %s", static_cast<int>(i), |
| 611 "Field %d with value %s", static_cast<int>(i), | 605 base::UTF16ToUTF8(submitted_form->field(i)->value).c_str())); |
| 612 base::UTF16ToUTF8(submitted_form->field(i)->value).c_str())); | |
| 613 const ServerFieldTypeSet& possible_types = | 606 const ServerFieldTypeSet& possible_types = |
| 614 submitted_form->field(i)->possible_types(); | 607 submitted_form->field(i)->possible_types(); |
| 615 EXPECT_EQ(expected_submitted_field_types_[i].size(), | 608 EXPECT_EQ(expected_submitted_field_types_[i].size(), |
| 616 possible_types.size()); | 609 possible_types.size()); |
| 617 for (ServerFieldTypeSet::const_iterator it = | 610 for (ServerFieldTypeSet::const_iterator it = |
| 618 expected_submitted_field_types_[i].begin(); | 611 expected_submitted_field_types_[i].begin(); |
| 619 it != expected_submitted_field_types_[i].end(); ++it) { | 612 it != expected_submitted_field_types_[i].end(); ++it) { |
| 620 EXPECT_TRUE(possible_types.count(*it)) | 613 EXPECT_TRUE(possible_types.count(*it)) |
| 621 << "Expected type: " << AutofillType(*it).ToString(); | 614 << "Expected type: " << AutofillType(*it).ToString(); |
| 622 } | 615 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 std::string credit_card_guid = | 668 std::string credit_card_guid = |
| 676 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 669 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 677 | 670 |
| 678 return MakeFrontendID(credit_card_guid, std::string()); | 671 return MakeFrontendID(credit_card_guid, std::string()); |
| 679 } | 672 } |
| 680 | 673 |
| 681 void AddSeenForm(std::unique_ptr<FormStructure> form) { | 674 void AddSeenForm(std::unique_ptr<FormStructure> form) { |
| 682 form_structures()->push_back(std::move(form)); | 675 form_structures()->push_back(std::move(form)); |
| 683 } | 676 } |
| 684 | 677 |
| 685 void ClearFormStructures() { | 678 void ClearFormStructures() { form_structures()->clear(); } |
| 686 form_structures()->clear(); | |
| 687 } | |
| 688 | 679 |
| 689 void ResetPaymentsClientForCardUpload(const char* server_id) { | 680 void ResetPaymentsClientForCardUpload(const char* server_id) { |
| 690 TestPaymentsClient* payments_client = | 681 TestPaymentsClient* payments_client = |
| 691 new TestPaymentsClient(context_getter_, this); | 682 new TestPaymentsClient(context_getter_, this); |
| 692 payments_client->server_id_ = server_id; | 683 payments_client->server_id_ = server_id; |
| 693 set_payments_client(payments_client); | 684 set_payments_client(payments_client); |
| 694 } | 685 } |
| 695 | 686 |
| 696 private: | 687 private: |
| 697 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result, | 688 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 request_context_ = new net::TestURLRequestContextGetter( | 849 request_context_ = new net::TestURLRequestContextGetter( |
| 859 base::ThreadTaskRunnerHandle::Get()); | 850 base::ThreadTaskRunnerHandle::Get()); |
| 860 autofill_driver_->SetURLRequestContext(request_context_.get()); | 851 autofill_driver_->SetURLRequestContext(request_context_.get()); |
| 861 autofill_manager_.reset(new TestAutofillManager( | 852 autofill_manager_.reset(new TestAutofillManager( |
| 862 autofill_driver_.get(), &autofill_client_, &personal_data_)); | 853 autofill_driver_.get(), &autofill_client_, &personal_data_)); |
| 863 download_manager_ = new TestAutofillDownloadManager( | 854 download_manager_ = new TestAutofillDownloadManager( |
| 864 autofill_driver_.get(), autofill_manager_.get()); | 855 autofill_driver_.get(), autofill_manager_.get()); |
| 865 // AutofillManager takes ownership of |download_manager_|. | 856 // AutofillManager takes ownership of |download_manager_|. |
| 866 autofill_manager_->set_download_manager(download_manager_); | 857 autofill_manager_->set_download_manager(download_manager_); |
| 867 external_delegate_.reset(new TestAutofillExternalDelegate( | 858 external_delegate_.reset(new TestAutofillExternalDelegate( |
| 868 autofill_manager_.get(), | 859 autofill_manager_.get(), autofill_driver_.get())); |
| 869 autofill_driver_.get())); | |
| 870 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 860 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 871 | 861 |
| 872 // Clear all the things. | 862 // Clear all the things. |
| 873 variations::testing::ClearAllVariationParams(); | 863 variations::testing::ClearAllVariationParams(); |
| 874 } | 864 } |
| 875 | 865 |
| 876 void TearDown() override { | 866 void TearDown() override { |
| 877 // Order of destruction is important as AutofillManager relies on | 867 // Order of destruction is important as AutofillManager relies on |
| 878 // PersonalDataManager to be around when it gets destroyed. | 868 // PersonalDataManager to be around when it gets destroyed. |
| 879 autofill_manager_.reset(); | 869 autofill_manager_.reset(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 (!personal_data_.GetProfiles().empty() || | 905 (!personal_data_.GetProfiles().empty() || |
| 916 !personal_data_.GetCreditCards().empty())) | 906 !personal_data_.GetCreditCards().empty())) |
| 917 autofill_manager_->WaitForAsyncUploadProcess(); | 907 autofill_manager_->WaitForAsyncUploadProcess(); |
| 918 autofill_manager_->OnFormSubmitted(form); | 908 autofill_manager_->OnFormSubmitted(form); |
| 919 } | 909 } |
| 920 | 910 |
| 921 void FillAutofillFormData(int query_id, | 911 void FillAutofillFormData(int query_id, |
| 922 const FormData& form, | 912 const FormData& form, |
| 923 const FormFieldData& field, | 913 const FormFieldData& field, |
| 924 int unique_id) { | 914 int unique_id) { |
| 925 autofill_manager_->FillOrPreviewForm( | 915 autofill_manager_->FillOrPreviewForm(AutofillDriver::FORM_DATA_ACTION_FILL, |
| 926 AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field, | 916 query_id, form, field, unique_id); |
| 927 unique_id); | |
| 928 } | 917 } |
| 929 | 918 |
| 930 // Calls |autofill_manager_->OnFillAutofillFormData()| with the specified | 919 // Calls |autofill_manager_->OnFillAutofillFormData()| with the specified |
| 931 // input parameters after setting up the expectation that the mock driver's | 920 // input parameters after setting up the expectation that the mock driver's |
| 932 // |SendFormDataToRenderer()| method will be called and saving the parameters | 921 // |SendFormDataToRenderer()| method will be called and saving the parameters |
| 933 // of that call into the |response_query_id| and |response_data| output | 922 // of that call into the |response_query_id| and |response_data| output |
| 934 // parameters. | 923 // parameters. |
| 935 void FillAutofillFormDataAndSaveResults(int input_query_id, | 924 void FillAutofillFormDataAndSaveResults(int input_query_id, |
| 936 const FormData& input_form, | 925 const FormData& input_form, |
| 937 const FormFieldData& input_field, | 926 const FormFieldData& input_field, |
| 938 int unique_id, | 927 int unique_id, |
| 939 int* response_query_id, | 928 int* response_query_id, |
| 940 FormData* response_data) { | 929 FormData* response_data) { |
| 941 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)). | 930 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
| 942 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), | 931 .WillOnce((DoAll(testing::SaveArg<0>(response_query_id), |
| 943 testing::SaveArg<2>(response_data)))); | 932 testing::SaveArg<2>(response_data)))); |
| 944 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); | 933 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); |
| 945 } | 934 } |
| 946 | 935 |
| 947 int MakeFrontendID(const std::string& cc_sid, | 936 int MakeFrontendID(const std::string& cc_sid, |
| 948 const std::string& profile_sid) const { | 937 const std::string& profile_sid) const { |
| 949 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); | 938 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); |
| 950 } | 939 } |
| 951 | 940 |
| 952 bool WillFillCreditCardNumber(const FormData& form, | 941 bool WillFillCreditCardNumber(const FormData& form, |
| 953 const FormFieldData& field) { | 942 const FormFieldData& field) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 968 form->origin = GURL("http://myform.com/form.html"); | 957 form->origin = GURL("http://myform.com/form.html"); |
| 969 form->action = GURL("http://myform.com/submit.html"); | 958 form->action = GURL("http://myform.com/submit.html"); |
| 970 } | 959 } |
| 971 | 960 |
| 972 FormFieldData field; | 961 FormFieldData field; |
| 973 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | 962 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 974 form->fields.push_back(field); | 963 form->fields.push_back(field); |
| 975 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 964 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 976 form->fields.push_back(field); | 965 form->fields.push_back(field); |
| 977 if (use_month_type) { | 966 if (use_month_type) { |
| 978 test::CreateTestFormField( | 967 test::CreateTestFormField("Expiration Date", "ccmonth", "", "month", |
| 979 "Expiration Date", "ccmonth", "", "month", &field); | 968 &field); |
| 980 form->fields.push_back(field); | 969 form->fields.push_back(field); |
| 981 } else { | 970 } else { |
| 982 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", | 971 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", |
| 983 &field); | 972 &field); |
| 984 form->fields.push_back(field); | 973 form->fields.push_back(field); |
| 985 test::CreateTestFormField("", "ccyear", "", "text", &field); | 974 test::CreateTestFormField("", "ccyear", "", "text", &field); |
| 986 form->fields.push_back(field); | 975 form->fields.push_back(field); |
| 987 } | 976 } |
| 988 test::CreateTestFormField("CVC", "cvc", "", "text", &field); | 977 test::CreateTestFormField("CVC", "cvc", "", "text", &field); |
| 989 form->fields.push_back(field); | 978 form->fields.push_back(field); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 // This line silences the warning from PaymentsClient about matching sync | 1022 // This line silences the warning from PaymentsClient about matching sync |
| 1034 // and Payments server types. | 1023 // and Payments server types. |
| 1035 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1024 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1036 "sync-url", "https://google.com"); | 1025 "sync-url", "https://google.com"); |
| 1037 | 1026 |
| 1038 CreateTestCreditCardFormData(form, true, false); | 1027 CreateTestCreditCardFormData(form, true, false); |
| 1039 FormsSeen(std::vector<FormData>(1, *form)); | 1028 FormsSeen(std::vector<FormData>(1, *form)); |
| 1040 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); | 1029 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 1041 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", | 1030 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", |
| 1042 "2017"); | 1031 "2017"); |
| 1043 card->SetTypeForMaskedCard(kVisaCard); | 1032 card->SetNetworkForMaskedCard(kVisaCard); |
| 1044 | 1033 |
| 1045 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) | 1034 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
| 1046 .Times(AtLeast(1)); | 1035 .Times(AtLeast(1)); |
| 1047 autofill_manager_->FillOrPreviewCreditCardForm( | 1036 autofill_manager_->FillOrPreviewCreditCardForm( |
| 1048 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | 1037 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, |
| 1049 form->fields[0], *card); | 1038 form->fields[0], *card); |
| 1050 } | 1039 } |
| 1051 | 1040 |
| 1052 // Convenience method for using and retrieving a mock autocomplete history | 1041 // Convenience method for using and retrieving a mock autocomplete history |
| 1053 // manager. | 1042 // manager. |
| 1054 MockAutocompleteHistoryManager* RecreateMockAutocompleteHistoryManager() { | 1043 MockAutocompleteHistoryManager* RecreateMockAutocompleteHistoryManager() { |
| 1055 MockAutocompleteHistoryManager* manager = new | 1044 MockAutocompleteHistoryManager* manager = |
| 1056 MockAutocompleteHistoryManager(autofill_driver_.get(), | 1045 new MockAutocompleteHistoryManager(autofill_driver_.get(), |
| 1057 autofill_manager_->client()); | 1046 autofill_manager_->client()); |
| 1058 autofill_manager_->autocomplete_history_manager_.reset(manager); | 1047 autofill_manager_->autocomplete_history_manager_.reset(manager); |
| 1059 return manager; | 1048 return manager; |
| 1060 } | 1049 } |
| 1061 | 1050 |
| 1062 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. | 1051 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. |
| 1063 CardUnmaskDelegate* full_card_unmask_delegate() { | 1052 CardUnmaskDelegate* full_card_unmask_delegate() { |
| 1064 DCHECK(autofill_manager_->full_card_request_); | 1053 DCHECK(autofill_manager_->full_card_request_); |
| 1065 return static_cast<CardUnmaskDelegate*>( | 1054 return static_cast<CardUnmaskDelegate*>( |
| 1066 autofill_manager_->full_card_request_.get()); | 1055 autofill_manager_->full_card_request_.get()); |
| 1067 } | 1056 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; | 1152 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; |
| 1164 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 1153 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 1165 TestAutofillDownloadManager* download_manager_; | 1154 TestAutofillDownloadManager* download_manager_; |
| 1166 TestPersonalDataManager personal_data_; | 1155 TestPersonalDataManager personal_data_; |
| 1167 base::FieldTrialList field_trial_list_; | 1156 base::FieldTrialList field_trial_list_; |
| 1168 base::test::ScopedFeatureList scoped_feature_list_; | 1157 base::test::ScopedFeatureList scoped_feature_list_; |
| 1169 }; | 1158 }; |
| 1170 | 1159 |
| 1171 class TestFormStructure : public FormStructure { | 1160 class TestFormStructure : public FormStructure { |
| 1172 public: | 1161 public: |
| 1173 explicit TestFormStructure(const FormData& form) | 1162 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} |
| 1174 : FormStructure(form) {} | |
| 1175 ~TestFormStructure() override {} | 1163 ~TestFormStructure() override {} |
| 1176 | 1164 |
| 1177 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, | 1165 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, |
| 1178 const std::vector<ServerFieldType>& server_types) { | 1166 const std::vector<ServerFieldType>& server_types) { |
| 1179 ASSERT_EQ(field_count(), heuristic_types.size()); | 1167 ASSERT_EQ(field_count(), heuristic_types.size()); |
| 1180 ASSERT_EQ(field_count(), server_types.size()); | 1168 ASSERT_EQ(field_count(), server_types.size()); |
| 1181 | 1169 |
| 1182 for (size_t i = 0; i < field_count(); ++i) { | 1170 for (size_t i = 0; i < field_count(); ++i) { |
| 1183 AutofillField* form_field = field(i); | 1171 AutofillField* form_field = field(i); |
| 1184 ASSERT_TRUE(form_field); | 1172 ASSERT_TRUE(form_field); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1197 // reloading a page or when the renderer processes a set of forms but detects | 1185 // reloading a page or when the renderer processes a set of forms but detects |
| 1198 // no changes) does not load the forms again. | 1186 // no changes) does not load the forms again. |
| 1199 TEST_F(AutofillManagerTest, OnFormsSeen_Empty) { | 1187 TEST_F(AutofillManagerTest, OnFormsSeen_Empty) { |
| 1200 // Set up our form data. | 1188 // Set up our form data. |
| 1201 FormData form; | 1189 FormData form; |
| 1202 test::CreateTestAddressFormData(&form); | 1190 test::CreateTestAddressFormData(&form); |
| 1203 std::vector<FormData> forms(1, form); | 1191 std::vector<FormData> forms(1, form); |
| 1204 | 1192 |
| 1205 base::HistogramTester histogram_tester; | 1193 base::HistogramTester histogram_tester; |
| 1206 FormsSeen(forms); | 1194 FormsSeen(forms); |
| 1207 histogram_tester.ExpectUniqueSample( | 1195 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
| 1208 "Autofill.UserHappiness", 0 /* FORMS_LOADED */, 1); | 1196 0 /* FORMS_LOADED */, 1); |
| 1209 | 1197 |
| 1210 // No more forms, metric is not logged. | 1198 // No more forms, metric is not logged. |
| 1211 forms.clear(); | 1199 forms.clear(); |
| 1212 FormsSeen(forms); | 1200 FormsSeen(forms); |
| 1213 histogram_tester.ExpectUniqueSample( | 1201 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
| 1214 "Autofill.UserHappiness", 0 /* FORMS_LOADED */, 1); | 1202 0 /* FORMS_LOADED */, 1); |
| 1215 } | 1203 } |
| 1216 | 1204 |
| 1217 // Test that calling OnFormsSeen consecutively with a different set of forms | 1205 // Test that calling OnFormsSeen consecutively with a different set of forms |
| 1218 // will query for each separately. | 1206 // will query for each separately. |
| 1219 TEST_F(AutofillManagerTest, OnFormsSeen_DifferentFormStructures) { | 1207 TEST_F(AutofillManagerTest, OnFormsSeen_DifferentFormStructures) { |
| 1220 // Set up our form data. | 1208 // Set up our form data. |
| 1221 FormData form; | 1209 FormData form; |
| 1222 test::CreateTestAddressFormData(&form); | 1210 test::CreateTestAddressFormData(&form); |
| 1223 std::vector<FormData> forms(1, form); | 1211 std::vector<FormData> forms(1, form); |
| 1224 | 1212 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 test::CreateTestAddressFormData(&form); | 1415 test::CreateTestAddressFormData(&form); |
| 1428 std::vector<FormData> forms(1, form); | 1416 std::vector<FormData> forms(1, form); |
| 1429 FormsSeen(forms); | 1417 FormsSeen(forms); |
| 1430 | 1418 |
| 1431 FormFieldData field; | 1419 FormFieldData field; |
| 1432 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); | 1420 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); |
| 1433 GetAutofillSuggestions(form, field); | 1421 GetAutofillSuggestions(form, field); |
| 1434 | 1422 |
| 1435 // Test that we sent the right values to the external delegate. | 1423 // Test that we sent the right values to the external delegate. |
| 1436 external_delegate_->CheckSuggestions( | 1424 external_delegate_->CheckSuggestions( |
| 1437 kDefaultPageID, | 1425 kDefaultPageID, Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1)); |
| 1438 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1)); | |
| 1439 } | 1426 } |
| 1440 | 1427 |
| 1441 // Tests that we return address profile suggestions values when the section | 1428 // Tests that we return address profile suggestions values when the section |
| 1442 // is already autofilled, and that we merge identical values. | 1429 // is already autofilled, and that we merge identical values. |
| 1443 TEST_F(AutofillManagerTest, | 1430 TEST_F(AutofillManagerTest, |
| 1444 GetProfileSuggestions_AlreadyAutofilledMergeValues) { | 1431 GetProfileSuggestions_AlreadyAutofilledMergeValues) { |
| 1445 // Set up our form data. | 1432 // Set up our form data. |
| 1446 FormData form; | 1433 FormData form; |
| 1447 test::CreateTestAddressFormData(&form); | 1434 test::CreateTestAddressFormData(&form); |
| 1448 std::vector<FormData> forms(1, form); | 1435 std::vector<FormData> forms(1, form); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 // First name is already autofilled which will make the section appear as | 1491 // First name is already autofilled which will make the section appear as |
| 1505 // "already autofilled". | 1492 // "already autofilled". |
| 1506 form.fields[0].is_autofilled = true; | 1493 form.fields[0].is_autofilled = true; |
| 1507 | 1494 |
| 1508 FormFieldData field; | 1495 FormFieldData field; |
| 1509 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); | 1496 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); |
| 1510 GetAutofillSuggestions(form, field); | 1497 GetAutofillSuggestions(form, field); |
| 1511 | 1498 |
| 1512 // Test that we sent the right values to the external delegate. No labels. | 1499 // Test that we sent the right values to the external delegate. No labels. |
| 1513 external_delegate_->CheckSuggestions( | 1500 external_delegate_->CheckSuggestions( |
| 1514 kDefaultPageID, | 1501 kDefaultPageID, Suggestion("Elvis", "" /* no label */, "", 1)); |
| 1515 Suggestion("Elvis", "" /* no label */, "", 1)); | |
| 1516 } | 1502 } |
| 1517 | 1503 |
| 1518 // Test that we return no suggestions when the form has no relevant fields. | 1504 // Test that we return no suggestions when the form has no relevant fields. |
| 1519 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnknownFields) { | 1505 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnknownFields) { |
| 1520 // Set up our form data. | 1506 // Set up our form data. |
| 1521 FormData form; | 1507 FormData form; |
| 1522 form.name = ASCIIToUTF16("MyForm"); | 1508 form.name = ASCIIToUTF16("MyForm"); |
| 1523 form.origin = GURL("http://myform.com/form.html"); | 1509 form.origin = GURL("http://myform.com/form.html"); |
| 1524 form.action = GURL("http://myform.com/submit.html"); | 1510 form.action = GURL("http://myform.com/submit.html"); |
| 1525 | 1511 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 FormData form; | 1572 FormData form; |
| 1587 CreateTestCreditCardFormData(&form, true, false); | 1573 CreateTestCreditCardFormData(&form, true, false); |
| 1588 std::vector<FormData> forms(1, form); | 1574 std::vector<FormData> forms(1, form); |
| 1589 FormsSeen(forms); | 1575 FormsSeen(forms); |
| 1590 | 1576 |
| 1591 FormFieldData field = form.fields[1]; | 1577 FormFieldData field = form.fields[1]; |
| 1592 GetAutofillSuggestions(form, field); | 1578 GetAutofillSuggestions(form, field); |
| 1593 | 1579 |
| 1594 // Test that we sent the right values to the external delegate. | 1580 // Test that we sent the right values to the external delegate. |
| 1595 external_delegate_->CheckSuggestions( | 1581 external_delegate_->CheckSuggestions( |
| 1596 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1582 kDefaultPageID, |
| 1597 "04/99", kVisaCard, | 1583 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1598 autofill_manager_->GetPackedCreditCardID(4)), | 1584 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1599 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1585 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1600 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1586 "10/98", kMasterCard, |
| 1587 autofill_manager_->GetPackedCreditCardID(5))); |
| 1601 } | 1588 } |
| 1602 | 1589 |
| 1603 // Test that we return all credit card profile suggestions when the triggering | 1590 // Test that we return all credit card profile suggestions when the triggering |
| 1604 // field has whitespace in it. | 1591 // field has whitespace in it. |
| 1605 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { | 1592 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { |
| 1606 // Set up our form data. | 1593 // Set up our form data. |
| 1607 FormData form; | 1594 FormData form; |
| 1608 CreateTestCreditCardFormData(&form, true, false); | 1595 CreateTestCreditCardFormData(&form, true, false); |
| 1609 std::vector<FormData> forms(1, form); | 1596 std::vector<FormData> forms(1, form); |
| 1610 FormsSeen(forms); | 1597 FormsSeen(forms); |
| 1611 | 1598 |
| 1612 FormFieldData field = form.fields[1]; | 1599 FormFieldData field = form.fields[1]; |
| 1613 field.value = ASCIIToUTF16(" "); | 1600 field.value = ASCIIToUTF16(" "); |
| 1614 GetAutofillSuggestions(form, field); | 1601 GetAutofillSuggestions(form, field); |
| 1615 | 1602 |
| 1616 // Test that we sent the right values to the external delegate. | 1603 // Test that we sent the right values to the external delegate. |
| 1617 external_delegate_->CheckSuggestions( | 1604 external_delegate_->CheckSuggestions( |
| 1618 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1605 kDefaultPageID, |
| 1619 "04/99", kVisaCard, | 1606 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1620 autofill_manager_->GetPackedCreditCardID(4)), | 1607 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1621 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1608 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1622 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1609 "10/98", kMasterCard, |
| 1610 autofill_manager_->GetPackedCreditCardID(5))); |
| 1623 } | 1611 } |
| 1624 | 1612 |
| 1625 // Test that we return all credit card profile suggestions when the triggering | 1613 // Test that we return all credit card profile suggestions when the triggering |
| 1626 // field has stop characters in it, which should be removed. | 1614 // field has stop characters in it, which should be removed. |
| 1627 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { | 1615 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { |
| 1628 // Set up our form data. | 1616 // Set up our form data. |
| 1629 FormData form; | 1617 FormData form; |
| 1630 CreateTestCreditCardFormData(&form, true, false); | 1618 CreateTestCreditCardFormData(&form, true, false); |
| 1631 std::vector<FormData> forms(1, form); | 1619 std::vector<FormData> forms(1, form); |
| 1632 FormsSeen(forms); | 1620 FormsSeen(forms); |
| 1633 | 1621 |
| 1634 FormFieldData field = form.fields[1]; | 1622 FormFieldData field = form.fields[1]; |
| 1635 field.value = ASCIIToUTF16("____-____-____-____"); | 1623 field.value = ASCIIToUTF16("____-____-____-____"); |
| 1636 GetAutofillSuggestions(form, field); | 1624 GetAutofillSuggestions(form, field); |
| 1637 | 1625 |
| 1638 // Test that we sent the right values to the external delegate. | 1626 // Test that we sent the right values to the external delegate. |
| 1639 external_delegate_->CheckSuggestions( | 1627 external_delegate_->CheckSuggestions( |
| 1640 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1628 kDefaultPageID, |
| 1641 "04/99", kVisaCard, | 1629 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1642 autofill_manager_->GetPackedCreditCardID(4)), | 1630 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1643 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1631 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1644 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1632 "10/98", kMasterCard, |
| 1633 autofill_manager_->GetPackedCreditCardID(5))); |
| 1645 } | 1634 } |
| 1646 | 1635 |
| 1647 // Test that we return all credit card profile suggestions when the triggering | 1636 // Test that we return all credit card profile suggestions when the triggering |
| 1648 // field has stop characters in it and some input. | 1637 // field has stop characters in it and some input. |
| 1649 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { | 1638 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1650 // Add a credit card with particular numbers that we will attempt to recall. | 1639 // Add a credit card with particular numbers that we will attempt to recall. |
| 1651 CreditCard credit_card; | 1640 CreditCard credit_card; |
| 1652 test::SetCreditCardInfo(&credit_card, "John Smith", | 1641 test::SetCreditCardInfo(&credit_card, "John Smith", |
| 1653 "5255667890123123", // Mastercard | 1642 "5255667890123123", // Mastercard |
| 1654 "08", "2017"); | 1643 "08", "2017"); |
| 1655 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1644 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| 1656 autofill_manager_->AddCreditCard(credit_card); | 1645 autofill_manager_->AddCreditCard(credit_card); |
| 1657 | 1646 |
| 1658 // Set up our form data. | 1647 // Set up our form data. |
| 1659 FormData form; | 1648 FormData form; |
| 1660 CreateTestCreditCardFormData(&form, true, false); | 1649 CreateTestCreditCardFormData(&form, true, false); |
| 1661 std::vector<FormData> forms(1, form); | 1650 std::vector<FormData> forms(1, form); |
| 1662 FormsSeen(forms); | 1651 FormsSeen(forms); |
| 1663 | 1652 |
| 1664 FormFieldData field = form.fields[1]; | 1653 FormFieldData field = form.fields[1]; |
| 1665 | 1654 |
| 1666 field.value = ASCIIToUTF16("5255-66__-____-____"); | 1655 field.value = ASCIIToUTF16("5255-66__-____-____"); |
| 1667 GetAutofillSuggestions(form, field); | 1656 GetAutofillSuggestions(form, field); |
| 1668 | 1657 |
| 1669 // Test that we sent the right value to the external delegate. | 1658 // Test that we sent the right value to the external delegate. |
| 1670 external_delegate_->CheckSuggestions( | 1659 external_delegate_->CheckSuggestions( |
| 1671 kDefaultPageID, Suggestion("MasterCard" + kUTF8MidlineEllipsis + "3123", | 1660 kDefaultPageID, |
| 1672 "08/17", kMasterCard, | 1661 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "3123", |
| 1673 autofill_manager_->GetPackedCreditCardID(7))); | 1662 "08/17", kMasterCard, |
| 1663 autofill_manager_->GetPackedCreditCardID(7))); |
| 1674 } | 1664 } |
| 1675 | 1665 |
| 1676 // Test that we return only matching credit card profile suggestions when the | 1666 // Test that we return only matching credit card profile suggestions when the |
| 1677 // selected form field has been partially filled out. | 1667 // selected form field has been partially filled out. |
| 1678 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) { | 1668 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_MatchCharacter) { |
| 1679 // Set up our form data. | 1669 // Set up our form data. |
| 1680 FormData form; | 1670 FormData form; |
| 1681 CreateTestCreditCardFormData(&form, true, false); | 1671 CreateTestCreditCardFormData(&form, true, false); |
| 1682 std::vector<FormData> forms(1, form); | 1672 std::vector<FormData> forms(1, form); |
| 1683 FormsSeen(forms); | 1673 FormsSeen(forms); |
| 1684 | 1674 |
| 1685 FormFieldData field; | 1675 FormFieldData field; |
| 1686 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 1676 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
| 1687 GetAutofillSuggestions(form, field); | 1677 GetAutofillSuggestions(form, field); |
| 1688 | 1678 |
| 1689 // Test that we sent the right values to the external delegate. | 1679 // Test that we sent the right values to the external delegate. |
| 1690 external_delegate_->CheckSuggestions( | 1680 external_delegate_->CheckSuggestions( |
| 1691 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1681 kDefaultPageID, |
| 1692 "04/99", kVisaCard, | 1682 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1693 autofill_manager_->GetPackedCreditCardID(4))); | 1683 kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
| 1694 } | 1684 } |
| 1695 | 1685 |
| 1696 // Test that we return credit card profile suggestions when the selected form | 1686 // Test that we return credit card profile suggestions when the selected form |
| 1697 // field is not the credit card number field. | 1687 // field is not the credit card number field. |
| 1698 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) { | 1688 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonCCNumber) { |
| 1699 // Set up our form data. | 1689 // Set up our form data. |
| 1700 FormData form; | 1690 FormData form; |
| 1701 CreateTestCreditCardFormData(&form, true, false); | 1691 CreateTestCreditCardFormData(&form, true, false); |
| 1702 std::vector<FormData> forms(1, form); | 1692 std::vector<FormData> forms(1, form); |
| 1703 FormsSeen(forms); | 1693 FormsSeen(forms); |
| 1704 | 1694 |
| 1705 const FormFieldData& field = form.fields[0]; | 1695 const FormFieldData& field = form.fields[0]; |
| 1706 GetAutofillSuggestions(form, field); | 1696 GetAutofillSuggestions(form, field); |
| 1707 | 1697 |
| 1708 #if defined(OS_ANDROID) | 1698 #if defined(OS_ANDROID) |
| 1709 static const std::string kVisaSuggestion = | 1699 static const std::string kVisaSuggestion = |
| 1710 "Visa" + kUTF8MidlineEllipsis + "3456"; | 1700 std::string("Visa") + kUTF8MidlineEllipsis + "3456"; |
| 1711 static const std::string kMcSuggestion = | 1701 static const std::string kMcSuggestion = |
| 1712 "MasterCard" + kUTF8MidlineEllipsis + "8765"; | 1702 std::string("MasterCard") + kUTF8MidlineEllipsis + "8765"; |
| 1713 #else | 1703 #else |
| 1714 static const std::string kVisaSuggestion = "*3456"; | 1704 static const std::string kVisaSuggestion = "*3456"; |
| 1715 static const std::string kMcSuggestion = "*8765"; | 1705 static const std::string kMcSuggestion = "*8765"; |
| 1716 #endif | 1706 #endif |
| 1717 | 1707 |
| 1718 // Test that we sent the right values to the external delegate. | 1708 // Test that we sent the right values to the external delegate. |
| 1719 external_delegate_->CheckSuggestions( | 1709 external_delegate_->CheckSuggestions( |
| 1720 kDefaultPageID, | 1710 kDefaultPageID, |
| 1721 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 1711 Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
| 1722 autofill_manager_->GetPackedCreditCardID(4)), | 1712 autofill_manager_->GetPackedCreditCardID(4)), |
| 1723 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, | 1713 Suggestion("Buddy Holly", kMcSuggestion, kMasterCard, |
| 1724 autofill_manager_->GetPackedCreditCardID(5))); | 1714 autofill_manager_->GetPackedCreditCardID(5))); |
| 1725 } | 1715 } |
| 1726 | 1716 |
| 1727 // Test that we return a warning explaining that credit card profile suggestions | 1717 // Test that we return a warning explaining that credit card profile suggestions |
| 1728 // are unavailable when the page and the form target URL are not secure. | 1718 // are unavailable when the page and the form target URL are not secure. |
| 1729 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonSecureContext) { | 1719 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_NonSecureContext) { |
| 1730 // Set up our form data. | 1720 // Set up our form data. |
| 1731 FormData form; | 1721 FormData form; |
| 1732 CreateTestCreditCardFormData(&form, /* is_https */ false, false); | 1722 CreateTestCreditCardFormData(&form, /* is_https */ false, false); |
| 1733 std::vector<FormData> forms(1, form); | 1723 std::vector<FormData> forms(1, form); |
| 1734 FormsSeen(forms); | 1724 FormsSeen(forms); |
| 1735 | 1725 |
| 1736 const FormFieldData& field = form.fields[0]; | 1726 const FormFieldData& field = form.fields[0]; |
| 1737 GetAutofillSuggestions(form, field); | 1727 GetAutofillSuggestions(form, field); |
| 1738 | 1728 |
| 1739 // Test that we sent the right values to the external delegate. | 1729 // Test that we sent the right values to the external delegate. |
| 1740 external_delegate_->CheckSuggestions( | 1730 external_delegate_->CheckSuggestions( |
| 1741 kDefaultPageID, | 1731 kDefaultPageID, Suggestion(l10n_util::GetStringUTF8( |
| 1742 Suggestion( | 1732 IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1743 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1733 "", "", -1)); |
| 1744 "", "", -1)); | |
| 1745 | 1734 |
| 1746 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1735 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1747 personal_data_.ClearCreditCards(); | 1736 personal_data_.ClearCreditCards(); |
| 1748 GetAutofillSuggestions(form, field); | 1737 GetAutofillSuggestions(form, field); |
| 1749 // Autocomplete suggestions are queried, but not Autofill. | 1738 // Autocomplete suggestions are queried, but not Autofill. |
| 1750 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1739 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1751 } | 1740 } |
| 1752 | 1741 |
| 1753 // Test that we return an extra "Payment not secure" warning when the page and | 1742 // Test that we return an extra "Payment not secure" warning when the page and |
| 1754 // the form target URL are not secure. | 1743 // the form target URL are not secure. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 FormData form; | 1791 FormData form; |
| 1803 CreateTestCreditCardFormData(&form, /* is_https */ true, false); | 1792 CreateTestCreditCardFormData(&form, /* is_https */ true, false); |
| 1804 std::vector<FormData> forms(1, form); | 1793 std::vector<FormData> forms(1, form); |
| 1805 FormsSeen(forms); | 1794 FormsSeen(forms); |
| 1806 | 1795 |
| 1807 FormFieldData field = form.fields[1]; | 1796 FormFieldData field = form.fields[1]; |
| 1808 GetAutofillSuggestions(form, field); | 1797 GetAutofillSuggestions(form, field); |
| 1809 | 1798 |
| 1810 // Test that we sent the right values to the external delegate. | 1799 // Test that we sent the right values to the external delegate. |
| 1811 external_delegate_->CheckSuggestions( | 1800 external_delegate_->CheckSuggestions( |
| 1812 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1801 kDefaultPageID, |
| 1813 "04/99", kVisaCard, | 1802 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1814 autofill_manager_->GetPackedCreditCardID(4)), | 1803 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1815 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1804 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1816 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1805 "10/98", kMasterCard, |
| 1806 autofill_manager_->GetPackedCreditCardID(5))); |
| 1817 } | 1807 } |
| 1818 | 1808 |
| 1819 // Test that we will eventually return the credit card signin promo when there | 1809 // Test that we will eventually return the credit card signin promo when there |
| 1820 // are no credit card suggestions and the promo is active. See the tests in | 1810 // are no credit card suggestions and the promo is active. See the tests in |
| 1821 // AutofillExternalDelegateTest that test whether the promo is added. | 1811 // AutofillExternalDelegateTest that test whether the promo is added. |
| 1822 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { | 1812 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { |
| 1823 personal_data_.ClearCreditCards(); | 1813 personal_data_.ClearCreditCards(); |
| 1824 | 1814 |
| 1825 // Set up our form data. | 1815 // Set up our form data. |
| 1826 FormData form; | 1816 FormData form; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 // Clear the form action. | 1876 // Clear the form action. |
| 1887 form.action = GURL(); | 1877 form.action = GURL(); |
| 1888 std::vector<FormData> forms(1, form); | 1878 std::vector<FormData> forms(1, form); |
| 1889 FormsSeen(forms); | 1879 FormsSeen(forms); |
| 1890 | 1880 |
| 1891 FormFieldData field = form.fields[1]; | 1881 FormFieldData field = form.fields[1]; |
| 1892 GetAutofillSuggestions(form, field); | 1882 GetAutofillSuggestions(form, field); |
| 1893 | 1883 |
| 1894 // Test that we sent the right values to the external delegate. | 1884 // Test that we sent the right values to the external delegate. |
| 1895 external_delegate_->CheckSuggestions( | 1885 external_delegate_->CheckSuggestions( |
| 1896 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1886 kDefaultPageID, |
| 1897 "04/99", kVisaCard, | 1887 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1898 autofill_manager_->GetPackedCreditCardID(4)), | 1888 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1899 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1889 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1900 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1890 "10/98", kMasterCard, |
| 1891 autofill_manager_->GetPackedCreditCardID(5))); |
| 1901 } | 1892 } |
| 1902 | 1893 |
| 1903 // Test that we return credit card suggestions for secure pages that have a | 1894 // Test that we return credit card suggestions for secure pages that have a |
| 1904 // form action set to "javascript:something". | 1895 // form action set to "javascript:something". |
| 1905 TEST_F(AutofillManagerTest, | 1896 TEST_F(AutofillManagerTest, |
| 1906 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) { | 1897 GetCreditCardSuggestions_SecureContext_JavascriptFormAction) { |
| 1907 // Set up our form data. | 1898 // Set up our form data. |
| 1908 FormData form; | 1899 FormData form; |
| 1909 CreateTestCreditCardFormData(&form, true, false); | 1900 CreateTestCreditCardFormData(&form, true, false); |
| 1910 // Have the form action be a javascript function (which is a valid URL). | 1901 // Have the form action be a javascript function (which is a valid URL). |
| 1911 form.action = GURL("javascript:alert('Hello');"); | 1902 form.action = GURL("javascript:alert('Hello');"); |
| 1912 std::vector<FormData> forms(1, form); | 1903 std::vector<FormData> forms(1, form); |
| 1913 FormsSeen(forms); | 1904 FormsSeen(forms); |
| 1914 | 1905 |
| 1915 FormFieldData field = form.fields[1]; | 1906 FormFieldData field = form.fields[1]; |
| 1916 GetAutofillSuggestions(form, field); | 1907 GetAutofillSuggestions(form, field); |
| 1917 | 1908 |
| 1918 // Test that we sent the right values to the external delegate. | 1909 // Test that we sent the right values to the external delegate. |
| 1919 external_delegate_->CheckSuggestions( | 1910 external_delegate_->CheckSuggestions( |
| 1920 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1911 kDefaultPageID, |
| 1921 "04/99", kVisaCard, | 1912 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1922 autofill_manager_->GetPackedCreditCardID(4)), | 1913 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1923 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1914 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1924 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1915 "10/98", kMasterCard, |
| 1916 autofill_manager_->GetPackedCreditCardID(5))); |
| 1925 } | 1917 } |
| 1926 | 1918 |
| 1927 // Test that we return all credit card suggestions in the case that two cards | 1919 // Test that we return all credit card suggestions in the case that two cards |
| 1928 // have the same obfuscated number. | 1920 // have the same obfuscated number. |
| 1929 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1921 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1930 // Add a credit card with the same obfuscated number as Elvis's. | 1922 // Add a credit card with the same obfuscated number as Elvis's. |
| 1931 // |credit_card| will be owned by the mock PersonalDataManager. | 1923 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1932 CreditCard credit_card; | 1924 CreditCard credit_card; |
| 1933 test::SetCreditCardInfo(&credit_card, "Elvis Presley", | 1925 test::SetCreditCardInfo(&credit_card, "Elvis Presley", |
| 1934 "5231567890123456", // Mastercard | 1926 "5231567890123456", // Mastercard |
| 1935 "05", "2999"); | 1927 "05", "2999"); |
| 1936 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1928 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| 1937 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1929 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 1938 autofill_manager_->AddCreditCard(credit_card); | 1930 autofill_manager_->AddCreditCard(credit_card); |
| 1939 | 1931 |
| 1940 // Set up our form data. | 1932 // Set up our form data. |
| 1941 FormData form; | 1933 FormData form; |
| 1942 CreateTestCreditCardFormData(&form, true, false); | 1934 CreateTestCreditCardFormData(&form, true, false); |
| 1943 std::vector<FormData> forms(1, form); | 1935 std::vector<FormData> forms(1, form); |
| 1944 FormsSeen(forms); | 1936 FormsSeen(forms); |
| 1945 | 1937 |
| 1946 FormFieldData field = form.fields[1]; | 1938 FormFieldData field = form.fields[1]; |
| 1947 GetAutofillSuggestions(form, field); | 1939 GetAutofillSuggestions(form, field); |
| 1948 | 1940 |
| 1949 // Test that we sent the right values to the external delegate. | 1941 // Test that we sent the right values to the external delegate. |
| 1950 external_delegate_->CheckSuggestions( | 1942 external_delegate_->CheckSuggestions( |
| 1951 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1943 kDefaultPageID, |
| 1952 "04/99", kVisaCard, | 1944 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1953 autofill_manager_->GetPackedCreditCardID(4)), | 1945 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1954 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1946 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1955 kMasterCard, autofill_manager_->GetPackedCreditCardID(5)), | 1947 "10/98", kMasterCard, |
| 1956 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "3456", "05/99", | 1948 autofill_manager_->GetPackedCreditCardID(5)), |
| 1957 kMasterCard, autofill_manager_->GetPackedCreditCardID(7))); | 1949 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "3456", |
| 1950 "05/99", kMasterCard, |
| 1951 autofill_manager_->GetPackedCreditCardID(7))); |
| 1958 } | 1952 } |
| 1959 | 1953 |
| 1960 // Test that we return profile and credit card suggestions for combined forms. | 1954 // Test that we return profile and credit card suggestions for combined forms. |
| 1961 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1955 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1962 // Set up our form data. | 1956 // Set up our form data. |
| 1963 FormData form; | 1957 FormData form; |
| 1964 test::CreateTestAddressFormData(&form); | 1958 test::CreateTestAddressFormData(&form); |
| 1965 CreateTestCreditCardFormData(&form, true, false); | 1959 CreateTestCreditCardFormData(&form, true, false); |
| 1966 std::vector<FormData> forms(1, form); | 1960 std::vector<FormData> forms(1, form); |
| 1967 FormsSeen(forms); | 1961 FormsSeen(forms); |
| 1968 | 1962 |
| 1969 FormFieldData field = form.fields[0]; | 1963 FormFieldData field = form.fields[0]; |
| 1970 GetAutofillSuggestions(form, field); | 1964 GetAutofillSuggestions(form, field); |
| 1971 | 1965 |
| 1972 // Test that we sent the right address suggestions to the external delegate. | 1966 // Test that we sent the right address suggestions to the external delegate. |
| 1973 external_delegate_->CheckSuggestions( | 1967 external_delegate_->CheckSuggestions( |
| 1974 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1968 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1975 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1969 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1976 | 1970 |
| 1977 const int kPageID2 = 2; | 1971 const int kPageID2 = 2; |
| 1978 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 1972 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 1979 GetAutofillSuggestions(kPageID2, form, field); | 1973 GetAutofillSuggestions(kPageID2, form, field); |
| 1980 | 1974 |
| 1981 // Test that we sent the credit card suggestions to the external delegate. | 1975 // Test that we sent the credit card suggestions to the external delegate. |
| 1982 external_delegate_->CheckSuggestions( | 1976 external_delegate_->CheckSuggestions( |
| 1983 kPageID2, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 1977 kPageID2, |
| 1984 "04/99", kVisaCard, | 1978 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 1985 autofill_manager_->GetPackedCreditCardID(4)), | 1979 kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
| 1986 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1980 Suggestion(std::string("MasterCard") + kUTF8MidlineEllipsis + "8765", |
| 1987 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1981 "10/98", kMasterCard, |
| 1982 autofill_manager_->GetPackedCreditCardID(5))); |
| 1988 } | 1983 } |
| 1989 | 1984 |
| 1990 // Test that for non-https forms with both address and credit card fields, we | 1985 // Test that for non-https forms with both address and credit card fields, we |
| 1991 // only return address suggestions. Instead of credit card suggestions, we | 1986 // only return address suggestions. Instead of credit card suggestions, we |
| 1992 // should return a warning explaining that credit card profile suggestions are | 1987 // should return a warning explaining that credit card profile suggestions are |
| 1993 // unavailable when the form is not https. | 1988 // unavailable when the form is not https. |
| 1994 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1989 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1995 // Set up our form data. | 1990 // Set up our form data. |
| 1996 FormData form; | 1991 FormData form; |
| 1997 test::CreateTestAddressFormData(&form); | 1992 test::CreateTestAddressFormData(&form); |
| 1998 CreateTestCreditCardFormData(&form, false, false); | 1993 CreateTestCreditCardFormData(&form, false, false); |
| 1999 std::vector<FormData> forms(1, form); | 1994 std::vector<FormData> forms(1, form); |
| 2000 FormsSeen(forms); | 1995 FormsSeen(forms); |
| 2001 | 1996 |
| 2002 FormFieldData field = form.fields[0]; | 1997 FormFieldData field = form.fields[0]; |
| 2003 GetAutofillSuggestions(form, field); | 1998 GetAutofillSuggestions(form, field); |
| 2004 | 1999 |
| 2005 // Test that we sent the right suggestions to the external delegate. | 2000 // Test that we sent the right suggestions to the external delegate. |
| 2006 external_delegate_->CheckSuggestions( | 2001 external_delegate_->CheckSuggestions( |
| 2007 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 2002 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 2008 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 2003 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 2009 | 2004 |
| 2010 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 2005 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 2011 const int kPageID2 = 2; | 2006 const int kPageID2 = 2; |
| 2012 GetAutofillSuggestions(kPageID2, form, field); | 2007 GetAutofillSuggestions(kPageID2, form, field); |
| 2013 | 2008 |
| 2014 // Test that we sent the right values to the external delegate. | 2009 // Test that we sent the right values to the external delegate. |
| 2015 external_delegate_->CheckSuggestions( | 2010 external_delegate_->CheckSuggestions( |
| 2016 kPageID2, | 2011 kPageID2, Suggestion(l10n_util::GetStringUTF8( |
| 2017 Suggestion( | 2012 IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 2018 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 2013 "", "", -1)); |
| 2019 "", "", -1)); | |
| 2020 | 2014 |
| 2021 // Clear the test credit cards and try again -- we shouldn't return a warning. | 2015 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 2022 personal_data_.ClearCreditCards(); | 2016 personal_data_.ClearCreditCards(); |
| 2023 GetAutofillSuggestions(form, field); | 2017 GetAutofillSuggestions(form, field); |
| 2024 external_delegate_->CheckNoSuggestions(kDefaultPageID); | 2018 external_delegate_->CheckNoSuggestions(kDefaultPageID); |
| 2025 } | 2019 } |
| 2026 | 2020 |
| 2027 // Test that we return autocomplete-like suggestions when trying to autofill | 2021 // Test that we return autocomplete-like suggestions when trying to autofill |
| 2028 // already filled forms. | 2022 // already filled forms. |
| 2029 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { | 2023 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2059 GetAutofillSuggestions(form, field); | 2053 GetAutofillSuggestions(form, field); |
| 2060 | 2054 |
| 2061 // Add some Autocomplete suggestions. | 2055 // Add some Autocomplete suggestions. |
| 2062 // This triggers the combined message send. | 2056 // This triggers the combined message send. |
| 2063 std::vector<base::string16> suggestions; | 2057 std::vector<base::string16> suggestions; |
| 2064 suggestions.push_back(ASCIIToUTF16("one")); | 2058 suggestions.push_back(ASCIIToUTF16("one")); |
| 2065 suggestions.push_back(ASCIIToUTF16("two")); | 2059 suggestions.push_back(ASCIIToUTF16("two")); |
| 2066 AutocompleteSuggestionsReturned(suggestions); | 2060 AutocompleteSuggestionsReturned(suggestions); |
| 2067 | 2061 |
| 2068 // Test that we sent the right values to the external delegate. | 2062 // Test that we sent the right values to the external delegate. |
| 2069 external_delegate_->CheckSuggestions( | 2063 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 2070 kDefaultPageID, | 2064 Suggestion("one", "", "", 0), |
| 2071 Suggestion("one", "", "", 0), | 2065 Suggestion("two", "", "", 0)); |
| 2072 Suggestion("two", "", "", 0)); | |
| 2073 } | 2066 } |
| 2074 | 2067 |
| 2075 // Test that we do not return duplicate values drawn from multiple profiles when | 2068 // Test that we do not return duplicate values drawn from multiple profiles when |
| 2076 // filling an already filled field. | 2069 // filling an already filled field. |
| 2077 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 2070 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
| 2078 // Set up our form data. | 2071 // Set up our form data. |
| 2079 FormData form; | 2072 FormData form; |
| 2080 test::CreateTestAddressFormData(&form); | 2073 test::CreateTestAddressFormData(&form); |
| 2081 std::vector<FormData> forms(1, form); | 2074 std::vector<FormData> forms(1, form); |
| 2082 FormsSeen(forms); | 2075 FormsSeen(forms); |
| 2083 | 2076 |
| 2084 // |profile| will be owned by the mock PersonalDataManager. | 2077 // |profile| will be owned by the mock PersonalDataManager. |
| 2085 std::unique_ptr<AutofillProfile> profile = | 2078 std::unique_ptr<AutofillProfile> profile = |
| 2086 base::MakeUnique<AutofillProfile>(); | 2079 base::MakeUnique<AutofillProfile>(); |
| 2087 test::SetProfileInfo(profile.get(), "Elvis", "", "", "", "", "", "", "", "", | 2080 test::SetProfileInfo(profile.get(), "Elvis", "", "", "", "", "", "", "", "", |
| 2088 "", "", ""); | 2081 "", "", ""); |
| 2089 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 2082 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 2090 autofill_manager_->AddProfile(std::move(profile)); | 2083 autofill_manager_->AddProfile(std::move(profile)); |
| 2091 | 2084 |
| 2092 FormFieldData& field = form.fields[0]; | 2085 FormFieldData& field = form.fields[0]; |
| 2093 field.is_autofilled = true; | 2086 field.is_autofilled = true; |
| 2094 field.value = ASCIIToUTF16("Elvis"); | 2087 field.value = ASCIIToUTF16("Elvis"); |
| 2095 GetAutofillSuggestions(form, field); | 2088 GetAutofillSuggestions(form, field); |
| 2096 | 2089 |
| 2097 // Test that we sent the right values to the external delegate. | 2090 // Test that we sent the right values to the external delegate. |
| 2098 external_delegate_->CheckSuggestions( | 2091 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 2099 kDefaultPageID, | 2092 Suggestion("Elvis", "", "", 1)); |
| 2100 Suggestion("Elvis", "", "", 1)); | |
| 2101 } | 2093 } |
| 2102 | 2094 |
| 2103 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { | 2095 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { |
| 2104 // Set up our form data. | 2096 // Set up our form data. |
| 2105 FormData form; | 2097 FormData form; |
| 2106 test::CreateTestAddressFormData(&form); | 2098 test::CreateTestAddressFormData(&form); |
| 2107 std::vector<FormData> forms(1, form); | 2099 std::vector<FormData> forms(1, form); |
| 2108 FormsSeen(forms); | 2100 FormsSeen(forms); |
| 2109 | 2101 |
| 2110 std::unique_ptr<AutofillProfile> profile = | 2102 std::unique_ptr<AutofillProfile> profile = |
| 2111 base::MakeUnique<AutofillProfile>(); | 2103 base::MakeUnique<AutofillProfile>(); |
| 2112 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 2104 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 2113 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), | 2105 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 2114 "en-US"); | 2106 "en-US"); |
| 2115 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 2107 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800PRAIRIE")); |
| 2116 ASCIIToUTF16("1800PRAIRIE")); | |
| 2117 autofill_manager_->AddProfile(std::move(profile)); | 2108 autofill_manager_->AddProfile(std::move(profile)); |
| 2118 | 2109 |
| 2119 const FormFieldData& field = form.fields[9]; | 2110 const FormFieldData& field = form.fields[9]; |
| 2120 GetAutofillSuggestions(form, field); | 2111 GetAutofillSuggestions(form, field); |
| 2121 | 2112 |
| 2122 // Test that we sent the right values to the external delegate. Inferred | 2113 // Test that we sent the right values to the external delegate. Inferred |
| 2123 // labels include the most private field of those that would be filled. | 2114 // labels include the most private field of those that would be filled. |
| 2124 external_delegate_->CheckSuggestions( | 2115 external_delegate_->CheckSuggestions( |
| 2125 kDefaultPageID, | 2116 kDefaultPageID, |
| 2126 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE | 2117 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2141 size_t max_length; | 2132 size_t max_length; |
| 2142 const char* const autocomplete_attribute; | 2133 const char* const autocomplete_attribute; |
| 2143 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, | 2134 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, |
| 2144 {"area code", "area_code", 3, "tel-area-code"}, | 2135 {"area code", "area_code", 3, "tel-area-code"}, |
| 2145 {"phone", "phone_prefix", 3, "tel-local-prefix"}, | 2136 {"phone", "phone_prefix", 3, "tel-local-prefix"}, |
| 2146 {"-", "phone_suffix", 4, "tel-local-suffix"}, | 2137 {"-", "phone_suffix", 4, "tel-local-suffix"}, |
| 2147 {"Phone Extension", "ext", 5, "tel-extension"}}; | 2138 {"Phone Extension", "ext", 5, "tel-extension"}}; |
| 2148 | 2139 |
| 2149 FormFieldData field; | 2140 FormFieldData field; |
| 2150 for (const auto& test_field : test_fields) { | 2141 for (const auto& test_field : test_fields) { |
| 2151 test::CreateTestFormField( | 2142 test::CreateTestFormField(test_field.label, test_field.name, "", "text", |
| 2152 test_field.label, test_field.name, "", "text", &field); | 2143 &field); |
| 2153 field.max_length = test_field.max_length; | 2144 field.max_length = test_field.max_length; |
| 2154 field.autocomplete_attribute = std::string(); | 2145 field.autocomplete_attribute = std::string(); |
| 2155 form.fields.push_back(field); | 2146 form.fields.push_back(field); |
| 2156 } | 2147 } |
| 2157 | 2148 |
| 2158 std::vector<FormData> forms(1, form); | 2149 std::vector<FormData> forms(1, form); |
| 2159 FormsSeen(forms); | 2150 FormsSeen(forms); |
| 2160 | 2151 |
| 2161 std::unique_ptr<AutofillProfile> profile = | 2152 std::unique_ptr<AutofillProfile> profile = |
| 2162 base::MakeUnique<AutofillProfile>(); | 2153 base::MakeUnique<AutofillProfile>(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2251 CreateTestCreditCardFormData(&form, true, false); | 2242 CreateTestCreditCardFormData(&form, true, false); |
| 2252 std::vector<FormData> forms(1, form); | 2243 std::vector<FormData> forms(1, form); |
| 2253 FormsSeen(forms); | 2244 FormsSeen(forms); |
| 2254 | 2245 |
| 2255 const char guid[] = "00000000-0000-0000-0000-000000000004"; | 2246 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 2256 int response_page_id = 0; | 2247 int response_page_id = 0; |
| 2257 FormData response_data; | 2248 FormData response_data; |
| 2258 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2249 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2259 MakeFrontendID(guid, std::string()), | 2250 MakeFrontendID(guid, std::string()), |
| 2260 &response_page_id, &response_data); | 2251 &response_page_id, &response_data); |
| 2261 ExpectFilledCreditCardFormElvis( | 2252 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 2262 response_page_id, response_data, kDefaultPageID, false); | 2253 kDefaultPageID, false); |
| 2263 } | 2254 } |
| 2264 | 2255 |
| 2265 // Test that whitespace is stripped from the credit card number. | 2256 // Test that whitespace is stripped from the credit card number. |
| 2266 TEST_F(AutofillManagerTest, FillCreditCardForm_StripCardNumberWhitespace) { | 2257 TEST_F(AutofillManagerTest, FillCreditCardForm_StripCardNumberWhitespace) { |
| 2267 // Same as the SetUp(), but generate Elvis card with whitespace in credit | 2258 // Same as the SetUp(), but generate Elvis card with whitespace in credit |
| 2268 // card number. | 2259 // card number. |
| 2269 personal_data_.CreateTestCreditCardWithWhitespace(); | 2260 personal_data_.CreateTestCreditCardWithWhitespace(); |
| 2270 // Set up our form data. | 2261 // Set up our form data. |
| 2271 FormData form; | 2262 FormData form; |
| 2272 CreateTestCreditCardFormData(&form, true, false); | 2263 CreateTestCreditCardFormData(&form, true, false); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 std::vector<FormData> forms(1, form); | 2307 std::vector<FormData> forms(1, form); |
| 2317 FormsSeen(forms); | 2308 FormsSeen(forms); |
| 2318 | 2309 |
| 2319 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2310 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 2320 int response_page_id = 0; | 2311 int response_page_id = 0; |
| 2321 FormData response_data; | 2312 FormData response_data; |
| 2322 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2313 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2323 MakeFrontendID(guid, std::string()), | 2314 MakeFrontendID(guid, std::string()), |
| 2324 &response_page_id, &response_data); | 2315 &response_page_id, &response_data); |
| 2325 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 2316 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2326 kDefaultPageID, false, "", ""); | 2317 kDefaultPageID, false, "", ""); |
| 2327 } | 2318 } |
| 2328 | 2319 |
| 2329 | |
| 2330 // Test that we correctly fill a credit card form with month input type. | 2320 // Test that we correctly fill a credit card form with month input type. |
| 2331 // 2. year empty, month non-empty | 2321 // 2. year empty, month non-empty |
| 2332 TEST_F(AutofillManagerTest, FillCreditCardForm_NoYearMonth) { | 2322 TEST_F(AutofillManagerTest, FillCreditCardForm_NoYearMonth) { |
| 2333 // Same as the SetUp(), but generate 4 credit cards with year month | 2323 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2334 // combination. | 2324 // combination. |
| 2335 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); | 2325 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); |
| 2336 // Set up our form data. | 2326 // Set up our form data. |
| 2337 FormData form; | 2327 FormData form; |
| 2338 CreateTestCreditCardFormData(&form, true, true); | 2328 CreateTestCreditCardFormData(&form, true, true); |
| 2339 std::vector<FormData> forms(1, form); | 2329 std::vector<FormData> forms(1, form); |
| 2340 FormsSeen(forms); | 2330 FormsSeen(forms); |
| 2341 | 2331 |
| 2342 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2332 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 2343 int response_page_id = 0; | 2333 int response_page_id = 0; |
| 2344 FormData response_data; | 2334 FormData response_data; |
| 2345 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2335 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2346 MakeFrontendID(guid, std::string()), | 2336 MakeFrontendID(guid, std::string()), |
| 2347 &response_page_id, &response_data); | 2337 &response_page_id, &response_data); |
| 2348 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 2338 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2349 kDefaultPageID, false, "", "04"); | 2339 kDefaultPageID, false, "", "04"); |
| 2350 } | 2340 } |
| 2351 | 2341 |
| 2352 // Test that we correctly fill a credit card form with month input type. | 2342 // Test that we correctly fill a credit card form with month input type. |
| 2353 // 3. year non-empty, month empty | 2343 // 3. year non-empty, month empty |
| 2354 TEST_F(AutofillManagerTest, FillCreditCardForm_YearNoMonth) { | 2344 TEST_F(AutofillManagerTest, FillCreditCardForm_YearNoMonth) { |
| 2355 // Same as the SetUp(), but generate 4 credit cards with year month | 2345 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2356 // combination. | 2346 // combination. |
| 2357 personal_data_.CreateTestCreditCardsYearAndMonth("2999", ""); | 2347 personal_data_.CreateTestCreditCardsYearAndMonth("2999", ""); |
| 2358 // Set up our form data. | 2348 // Set up our form data. |
| 2359 FormData form; | 2349 FormData form; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 | 2443 |
| 2454 // Now fill the credit card data. | 2444 // Now fill the credit card data. |
| 2455 const int kPageID2 = 2; | 2445 const int kPageID2 = 2; |
| 2456 const char guid2[] = "00000000-0000-0000-0000-000000000004"; | 2446 const char guid2[] = "00000000-0000-0000-0000-000000000004"; |
| 2457 response_page_id = 0; | 2447 response_page_id = 0; |
| 2458 { | 2448 { |
| 2459 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 2449 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 2460 MakeFrontendID(guid2, std::string()), | 2450 MakeFrontendID(guid2, std::string()), |
| 2461 &response_page_id, &response_data); | 2451 &response_page_id, &response_data); |
| 2462 SCOPED_TRACE("Credit card"); | 2452 SCOPED_TRACE("Credit card"); |
| 2463 ExpectFilledCreditCardFormElvis( | 2453 ExpectFilledCreditCardFormElvis(response_page_id, response_data, kPageID2, |
| 2464 response_page_id, response_data, kPageID2, true); | 2454 true); |
| 2465 } | 2455 } |
| 2466 } | 2456 } |
| 2467 | 2457 |
| 2468 // Test that a field with an unrecognized autocomplete attribute is not filled. | 2458 // Test that a field with an unrecognized autocomplete attribute is not filled. |
| 2469 TEST_F(AutofillManagerTest, FillAddressForm_UnrecognizedAttribute) { | 2459 TEST_F(AutofillManagerTest, FillAddressForm_UnrecognizedAttribute) { |
| 2470 FormData address_form; | 2460 FormData address_form; |
| 2471 address_form.name = ASCIIToUTF16("MyForm"); | 2461 address_form.name = ASCIIToUTF16("MyForm"); |
| 2472 address_form.origin = GURL("https://myform.com/form.html"); | 2462 address_form.origin = GURL("https://myform.com/form.html"); |
| 2473 address_form.action = GURL("https://myform.com/submit.html"); | 2463 address_form.action = GURL("https://myform.com/submit.html"); |
| 2474 FormFieldData field; | 2464 FormFieldData field; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2767 FormData response_data; | 2757 FormData response_data; |
| 2768 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2758 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2769 MakeFrontendID(std::string(), guid), | 2759 MakeFrontendID(std::string(), guid), |
| 2770 &response_page_id, &response_data); | 2760 &response_page_id, &response_data); |
| 2771 | 2761 |
| 2772 // The whole form should be filled as all the fields belong to the same | 2762 // The whole form should be filled as all the fields belong to the same |
| 2773 // logical section. | 2763 // logical section. |
| 2774 ASSERT_EQ(6U, response_data.fields.size()); | 2764 ASSERT_EQ(6U, response_data.fields.size()); |
| 2775 ExpectFilledField("First Name", "firstname", "Elvis", "text", | 2765 ExpectFilledField("First Name", "firstname", "Elvis", "text", |
| 2776 response_data.fields[0]); | 2766 response_data.fields[0]); |
| 2777 ExpectFilledField("", "lastname", "Presley", "text", | 2767 ExpectFilledField("", "lastname", "Presley", "text", response_data.fields[1]); |
| 2778 response_data.fields[1]); | |
| 2779 ExpectFilledField("", "email", "theking@gmail.com", "text", | 2768 ExpectFilledField("", "email", "theking@gmail.com", "text", |
| 2780 response_data.fields[2]); | 2769 response_data.fields[2]); |
| 2781 ExpectFilledField("Phone Number", "phonenumber", "12345678901", "tel", | 2770 ExpectFilledField("Phone Number", "phonenumber", "12345678901", "tel", |
| 2782 response_data.fields[3]); | 2771 response_data.fields[3]); |
| 2783 ExpectFilledField("", "email_", "theking@gmail.com", "text", | 2772 ExpectFilledField("", "email_", "theking@gmail.com", "text", |
| 2784 response_data.fields[4]); | 2773 response_data.fields[4]); |
| 2785 ExpectFilledField("Country", "country", "United States", "text", | 2774 ExpectFilledField("Country", "country", "United States", "text", |
| 2786 response_data.fields[5]); | 2775 response_data.fields[5]); |
| 2787 } | 2776 } |
| 2788 | 2777 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2804 // Fill the first section. | 2793 // Fill the first section. |
| 2805 const char guid[] = "00000000-0000-0000-0000-000000000001"; | 2794 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 2806 int response_page_id = 0; | 2795 int response_page_id = 0; |
| 2807 FormData response_data; | 2796 FormData response_data; |
| 2808 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2797 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2809 MakeFrontendID(std::string(), guid), | 2798 MakeFrontendID(std::string(), guid), |
| 2810 &response_page_id, &response_data); | 2799 &response_page_id, &response_data); |
| 2811 { | 2800 { |
| 2812 SCOPED_TRACE("Address 1"); | 2801 SCOPED_TRACE("Address 1"); |
| 2813 // The second address section should be empty. | 2802 // The second address section should be empty. |
| 2814 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); | 2803 ASSERT_EQ(response_data.fields.size(), 2 * kAddressFormSize); |
| 2815 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 2804 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
| 2816 EXPECT_EQ(base::string16(), response_data.fields[i].value); | 2805 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 2817 } | 2806 } |
| 2818 | 2807 |
| 2819 // The first address section should be filled with Elvis's data. | 2808 // The first address section should be filled with Elvis's data. |
| 2820 response_data.fields.resize(kAddressFormSize); | 2809 response_data.fields.resize(kAddressFormSize); |
| 2821 ExpectFilledAddressFormElvis(response_page_id, response_data, | 2810 ExpectFilledAddressFormElvis(response_page_id, response_data, |
| 2822 kDefaultPageID, false); | 2811 kDefaultPageID, false); |
| 2823 } | 2812 } |
| 2824 | 2813 |
| 2825 // Fill the second section, with the initiating field somewhere in the middle | 2814 // Fill the second section, with the initiating field somewhere in the middle |
| 2826 // of the section. | 2815 // of the section. |
| 2827 const int kPageID2 = 2; | 2816 const int kPageID2 = 2; |
| 2828 const char guid2[] = "00000000-0000-0000-0000-000000000001"; | 2817 const char guid2[] = "00000000-0000-0000-0000-000000000001"; |
| 2829 ASSERT_LT(9U, kAddressFormSize); | 2818 ASSERT_LT(9U, kAddressFormSize); |
| 2830 response_page_id = 0; | 2819 response_page_id = 0; |
| 2831 FillAutofillFormDataAndSaveResults( | 2820 FillAutofillFormDataAndSaveResults( |
| 2832 kPageID2, form, form.fields[kAddressFormSize + 9], | 2821 kPageID2, form, form.fields[kAddressFormSize + 9], |
| 2833 MakeFrontendID(std::string(), guid2), &response_page_id, &response_data); | 2822 MakeFrontendID(std::string(), guid2), &response_page_id, &response_data); |
| 2834 { | 2823 { |
| 2835 SCOPED_TRACE("Address 2"); | 2824 SCOPED_TRACE("Address 2"); |
| 2836 ASSERT_EQ(response_data.fields.size(), form.fields.size()); | 2825 ASSERT_EQ(response_data.fields.size(), form.fields.size()); |
| 2837 | 2826 |
| 2838 // The first address section should be empty. | 2827 // The first address section should be empty. |
| 2839 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); | 2828 ASSERT_EQ(response_data.fields.size(), 2 * kAddressFormSize); |
| 2840 for (size_t i = 0; i < kAddressFormSize; ++i) { | 2829 for (size_t i = 0; i < kAddressFormSize; ++i) { |
| 2841 EXPECT_EQ(base::string16(), response_data.fields[i].value); | 2830 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 2842 } | 2831 } |
| 2843 | 2832 |
| 2844 // The second address section should be filled with Elvis's data. | 2833 // The second address section should be filled with Elvis's data. |
| 2845 FormData secondSection = response_data; | 2834 FormData secondSection = response_data; |
| 2846 secondSection.fields.erase(secondSection.fields.begin(), | 2835 secondSection.fields.erase(secondSection.fields.begin(), |
| 2847 secondSection.fields.begin() + kAddressFormSize); | 2836 secondSection.fields.begin() + kAddressFormSize); |
| 2848 for (size_t i = 0; i < kAddressFormSize; ++i) { | 2837 for (size_t i = 0; i < kAddressFormSize; ++i) { |
| 2849 // Restore the expected field names. | 2838 // Restore the expected field names. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2954 MakeFrontendID(std::string(), guid2), | 2943 MakeFrontendID(std::string(), guid2), |
| 2955 &response_page_id, &response_data); | 2944 &response_page_id, &response_data); |
| 2956 { | 2945 { |
| 2957 SCOPED_TRACE("Billing address"); | 2946 SCOPED_TRACE("Billing address"); |
| 2958 EXPECT_EQ(kPageID2, response_page_id); | 2947 EXPECT_EQ(kPageID2, response_page_id); |
| 2959 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); | 2948 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 2960 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); | 2949 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 2961 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); | 2950 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 2962 ASSERT_EQ(11U, response_data.fields.size()); | 2951 ASSERT_EQ(11U, response_data.fields.size()); |
| 2963 | 2952 |
| 2964 ExpectFilledField("", "country", "US", "text", | 2953 ExpectFilledField("", "country", "US", "text", response_data.fields[0]); |
| 2965 response_data.fields[0]); | |
| 2966 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); | 2954 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); |
| 2967 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); | 2955 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); |
| 2968 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", | 2956 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", |
| 2969 response_data.fields[3]); | 2957 response_data.fields[3]); |
| 2970 ExpectFilledField("", "city", "Memphis", "text", response_data.fields[4]); | 2958 ExpectFilledField("", "city", "Memphis", "text", response_data.fields[4]); |
| 2971 ExpectFilledField("", "state", "Tennessee", "text", | 2959 ExpectFilledField("", "state", "Tennessee", "text", |
| 2972 response_data.fields[5]); | 2960 response_data.fields[5]); |
| 2973 ExpectFilledField("", "zip", "38116", "text", response_data.fields[6]); | 2961 ExpectFilledField("", "zip", "38116", "text", response_data.fields[6]); |
| 2974 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); | 2962 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); |
| 2975 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); | 2963 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3066 | 3054 |
| 3067 // Now fill the credit card data. | 3055 // Now fill the credit card data. |
| 3068 const int kPageID2 = 2; | 3056 const int kPageID2 = 2; |
| 3069 const char guid2[] = "00000000-0000-0000-0000-000000000004"; | 3057 const char guid2[] = "00000000-0000-0000-0000-000000000004"; |
| 3070 response_page_id = 0; | 3058 response_page_id = 0; |
| 3071 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 3059 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 3072 MakeFrontendID(guid2, std::string()), | 3060 MakeFrontendID(guid2, std::string()), |
| 3073 &response_page_id, &response_data); | 3061 &response_page_id, &response_data); |
| 3074 { | 3062 { |
| 3075 SCOPED_TRACE("Credit card 1"); | 3063 SCOPED_TRACE("Credit card 1"); |
| 3076 ExpectFilledCreditCardFormElvis( | 3064 ExpectFilledCreditCardFormElvis(response_page_id, response_data, kPageID2, |
| 3077 response_page_id, response_data, kPageID2, true); | 3065 true); |
| 3078 } | 3066 } |
| 3079 | 3067 |
| 3080 // Now set the credit card fields to also be auto-filled, and try again to | 3068 // Now set the credit card fields to also be auto-filled, and try again to |
| 3081 // fill the credit card data | 3069 // fill the credit card data |
| 3082 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); | 3070 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); |
| 3083 iter != form.fields.end(); | 3071 iter != form.fields.end(); ++iter) { |
| 3084 ++iter) { | |
| 3085 iter->is_autofilled = true; | 3072 iter->is_autofilled = true; |
| 3086 } | 3073 } |
| 3087 | 3074 |
| 3088 const int kPageID3 = 3; | 3075 const int kPageID3 = 3; |
| 3089 response_page_id = 0; | 3076 response_page_id = 0; |
| 3090 FillAutofillFormDataAndSaveResults( | 3077 FillAutofillFormDataAndSaveResults( |
| 3091 kPageID3, form, form.fields[form.fields.size() - 2], | 3078 kPageID3, form, form.fields[form.fields.size() - 2], |
| 3092 MakeFrontendID(guid2, std::string()), &response_page_id, &response_data); | 3079 MakeFrontendID(guid2, std::string()), &response_page_id, &response_data); |
| 3093 { | 3080 { |
| 3094 SCOPED_TRACE("Credit card 2"); | 3081 SCOPED_TRACE("Credit card 2"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3109 form_with_us_number_max_length.action = | 3096 form_with_us_number_max_length.action = |
| 3110 GURL("http://myform.com/phone_submit.html"); | 3097 GURL("http://myform.com/phone_submit.html"); |
| 3111 FormData form_with_autocompletetype = form_with_us_number_max_length; | 3098 FormData form_with_autocompletetype = form_with_us_number_max_length; |
| 3112 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm"); | 3099 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm"); |
| 3113 | 3100 |
| 3114 struct { | 3101 struct { |
| 3115 const char* label; | 3102 const char* label; |
| 3116 const char* name; | 3103 const char* name; |
| 3117 size_t max_length; | 3104 size_t max_length; |
| 3118 const char* autocomplete_attribute; | 3105 const char* autocomplete_attribute; |
| 3119 } test_fields[] = { | 3106 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, |
| 3120 { "country code", "country_code", 1, "tel-country-code" }, | 3107 {"area code", "area_code", 3, "tel-area-code"}, |
| 3121 { "area code", "area_code", 3, "tel-area-code" }, | 3108 {"phone", "phone_prefix", 3, "tel-local-prefix"}, |
| 3122 { "phone", "phone_prefix", 3, "tel-local-prefix" }, | 3109 {"-", "phone_suffix", 4, "tel-local-suffix"}, |
| 3123 { "-", "phone_suffix", 4, "tel-local-suffix" }, | 3110 {"Phone Extension", "ext", 3, "tel-extension"}}; |
| 3124 { "Phone Extension", "ext", 3, "tel-extension" } | |
| 3125 }; | |
| 3126 | 3111 |
| 3127 FormFieldData field; | 3112 FormFieldData field; |
| 3128 const size_t default_max_length = field.max_length; | 3113 const size_t default_max_length = field.max_length; |
| 3129 for (const auto& test_field : test_fields) { | 3114 for (const auto& test_field : test_fields) { |
| 3130 test::CreateTestFormField( | 3115 test::CreateTestFormField(test_field.label, test_field.name, "", "text", |
| 3131 test_field.label, test_field.name, "", "text", &field); | 3116 &field); |
| 3132 field.max_length = test_field.max_length; | 3117 field.max_length = test_field.max_length; |
| 3133 field.autocomplete_attribute = std::string(); | 3118 field.autocomplete_attribute = std::string(); |
| 3134 form_with_us_number_max_length.fields.push_back(field); | 3119 form_with_us_number_max_length.fields.push_back(field); |
| 3135 | 3120 |
| 3136 field.max_length = default_max_length; | 3121 field.max_length = default_max_length; |
| 3137 field.autocomplete_attribute = test_field.autocomplete_attribute; | 3122 field.autocomplete_attribute = test_field.autocomplete_attribute; |
| 3138 form_with_autocompletetype.fields.push_back(field); | 3123 form_with_autocompletetype.fields.push_back(field); |
| 3139 } | 3124 } |
| 3140 | 3125 |
| 3141 std::vector<FormData> forms; | 3126 std::vector<FormData> forms; |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3592 signatures.push_back(form_structure->FormSignatureAsStr()); | 3577 signatures.push_back(form_structure->FormSignatureAsStr()); |
| 3593 signatures.push_back(form_structure2->FormSignatureAsStr()); | 3578 signatures.push_back(form_structure2->FormSignatureAsStr()); |
| 3594 | 3579 |
| 3595 base::HistogramTester histogram_tester; | 3580 base::HistogramTester histogram_tester; |
| 3596 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); | 3581 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); |
| 3597 // Verify that FormStructure::ParseQueryResponse was called (here and below). | 3582 // Verify that FormStructure::ParseQueryResponse was called (here and below). |
| 3598 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 3583 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 3599 AutofillMetrics::QUERY_RESPONSE_RECEIVED, | 3584 AutofillMetrics::QUERY_RESPONSE_RECEIVED, |
| 3600 1); | 3585 1); |
| 3601 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 3586 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 3602 AutofillMetrics::QUERY_RESPONSE_PARSED, | 3587 AutofillMetrics::QUERY_RESPONSE_PARSED, 1); |
| 3603 1); | |
| 3604 // We expect the server type to have been applied to the first field of the | 3588 // We expect the server type to have been applied to the first field of the |
| 3605 // first form. | 3589 // first form. |
| 3606 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->Type().GetStorableType()); | 3590 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->Type().GetStorableType()); |
| 3607 | 3591 |
| 3608 // We expect the server types to have been applied to the second form. | 3592 // We expect the server types to have been applied to the second form. |
| 3609 EXPECT_EQ(NAME_LAST, form_structure2->field(0)->Type().GetStorableType()); | 3593 EXPECT_EQ(NAME_LAST, form_structure2->field(0)->Type().GetStorableType()); |
| 3610 EXPECT_EQ(NAME_MIDDLE, form_structure2->field(1)->Type().GetStorableType()); | 3594 EXPECT_EQ(NAME_MIDDLE, form_structure2->field(1)->Type().GetStorableType()); |
| 3611 EXPECT_EQ(ADDRESS_HOME_ZIP, | 3595 EXPECT_EQ(ADDRESS_HOME_ZIP, |
| 3612 form_structure2->field(2)->Type().GetStorableType()); | 3596 form_structure2->field(2)->Type().GetStorableType()); |
| 3613 } | 3597 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3922 {"(234)567-8901", PHONE_HOME_CITY_AND_NUMBER}, | 3906 {"(234)567-8901", PHONE_HOME_CITY_AND_NUMBER}, |
| 3923 {"2345678901", PHONE_HOME_CITY_AND_NUMBER}, | 3907 {"2345678901", PHONE_HOME_CITY_AND_NUMBER}, |
| 3924 {"1", PHONE_HOME_COUNTRY_CODE}, | 3908 {"1", PHONE_HOME_COUNTRY_CODE}, |
| 3925 {"234", PHONE_HOME_CITY_CODE}, | 3909 {"234", PHONE_HOME_CITY_CODE}, |
| 3926 {"5678901", PHONE_HOME_NUMBER}, | 3910 {"5678901", PHONE_HOME_NUMBER}, |
| 3927 {"567", PHONE_HOME_NUMBER}, | 3911 {"567", PHONE_HOME_NUMBER}, |
| 3928 {"8901", PHONE_HOME_NUMBER}, | 3912 {"8901", PHONE_HOME_NUMBER}, |
| 3929 | 3913 |
| 3930 // Test a European profile. | 3914 // Test a European profile. |
| 3931 {"Paris", ADDRESS_HOME_CITY}, | 3915 {"Paris", ADDRESS_HOME_CITY}, |
| 3932 {"ÃŽle de France", ADDRESS_HOME_STATE}, // Exact match | 3916 {"ÃŽle de France", ADDRESS_HOME_STATE}, // Exact match |
| 3933 {"Ile de France", ADDRESS_HOME_STATE}, // Missing accent. | 3917 {"Ile de France", ADDRESS_HOME_STATE}, // Missing accent. |
| 3934 {"-Ile-de-France-", ADDRESS_HOME_STATE}, // Extra punctuation. | 3918 {"-Ile-de-France-", ADDRESS_HOME_STATE}, // Extra punctuation. |
| 3935 {"île dÉ FrÃÑÇË", ADDRESS_HOME_STATE}, // Other accents & case mismatch. | 3919 {"île dÉ FrÃÑÇË", ADDRESS_HOME_STATE}, // Other accents & case mismatch. |
| 3936 {"75008", ADDRESS_HOME_ZIP}, | 3920 {"75008", ADDRESS_HOME_ZIP}, |
| 3937 {"FR", ADDRESS_HOME_COUNTRY}, | 3921 {"FR", ADDRESS_HOME_COUNTRY}, |
| 3938 {"France", ADDRESS_HOME_COUNTRY}, | 3922 {"France", ADDRESS_HOME_COUNTRY}, |
| 3939 {"33249197070", PHONE_HOME_WHOLE_NUMBER}, | 3923 {"33249197070", PHONE_HOME_WHOLE_NUMBER}, |
| 3940 {"+33 2 49 19 70 70", PHONE_HOME_WHOLE_NUMBER}, | 3924 {"+33 2 49 19 70 70", PHONE_HOME_WHOLE_NUMBER}, |
| 3941 {"2 49 19 70 70", PHONE_HOME_CITY_AND_NUMBER}, | 3925 {"2 49 19 70 70", PHONE_HOME_CITY_AND_NUMBER}, |
| 3942 {"249197070", PHONE_HOME_CITY_AND_NUMBER}, | 3926 {"249197070", PHONE_HOME_CITY_AND_NUMBER}, |
| 3943 {"33", PHONE_HOME_COUNTRY_CODE}, | 3927 {"33", PHONE_HOME_COUNTRY_CODE}, |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4519 | 4503 |
| 4520 // Verify whether suggestions are populated correctly for one of the middle | 4504 // Verify whether suggestions are populated correctly for one of the middle |
| 4521 // credit card number fields when filled partially. | 4505 // credit card number fields when filled partially. |
| 4522 FormFieldData number_field = form.fields[3]; | 4506 FormFieldData number_field = form.fields[3]; |
| 4523 number_field.value = ASCIIToUTF16("901"); | 4507 number_field.value = ASCIIToUTF16("901"); |
| 4524 | 4508 |
| 4525 // Get the suggestions for already filled credit card |number_field|. | 4509 // Get the suggestions for already filled credit card |number_field|. |
| 4526 GetAutofillSuggestions(form, number_field); | 4510 GetAutofillSuggestions(form, number_field); |
| 4527 | 4511 |
| 4528 external_delegate_->CheckSuggestions( | 4512 external_delegate_->CheckSuggestions( |
| 4529 kDefaultPageID, Suggestion("Visa" + kUTF8MidlineEllipsis + "3456", | 4513 kDefaultPageID, |
| 4530 "04/99", kVisaCard, | 4514 Suggestion(std::string("Visa") + kUTF8MidlineEllipsis + "3456", "04/99", |
| 4531 autofill_manager_->GetPackedCreditCardID(4))); | 4515 kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
| 4532 } | 4516 } |
| 4533 | 4517 |
| 4534 // Test that inputs detected to be CVC inputs are forced to | 4518 // Test that inputs detected to be CVC inputs are forced to |
| 4535 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. | 4519 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. |
| 4536 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { | 4520 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { |
| 4537 FormData form_seen_by_ahm; | 4521 FormData form_seen_by_ahm; |
| 4538 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); | 4522 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager(); |
| 4539 EXPECT_CALL(*m, OnWillSubmitForm(_)).WillOnce(SaveArg<0>(&form_seen_by_ahm)); | 4523 EXPECT_CALL(*m, OnWillSubmitForm(_)).WillOnce(SaveArg<0>(&form_seen_by_ahm)); |
| 4540 | 4524 |
| 4541 FormData form; | 4525 FormData form; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4702 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4686 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 4703 | 4687 |
| 4704 FormSubmitted(credit_card_form); | 4688 FormSubmitted(credit_card_form); |
| 4705 | 4689 |
| 4706 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4690 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 4707 EXPECT_TRUE(autofill_manager_->GetLocalCreditCards().empty()); | 4691 EXPECT_TRUE(autofill_manager_->GetLocalCreditCards().empty()); |
| 4708 ASSERT_EQ(1U, autofill_manager_->GetCreditCards().size()); | 4692 ASSERT_EQ(1U, autofill_manager_->GetCreditCards().size()); |
| 4709 const CreditCard* const saved_card = autofill_manager_->GetCreditCards()[0]; | 4693 const CreditCard* const saved_card = autofill_manager_->GetCreditCards()[0]; |
| 4710 EXPECT_EQ(CreditCard::OK, saved_card->GetServerStatus()); | 4694 EXPECT_EQ(CreditCard::OK, saved_card->GetServerStatus()); |
| 4711 EXPECT_EQ(base::ASCIIToUTF16("1111"), saved_card->LastFourDigits()); | 4695 EXPECT_EQ(base::ASCIIToUTF16("1111"), saved_card->LastFourDigits()); |
| 4712 EXPECT_EQ(kVisaCard, saved_card->type()); | 4696 EXPECT_EQ(kVisaCard, saved_card->network()); |
| 4713 EXPECT_EQ(11, saved_card->expiration_month()); | 4697 EXPECT_EQ(11, saved_card->expiration_month()); |
| 4714 EXPECT_EQ(2017, saved_card->expiration_year()); | 4698 EXPECT_EQ(2017, saved_card->expiration_year()); |
| 4715 EXPECT_EQ(server_id, saved_card->server_id()); | 4699 EXPECT_EQ(server_id, saved_card->server_id()); |
| 4716 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, saved_card->record_type()); | 4700 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, saved_card->record_type()); |
| 4717 EXPECT_EQ(base::ASCIIToUTF16(card_number), saved_card->number()); | 4701 EXPECT_EQ(base::ASCIIToUTF16(card_number), saved_card->number()); |
| 4718 } | 4702 } |
| 4719 | 4703 |
| 4720 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4704 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4721 #if defined(OS_ANDROID) | 4705 #if defined(OS_ANDROID) |
| 4722 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu
reNotEnabled | 4706 #define MAYBE_UploadCreditCard_FeatureNotEnabled \ |
| 4707 DISABLED_UploadCreditCard_FeatureNotEnabled |
| 4723 #else | 4708 #else |
| 4724 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab
led | 4709 #define MAYBE_UploadCreditCard_FeatureNotEnabled \ |
| 4710 UploadCreditCard_FeatureNotEnabled |
| 4725 #endif | 4711 #endif |
| 4726 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { | 4712 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { |
| 4727 personal_data_.ClearAutofillProfiles(); | 4713 personal_data_.ClearAutofillProfiles(); |
| 4728 autofill_manager_->set_credit_card_upload_enabled(false); | 4714 autofill_manager_->set_credit_card_upload_enabled(false); |
| 4729 | 4715 |
| 4730 // Create, fill and submit an address form in order to establish a recent | 4716 // Create, fill and submit an address form in order to establish a recent |
| 4731 // profile which can be selected for the upload request. | 4717 // profile which can be selected for the upload request. |
| 4732 FormData address_form; | 4718 FormData address_form; |
| 4733 test::CreateTestAddressFormData(&address_form); | 4719 test::CreateTestAddressFormData(&address_form); |
| 4734 FormsSeen(std::vector<FormData>(1, address_form)); | 4720 FormsSeen(std::vector<FormData>(1, address_form)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4753 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); | 4739 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); |
| 4754 FormSubmitted(credit_card_form); | 4740 FormSubmitted(credit_card_form); |
| 4755 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 4741 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
| 4756 | 4742 |
| 4757 // Verify that no histogram entry was logged called. | 4743 // Verify that no histogram entry was logged called. |
| 4758 histogram_tester.ExpectTotalCount("Autofill.CardUploadDecisionExpanded", 0); | 4744 histogram_tester.ExpectTotalCount("Autofill.CardUploadDecisionExpanded", 0); |
| 4759 } | 4745 } |
| 4760 | 4746 |
| 4761 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4747 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4762 #if defined(OS_ANDROID) | 4748 #if defined(OS_ANDROID) |
| 4763 #define MAYBE_UploadCreditCard_CvcUnavailable DISABLED_UploadCreditCard_CvcUnava
ilable | 4749 #define MAYBE_UploadCreditCard_CvcUnavailable \ |
| 4750 DISABLED_UploadCreditCard_CvcUnavailable |
| 4764 #else | 4751 #else |
| 4765 #define MAYBE_UploadCreditCard_CvcUnavailable UploadCreditCard_CvcUnavailable | 4752 #define MAYBE_UploadCreditCard_CvcUnavailable UploadCreditCard_CvcUnavailable |
| 4766 #endif | 4753 #endif |
| 4767 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcUnavailable) { | 4754 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcUnavailable) { |
| 4768 EnableUkmLogging(); | 4755 EnableUkmLogging(); |
| 4769 personal_data_.ClearAutofillProfiles(); | 4756 personal_data_.ClearAutofillProfiles(); |
| 4770 autofill_manager_->set_credit_card_upload_enabled(true); | 4757 autofill_manager_->set_credit_card_upload_enabled(true); |
| 4771 | 4758 |
| 4772 // Create, fill and submit an address form in order to establish a recent | 4759 // Create, fill and submit an address form in order to establish a recent |
| 4773 // profile which can be selected for the upload request. | 4760 // profile which can be selected for the upload request. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4812 std::string sample; | 4799 std::string sample; |
| 4813 rappor::RapporType type; | 4800 rappor::RapporType type; |
| 4814 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 4801 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4815 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); | 4802 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 4816 EXPECT_EQ("myform.com", sample); | 4803 EXPECT_EQ("myform.com", sample); |
| 4817 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4804 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 4818 } | 4805 } |
| 4819 | 4806 |
| 4820 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4807 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4821 #if defined(OS_ANDROID) | 4808 #if defined(OS_ANDROID) |
| 4822 #define MAYBE_UploadCreditCard_CvcInvalidLength DISABLED_UploadCreditCard_CvcInv
alidLength | 4809 #define MAYBE_UploadCreditCard_CvcInvalidLength \ |
| 4810 DISABLED_UploadCreditCard_CvcInvalidLength |
| 4823 #else | 4811 #else |
| 4824 #define MAYBE_UploadCreditCard_CvcInvalidLength UploadCreditCard_CvcInvalidLengt
h | 4812 #define MAYBE_UploadCreditCard_CvcInvalidLength \ |
| 4813 UploadCreditCard_CvcInvalidLength |
| 4825 #endif | 4814 #endif |
| 4826 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcInvalidLength) { | 4815 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcInvalidLength) { |
| 4827 EnableUkmLogging(); | 4816 EnableUkmLogging(); |
| 4828 personal_data_.ClearAutofillProfiles(); | 4817 personal_data_.ClearAutofillProfiles(); |
| 4829 autofill_manager_->set_credit_card_upload_enabled(true); | 4818 autofill_manager_->set_credit_card_upload_enabled(true); |
| 4830 | 4819 |
| 4831 // Create, fill and submit an address form in order to establish a recent | 4820 // Create, fill and submit an address form in order to establish a recent |
| 4832 // profile which can be selected for the upload request. | 4821 // profile which can be selected for the upload request. |
| 4833 FormData address_form; | 4822 FormData address_form; |
| 4834 test::CreateTestAddressFormData(&address_form); | 4823 test::CreateTestAddressFormData(&address_form); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4868 std::string sample; | 4857 std::string sample; |
| 4869 rappor::RapporType type; | 4858 rappor::RapporType type; |
| 4870 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 4859 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4871 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); | 4860 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 4872 EXPECT_EQ("myform.com", sample); | 4861 EXPECT_EQ("myform.com", sample); |
| 4873 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 4862 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 4874 } | 4863 } |
| 4875 | 4864 |
| 4876 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4865 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4877 #if defined(OS_ANDROID) | 4866 #if defined(OS_ANDROID) |
| 4878 #define MAYBE_UploadCreditCard_MultipleCvcFields DISABLED_UploadCreditCard_Multi
pleCvcFields | 4867 #define MAYBE_UploadCreditCard_MultipleCvcFields \ |
| 4868 DISABLED_UploadCreditCard_MultipleCvcFields |
| 4879 #else | 4869 #else |
| 4880 #define MAYBE_UploadCreditCard_MultipleCvcFields UploadCreditCard_MultipleCvcFie
lds | 4870 #define MAYBE_UploadCreditCard_MultipleCvcFields \ |
| 4871 UploadCreditCard_MultipleCvcFields |
| 4881 #endif | 4872 #endif |
| 4882 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_MultipleCvcFields) { | 4873 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_MultipleCvcFields) { |
| 4883 EnableUkmLogging(); | 4874 EnableUkmLogging(); |
| 4884 autofill_manager_->set_credit_card_upload_enabled(true); | 4875 autofill_manager_->set_credit_card_upload_enabled(true); |
| 4885 | 4876 |
| 4886 // Remove the profiles that were created in the TestPersonalDataManager | 4877 // Remove the profiles that were created in the TestPersonalDataManager |
| 4887 // constructor because they would result in conflicting names that would | 4878 // constructor because they would result in conflicting names that would |
| 4888 // prevent the upload. | 4879 // prevent the upload. |
| 4889 personal_data_.ClearAutofillProfiles(); | 4880 personal_data_.ClearAutofillProfiles(); |
| 4890 | 4881 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4927 credit_card_form.fields[5].value = ASCIIToUTF16("123"); | 4918 credit_card_form.fields[5].value = ASCIIToUTF16("123"); |
| 4928 | 4919 |
| 4929 base::HistogramTester histogram_tester; | 4920 base::HistogramTester histogram_tester; |
| 4930 | 4921 |
| 4931 // A CVC value appeared in one of the two CVC fields, upload should happen. | 4922 // A CVC value appeared in one of the two CVC fields, upload should happen. |
| 4932 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4923 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 4933 FormSubmitted(credit_card_form); | 4924 FormSubmitted(credit_card_form); |
| 4934 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4925 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 4935 | 4926 |
| 4936 // Verify that the correct histogram entry (and only that) was logged. | 4927 // Verify that the correct histogram entry (and only that) was logged. |
| 4937 histogram_tester.ExpectUniqueSample( | 4928 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", |
| 4938 "Autofill.CardUploadDecisionExpanded", | 4929 AutofillMetrics::UPLOAD_OFFERED, 1); |
| 4939 AutofillMetrics::UPLOAD_OFFERED, 1); | |
| 4940 // Verify that the correct UKM was logged. | 4930 // Verify that the correct UKM was logged. |
| 4941 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 4931 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 4942 } | 4932 } |
| 4943 | 4933 |
| 4944 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4934 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4945 #if defined(OS_ANDROID) | 4935 #if defined(OS_ANDROID) |
| 4946 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \ | 4936 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \ |
| 4947 DISABLED_UploadCreditCard_NoCvcFieldOnForm | 4937 DISABLED_UploadCreditCard_NoCvcFieldOnForm |
| 4948 #else | 4938 #else |
| 4949 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \ | 4939 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \ |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5075 std::string sample; | 5065 std::string sample; |
| 5076 rappor::RapporType type; | 5066 rappor::RapporType type; |
| 5077 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5067 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5078 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); | 5068 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 5079 EXPECT_EQ("myform.com", sample); | 5069 EXPECT_EQ("myform.com", sample); |
| 5080 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5070 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5081 } | 5071 } |
| 5082 | 5072 |
| 5083 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5073 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5084 #if defined(OS_ANDROID) | 5074 #if defined(OS_ANDROID) |
| 5085 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr
ofileAvailable | 5075 #define MAYBE_UploadCreditCard_NoProfileAvailable \ |
| 5076 DISABLED_UploadCreditCard_NoProfileAvailable |
| 5086 #else | 5077 #else |
| 5087 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai
lable | 5078 #define MAYBE_UploadCreditCard_NoProfileAvailable \ |
| 5079 UploadCreditCard_NoProfileAvailable |
| 5088 #endif | 5080 #endif |
| 5089 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) { | 5081 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) { |
| 5090 EnableUkmLogging(); | 5082 EnableUkmLogging(); |
| 5091 personal_data_.ClearAutofillProfiles(); | 5083 personal_data_.ClearAutofillProfiles(); |
| 5092 autofill_manager_->set_credit_card_upload_enabled(true); | 5084 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5093 | 5085 |
| 5094 // Don't fill or submit an address form. | 5086 // Don't fill or submit an address form. |
| 5095 | 5087 |
| 5096 // Set up our credit card form data. | 5088 // Set up our credit card form data. |
| 5097 FormData credit_card_form; | 5089 FormData credit_card_form; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5125 std::string sample; | 5117 std::string sample; |
| 5126 rappor::RapporType type; | 5118 rappor::RapporType type; |
| 5127 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5119 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5128 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); | 5120 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); |
| 5129 EXPECT_EQ("myform.com", sample); | 5121 EXPECT_EQ("myform.com", sample); |
| 5130 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5122 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5131 } | 5123 } |
| 5132 | 5124 |
| 5133 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5125 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5134 #if defined(OS_ANDROID) | 5126 #if defined(OS_ANDROID) |
| 5135 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable DISABLED_Uplo
adCreditCard_CvcUnavailableAndNoProfileAvailable | 5127 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ |
| 5128 DISABLED_UploadCreditCard_CvcUnavailableAndNoProfileAvailable |
| 5136 #else | 5129 #else |
| 5137 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable UploadCreditC
ard_CvcUnavailableAndNoProfileAvailable | 5130 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ |
| 5131 UploadCreditCard_CvcUnavailableAndNoProfileAvailable |
| 5138 #endif | 5132 #endif |
| 5139 TEST_F(AutofillManagerTest, | 5133 TEST_F(AutofillManagerTest, |
| 5140 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { | 5134 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { |
| 5141 EnableUkmLogging(); | 5135 EnableUkmLogging(); |
| 5142 personal_data_.ClearAutofillProfiles(); | 5136 personal_data_.ClearAutofillProfiles(); |
| 5143 autofill_manager_->set_credit_card_upload_enabled(true); | 5137 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5144 | 5138 |
| 5145 // Don't fill or submit an address form. | 5139 // Don't fill or submit an address form. |
| 5146 | 5140 |
| 5147 // Set up our credit card form data. | 5141 // Set up our credit card form data. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5178 std::string sample; | 5172 std::string sample; |
| 5179 rappor::RapporType type; | 5173 rappor::RapporType type; |
| 5180 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5174 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5181 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); | 5175 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 5182 EXPECT_EQ("myform.com", sample); | 5176 EXPECT_EQ("myform.com", sample); |
| 5183 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5177 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5184 } | 5178 } |
| 5185 | 5179 |
| 5186 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5180 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5187 #if defined(OS_ANDROID) | 5181 #if defined(OS_ANDROID) |
| 5188 #define MAYBE_UploadCreditCard_NoNameAvailable DISABLED_UploadCreditCard_NoNameA
vailable | 5182 #define MAYBE_UploadCreditCard_NoNameAvailable \ |
| 5183 DISABLED_UploadCreditCard_NoNameAvailable |
| 5189 #else | 5184 #else |
| 5190 #define MAYBE_UploadCreditCard_NoNameAvailable UploadCreditCard_NoNameAvailable | 5185 #define MAYBE_UploadCreditCard_NoNameAvailable UploadCreditCard_NoNameAvailable |
| 5191 #endif | 5186 #endif |
| 5192 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoNameAvailable) { | 5187 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoNameAvailable) { |
| 5193 EnableUkmLogging(); | 5188 EnableUkmLogging(); |
| 5194 personal_data_.ClearAutofillProfiles(); | 5189 personal_data_.ClearAutofillProfiles(); |
| 5195 autofill_manager_->set_credit_card_upload_enabled(true); | 5190 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5196 | 5191 |
| 5197 // Create, fill and submit an address form in order to establish a recent | 5192 // Create, fill and submit an address form in order to establish a recent |
| 5198 // profile which can be selected for the upload request. | 5193 // profile which can be selected for the upload request. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5234 std::string sample; | 5229 std::string sample; |
| 5235 rappor::RapporType type; | 5230 rappor::RapporType type; |
| 5236 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5231 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5237 "Autofill.CardUploadNotOfferedNoName", &sample, &type)); | 5232 "Autofill.CardUploadNotOfferedNoName", &sample, &type)); |
| 5238 EXPECT_EQ("myform.com", sample); | 5233 EXPECT_EQ("myform.com", sample); |
| 5239 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5234 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5240 } | 5235 } |
| 5241 | 5236 |
| 5242 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5237 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5243 #if defined(OS_ANDROID) | 5238 #if defined(OS_ANDROID) |
| 5244 #define MAYBE_UploadCreditCard_ZipCodesConflict DISABLED_UploadCreditCard_ZipCod
esConflict | 5239 #define MAYBE_UploadCreditCard_ZipCodesConflict \ |
| 5240 DISABLED_UploadCreditCard_ZipCodesConflict |
| 5245 #else | 5241 #else |
| 5246 #define MAYBE_UploadCreditCard_ZipCodesConflict UploadCreditCard_ZipCodesConflic
t | 5242 #define MAYBE_UploadCreditCard_ZipCodesConflict \ |
| 5243 UploadCreditCard_ZipCodesConflict |
| 5247 #endif | 5244 #endif |
| 5248 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesConflict) { | 5245 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesConflict) { |
| 5249 EnableUkmLogging(); | 5246 EnableUkmLogging(); |
| 5250 personal_data_.ClearAutofillProfiles(); | 5247 personal_data_.ClearAutofillProfiles(); |
| 5251 autofill_manager_->set_credit_card_upload_enabled(true); | 5248 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5252 | 5249 |
| 5253 // Create, fill and submit two address forms with different zip codes. | 5250 // Create, fill and submit two address forms with different zip codes. |
| 5254 FormData address_form1, address_form2; | 5251 FormData address_form1, address_form2; |
| 5255 test::CreateTestAddressFormData(&address_form1); | 5252 test::CreateTestAddressFormData(&address_form1); |
| 5256 test::CreateTestAddressFormData(&address_form2); | 5253 test::CreateTestAddressFormData(&address_form2); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5291 histogram_tester.ExpectUniqueSample( | 5288 histogram_tester.ExpectUniqueSample( |
| 5292 "Autofill.CardUploadDecisionExpanded", | 5289 "Autofill.CardUploadDecisionExpanded", |
| 5293 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS, 1); | 5290 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS, 1); |
| 5294 // Verify that the correct UKM was logged. | 5291 // Verify that the correct UKM was logged. |
| 5295 ExpectCardUploadDecisionUkm( | 5292 ExpectCardUploadDecisionUkm( |
| 5296 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS); | 5293 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS); |
| 5297 } | 5294 } |
| 5298 | 5295 |
| 5299 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5296 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5300 #if defined(OS_ANDROID) | 5297 #if defined(OS_ANDROID) |
| 5301 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch DISABLED_UploadCreditCard
_ZipCodesHavePrefixMatch | 5298 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch \ |
| 5299 DISABLED_UploadCreditCard_ZipCodesHavePrefixMatch |
| 5302 #else | 5300 #else |
| 5303 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch UploadCreditCard_ZipCodes
HavePrefixMatch | 5301 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch \ |
| 5302 UploadCreditCard_ZipCodesHavePrefixMatch |
| 5304 #endif | 5303 #endif |
| 5305 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch) { | 5304 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch) { |
| 5306 EnableUkmLogging(); | 5305 EnableUkmLogging(); |
| 5307 personal_data_.ClearAutofillProfiles(); | 5306 personal_data_.ClearAutofillProfiles(); |
| 5308 autofill_manager_->set_credit_card_upload_enabled(true); | 5307 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5309 | 5308 |
| 5310 // Create, fill and submit two address forms with different zip codes. | 5309 // Create, fill and submit two address forms with different zip codes. |
| 5311 FormData address_form1, address_form2; | 5310 FormData address_form1, address_form2; |
| 5312 test::CreateTestAddressFormData(&address_form1); | 5311 test::CreateTestAddressFormData(&address_form1); |
| 5313 test::CreateTestAddressFormData(&address_form2); | 5312 test::CreateTestAddressFormData(&address_form2); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5336 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 5335 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5337 | 5336 |
| 5338 base::HistogramTester histogram_tester; | 5337 base::HistogramTester histogram_tester; |
| 5339 | 5338 |
| 5340 // One zip is a prefix of the other, upload should happen. | 5339 // One zip is a prefix of the other, upload should happen. |
| 5341 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5340 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5342 FormSubmitted(credit_card_form); | 5341 FormSubmitted(credit_card_form); |
| 5343 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 5342 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5344 | 5343 |
| 5345 // Verify that the correct histogram entry (and only that) was logged. | 5344 // Verify that the correct histogram entry (and only that) was logged. |
| 5346 histogram_tester.ExpectUniqueSample( | 5345 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", |
| 5347 "Autofill.CardUploadDecisionExpanded", | 5346 AutofillMetrics::UPLOAD_OFFERED, 1); |
| 5348 AutofillMetrics::UPLOAD_OFFERED, 1); | |
| 5349 // Verify that the correct UKM was logged. | 5347 // Verify that the correct UKM was logged. |
| 5350 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 5348 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5351 } | 5349 } |
| 5352 | 5350 |
| 5353 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5351 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5354 #if defined(OS_ANDROID) | 5352 #if defined(OS_ANDROID) |
| 5355 #define MAYBE_UploadCreditCard_NoZipCodeAvailable DISABLED_UploadCreditCard_NoZi
pCodeAvailable | 5353 #define MAYBE_UploadCreditCard_NoZipCodeAvailable \ |
| 5354 DISABLED_UploadCreditCard_NoZipCodeAvailable |
| 5356 #else | 5355 #else |
| 5357 #define MAYBE_UploadCreditCard_NoZipCodeAvailable UploadCreditCard_NoZipCodeAvai
lable | 5356 #define MAYBE_UploadCreditCard_NoZipCodeAvailable \ |
| 5357 UploadCreditCard_NoZipCodeAvailable |
| 5358 #endif | 5358 #endif |
| 5359 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoZipCodeAvailable) { | 5359 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoZipCodeAvailable) { |
| 5360 EnableUkmLogging(); | 5360 EnableUkmLogging(); |
| 5361 personal_data_.ClearAutofillProfiles(); | 5361 personal_data_.ClearAutofillProfiles(); |
| 5362 autofill_manager_->set_credit_card_upload_enabled(true); | 5362 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5363 | 5363 |
| 5364 // Create, fill and submit an address form in order to establish a recent | 5364 // Create, fill and submit an address form in order to establish a recent |
| 5365 // profile which can be selected for the upload request. | 5365 // profile which can be selected for the upload request. |
| 5366 FormData address_form; | 5366 FormData address_form; |
| 5367 test::CreateTestAddressFormData(&address_form); | 5367 test::CreateTestAddressFormData(&address_form); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5398 // Verify that the correct histogram entry (and only that) was logged. | 5398 // Verify that the correct histogram entry (and only that) was logged. |
| 5399 histogram_tester.ExpectUniqueSample( | 5399 histogram_tester.ExpectUniqueSample( |
| 5400 "Autofill.CardUploadDecisionExpanded", | 5400 "Autofill.CardUploadDecisionExpanded", |
| 5401 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, 1); | 5401 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, 1); |
| 5402 // Verify that the correct UKM was logged. | 5402 // Verify that the correct UKM was logged. |
| 5403 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | 5403 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); |
| 5404 } | 5404 } |
| 5405 | 5405 |
| 5406 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5406 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5407 #if defined(OS_ANDROID) | 5407 #if defined(OS_ANDROID) |
| 5408 #define MAYBE_UploadCreditCard_NamesMatchLoosely DISABLED_UploadCreditCard_Names
MatchLoosely | 5408 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ |
| 5409 DISABLED_UploadCreditCard_NamesMatchLoosely |
| 5409 #else | 5410 #else |
| 5410 #define MAYBE_UploadCreditCard_NamesMatchLoosely UploadCreditCard_NamesMatchLoos
ely | 5411 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ |
| 5412 UploadCreditCard_NamesMatchLoosely |
| 5411 #endif | 5413 #endif |
| 5412 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) { | 5414 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) { |
| 5413 EnableUkmLogging(); | 5415 EnableUkmLogging(); |
| 5414 personal_data_.ClearAutofillProfiles(); | 5416 personal_data_.ClearAutofillProfiles(); |
| 5415 autofill_manager_->set_credit_card_upload_enabled(true); | 5417 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5416 | 5418 |
| 5417 // Create, fill and submit two address forms with different names. | 5419 // Create, fill and submit two address forms with different names. |
| 5418 FormData address_form1, address_form2; | 5420 FormData address_form1, address_form2; |
| 5419 test::CreateTestAddressFormData(&address_form1); | 5421 test::CreateTestAddressFormData(&address_form1); |
| 5420 test::CreateTestAddressFormData(&address_form2); | 5422 test::CreateTestAddressFormData(&address_form2); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5446 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 5448 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5447 | 5449 |
| 5448 base::HistogramTester histogram_tester; | 5450 base::HistogramTester histogram_tester; |
| 5449 | 5451 |
| 5450 // Names match loosely, upload should happen. | 5452 // Names match loosely, upload should happen. |
| 5451 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5453 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5452 FormSubmitted(credit_card_form); | 5454 FormSubmitted(credit_card_form); |
| 5453 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 5455 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5454 | 5456 |
| 5455 // Verify that the correct histogram entry (and only that) was logged. | 5457 // Verify that the correct histogram entry (and only that) was logged. |
| 5456 histogram_tester.ExpectUniqueSample( | 5458 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", |
| 5457 "Autofill.CardUploadDecisionExpanded", | 5459 AutofillMetrics::UPLOAD_OFFERED, 1); |
| 5458 AutofillMetrics::UPLOAD_OFFERED, 1); | |
| 5459 // Verify that the correct UKM was logged. | 5460 // Verify that the correct UKM was logged. |
| 5460 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 5461 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 5461 } | 5462 } |
| 5462 | 5463 |
| 5463 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5464 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5464 #if defined(OS_ANDROID) | 5465 #if defined(OS_ANDROID) |
| 5465 #define MAYBE_UploadCreditCard_NamesHaveToMatch DISABLED_UploadCreditCard_NamesH
aveToMatch | 5466 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ |
| 5467 DISABLED_UploadCreditCard_NamesHaveToMatch |
| 5466 #else | 5468 #else |
| 5467 #define MAYBE_UploadCreditCard_NamesHaveToMatch UploadCreditCard_NamesHaveToMatc
h | 5469 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ |
| 5470 UploadCreditCard_NamesHaveToMatch |
| 5468 #endif | 5471 #endif |
| 5469 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { | 5472 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { |
| 5470 EnableUkmLogging(); | 5473 EnableUkmLogging(); |
| 5471 personal_data_.ClearAutofillProfiles(); | 5474 personal_data_.ClearAutofillProfiles(); |
| 5472 autofill_manager_->set_credit_card_upload_enabled(true); | 5475 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5473 | 5476 |
| 5474 // Create, fill and submit two address forms with different names. | 5477 // Create, fill and submit two address forms with different names. |
| 5475 FormData address_form1, address_form2; | 5478 FormData address_form1, address_form2; |
| 5476 test::CreateTestAddressFormData(&address_form1); | 5479 test::CreateTestAddressFormData(&address_form1); |
| 5477 test::CreateTestAddressFormData(&address_form2); | 5480 test::CreateTestAddressFormData(&address_form2); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5520 std::string sample; | 5523 std::string sample; |
| 5521 rappor::RapporType type; | 5524 rappor::RapporType type; |
| 5522 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5525 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5523 "Autofill.CardUploadNotOfferedConflictingNames", &sample, &type)); | 5526 "Autofill.CardUploadNotOfferedConflictingNames", &sample, &type)); |
| 5524 EXPECT_EQ("myform.com", sample); | 5527 EXPECT_EQ("myform.com", sample); |
| 5525 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5528 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5526 } | 5529 } |
| 5527 | 5530 |
| 5528 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5531 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5529 #if defined(OS_ANDROID) | 5532 #if defined(OS_ANDROID) |
| 5530 #define MAYBE_UploadCreditCard_UploadDetailsFails DISABLED_UploadCreditCard_Uplo
adDetailsFails | 5533 #define MAYBE_UploadCreditCard_UploadDetailsFails \ |
| 5534 DISABLED_UploadCreditCard_UploadDetailsFails |
| 5531 #else | 5535 #else |
| 5532 #define MAYBE_UploadCreditCard_UploadDetailsFails UploadCreditCard_UploadDetails
Fails | 5536 #define MAYBE_UploadCreditCard_UploadDetailsFails \ |
| 5537 UploadCreditCard_UploadDetailsFails |
| 5533 #endif | 5538 #endif |
| 5534 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) { | 5539 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) { |
| 5535 EnableUkmLogging(); | 5540 EnableUkmLogging(); |
| 5536 personal_data_.ClearAutofillProfiles(); | 5541 personal_data_.ClearAutofillProfiles(); |
| 5537 autofill_manager_->set_credit_card_upload_enabled(true); | 5542 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5538 | 5543 |
| 5539 // Anything other than "en-US" will cause GetUploadDetails to return a failure | 5544 // Anything other than "en-US" will cause GetUploadDetails to return a failure |
| 5540 // response. | 5545 // response. |
| 5541 autofill_manager_->set_app_locale("pt-BR"); | 5546 autofill_manager_->set_app_locale("pt-BR"); |
| 5542 | 5547 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5652 std::vector<FormData> forms(1, form); | 5657 std::vector<FormData> forms(1, form); |
| 5653 FormsSeen(forms); | 5658 FormsSeen(forms); |
| 5654 | 5659 |
| 5655 FormFieldData field; | 5660 FormFieldData field; |
| 5656 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", | 5661 test::CreateTestFormField("Name on Card", "nameoncard", "pres", "text", |
| 5657 &field); | 5662 &field); |
| 5658 GetAutofillSuggestions(form, field); | 5663 GetAutofillSuggestions(form, field); |
| 5659 | 5664 |
| 5660 #if defined(OS_ANDROID) | 5665 #if defined(OS_ANDROID) |
| 5661 static const std::string kVisaSuggestion = | 5666 static const std::string kVisaSuggestion = |
| 5662 "Visa" + kUTF8MidlineEllipsis + "3456"; | 5667 std::string("Visa") + kUTF8MidlineEllipsis + "3456"; |
| 5663 #else | 5668 #else |
| 5664 static const std::string kVisaSuggestion = "*3456"; | 5669 static const std::string kVisaSuggestion = "*3456"; |
| 5665 #endif | 5670 #endif |
| 5666 | 5671 |
| 5667 external_delegate_->CheckSuggestions( | 5672 external_delegate_->CheckSuggestions( |
| 5668 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, | 5673 kDefaultPageID, Suggestion("Elvis Presley", kVisaSuggestion, kVisaCard, |
| 5669 autofill_manager_->GetPackedCreditCardID(4))); | 5674 autofill_manager_->GetPackedCreditCardID(4))); |
| 5670 } | 5675 } |
| 5671 | 5676 |
| 5672 // Verify that typing "lvis" will not match any of the credit card name when | 5677 // Verify that typing "lvis" will not match any of the credit card name when |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6185 | 6190 |
| 6186 // Wait for upload to complete (will check expected types as well). | 6191 // Wait for upload to complete (will check expected types as well). |
| 6187 autofill_manager_->WaitForAsyncUploadProcess(); | 6192 autofill_manager_->WaitForAsyncUploadProcess(); |
| 6188 | 6193 |
| 6189 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6194 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 6190 EXPECT_NE(uploaded_available_types.end(), | 6195 EXPECT_NE(uploaded_available_types.end(), |
| 6191 uploaded_available_types.find(autofill::PASSWORD)); | 6196 uploaded_available_types.find(autofill::PASSWORD)); |
| 6192 } | 6197 } |
| 6193 | 6198 |
| 6194 } // namespace autofill | 6199 } // namespace autofill |
| OLD | NEW |