| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 form->action = GURL("http://myform.com/submit.html"); | 236 form->action = GURL("http://myform.com/submit.html"); |
| 237 form->user_submitted = true; | 237 form->user_submitted = true; |
| 238 | 238 |
| 239 FormFieldData field; | 239 FormFieldData field; |
| 240 test::CreateTestFormField("Shipping1", "option", "option1", "radio", &field); | 240 test::CreateTestFormField("Shipping1", "option", "option1", "radio", &field); |
| 241 form->fields.push_back(field); | 241 form->fields.push_back(field); |
| 242 test::CreateTestFormField("Shipping2", "option", "option2", "radio", &field); | 242 test::CreateTestFormField("Shipping2", "option", "option2", "radio", &field); |
| 243 form->fields.push_back(field); | 243 form->fields.push_back(field); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Populates |form| with data corresponding to a simple address form. | |
| 247 // Note that this actually appends fields to the form data, which can be useful | |
| 248 // for building up more complex test forms. | |
| 249 void CreateTestAddressFormData(FormData* form) { | |
| 250 form->name = ASCIIToUTF16("MyForm"); | |
| 251 form->method = ASCIIToUTF16("POST"); | |
| 252 form->origin = GURL("http://myform.com/form.html"); | |
| 253 form->action = GURL("http://myform.com/submit.html"); | |
| 254 form->user_submitted = true; | |
| 255 | |
| 256 FormFieldData field; | |
| 257 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | |
| 258 form->fields.push_back(field); | |
| 259 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); | |
| 260 form->fields.push_back(field); | |
| 261 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | |
| 262 form->fields.push_back(field); | |
| 263 test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field); | |
| 264 form->fields.push_back(field); | |
| 265 test::CreateTestFormField("Address Line 2", "addr2", "", "text", &field); | |
| 266 form->fields.push_back(field); | |
| 267 test::CreateTestFormField("City", "city", "", "text", &field); | |
| 268 form->fields.push_back(field); | |
| 269 test::CreateTestFormField("State", "state", "", "text", &field); | |
| 270 form->fields.push_back(field); | |
| 271 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); | |
| 272 form->fields.push_back(field); | |
| 273 test::CreateTestFormField("Country", "country", "", "text", &field); | |
| 274 form->fields.push_back(field); | |
| 275 test::CreateTestFormField("Phone Number", "phonenumber", "", "tel", &field); | |
| 276 form->fields.push_back(field); | |
| 277 test::CreateTestFormField("Email", "email", "", "email", &field); | |
| 278 form->fields.push_back(field); | |
| 279 } | |
| 280 | |
| 281 // Populates |form| with data corresponding to a simple credit card form. | 246 // Populates |form| with data corresponding to a simple credit card form. |
| 282 // Note that this actually appends fields to the form data, which can be useful | 247 // Note that this actually appends fields to the form data, which can be useful |
| 283 // for building up more complex test forms. | 248 // for building up more complex test forms. |
| 284 void CreateTestCreditCardFormData(FormData* form, | 249 void CreateTestCreditCardFormData(FormData* form, |
| 285 bool is_https, | 250 bool is_https, |
| 286 bool use_month_type) { | 251 bool use_month_type) { |
| 287 form->name = ASCIIToUTF16("MyForm"); | 252 form->name = ASCIIToUTF16("MyForm"); |
| 288 form->method = ASCIIToUTF16("POST"); | 253 form->method = ASCIIToUTF16("POST"); |
| 289 if (is_https) { | 254 if (is_https) { |
| 290 form->origin = GURL("https://myform.com/form.html"); | 255 form->origin = GURL("https://myform.com/form.html"); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 MockAutocompleteHistoryManager(AutofillDriver* driver, | 449 MockAutocompleteHistoryManager(AutofillDriver* driver, |
| 485 AutofillManagerDelegate* delegate) | 450 AutofillManagerDelegate* delegate) |
| 486 : AutocompleteHistoryManager(driver, delegate) {} | 451 : AutocompleteHistoryManager(driver, delegate) {} |
| 487 | 452 |
| 488 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); | 453 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); |
| 489 | 454 |
| 490 private: | 455 private: |
| 491 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); | 456 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); |
| 492 }; | 457 }; |
| 493 | 458 |
| 459 class MockAutofillDriver : public TestAutofillDriver { |
| 460 public: |
| 461 explicit MockAutofillDriver(content::WebContents* web_contents) |
| 462 : TestAutofillDriver(web_contents) {} |
| 463 |
| 464 // Mock methods to enable testability. |
| 465 MOCK_METHOD2(SendFormDataToRenderer, void(int query_id, |
| 466 const FormData& data)); |
| 467 |
| 468 private: |
| 469 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
| 470 }; |
| 471 |
| 494 class TestAutofillManager : public AutofillManager { | 472 class TestAutofillManager : public AutofillManager { |
| 495 public: | 473 public: |
| 496 TestAutofillManager(AutofillDriver* driver, | 474 TestAutofillManager(AutofillDriver* driver, |
| 497 autofill::AutofillManagerDelegate* delegate, | 475 autofill::AutofillManagerDelegate* delegate, |
| 498 TestPersonalDataManager* personal_data) | 476 TestPersonalDataManager* personal_data) |
| 499 : AutofillManager(driver, delegate, personal_data), | 477 : AutofillManager(driver, delegate, personal_data), |
| 500 personal_data_(personal_data), | 478 personal_data_(personal_data), |
| 501 autofill_enabled_(true) {} | 479 autofill_enabled_(true) {} |
| 502 virtual ~TestAutofillManager() {} | 480 virtual ~TestAutofillManager() {} |
| 503 | 481 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 profile->CreateRequestContext(); | 658 profile->CreateRequestContext(); |
| 681 browser_context_.reset(profile); | 659 browser_context_.reset(profile); |
| 682 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 660 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 683 profile, TestPersonalDataManager::Build); | 661 profile, TestPersonalDataManager::Build); |
| 684 | 662 |
| 685 ChromeRenderViewHostTestHarness::SetUp(); | 663 ChromeRenderViewHostTestHarness::SetUp(); |
| 686 | 664 |
| 687 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 665 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 688 | 666 |
| 689 personal_data_.SetBrowserContext(profile); | 667 personal_data_.SetBrowserContext(profile); |
| 690 autofill_driver_.reset(new TestAutofillDriver(web_contents())); | 668 autofill_driver_.reset(new MockAutofillDriver(web_contents())); |
| 691 autofill_manager_.reset(new TestAutofillManager( | 669 autofill_manager_.reset(new TestAutofillManager( |
| 692 autofill_driver_.get(), | 670 autofill_driver_.get(), |
| 693 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | 671 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 694 &personal_data_)); | 672 &personal_data_)); |
| 695 } | 673 } |
| 696 | 674 |
| 697 virtual void TearDown() OVERRIDE { | 675 virtual void TearDown() OVERRIDE { |
| 698 // Order of destruction is important as AutofillManager relies on | 676 // Order of destruction is important as AutofillManager relies on |
| 699 // PersonalDataManager to be around when it gets destroyed. Also, a real | 677 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 700 // AutofillManager is tied to the lifetime of the WebContents, so it must | 678 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 autofill_manager_->WaitForAsyncFormSubmit(); | 731 autofill_manager_->WaitForAsyncFormSubmit(); |
| 754 } | 732 } |
| 755 | 733 |
| 756 void FillAutofillFormData(int query_id, | 734 void FillAutofillFormData(int query_id, |
| 757 const FormData& form, | 735 const FormData& form, |
| 758 const FormFieldData& field, | 736 const FormFieldData& field, |
| 759 int unique_id) { | 737 int unique_id) { |
| 760 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 738 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
| 761 } | 739 } |
| 762 | 740 |
| 741 // Calls |autofill_manager_->OnFillAutofillFormData()| with the specified |
| 742 // input parameters after setting up the expectation that the mock driver's |
| 743 // |SendFormDataToRenderer()| method will be called and saving the parameters |
| 744 // of that call into the |response_query_id| and |response_data| output |
| 745 // parameters. |
| 746 void FillAutofillFormDataAndSaveResults(int input_query_id, |
| 747 const FormData& input_form, |
| 748 const FormFieldData& input_field, |
| 749 int unique_id, |
| 750 int* response_query_id, |
| 751 FormData* response_data) { |
| 752 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)). |
| 753 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), |
| 754 testing::SaveArg<1>(response_data)))); |
| 755 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); |
| 756 } |
| 757 |
| 763 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 758 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { |
| 764 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 759 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); |
| 765 } | 760 } |
| 766 | 761 |
| 767 bool GetAutofillSuggestionsMessage(int* page_id, | 762 bool GetAutofillSuggestionsMessage(int* page_id, |
| 768 std::vector<base::string16>* values, | 763 std::vector<base::string16>* values, |
| 769 std::vector<base::string16>* labels, | 764 std::vector<base::string16>* labels, |
| 770 std::vector<base::string16>* icons, | 765 std::vector<base::string16>* icons, |
| 771 std::vector<int>* unique_ids) { | 766 std::vector<int>* unique_ids) { |
| 772 const uint32 kMsgID = AutofillMsg_SuggestionsReturned::ID; | 767 const uint32 kMsgID = AutofillMsg_SuggestionsReturned::ID; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 793 return true; | 788 return true; |
| 794 } | 789 } |
| 795 | 790 |
| 796 bool HasSeenAutofillGetAllFormsMessage() { | 791 bool HasSeenAutofillGetAllFormsMessage() { |
| 797 const uint32 kMsgID = AutofillMsg_GetAllForms::ID; | 792 const uint32 kMsgID = AutofillMsg_GetAllForms::ID; |
| 798 const IPC::Message* message = | 793 const IPC::Message* message = |
| 799 process()->sink().GetFirstMessageMatching(kMsgID); | 794 process()->sink().GetFirstMessageMatching(kMsgID); |
| 800 return message != NULL; | 795 return message != NULL; |
| 801 } | 796 } |
| 802 | 797 |
| 803 bool GetAutofillFormDataFilledMessage(int* page_id, FormData* results) { | |
| 804 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; | |
| 805 const IPC::Message* message = | |
| 806 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 807 if (!message) | |
| 808 return false; | |
| 809 Tuple2<int, FormData> autofill_param; | |
| 810 AutofillMsg_FormDataFilled::Read(message, &autofill_param); | |
| 811 if (page_id) | |
| 812 *page_id = autofill_param.a; | |
| 813 if (results) | |
| 814 *results = autofill_param.b; | |
| 815 | |
| 816 process()->sink().ClearMessages(); | |
| 817 return true; | |
| 818 } | |
| 819 | |
| 820 protected: | 798 protected: |
| 821 scoped_ptr<TestAutofillDriver> autofill_driver_; | 799 scoped_ptr<MockAutofillDriver> autofill_driver_; |
| 822 scoped_ptr<TestAutofillManager> autofill_manager_; | 800 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 823 TestPersonalDataManager personal_data_; | 801 TestPersonalDataManager personal_data_; |
| 824 | 802 |
| 825 // Used when we want an off the record profile. This will store the original | 803 // Used when we want an off the record profile. This will store the original |
| 826 // profile from which the off the record profile is derived. | 804 // profile from which the off the record profile is derived. |
| 827 scoped_ptr<Profile> other_browser_context_; | 805 scoped_ptr<Profile> other_browser_context_; |
| 828 }; | 806 }; |
| 829 | 807 |
| 830 class TestFormStructure : public FormStructure { | 808 class TestFormStructure : public FormStructure { |
| 831 public: | 809 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 848 UpdateAutofillCount(); | 826 UpdateAutofillCount(); |
| 849 } | 827 } |
| 850 | 828 |
| 851 private: | 829 private: |
| 852 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 830 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
| 853 }; | 831 }; |
| 854 | 832 |
| 855 // Test that browser asks for all forms when Autocheckout is enabled. | 833 // Test that browser asks for all forms when Autocheckout is enabled. |
| 856 TEST_F(AutofillManagerTest, GetAllForms) { | 834 TEST_F(AutofillManagerTest, GetAllForms) { |
| 857 FormData form; | 835 FormData form; |
| 858 CreateTestAddressFormData(&form); | 836 test::CreateTestAddressFormData(&form); |
| 859 std::vector<FormData> forms(1, form); | 837 std::vector<FormData> forms(1, form); |
| 860 // Enable autocheckout. | 838 // Enable autocheckout. |
| 861 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 839 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 862 | 840 |
| 863 PartialFormsSeen(forms); | 841 PartialFormsSeen(forms); |
| 864 | 842 |
| 865 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | 843 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
| 866 } | 844 } |
| 867 | 845 |
| 868 // Test that we return all address profile suggestions when all form fields are | 846 // Test that we return all address profile suggestions when all form fields are |
| 869 // empty. | 847 // empty. |
| 870 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 848 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
| 871 // Set up our form data. | 849 // Set up our form data. |
| 872 FormData form; | 850 FormData form; |
| 873 CreateTestAddressFormData(&form); | 851 test::CreateTestAddressFormData(&form); |
| 874 std::vector<FormData> forms(1, form); | 852 std::vector<FormData> forms(1, form); |
| 875 FormsSeen(forms); | 853 FormsSeen(forms); |
| 876 | 854 |
| 877 const FormFieldData& field = form.fields[0]; | 855 const FormFieldData& field = form.fields[0]; |
| 878 GetAutofillSuggestions(form, field); | 856 GetAutofillSuggestions(form, field); |
| 879 | 857 |
| 880 // No suggestions provided, so send an empty vector as the results. | 858 // No suggestions provided, so send an empty vector as the results. |
| 881 // This triggers the combined message send. | 859 // This triggers the combined message send. |
| 882 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 860 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 883 | 861 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 907 expected_labels, expected_icons, expected_unique_ids); | 885 expected_labels, expected_icons, expected_unique_ids); |
| 908 } | 886 } |
| 909 | 887 |
| 910 // Test that in the case of Autocheckout, forms seen are in order supplied. | 888 // Test that in the case of Autocheckout, forms seen are in order supplied. |
| 911 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { | 889 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { |
| 912 FormData shipping_options; | 890 FormData shipping_options; |
| 913 CreateTestShippingOptionsFormData(&shipping_options); | 891 CreateTestShippingOptionsFormData(&shipping_options); |
| 914 FormData user_supplied; | 892 FormData user_supplied; |
| 915 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 893 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
| 916 FormData address; | 894 FormData address; |
| 917 CreateTestAddressFormData(&address); | 895 test::CreateTestAddressFormData(&address); |
| 918 | 896 |
| 919 // Push user_supplied before address and observe order changing when | 897 // Push user_supplied before address and observe order changing when |
| 920 // Autocheckout is not enabled.. | 898 // Autocheckout is not enabled.. |
| 921 std::vector<FormData> forms; | 899 std::vector<FormData> forms; |
| 922 forms.push_back(shipping_options); | 900 forms.push_back(shipping_options); |
| 923 forms.push_back(user_supplied); | 901 forms.push_back(user_supplied); |
| 924 forms.push_back(address); | 902 forms.push_back(address); |
| 925 | 903 |
| 926 // Test without enabling Autocheckout. FormStructure should only contain | 904 // Test without enabling Autocheckout. FormStructure should only contain |
| 927 // form1. Shipping Options form will not qualify as parsable form. | 905 // form1. Shipping Options form will not qualify as parsable form. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 944 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 922 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
| 945 } | 923 } |
| 946 | 924 |
| 947 // Test that in the case of Autocheckout, forms seen are in order supplied. | 925 // Test that in the case of Autocheckout, forms seen are in order supplied. |
| 948 TEST_F(AutofillManagerTest, DynamicFormsSeen) { | 926 TEST_F(AutofillManagerTest, DynamicFormsSeen) { |
| 949 FormData shipping_options; | 927 FormData shipping_options; |
| 950 CreateTestShippingOptionsFormData(&shipping_options); | 928 CreateTestShippingOptionsFormData(&shipping_options); |
| 951 FormData user_supplied; | 929 FormData user_supplied; |
| 952 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 930 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
| 953 FormData address; | 931 FormData address; |
| 954 CreateTestAddressFormData(&address); | 932 test::CreateTestAddressFormData(&address); |
| 955 | 933 |
| 956 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 934 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 957 // Push user_supplied only | 935 // Push user_supplied only |
| 958 std::vector<FormData> forms; | 936 std::vector<FormData> forms; |
| 959 forms.push_back(user_supplied); | 937 forms.push_back(user_supplied); |
| 960 | 938 |
| 961 // Make sure normal form is handled correctly. | 939 // Make sure normal form is handled correctly. |
| 962 FormsSeen(forms); | 940 FormsSeen(forms); |
| 963 std::vector<FormStructure*> form_structures; | 941 std::vector<FormStructure*> form_structures; |
| 964 form_structures = autofill_manager_->GetFormStructures(); | 942 form_structures = autofill_manager_->GetFormStructures(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 978 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); | 956 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
| 979 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); | 957 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); |
| 980 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 958 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
| 981 } | 959 } |
| 982 | 960 |
| 983 // Test that we return only matching address profile suggestions when the | 961 // Test that we return only matching address profile suggestions when the |
| 984 // selected form field has been partially filled out. | 962 // selected form field has been partially filled out. |
| 985 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 963 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
| 986 // Set up our form data. | 964 // Set up our form data. |
| 987 FormData form; | 965 FormData form; |
| 988 CreateTestAddressFormData(&form); | 966 test::CreateTestAddressFormData(&form); |
| 989 std::vector<FormData> forms(1, form); | 967 std::vector<FormData> forms(1, form); |
| 990 FormsSeen(forms); | 968 FormsSeen(forms); |
| 991 | 969 |
| 992 FormFieldData field; | 970 FormFieldData field; |
| 993 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); | 971 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); |
| 994 GetAutofillSuggestions(form, field); | 972 GetAutofillSuggestions(form, field); |
| 995 | 973 |
| 996 // No suggestions provided, so send an empty vector as the results. | 974 // No suggestions provided, so send an empty vector as the results. |
| 997 // This triggers the combined message send. | 975 // This triggers the combined message send. |
| 998 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 976 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 FormsSeen(forms); | 1017 FormsSeen(forms); |
| 1040 | 1018 |
| 1041 GetAutofillSuggestions(form, field); | 1019 GetAutofillSuggestions(form, field); |
| 1042 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1020 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
| 1043 } | 1021 } |
| 1044 | 1022 |
| 1045 // Test that we cull duplicate profile suggestions. | 1023 // Test that we cull duplicate profile suggestions. |
| 1046 TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) { | 1024 TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) { |
| 1047 // Set up our form data. | 1025 // Set up our form data. |
| 1048 FormData form; | 1026 FormData form; |
| 1049 CreateTestAddressFormData(&form); | 1027 test::CreateTestAddressFormData(&form); |
| 1050 std::vector<FormData> forms(1, form); | 1028 std::vector<FormData> forms(1, form); |
| 1051 FormsSeen(forms); | 1029 FormsSeen(forms); |
| 1052 | 1030 |
| 1053 // Add a duplicate profile. | 1031 // Add a duplicate profile. |
| 1054 AutofillProfile* duplicate_profile = | 1032 AutofillProfile* duplicate_profile = |
| 1055 new AutofillProfile( | 1033 new AutofillProfile( |
| 1056 *(autofill_manager_->GetProfileWithGUID( | 1034 *(autofill_manager_->GetProfileWithGUID( |
| 1057 "00000000-0000-0000-0000-000000000001"))); | 1035 "00000000-0000-0000-0000-000000000001"))); |
| 1058 autofill_manager_->AddProfile(duplicate_profile); | 1036 autofill_manager_->AddProfile(duplicate_profile); |
| 1059 | 1037 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1085 int expected_unique_ids[] = {1, 2}; | 1063 int expected_unique_ids[] = {1, 2}; |
| 1086 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1064 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1087 kDefaultPageID, arraysize(expected_values), expected_values, | 1065 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1088 expected_labels, expected_icons, expected_unique_ids); | 1066 expected_labels, expected_icons, expected_unique_ids); |
| 1089 } | 1067 } |
| 1090 | 1068 |
| 1091 // Test that we return no suggestions when autofill is disabled. | 1069 // Test that we return no suggestions when autofill is disabled. |
| 1092 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 1070 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
| 1093 // Set up our form data. | 1071 // Set up our form data. |
| 1094 FormData form; | 1072 FormData form; |
| 1095 CreateTestAddressFormData(&form); | 1073 test::CreateTestAddressFormData(&form); |
| 1096 std::vector<FormData> forms(1, form); | 1074 std::vector<FormData> forms(1, form); |
| 1097 FormsSeen(forms); | 1075 FormsSeen(forms); |
| 1098 | 1076 |
| 1099 // Disable Autofill. | 1077 // Disable Autofill. |
| 1100 autofill_manager_->set_autofill_enabled(false); | 1078 autofill_manager_->set_autofill_enabled(false); |
| 1101 | 1079 |
| 1102 const FormFieldData& field = form.fields[0]; | 1080 const FormFieldData& field = form.fields[0]; |
| 1103 GetAutofillSuggestions(form, field); | 1081 GetAutofillSuggestions(form, field); |
| 1104 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1082 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
| 1105 } | 1083 } |
| 1106 | 1084 |
| 1107 // Test that we return a warning explaining that autofill suggestions are | 1085 // Test that we return a warning explaining that autofill suggestions are |
| 1108 // unavailable when the form method is GET rather than POST. | 1086 // unavailable when the form method is GET rather than POST. |
| 1109 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { | 1087 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { |
| 1110 // Set up our form data. | 1088 // Set up our form data. |
| 1111 FormData form; | 1089 FormData form; |
| 1112 CreateTestAddressFormData(&form); | 1090 test::CreateTestAddressFormData(&form); |
| 1113 form.method = ASCIIToUTF16("GET"); | 1091 form.method = ASCIIToUTF16("GET"); |
| 1114 std::vector<FormData> forms(1, form); | 1092 std::vector<FormData> forms(1, form); |
| 1115 FormsSeen(forms); | 1093 FormsSeen(forms); |
| 1116 | 1094 |
| 1117 const FormFieldData& field = form.fields[0]; | 1095 const FormFieldData& field = form.fields[0]; |
| 1118 GetAutofillSuggestions(form, field); | 1096 GetAutofillSuggestions(form, field); |
| 1119 | 1097 |
| 1120 // No suggestions provided, so send an empty vector as the results. | 1098 // No suggestions provided, so send an empty vector as the results. |
| 1121 // This triggers the combined message send. | 1099 // This triggers the combined message send. |
| 1122 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1100 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 }; | 1398 }; |
| 1421 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1399 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1422 kDefaultPageID, arraysize(expected_values), expected_values, | 1400 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1423 expected_labels, expected_icons, expected_unique_ids); | 1401 expected_labels, expected_icons, expected_unique_ids); |
| 1424 } | 1402 } |
| 1425 | 1403 |
| 1426 // Test that we return profile and credit card suggestions for combined forms. | 1404 // Test that we return profile and credit card suggestions for combined forms. |
| 1427 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1405 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1428 // Set up our form data. | 1406 // Set up our form data. |
| 1429 FormData form; | 1407 FormData form; |
| 1430 CreateTestAddressFormData(&form); | 1408 test::CreateTestAddressFormData(&form); |
| 1431 CreateTestCreditCardFormData(&form, true, false); | 1409 CreateTestCreditCardFormData(&form, true, false); |
| 1432 std::vector<FormData> forms(1, form); | 1410 std::vector<FormData> forms(1, form); |
| 1433 FormsSeen(forms); | 1411 FormsSeen(forms); |
| 1434 | 1412 |
| 1435 FormFieldData field = form.fields[0]; | 1413 FormFieldData field = form.fields[0]; |
| 1436 GetAutofillSuggestions(form, field); | 1414 GetAutofillSuggestions(form, field); |
| 1437 | 1415 |
| 1438 // No suggestions provided, so send an empty vector as the results. | 1416 // No suggestions provided, so send an empty vector as the results. |
| 1439 // This triggers the combined message send. | 1417 // This triggers the combined message send. |
| 1440 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1418 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 expected_labels2, expected_icons2, expected_unique_ids2); | 1472 expected_labels2, expected_icons2, expected_unique_ids2); |
| 1495 } | 1473 } |
| 1496 | 1474 |
| 1497 // Test that for non-https forms with both address and credit card fields, we | 1475 // Test that for non-https forms with both address and credit card fields, we |
| 1498 // only return address suggestions. Instead of credit card suggestions, we | 1476 // only return address suggestions. Instead of credit card suggestions, we |
| 1499 // should return a warning explaining that credit card profile suggestions are | 1477 // should return a warning explaining that credit card profile suggestions are |
| 1500 // unavailable when the form is not https. | 1478 // unavailable when the form is not https. |
| 1501 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1479 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1502 // Set up our form data. | 1480 // Set up our form data. |
| 1503 FormData form; | 1481 FormData form; |
| 1504 CreateTestAddressFormData(&form); | 1482 test::CreateTestAddressFormData(&form); |
| 1505 CreateTestCreditCardFormData(&form, false, false); | 1483 CreateTestCreditCardFormData(&form, false, false); |
| 1506 std::vector<FormData> forms(1, form); | 1484 std::vector<FormData> forms(1, form); |
| 1507 FormsSeen(forms); | 1485 FormsSeen(forms); |
| 1508 | 1486 |
| 1509 FormFieldData field = form.fields[0]; | 1487 FormFieldData field = form.fields[0]; |
| 1510 GetAutofillSuggestions(form, field); | 1488 GetAutofillSuggestions(form, field); |
| 1511 | 1489 |
| 1512 // No suggestions provided, so send an empty vector as the results. | 1490 // No suggestions provided, so send an empty vector as the results. |
| 1513 // This triggers the combined message send. | 1491 // This triggers the combined message send. |
| 1514 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1492 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1539 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1562 personal_data_.ClearCreditCards(); | 1540 personal_data_.ClearCreditCards(); |
| 1563 GetAutofillSuggestions(form, field); | 1541 GetAutofillSuggestions(form, field); |
| 1564 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1542 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
| 1565 } | 1543 } |
| 1566 | 1544 |
| 1567 // Test that we correctly combine autofill and autocomplete suggestions. | 1545 // Test that we correctly combine autofill and autocomplete suggestions. |
| 1568 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { | 1546 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { |
| 1569 // Set up our form data. | 1547 // Set up our form data. |
| 1570 FormData form; | 1548 FormData form; |
| 1571 CreateTestAddressFormData(&form); | 1549 test::CreateTestAddressFormData(&form); |
| 1572 std::vector<FormData> forms(1, form); | 1550 std::vector<FormData> forms(1, form); |
| 1573 FormsSeen(forms); | 1551 FormsSeen(forms); |
| 1574 | 1552 |
| 1575 const FormFieldData& field = form.fields[0]; | 1553 const FormFieldData& field = form.fields[0]; |
| 1576 GetAutofillSuggestions(form, field); | 1554 GetAutofillSuggestions(form, field); |
| 1577 | 1555 |
| 1578 // Add some Autocomplete suggestions. | 1556 // Add some Autocomplete suggestions. |
| 1579 // This triggers the combined message send. | 1557 // This triggers the combined message send. |
| 1580 std::vector<base::string16> suggestions; | 1558 std::vector<base::string16> suggestions; |
| 1581 suggestions.push_back(ASCIIToUTF16("Jay")); | 1559 suggestions.push_back(ASCIIToUTF16("Jay")); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1611 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1589 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1612 kDefaultPageID, arraysize(expected_values), expected_values, | 1590 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1613 expected_labels, expected_icons, expected_unique_ids); | 1591 expected_labels, expected_icons, expected_unique_ids); |
| 1614 } | 1592 } |
| 1615 | 1593 |
| 1616 // Test that we return autocomplete-like suggestions when trying to autofill | 1594 // Test that we return autocomplete-like suggestions when trying to autofill |
| 1617 // already filled forms. | 1595 // already filled forms. |
| 1618 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { | 1596 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { |
| 1619 // Set up our form data. | 1597 // Set up our form data. |
| 1620 FormData form; | 1598 FormData form; |
| 1621 CreateTestAddressFormData(&form); | 1599 test::CreateTestAddressFormData(&form); |
| 1622 std::vector<FormData> forms(1, form); | 1600 std::vector<FormData> forms(1, form); |
| 1623 FormsSeen(forms); | 1601 FormsSeen(forms); |
| 1624 | 1602 |
| 1625 // Mark one of the fields as filled. | 1603 // Mark one of the fields as filled. |
| 1626 form.fields[2].is_autofilled = true; | 1604 form.fields[2].is_autofilled = true; |
| 1627 const FormFieldData& field = form.fields[0]; | 1605 const FormFieldData& field = form.fields[0]; |
| 1628 GetAutofillSuggestions(form, field); | 1606 GetAutofillSuggestions(form, field); |
| 1629 | 1607 |
| 1630 // No suggestions provided, so send an empty vector as the results. | 1608 // No suggestions provided, so send an empty vector as the results. |
| 1631 // This triggers the combined message send. | 1609 // This triggers the combined message send. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1649 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1627 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1650 kDefaultPageID, arraysize(expected_values), expected_values, | 1628 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1651 expected_labels, expected_icons, expected_unique_ids); | 1629 expected_labels, expected_icons, expected_unique_ids); |
| 1652 } | 1630 } |
| 1653 | 1631 |
| 1654 // Test that nothing breaks when there are autocomplete suggestions but no | 1632 // Test that nothing breaks when there are autocomplete suggestions but no |
| 1655 // autofill suggestions. | 1633 // autofill suggestions. |
| 1656 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { | 1634 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { |
| 1657 // Set up our form data. | 1635 // Set up our form data. |
| 1658 FormData form; | 1636 FormData form; |
| 1659 CreateTestAddressFormData(&form); | 1637 test::CreateTestAddressFormData(&form); |
| 1660 FormFieldData field; | 1638 FormFieldData field; |
| 1661 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); | 1639 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); |
| 1662 form.fields.push_back(field); | 1640 form.fields.push_back(field); |
| 1663 std::vector<FormData> forms(1, form); | 1641 std::vector<FormData> forms(1, form); |
| 1664 FormsSeen(forms); | 1642 FormsSeen(forms); |
| 1665 | 1643 |
| 1666 GetAutofillSuggestions(form, field); | 1644 GetAutofillSuggestions(form, field); |
| 1667 | 1645 |
| 1668 // Add some Autocomplete suggestions. | 1646 // Add some Autocomplete suggestions. |
| 1669 // This triggers the combined message send. | 1647 // This triggers the combined message send. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1691 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1669 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1692 kDefaultPageID, arraysize(expected_values), expected_values, | 1670 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1693 expected_labels, expected_icons, expected_unique_ids); | 1671 expected_labels, expected_icons, expected_unique_ids); |
| 1694 } | 1672 } |
| 1695 | 1673 |
| 1696 // Test that we do not return duplicate values drawn from multiple profiles when | 1674 // Test that we do not return duplicate values drawn from multiple profiles when |
| 1697 // filling an already filled field. | 1675 // filling an already filled field. |
| 1698 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 1676 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
| 1699 // Set up our form data. | 1677 // Set up our form data. |
| 1700 FormData form; | 1678 FormData form; |
| 1701 CreateTestAddressFormData(&form); | 1679 test::CreateTestAddressFormData(&form); |
| 1702 std::vector<FormData> forms(1, form); | 1680 std::vector<FormData> forms(1, form); |
| 1703 FormsSeen(forms); | 1681 FormsSeen(forms); |
| 1704 | 1682 |
| 1705 // |profile| will be owned by the mock PersonalDataManager. | 1683 // |profile| will be owned by the mock PersonalDataManager. |
| 1706 AutofillProfile* profile = new AutofillProfile; | 1684 AutofillProfile* profile = new AutofillProfile; |
| 1707 test::SetProfileInfo( | 1685 test::SetProfileInfo( |
| 1708 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); | 1686 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); |
| 1709 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1687 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1710 autofill_manager_->AddProfile(profile); | 1688 autofill_manager_->AddProfile(profile); |
| 1711 | 1689 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1734 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1712 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1735 kDefaultPageID, arraysize(expected_values), expected_values, | 1713 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1736 expected_labels, expected_icons, expected_unique_ids); | 1714 expected_labels, expected_icons, expected_unique_ids); |
| 1737 } | 1715 } |
| 1738 | 1716 |
| 1739 // Test that a non-default value is suggested for multi-valued profile, on an | 1717 // Test that a non-default value is suggested for multi-valued profile, on an |
| 1740 // unfilled form. | 1718 // unfilled form. |
| 1741 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { | 1719 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { |
| 1742 // Set up our form data. | 1720 // Set up our form data. |
| 1743 FormData form; | 1721 FormData form; |
| 1744 CreateTestAddressFormData(&form); | 1722 test::CreateTestAddressFormData(&form); |
| 1745 std::vector<FormData> forms(1, form); | 1723 std::vector<FormData> forms(1, form); |
| 1746 FormsSeen(forms); | 1724 FormsSeen(forms); |
| 1747 | 1725 |
| 1748 // |profile| will be owned by the mock PersonalDataManager. | 1726 // |profile| will be owned by the mock PersonalDataManager. |
| 1749 AutofillProfile* profile = new AutofillProfile; | 1727 AutofillProfile* profile = new AutofillProfile; |
| 1750 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", | 1728 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", |
| 1751 "", "", "", "", "", "", ""); | 1729 "", "", "", "", "", "", ""); |
| 1752 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1730 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1753 std::vector<base::string16> multi_values(2); | 1731 std::vector<base::string16> multi_values(2); |
| 1754 multi_values[0] = ASCIIToUTF16("Elvis Presley"); | 1732 multi_values[0] = ASCIIToUTF16("Elvis Presley"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 expected_values, expected_labels, expected_icons, | 1799 expected_values, expected_labels, expected_icons, |
| 1822 expected_unique_ids); | 1800 expected_unique_ids); |
| 1823 } | 1801 } |
| 1824 } | 1802 } |
| 1825 | 1803 |
| 1826 // Test that all values are suggested for multi-valued profile, on a filled | 1804 // Test that all values are suggested for multi-valued profile, on a filled |
| 1827 // form. This is the per-field "override" case. | 1805 // form. This is the per-field "override" case. |
| 1828 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { | 1806 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { |
| 1829 // Set up our form data. | 1807 // Set up our form data. |
| 1830 FormData form; | 1808 FormData form; |
| 1831 CreateTestAddressFormData(&form); | 1809 test::CreateTestAddressFormData(&form); |
| 1832 std::vector<FormData> forms(1, form); | 1810 std::vector<FormData> forms(1, form); |
| 1833 FormsSeen(forms); | 1811 FormsSeen(forms); |
| 1834 | 1812 |
| 1835 // |profile| will be owned by the mock PersonalDataManager. | 1813 // |profile| will be owned by the mock PersonalDataManager. |
| 1836 AutofillProfile* profile = new AutofillProfile; | 1814 AutofillProfile* profile = new AutofillProfile; |
| 1837 profile->set_guid("00000000-0000-0000-0000-000000000102"); | 1815 profile->set_guid("00000000-0000-0000-0000-000000000102"); |
| 1838 std::vector<base::string16> multi_values(3); | 1816 std::vector<base::string16> multi_values(3); |
| 1839 multi_values[0] = ASCIIToUTF16("Travis Smith"); | 1817 multi_values[0] = ASCIIToUTF16("Travis Smith"); |
| 1840 multi_values[1] = ASCIIToUTF16("Cynthia Love"); | 1818 multi_values[1] = ASCIIToUTF16("Cynthia Love"); |
| 1841 multi_values[2] = ASCIIToUTF16("Zac Mango"); | 1819 multi_values[2] = ASCIIToUTF16("Zac Mango"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1872 base::string16() }; | 1850 base::string16() }; |
| 1873 int expected_unique_ids[] = { 1, 2, 3 }; | 1851 int expected_unique_ids[] = { 1, 2, 3 }; |
| 1874 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1852 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1875 kDefaultPageID, arraysize(expected_values), expected_values, | 1853 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1876 expected_labels, expected_icons, expected_unique_ids); | 1854 expected_labels, expected_icons, expected_unique_ids); |
| 1877 } | 1855 } |
| 1878 | 1856 |
| 1879 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { | 1857 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { |
| 1880 // Set up our form data. | 1858 // Set up our form data. |
| 1881 FormData form; | 1859 FormData form; |
| 1882 CreateTestAddressFormData(&form); | 1860 test::CreateTestAddressFormData(&form); |
| 1883 std::vector<FormData> forms(1, form); | 1861 std::vector<FormData> forms(1, form); |
| 1884 FormsSeen(forms); | 1862 FormsSeen(forms); |
| 1885 | 1863 |
| 1886 AutofillProfile* profile = new AutofillProfile; | 1864 AutofillProfile* profile = new AutofillProfile; |
| 1887 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1865 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1888 std::vector<base::string16> multi_values(1); | 1866 std::vector<base::string16> multi_values(1); |
| 1889 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); | 1867 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); |
| 1890 profile->SetRawMultiInfo(NAME_FULL, multi_values); | 1868 profile->SetRawMultiInfo(NAME_FULL, multi_values); |
| 1891 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); | 1869 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); |
| 1892 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); | 1870 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 int expected_unique_ids[] = {1, 2, 3}; | 1903 int expected_unique_ids[] = {1, 2, 3}; |
| 1926 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1904 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1927 kDefaultPageID, arraysize(expected_values), expected_values, | 1905 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1928 expected_labels, expected_icons, expected_unique_ids); | 1906 expected_labels, expected_icons, expected_unique_ids); |
| 1929 } | 1907 } |
| 1930 | 1908 |
| 1931 // Test that we correctly fill an address form. | 1909 // Test that we correctly fill an address form. |
| 1932 TEST_F(AutofillManagerTest, FillAddressForm) { | 1910 TEST_F(AutofillManagerTest, FillAddressForm) { |
| 1933 // Set up our form data. | 1911 // Set up our form data. |
| 1934 FormData form; | 1912 FormData form; |
| 1935 CreateTestAddressFormData(&form); | 1913 test::CreateTestAddressFormData(&form); |
| 1936 std::vector<FormData> forms(1, form); | 1914 std::vector<FormData> forms(1, form); |
| 1937 FormsSeen(forms); | 1915 FormsSeen(forms); |
| 1938 | 1916 |
| 1939 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1917 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 1940 GUIDPair empty(std::string(), 0); | 1918 GUIDPair empty(std::string(), 0); |
| 1941 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 1919 int response_page_id = 0; |
| 1942 PackGUIDs(empty, guid)); | 1920 FormData response_data; |
| 1943 | 1921 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1944 int page_id = 0; | 1922 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 1945 FormData results; | 1923 ExpectFilledAddressFormElvis( |
| 1946 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1924 response_page_id, response_data, kDefaultPageID, false); |
| 1947 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 1948 } | 1925 } |
| 1949 | 1926 |
| 1950 // Test that we correctly fill an address form from an auxiliary profile. | 1927 // Test that we correctly fill an address form from an auxiliary profile. |
| 1951 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1928 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
| 1952 personal_data_.ClearAutofillProfiles(); | 1929 personal_data_.ClearAutofillProfiles(); |
| 1953 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); | 1930 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); |
| 1954 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1931 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); |
| 1955 personal_data_.CreateTestAuxiliaryProfiles(); | 1932 personal_data_.CreateTestAuxiliaryProfiles(); |
| 1956 | 1933 |
| 1957 // Set up our form data. | 1934 // Set up our form data. |
| 1958 FormData form; | 1935 FormData form; |
| 1959 CreateTestAddressFormData(&form); | 1936 test::CreateTestAddressFormData(&form); |
| 1960 std::vector<FormData> forms(1, form); | 1937 std::vector<FormData> forms(1, form); |
| 1961 FormsSeen(forms); | 1938 FormsSeen(forms); |
| 1962 | 1939 |
| 1963 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1940 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 1964 GUIDPair empty(std::string(), 0); | 1941 GUIDPair empty(std::string(), 0); |
| 1965 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 1942 int response_page_id = 0; |
| 1966 PackGUIDs(empty, guid)); | 1943 FormData response_data; |
| 1967 | 1944 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1968 int page_id = 0; | 1945 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 1969 FormData results; | 1946 ExpectFilledAddressFormElvis( |
| 1970 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1947 response_page_id, response_data, kDefaultPageID, false); |
| 1971 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 1972 } | 1948 } |
| 1973 | 1949 |
| 1974 // Test that we correctly fill a credit card form. | 1950 // Test that we correctly fill a credit card form. |
| 1975 TEST_F(AutofillManagerTest, FillCreditCardForm) { | 1951 TEST_F(AutofillManagerTest, FillCreditCardForm) { |
| 1976 // Set up our form data. | 1952 // Set up our form data. |
| 1977 FormData form; | 1953 FormData form; |
| 1978 CreateTestCreditCardFormData(&form, true, false); | 1954 CreateTestCreditCardFormData(&form, true, false); |
| 1979 std::vector<FormData> forms(1, form); | 1955 std::vector<FormData> forms(1, form); |
| 1980 FormsSeen(forms); | 1956 FormsSeen(forms); |
| 1981 | 1957 |
| 1982 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); | 1958 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); |
| 1983 GUIDPair empty(std::string(), 0); | 1959 GUIDPair empty(std::string(), 0); |
| 1984 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 1960 int response_page_id = 0; |
| 1985 PackGUIDs(guid, empty)); | 1961 FormData response_data; |
| 1986 | 1962 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1987 int page_id = 0; | 1963 PackGUIDs(guid, empty), &response_page_id, &response_data); |
| 1988 FormData results; | 1964 ExpectFilledCreditCardFormElvis( |
| 1989 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1965 response_page_id, response_data, kDefaultPageID, false); |
| 1990 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); | |
| 1991 } | 1966 } |
| 1992 | 1967 |
| 1993 // Test that we correctly fill a credit card form with month input type. | 1968 // Test that we correctly fill a credit card form with month input type. |
| 1994 // 1. year empty, month empty | 1969 // 1. year empty, month empty |
| 1995 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1970 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { |
| 1996 // Same as the SetUp(), but generate 4 credit cards with year month | 1971 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1997 // combination. | 1972 // combination. |
| 1998 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1973 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
| 1999 // Set up our form data. | 1974 // Set up our form data. |
| 2000 FormData form; | 1975 FormData form; |
| 2001 CreateTestCreditCardFormData(&form, true, true); | 1976 CreateTestCreditCardFormData(&form, true, true); |
| 2002 std::vector<FormData> forms(1, form); | 1977 std::vector<FormData> forms(1, form); |
| 2003 FormsSeen(forms); | 1978 FormsSeen(forms); |
| 2004 | 1979 |
| 2005 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 1980 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); |
| 2006 GUIDPair empty(std::string(), 0); | 1981 GUIDPair empty(std::string(), 0); |
| 2007 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 1982 int response_page_id = 0; |
| 2008 PackGUIDs(guid, empty)); | 1983 FormData response_data; |
| 2009 | 1984 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2010 int page_id = 0; | 1985 PackGUIDs(guid, empty), &response_page_id, &response_data); |
| 2011 FormData results; | 1986 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2012 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2013 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 2014 kDefaultPageID, false, "", ""); | 1987 kDefaultPageID, false, "", ""); |
| 2015 } | 1988 } |
| 2016 | 1989 |
| 2017 | 1990 |
| 2018 // Test that we correctly fill a credit card form with month input type. | 1991 // Test that we correctly fill a credit card form with month input type. |
| 2019 // 2. year empty, month non-empty | 1992 // 2. year empty, month non-empty |
| 2020 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { | 1993 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { |
| 2021 // Same as the SetUp(), but generate 4 credit cards with year month | 1994 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2022 // combination. | 1995 // combination. |
| 2023 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); | 1996 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); |
| 2024 // Set up our form data. | 1997 // Set up our form data. |
| 2025 FormData form; | 1998 FormData form; |
| 2026 CreateTestCreditCardFormData(&form, true, true); | 1999 CreateTestCreditCardFormData(&form, true, true); |
| 2027 std::vector<FormData> forms(1, form); | 2000 std::vector<FormData> forms(1, form); |
| 2028 FormsSeen(forms); | 2001 FormsSeen(forms); |
| 2029 | 2002 |
| 2030 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 2003 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); |
| 2031 GUIDPair empty(std::string(), 0); | 2004 GUIDPair empty(std::string(), 0); |
| 2032 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 2005 int response_page_id = 0; |
| 2033 PackGUIDs(guid, empty)); | 2006 FormData response_data; |
| 2034 | 2007 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2035 int page_id = 0; | 2008 PackGUIDs(guid, empty), &response_page_id, &response_data); |
| 2036 FormData results; | 2009 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2037 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2038 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 2039 kDefaultPageID, false, "", "04"); | 2010 kDefaultPageID, false, "", "04"); |
| 2040 } | 2011 } |
| 2041 | 2012 |
| 2042 // Test that we correctly fill a credit card form with month input type. | 2013 // Test that we correctly fill a credit card form with month input type. |
| 2043 // 3. year non-empty, month empty | 2014 // 3. year non-empty, month empty |
| 2044 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { | 2015 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { |
| 2045 // Same as the SetUp(), but generate 4 credit cards with year month | 2016 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2046 // combination. | 2017 // combination. |
| 2047 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); | 2018 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); |
| 2048 // Set up our form data. | 2019 // Set up our form data. |
| 2049 FormData form; | 2020 FormData form; |
| 2050 CreateTestCreditCardFormData(&form, true, true); | 2021 CreateTestCreditCardFormData(&form, true, true); |
| 2051 std::vector<FormData> forms(1, form); | 2022 std::vector<FormData> forms(1, form); |
| 2052 FormsSeen(forms); | 2023 FormsSeen(forms); |
| 2053 | 2024 |
| 2054 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 2025 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); |
| 2055 GUIDPair empty(std::string(), 0); | 2026 GUIDPair empty(std::string(), 0); |
| 2056 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 2027 int response_page_id = 0; |
| 2057 PackGUIDs(guid, empty)); | 2028 FormData response_data; |
| 2058 | 2029 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2059 int page_id = 0; | 2030 PackGUIDs(guid, empty), &response_page_id, &response_data); |
| 2060 FormData results; | 2031 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2061 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2062 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 2063 kDefaultPageID, false, "2012", ""); | 2032 kDefaultPageID, false, "2012", ""); |
| 2064 } | 2033 } |
| 2065 | 2034 |
| 2066 // Test that we correctly fill a credit card form with month input type. | 2035 // Test that we correctly fill a credit card form with month input type. |
| 2067 // 4. year non-empty, month empty | 2036 // 4. year non-empty, month empty |
| 2068 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { | 2037 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { |
| 2069 // Same as the SetUp(), but generate 4 credit cards with year month | 2038 // Same as the SetUp(), but generate 4 credit cards with year month |
| 2070 // combination. | 2039 // combination. |
| 2071 personal_data_.ClearCreditCards(); | 2040 personal_data_.ClearCreditCards(); |
| 2072 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); | 2041 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); |
| 2073 // Set up our form data. | 2042 // Set up our form data. |
| 2074 FormData form; | 2043 FormData form; |
| 2075 CreateTestCreditCardFormData(&form, true, true); | 2044 CreateTestCreditCardFormData(&form, true, true); |
| 2076 std::vector<FormData> forms(1, form); | 2045 std::vector<FormData> forms(1, form); |
| 2077 FormsSeen(forms); | 2046 FormsSeen(forms); |
| 2078 | 2047 |
| 2079 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 2048 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); |
| 2080 GUIDPair empty(std::string(), 0); | 2049 GUIDPair empty(std::string(), 0); |
| 2081 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 2050 int response_page_id = 0; |
| 2082 PackGUIDs(guid, empty)); | 2051 FormData response_data; |
| 2083 | 2052 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2084 int page_id = 0; | 2053 PackGUIDs(guid, empty), &response_page_id, &response_data); |
| 2085 FormData results; | 2054 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 2086 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2087 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | |
| 2088 kDefaultPageID, false, "2012", "04"); | 2055 kDefaultPageID, false, "2012", "04"); |
| 2089 } | 2056 } |
| 2090 | 2057 |
| 2091 // Test that we correctly fill a combined address and credit card form. | 2058 // Test that we correctly fill a combined address and credit card form. |
| 2092 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { | 2059 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { |
| 2093 // Set up our form data. | 2060 // Set up our form data. |
| 2094 FormData form; | 2061 FormData form; |
| 2095 CreateTestAddressFormData(&form); | 2062 test::CreateTestAddressFormData(&form); |
| 2096 CreateTestCreditCardFormData(&form, true, false); | 2063 CreateTestCreditCardFormData(&form, true, false); |
| 2097 std::vector<FormData> forms(1, form); | 2064 std::vector<FormData> forms(1, form); |
| 2098 FormsSeen(forms); | 2065 FormsSeen(forms); |
| 2099 | 2066 |
| 2100 // First fill the address data. | 2067 // First fill the address data. |
| 2101 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2068 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2102 GUIDPair empty(std::string(), 0); | 2069 GUIDPair empty(std::string(), 0); |
| 2103 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2070 int response_page_id = 0; |
| 2104 PackGUIDs(empty, guid)); | 2071 FormData response_data; |
| 2105 | |
| 2106 int page_id = 0; | |
| 2107 FormData results; | |
| 2108 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2109 { | 2072 { |
| 2110 SCOPED_TRACE("Address"); | 2073 SCOPED_TRACE("Address"); |
| 2111 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, true); | 2074 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2075 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2076 ExpectFilledAddressFormElvis( |
| 2077 response_page_id, response_data, kDefaultPageID, true); |
| 2112 } | 2078 } |
| 2113 | 2079 |
| 2114 // Now fill the credit card data. | 2080 // Now fill the credit card data. |
| 2115 const int kPageID2 = 2; | 2081 const int kPageID2 = 2; |
| 2116 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); | 2082 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); |
| 2117 FillAutofillFormData(kPageID2, form, form.fields.back(), | 2083 response_page_id = 0; |
| 2118 PackGUIDs(guid2, empty)); | |
| 2119 | |
| 2120 page_id = 0; | |
| 2121 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2122 { | 2084 { |
| 2085 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 2086 PackGUIDs(guid2, empty), &response_page_id, &response_data); |
| 2123 SCOPED_TRACE("Credit card"); | 2087 SCOPED_TRACE("Credit card"); |
| 2124 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 2088 ExpectFilledCreditCardFormElvis( |
| 2089 response_page_id, response_data, kPageID2, true); |
| 2125 } | 2090 } |
| 2126 } | 2091 } |
| 2127 | 2092 |
| 2128 // Test that we correctly fill a form that has multiple logical sections, e.g. | 2093 // Test that we correctly fill a form that has multiple logical sections, e.g. |
| 2129 // both a billing and a shipping address. | 2094 // both a billing and a shipping address. |
| 2130 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) { | 2095 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) { |
| 2131 // Set up our form data. | 2096 // Set up our form data. |
| 2132 FormData form; | 2097 FormData form; |
| 2133 CreateTestAddressFormData(&form); | 2098 test::CreateTestAddressFormData(&form); |
| 2134 const size_t kAddressFormSize = form.fields.size(); | 2099 const size_t kAddressFormSize = form.fields.size(); |
| 2135 CreateTestAddressFormData(&form); | 2100 test::CreateTestAddressFormData(&form); |
| 2136 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 2101 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
| 2137 // Make sure the fields have distinct names. | 2102 // Make sure the fields have distinct names. |
| 2138 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); | 2103 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); |
| 2139 } | 2104 } |
| 2140 std::vector<FormData> forms(1, form); | 2105 std::vector<FormData> forms(1, form); |
| 2141 FormsSeen(forms); | 2106 FormsSeen(forms); |
| 2142 | 2107 |
| 2143 // Fill the first section. | 2108 // Fill the first section. |
| 2144 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2109 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2145 GUIDPair empty(std::string(), 0); | 2110 GUIDPair empty(std::string(), 0); |
| 2146 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2111 int response_page_id = 0; |
| 2147 PackGUIDs(empty, guid)); | 2112 FormData response_data; |
| 2148 | 2113 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2149 int page_id = 0; | 2114 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2150 FormData results; | |
| 2151 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2152 { | 2115 { |
| 2153 SCOPED_TRACE("Address 1"); | 2116 SCOPED_TRACE("Address 1"); |
| 2154 | |
| 2155 // The second address section should be empty. | 2117 // The second address section should be empty. |
| 2156 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize); | 2118 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); |
| 2157 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 2119 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
| 2158 EXPECT_EQ(base::string16(), results.fields[i].value); | 2120 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 2159 } | 2121 } |
| 2160 | 2122 |
| 2161 // The first address section should be filled with Elvis's data. | 2123 // The first address section should be filled with Elvis's data. |
| 2162 results.fields.resize(kAddressFormSize); | 2124 response_data.fields.resize(kAddressFormSize); |
| 2163 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2125 ExpectFilledAddressFormElvis( |
| 2126 response_page_id, response_data, kDefaultPageID, false); |
| 2164 } | 2127 } |
| 2165 | 2128 |
| 2166 // Fill the second section, with the initiating field somewhere in the middle | 2129 // Fill the second section, with the initiating field somewhere in the middle |
| 2167 // of the section. | 2130 // of the section. |
| 2168 const int kPageID2 = 2; | 2131 const int kPageID2 = 2; |
| 2169 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); | 2132 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); |
| 2170 ASSERT_LT(9U, kAddressFormSize); | 2133 ASSERT_LT(9U, kAddressFormSize); |
| 2171 FillAutofillFormData(kPageID2, form, form.fields[kAddressFormSize + 9], | 2134 response_page_id = 0; |
| 2172 PackGUIDs(empty, guid2)); | 2135 FillAutofillFormDataAndSaveResults( |
| 2173 | 2136 kPageID2, form, form.fields[kAddressFormSize + 9], |
| 2174 page_id = 0; | 2137 PackGUIDs(empty, guid2), &response_page_id, &response_data); |
| 2175 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2176 { | 2138 { |
| 2177 SCOPED_TRACE("Address 2"); | 2139 SCOPED_TRACE("Address 2"); |
| 2178 ASSERT_EQ(results.fields.size(), form.fields.size()); | 2140 ASSERT_EQ(response_data.fields.size(), form.fields.size()); |
| 2179 | 2141 |
| 2180 // The first address section should be empty. | 2142 // The first address section should be empty. |
| 2181 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize); | 2143 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); |
| 2182 for (size_t i = 0; i < kAddressFormSize; ++i) { | 2144 for (size_t i = 0; i < kAddressFormSize; ++i) { |
| 2183 EXPECT_EQ(base::string16(), results.fields[i].value); | 2145 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 2184 } | 2146 } |
| 2185 | 2147 |
| 2186 // The second address section should be filled with Elvis's data. | 2148 // The second address section should be filled with Elvis's data. |
| 2187 FormData secondSection = results; | 2149 FormData secondSection = response_data; |
| 2188 secondSection.fields.erase(secondSection.fields.begin(), | 2150 secondSection.fields.erase(secondSection.fields.begin(), |
| 2189 secondSection.fields.begin() + kAddressFormSize); | 2151 secondSection.fields.begin() + kAddressFormSize); |
| 2190 for (size_t i = 0; i < kAddressFormSize; ++i) { | 2152 for (size_t i = 0; i < kAddressFormSize; ++i) { |
| 2191 // Restore the expected field names. | 2153 // Restore the expected field names. |
| 2192 base::string16 name = secondSection.fields[i].name; | 2154 base::string16 name = secondSection.fields[i].name; |
| 2193 base::string16 original_name = name.substr(0, name.size() - 1); | 2155 base::string16 original_name = name.substr(0, name.size() - 1); |
| 2194 secondSection.fields[i].name = original_name; | 2156 secondSection.fields[i].name = original_name; |
| 2195 } | 2157 } |
| 2196 ExpectFilledAddressFormElvis(page_id, secondSection, kPageID2, false); | 2158 ExpectFilledAddressFormElvis( |
| 2159 response_page_id, secondSection, kPageID2, false); |
| 2197 } | 2160 } |
| 2198 } | 2161 } |
| 2199 | 2162 |
| 2200 // Test that we correctly fill a form that has author-specified sections, which | 2163 // Test that we correctly fill a form that has author-specified sections, which |
| 2201 // might not match our expected section breakdown. | 2164 // might not match our expected section breakdown. |
| 2202 TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) { | 2165 TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) { |
| 2203 // Create a form with a billing section and an unnamed section, interleaved. | 2166 // Create a form with a billing section and an unnamed section, interleaved. |
| 2204 // The billing section includes both address and credit card fields. | 2167 // The billing section includes both address and credit card fields. |
| 2205 FormData form; | 2168 FormData form; |
| 2206 form.name = ASCIIToUTF16("MyForm"); | 2169 form.name = ASCIIToUTF16("MyForm"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2254 test::CreateTestFormField("", "email", "", "text", &field); | 2217 test::CreateTestFormField("", "email", "", "text", &field); |
| 2255 field.autocomplete_attribute = "email"; | 2218 field.autocomplete_attribute = "email"; |
| 2256 form.fields.push_back(field); | 2219 form.fields.push_back(field); |
| 2257 | 2220 |
| 2258 std::vector<FormData> forms(1, form); | 2221 std::vector<FormData> forms(1, form); |
| 2259 FormsSeen(forms); | 2222 FormsSeen(forms); |
| 2260 | 2223 |
| 2261 // Fill the unnamed section. | 2224 // Fill the unnamed section. |
| 2262 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2225 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2263 GUIDPair empty(std::string(), 0); | 2226 GUIDPair empty(std::string(), 0); |
| 2264 FillAutofillFormData(kDefaultPageID, form, form.fields[1], | 2227 int response_page_id = 0; |
| 2265 PackGUIDs(empty, guid)); | 2228 FormData response_data; |
| 2266 | 2229 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[1], |
| 2267 int page_id = 0; | 2230 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2268 FormData results; | |
| 2269 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2270 { | 2231 { |
| 2271 SCOPED_TRACE("Unnamed section"); | 2232 SCOPED_TRACE("Unnamed section"); |
| 2272 EXPECT_EQ(kDefaultPageID, page_id); | 2233 EXPECT_EQ(kDefaultPageID, response_page_id); |
| 2273 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 2234 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 2274 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 2235 EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method); |
| 2275 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); | 2236 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 2276 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); | 2237 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 2277 EXPECT_TRUE(results.user_submitted); | 2238 EXPECT_TRUE(response_data.user_submitted); |
| 2278 ASSERT_EQ(11U, results.fields.size()); | 2239 ASSERT_EQ(11U, response_data.fields.size()); |
| 2279 | 2240 |
| 2280 ExpectFilledField("", "country", "", "text", results.fields[0]); | 2241 ExpectFilledField("", "country", "", "text", response_data.fields[0]); |
| 2281 ExpectFilledField("", "firstname", "Elvis", "text", results.fields[1]); | 2242 ExpectFilledField("", "firstname", "Elvis", "text", |
| 2282 ExpectFilledField("", "lastname", "Presley", "text", results.fields[2]); | 2243 response_data.fields[1]); |
| 2283 ExpectFilledField("", "address", "", "text", results.fields[3]); | 2244 ExpectFilledField("", "lastname", "Presley", "text", |
| 2284 ExpectFilledField("", "city", "", "text", results.fields[4]); | 2245 response_data.fields[2]); |
| 2285 ExpectFilledField("", "state", "", "text", results.fields[5]); | 2246 ExpectFilledField("", "address", "", "text", response_data.fields[3]); |
| 2286 ExpectFilledField("", "zip", "", "text", results.fields[6]); | 2247 ExpectFilledField("", "city", "", "text", response_data.fields[4]); |
| 2287 ExpectFilledField("", "ccname", "", "text", results.fields[7]); | 2248 ExpectFilledField("", "state", "", "text", response_data.fields[5]); |
| 2288 ExpectFilledField("", "ccnumber", "", "text", results.fields[8]); | 2249 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); |
| 2289 ExpectFilledField("", "ccexp", "", "text", results.fields[9]); | 2250 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); |
| 2251 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); |
| 2252 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); |
| 2290 ExpectFilledField("", "email", "theking@gmail.com", "text", | 2253 ExpectFilledField("", "email", "theking@gmail.com", "text", |
| 2291 results.fields[10]); | 2254 response_data.fields[10]); |
| 2292 } | 2255 } |
| 2293 | 2256 |
| 2294 // Fill the address portion of the billing section. | 2257 // Fill the address portion of the billing section. |
| 2295 const int kPageID2 = 2; | 2258 const int kPageID2 = 2; |
| 2296 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); | 2259 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); |
| 2297 FillAutofillFormData(kPageID2, form, form.fields[0], | 2260 response_page_id = 0; |
| 2298 PackGUIDs(empty, guid2)); | 2261 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], |
| 2299 | 2262 PackGUIDs(empty, guid2), &response_page_id, &response_data); |
| 2300 page_id = 0; | |
| 2301 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2302 { | 2263 { |
| 2303 SCOPED_TRACE("Billing address"); | 2264 SCOPED_TRACE("Billing address"); |
| 2304 EXPECT_EQ(kPageID2, page_id); | 2265 EXPECT_EQ(kPageID2, response_page_id); |
| 2305 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 2266 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 2306 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 2267 EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method); |
| 2307 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); | 2268 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 2308 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); | 2269 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 2309 EXPECT_TRUE(results.user_submitted); | 2270 EXPECT_TRUE(response_data.user_submitted); |
| 2310 ASSERT_EQ(11U, results.fields.size()); | 2271 ASSERT_EQ(11U, response_data.fields.size()); |
| 2311 | 2272 |
| 2312 ExpectFilledField("", "country", "United States", "text", | 2273 ExpectFilledField("", "country", "United States", "text", |
| 2313 results.fields[0]); | 2274 response_data.fields[0]); |
| 2314 ExpectFilledField("", "firstname", "", "text", results.fields[1]); | 2275 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); |
| 2315 ExpectFilledField("", "lastname", "", "text", results.fields[2]); | 2276 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); |
| 2316 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", | 2277 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", |
| 2317 results.fields[3]); | 2278 response_data.fields[3]); |
| 2318 ExpectFilledField("", "city", "Memphis", "text", results.fields[4]); | 2279 ExpectFilledField("", "city", "Memphis", "text", response_data.fields[4]); |
| 2319 ExpectFilledField("", "state", "Tennessee", "text", results.fields[5]); | 2280 ExpectFilledField("", "state", "Tennessee", "text", |
| 2320 ExpectFilledField("", "zip", "38116", "text", results.fields[6]); | 2281 response_data.fields[5]); |
| 2321 ExpectFilledField("", "ccname", "", "text", results.fields[7]); | 2282 ExpectFilledField("", "zip", "38116", "text", response_data.fields[6]); |
| 2322 ExpectFilledField("", "ccnumber", "", "text", results.fields[8]); | 2283 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); |
| 2323 ExpectFilledField("", "ccexp", "", "text", results.fields[9]); | 2284 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); |
| 2324 ExpectFilledField("", "email", "", "text", results.fields[10]); | 2285 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); |
| 2286 ExpectFilledField("", "email", "", "text", response_data.fields[10]); |
| 2325 } | 2287 } |
| 2326 | 2288 |
| 2327 // Fill the credit card portion of the billing section. | 2289 // Fill the credit card portion of the billing section. |
| 2328 const int kPageID3 = 3; | 2290 const int kPageID3 = 3; |
| 2329 GUIDPair guid3("00000000-0000-0000-0000-000000000004", 0); | 2291 GUIDPair guid3("00000000-0000-0000-0000-000000000004", 0); |
| 2330 FillAutofillFormData(kPageID3, form, form.fields[form.fields.size() - 2], | 2292 response_page_id = 0; |
| 2331 PackGUIDs(guid3, empty)); | 2293 FillAutofillFormDataAndSaveResults( |
| 2332 | 2294 kPageID3, form, form.fields[form.fields.size() - 2], |
| 2333 page_id = 0; | 2295 PackGUIDs(guid3, empty), &response_page_id, &response_data); |
| 2334 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2335 { | 2296 { |
| 2336 SCOPED_TRACE("Credit card"); | 2297 SCOPED_TRACE("Credit card"); |
| 2337 EXPECT_EQ(kPageID3, page_id); | 2298 EXPECT_EQ(kPageID3, response_page_id); |
| 2338 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 2299 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 2339 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 2300 EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method); |
| 2340 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); | 2301 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 2341 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); | 2302 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 2342 EXPECT_TRUE(results.user_submitted); | 2303 EXPECT_TRUE(response_data.user_submitted); |
| 2343 ASSERT_EQ(11U, results.fields.size()); | 2304 ASSERT_EQ(11U, response_data.fields.size()); |
| 2344 | 2305 |
| 2345 ExpectFilledField("", "country", "", "text", results.fields[0]); | 2306 ExpectFilledField("", "country", "", "text", response_data.fields[0]); |
| 2346 ExpectFilledField("", "firstname", "", "text", results.fields[1]); | 2307 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); |
| 2347 ExpectFilledField("", "lastname", "", "text", results.fields[2]); | 2308 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); |
| 2348 ExpectFilledField("", "address", "", "text", results.fields[3]); | 2309 ExpectFilledField("", "address", "", "text", response_data.fields[3]); |
| 2349 ExpectFilledField("", "city", "", "text", results.fields[4]); | 2310 ExpectFilledField("", "city", "", "text", response_data.fields[4]); |
| 2350 ExpectFilledField("", "state", "", "text", results.fields[5]); | 2311 ExpectFilledField("", "state", "", "text", response_data.fields[5]); |
| 2351 ExpectFilledField("", "zip", "", "text", results.fields[6]); | 2312 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); |
| 2352 ExpectFilledField("", "ccname", "Elvis Presley", "text", results.fields[7]); | 2313 ExpectFilledField("", "ccname", "Elvis Presley", "text", |
| 2314 response_data.fields[7]); |
| 2353 ExpectFilledField("", "ccnumber", "4234567890123456", "text", | 2315 ExpectFilledField("", "ccnumber", "4234567890123456", "text", |
| 2354 results.fields[8]); | 2316 response_data.fields[8]); |
| 2355 ExpectFilledField("", "ccexp", "04/2012", "text", results.fields[9]); | 2317 ExpectFilledField("", "ccexp", "04/2012", "text", response_data.fields[9]); |
| 2356 ExpectFilledField("", "email", "", "text", results.fields[10]); | 2318 ExpectFilledField("", "email", "", "text", response_data.fields[10]); |
| 2357 } | 2319 } |
| 2358 } | 2320 } |
| 2359 | 2321 |
| 2360 // Test that we correctly fill a form that has a single logical section with | 2322 // Test that we correctly fill a form that has a single logical section with |
| 2361 // multiple email address fields. | 2323 // multiple email address fields. |
| 2362 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { | 2324 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { |
| 2363 // Set up our form data. | 2325 // Set up our form data. |
| 2364 FormData form; | 2326 FormData form; |
| 2365 CreateTestAddressFormData(&form); | 2327 test::CreateTestAddressFormData(&form); |
| 2366 FormFieldData field; | 2328 FormFieldData field; |
| 2367 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); | 2329 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); |
| 2368 form.fields.push_back(field); | 2330 form.fields.push_back(field); |
| 2369 | 2331 |
| 2370 std::vector<FormData> forms(1, form); | 2332 std::vector<FormData> forms(1, form); |
| 2371 FormsSeen(forms); | 2333 FormsSeen(forms); |
| 2372 | 2334 |
| 2373 // Fill the form. | 2335 // Fill the form. |
| 2374 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2336 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2375 GUIDPair empty(std::string(), 0); | 2337 GUIDPair empty(std::string(), 0); |
| 2376 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2338 int response_page_id = 0; |
| 2377 PackGUIDs(empty, guid)); | 2339 FormData response_data; |
| 2378 | 2340 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2379 int page_id = 0; | 2341 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2380 FormData results; | |
| 2381 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2382 | 2342 |
| 2383 // The second email address should be filled. | 2343 // The second email address should be filled. |
| 2384 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), results.fields.back().value); | 2344 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), |
| 2345 response_data.fields.back().value); |
| 2385 | 2346 |
| 2386 // The remainder of the form should be filled as usual. | 2347 // The remainder of the form should be filled as usual. |
| 2387 results.fields.pop_back(); | 2348 response_data.fields.pop_back(); |
| 2388 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2349 ExpectFilledAddressFormElvis( |
| 2350 response_page_id, response_data, kDefaultPageID, false); |
| 2389 } | 2351 } |
| 2390 | 2352 |
| 2391 // Test that we correctly fill a previously auto-filled form. | 2353 // Test that we correctly fill a previously auto-filled form. |
| 2392 TEST_F(AutofillManagerTest, FillAutofilledForm) { | 2354 TEST_F(AutofillManagerTest, FillAutofilledForm) { |
| 2393 // Set up our form data. | 2355 // Set up our form data. |
| 2394 FormData form; | 2356 FormData form; |
| 2395 CreateTestAddressFormData(&form); | 2357 test::CreateTestAddressFormData(&form); |
| 2396 // Mark one of the address fields as autofilled. | 2358 // Mark one of the address fields as autofilled. |
| 2397 form.fields[4].is_autofilled = true; | 2359 form.fields[4].is_autofilled = true; |
| 2398 CreateTestCreditCardFormData(&form, true, false); | 2360 CreateTestCreditCardFormData(&form, true, false); |
| 2399 std::vector<FormData> forms(1, form); | 2361 std::vector<FormData> forms(1, form); |
| 2400 FormsSeen(forms); | 2362 FormsSeen(forms); |
| 2401 | 2363 |
| 2402 // First fill the address data. | 2364 // First fill the address data. |
| 2403 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2365 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2404 GUIDPair empty(std::string(), 0); | 2366 GUIDPair empty(std::string(), 0); |
| 2405 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 2367 int response_page_id = 0; |
| 2406 PackGUIDs(empty, guid)); | 2368 FormData response_data; |
| 2407 | 2369 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2408 int page_id = 0; | 2370 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2409 FormData results; | |
| 2410 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2411 { | 2371 { |
| 2412 SCOPED_TRACE("Address"); | 2372 SCOPED_TRACE("Address"); |
| 2413 ExpectFilledForm(page_id, results, kDefaultPageID, | 2373 ExpectFilledForm(response_page_id, response_data, kDefaultPageID, |
| 2414 "Elvis", "", "", "", "", "", "", "", "", "", "", "", "", | 2374 "Elvis", "", "", "", "", "", "", "", "", "", "", "", "", |
| 2415 "", "", true, true, false); | 2375 "", "", true, true, false); |
| 2416 } | 2376 } |
| 2417 | 2377 |
| 2418 // Now fill the credit card data. | 2378 // Now fill the credit card data. |
| 2419 const int kPageID2 = 2; | 2379 const int kPageID2 = 2; |
| 2420 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); | 2380 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); |
| 2421 FillAutofillFormData(kPageID2, form, form.fields.back(), | 2381 response_page_id = 0; |
| 2422 PackGUIDs(guid2, empty)); | 2382 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 2423 | 2383 PackGUIDs(guid2, empty), &response_page_id, &response_data); |
| 2424 page_id = 0; | |
| 2425 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2426 { | 2384 { |
| 2427 SCOPED_TRACE("Credit card 1"); | 2385 SCOPED_TRACE("Credit card 1"); |
| 2428 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 2386 ExpectFilledCreditCardFormElvis( |
| 2387 response_page_id, response_data, kPageID2, true); |
| 2429 } | 2388 } |
| 2430 | 2389 |
| 2431 // Now set the credit card fields to also be auto-filled, and try again to | 2390 // Now set the credit card fields to also be auto-filled, and try again to |
| 2432 // fill the credit card data | 2391 // fill the credit card data |
| 2433 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); | 2392 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); |
| 2434 iter != form.fields.end(); | 2393 iter != form.fields.end(); |
| 2435 ++iter) { | 2394 ++iter) { |
| 2436 iter->is_autofilled = true; | 2395 iter->is_autofilled = true; |
| 2437 } | 2396 } |
| 2438 | 2397 |
| 2439 const int kPageID3 = 3; | 2398 const int kPageID3 = 3; |
| 2440 FillAutofillFormData(kPageID3, form, *form.fields.rbegin(), | 2399 response_page_id = 0; |
| 2441 PackGUIDs(guid2, empty)); | 2400 FillAutofillFormDataAndSaveResults(kPageID3, form, *form.fields.rbegin(), |
| 2442 | 2401 PackGUIDs(guid2, empty), &response_page_id, &response_data); |
| 2443 page_id = 0; | |
| 2444 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2445 { | 2402 { |
| 2446 SCOPED_TRACE("Credit card 2"); | 2403 SCOPED_TRACE("Credit card 2"); |
| 2447 ExpectFilledForm(page_id, results, kPageID3, | 2404 ExpectFilledForm(response_page_id, response_data, kPageID3, |
| 2448 "", "", "", "", "", "", "", "", "", "", "", "", "", "", | 2405 "", "", "", "", "", "", "", "", "", "", "", "", "", "", |
| 2449 "2012", true, true, false); | 2406 "2012", true, true, false); |
| 2450 } | 2407 } |
| 2451 } | 2408 } |
| 2452 | 2409 |
| 2453 // Test that we correctly fill an address form with a non-default variant for a | 2410 // Test that we correctly fill an address form with a non-default variant for a |
| 2454 // multi-valued field. | 2411 // multi-valued field. |
| 2455 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { | 2412 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { |
| 2456 // Set up our form data. | 2413 // Set up our form data. |
| 2457 FormData form; | 2414 FormData form; |
| 2458 CreateTestAddressFormData(&form); | 2415 test::CreateTestAddressFormData(&form); |
| 2459 std::vector<FormData> forms(1, form); | 2416 std::vector<FormData> forms(1, form); |
| 2460 FormsSeen(forms); | 2417 FormsSeen(forms); |
| 2461 | 2418 |
| 2462 // Add a name variant to the Elvis profile. | 2419 // Add a name variant to the Elvis profile. |
| 2463 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( | 2420 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( |
| 2464 "00000000-0000-0000-0000-000000000001"); | 2421 "00000000-0000-0000-0000-000000000001"); |
| 2465 const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL); | 2422 const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL); |
| 2466 | 2423 |
| 2467 std::vector<base::string16> name_variants; | 2424 std::vector<base::string16> name_variants; |
| 2468 name_variants.push_back(ASCIIToUTF16("Some Other Guy")); | 2425 name_variants.push_back(ASCIIToUTF16("Some Other Guy")); |
| 2469 name_variants.push_back(elvis_name); | 2426 name_variants.push_back(elvis_name); |
| 2470 profile->SetRawMultiInfo(NAME_FULL, name_variants); | 2427 profile->SetRawMultiInfo(NAME_FULL, name_variants); |
| 2471 | 2428 |
| 2472 GUIDPair guid(profile->guid(), 1); | 2429 GUIDPair guid(profile->guid(), 1); |
| 2473 GUIDPair empty(std::string(), 0); | 2430 GUIDPair empty(std::string(), 0); |
| 2474 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2431 int response_page_id = 0; |
| 2475 PackGUIDs(empty, guid)); | 2432 FormData response_data1; |
| 2476 | 2433 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2477 int page_id = 0; | 2434 PackGUIDs(empty, guid), &response_page_id, &response_data1); |
| 2478 FormData results1; | |
| 2479 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results1)); | |
| 2480 { | 2435 { |
| 2481 SCOPED_TRACE("Valid variant"); | 2436 SCOPED_TRACE("Valid variant"); |
| 2482 ExpectFilledAddressFormElvis(page_id, results1, kDefaultPageID, false); | 2437 ExpectFilledAddressFormElvis( |
| 2438 response_page_id, response_data1, kDefaultPageID, false); |
| 2483 } | 2439 } |
| 2484 | 2440 |
| 2485 // Try filling with a variant that doesn't exist. The fields to which this | 2441 // Try filling with a variant that doesn't exist. The fields to which this |
| 2486 // variant would normally apply should not be filled. | 2442 // variant would normally apply should not be filled. |
| 2487 const int kPageID2 = 2; | 2443 const int kPageID2 = 2; |
| 2488 GUIDPair guid2(profile->guid(), 2); | 2444 GUIDPair guid2(profile->guid(), 2); |
| 2489 FillAutofillFormData(kPageID2, form, form.fields[0], | 2445 response_page_id = 0; |
| 2490 PackGUIDs(empty, guid2)); | 2446 FormData response_data2; |
| 2491 | 2447 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], |
| 2492 page_id = 0; | 2448 PackGUIDs(empty, guid2), &response_page_id, &response_data2); |
| 2493 FormData results2; | |
| 2494 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results2)); | |
| 2495 { | 2449 { |
| 2496 SCOPED_TRACE("Invalid variant"); | 2450 SCOPED_TRACE("Invalid variant"); |
| 2497 ExpectFilledForm(page_id, results2, kPageID2, "", "", "", | 2451 ExpectFilledForm(response_page_id, response_data2, kPageID2, "", "", "", |
| 2498 "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 2452 "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
| 2499 "Tennessee", "38116", "United States", "12345678901", | 2453 "Tennessee", "38116", "United States", "12345678901", |
| 2500 "theking@gmail.com", "", "", "", "", true, false, false); | 2454 "theking@gmail.com", "", "", "", "", true, false, false); |
| 2501 } | 2455 } |
| 2502 } | 2456 } |
| 2503 | 2457 |
| 2504 // Test that we correctly fill a phone number split across multiple fields. | 2458 // Test that we correctly fill a phone number split across multiple fields. |
| 2505 TEST_F(AutofillManagerTest, FillPhoneNumber) { | 2459 TEST_F(AutofillManagerTest, FillPhoneNumber) { |
| 2506 // In one form, rely on the maxlength attribute to imply phone number parts. | 2460 // In one form, rely on the maxlength attribute to imply phone number parts. |
| 2507 // In the other form, rely on the autocompletetype attribute. | 2461 // In the other form, rely on the autocompletetype attribute. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 | 2502 |
| 2549 // We should be able to fill prefix and suffix fields for US numbers. | 2503 // We should be able to fill prefix and suffix fields for US numbers. |
| 2550 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( | 2504 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( |
| 2551 "00000000-0000-0000-0000-000000000002"); | 2505 "00000000-0000-0000-0000-000000000002"); |
| 2552 ASSERT_TRUE(work_profile != NULL); | 2506 ASSERT_TRUE(work_profile != NULL); |
| 2553 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 2507 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 2554 ASCIIToUTF16("16505554567")); | 2508 ASCIIToUTF16("16505554567")); |
| 2555 | 2509 |
| 2556 GUIDPair guid(work_profile->guid(), 0); | 2510 GUIDPair guid(work_profile->guid(), 0); |
| 2557 GUIDPair empty(std::string(), 0); | 2511 GUIDPair empty(std::string(), 0); |
| 2512 int page_id = 1; |
| 2513 int response_page_id = 0; |
| 2514 FormData response_data1; |
| 2515 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2516 *form_with_maxlength.fields.begin(), |
| 2517 PackGUIDs(empty, guid), &response_page_id, &response_data1); |
| 2518 EXPECT_EQ(1, response_page_id); |
| 2558 | 2519 |
| 2559 int page_id = 1; | 2520 ASSERT_EQ(5U, response_data1.fields.size()); |
| 2560 FillAutofillFormData(page_id, form_with_maxlength, | 2521 EXPECT_EQ(ASCIIToUTF16("1"), response_data1.fields[0].value); |
| 2561 *form_with_maxlength.fields.begin(), | 2522 EXPECT_EQ(ASCIIToUTF16("650"), response_data1.fields[1].value); |
| 2562 PackGUIDs(empty, guid)); | 2523 EXPECT_EQ(ASCIIToUTF16("555"), response_data1.fields[2].value); |
| 2563 page_id = 0; | 2524 EXPECT_EQ(ASCIIToUTF16("4567"), response_data1.fields[3].value); |
| 2564 FormData results1; | 2525 EXPECT_EQ(base::string16(), response_data1.fields[4].value); |
| 2565 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results1)); | |
| 2566 EXPECT_EQ(1, page_id); | |
| 2567 | |
| 2568 ASSERT_EQ(5U, results1.fields.size()); | |
| 2569 EXPECT_EQ(ASCIIToUTF16("1"), results1.fields[0].value); | |
| 2570 EXPECT_EQ(ASCIIToUTF16("650"), results1.fields[1].value); | |
| 2571 EXPECT_EQ(ASCIIToUTF16("555"), results1.fields[2].value); | |
| 2572 EXPECT_EQ(ASCIIToUTF16("4567"), results1.fields[3].value); | |
| 2573 EXPECT_EQ(base::string16(), results1.fields[4].value); | |
| 2574 | 2526 |
| 2575 page_id = 2; | 2527 page_id = 2; |
| 2576 FillAutofillFormData(page_id, form_with_autocompletetype, | 2528 response_page_id = 0; |
| 2577 *form_with_autocompletetype.fields.begin(), | 2529 FormData response_data2; |
| 2578 PackGUIDs(empty, guid)); | 2530 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, |
| 2579 page_id = 0; | 2531 *form_with_autocompletetype.fields.begin(), |
| 2580 FormData results2; | 2532 PackGUIDs(empty, guid), &response_page_id, &response_data2); |
| 2581 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results2)); | 2533 EXPECT_EQ(2, response_page_id); |
| 2582 EXPECT_EQ(2, page_id); | |
| 2583 | 2534 |
| 2584 ASSERT_EQ(5U, results2.fields.size()); | 2535 ASSERT_EQ(5U, response_data2.fields.size()); |
| 2585 EXPECT_EQ(ASCIIToUTF16("1"), results2.fields[0].value); | 2536 EXPECT_EQ(ASCIIToUTF16("1"), response_data2.fields[0].value); |
| 2586 EXPECT_EQ(ASCIIToUTF16("650"), results2.fields[1].value); | 2537 EXPECT_EQ(ASCIIToUTF16("650"), response_data2.fields[1].value); |
| 2587 EXPECT_EQ(ASCIIToUTF16("555"), results2.fields[2].value); | 2538 EXPECT_EQ(ASCIIToUTF16("555"), response_data2.fields[2].value); |
| 2588 EXPECT_EQ(ASCIIToUTF16("4567"), results2.fields[3].value); | 2539 EXPECT_EQ(ASCIIToUTF16("4567"), response_data2.fields[3].value); |
| 2589 EXPECT_EQ(base::string16(), results2.fields[4].value); | 2540 EXPECT_EQ(base::string16(), response_data2.fields[4].value); |
| 2590 | 2541 |
| 2591 // We should not be able to fill prefix and suffix fields for international | 2542 // We should not be able to fill prefix and suffix fields for international |
| 2592 // numbers. | 2543 // numbers. |
| 2593 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); | 2544 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); |
| 2594 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 2545 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 2595 ASCIIToUTF16("447700954321")); | 2546 ASCIIToUTF16("447700954321")); |
| 2596 page_id = 3; | 2547 page_id = 3; |
| 2597 FillAutofillFormData(page_id, form_with_maxlength, | 2548 response_page_id = 0; |
| 2598 *form_with_maxlength.fields.begin(), | 2549 FormData response_data3; |
| 2599 PackGUIDs(empty, guid)); | 2550 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2600 page_id = 0; | 2551 *form_with_maxlength.fields.begin(), |
| 2601 FormData results3; | 2552 PackGUIDs(empty, guid), &response_page_id, &response_data3); |
| 2602 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results3)); | 2553 EXPECT_EQ(3, response_page_id); |
| 2603 EXPECT_EQ(3, page_id); | |
| 2604 | 2554 |
| 2605 ASSERT_EQ(5U, results3.fields.size()); | 2555 ASSERT_EQ(5U, response_data3.fields.size()); |
| 2606 EXPECT_EQ(ASCIIToUTF16("44"), results3.fields[0].value); | 2556 EXPECT_EQ(ASCIIToUTF16("44"), response_data3.fields[0].value); |
| 2607 EXPECT_EQ(ASCIIToUTF16("7700"), results3.fields[1].value); | 2557 EXPECT_EQ(ASCIIToUTF16("7700"), response_data3.fields[1].value); |
| 2608 EXPECT_EQ(ASCIIToUTF16("954321"), results3.fields[2].value); | 2558 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[2].value); |
| 2609 EXPECT_EQ(ASCIIToUTF16("954321"), results3.fields[3].value); | 2559 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[3].value); |
| 2610 EXPECT_EQ(base::string16(), results3.fields[4].value); | 2560 EXPECT_EQ(base::string16(), response_data3.fields[4].value); |
| 2611 | 2561 |
| 2612 page_id = 4; | 2562 page_id = 4; |
| 2613 FillAutofillFormData(page_id, form_with_autocompletetype, | 2563 response_page_id = 0; |
| 2614 *form_with_autocompletetype.fields.begin(), | 2564 FormData response_data4; |
| 2615 PackGUIDs(empty, guid)); | 2565 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, |
| 2616 page_id = 0; | 2566 *form_with_autocompletetype.fields.begin(), |
| 2617 FormData results4; | 2567 PackGUIDs(empty, guid), &response_page_id, &response_data4); |
| 2618 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results4)); | 2568 EXPECT_EQ(4, response_page_id); |
| 2619 EXPECT_EQ(4, page_id); | |
| 2620 | 2569 |
| 2621 ASSERT_EQ(5U, results4.fields.size()); | 2570 ASSERT_EQ(5U, response_data4.fields.size()); |
| 2622 EXPECT_EQ(ASCIIToUTF16("44"), results4.fields[0].value); | 2571 EXPECT_EQ(ASCIIToUTF16("44"), response_data4.fields[0].value); |
| 2623 EXPECT_EQ(ASCIIToUTF16("7700"), results4.fields[1].value); | 2572 EXPECT_EQ(ASCIIToUTF16("7700"), response_data4.fields[1].value); |
| 2624 EXPECT_EQ(ASCIIToUTF16("954321"), results4.fields[2].value); | 2573 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[2].value); |
| 2625 EXPECT_EQ(ASCIIToUTF16("954321"), results4.fields[3].value); | 2574 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[3].value); |
| 2626 EXPECT_EQ(base::string16(), results4.fields[4].value); | 2575 EXPECT_EQ(base::string16(), response_data4.fields[4].value); |
| 2627 | 2576 |
| 2628 // We should fill all phone fields with the same phone number variant. | 2577 // We should fill all phone fields with the same phone number variant. |
| 2629 std::vector<base::string16> phone_variants; | 2578 std::vector<base::string16> phone_variants; |
| 2630 phone_variants.push_back(ASCIIToUTF16("16505554567")); | 2579 phone_variants.push_back(ASCIIToUTF16("16505554567")); |
| 2631 phone_variants.push_back(ASCIIToUTF16("18887771234")); | 2580 phone_variants.push_back(ASCIIToUTF16("18887771234")); |
| 2632 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 2581 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 2633 work_profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_variants); | 2582 work_profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_variants); |
| 2634 | 2583 |
| 2635 page_id = 5; | 2584 page_id = 5; |
| 2585 response_page_id = 0; |
| 2586 FormData response_data5; |
| 2636 GUIDPair variant_guid(work_profile->guid(), 1); | 2587 GUIDPair variant_guid(work_profile->guid(), 1); |
| 2637 FillAutofillFormData(page_id, form_with_maxlength, | 2588 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2638 *form_with_maxlength.fields.begin(), | 2589 *form_with_maxlength.fields.begin(), |
| 2639 PackGUIDs(empty, variant_guid)); | 2590 PackGUIDs(empty, variant_guid), &response_page_id, &response_data5); |
| 2640 page_id = 0; | 2591 EXPECT_EQ(5, response_page_id); |
| 2641 FormData results5; | |
| 2642 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results5)); | |
| 2643 EXPECT_EQ(5, page_id); | |
| 2644 | 2592 |
| 2645 ASSERT_EQ(5U, results5.fields.size()); | 2593 ASSERT_EQ(5U, response_data5.fields.size()); |
| 2646 EXPECT_EQ(ASCIIToUTF16("1"), results5.fields[0].value); | 2594 EXPECT_EQ(ASCIIToUTF16("1"), response_data5.fields[0].value); |
| 2647 EXPECT_EQ(ASCIIToUTF16("888"), results5.fields[1].value); | 2595 EXPECT_EQ(ASCIIToUTF16("888"), response_data5.fields[1].value); |
| 2648 EXPECT_EQ(ASCIIToUTF16("777"), results5.fields[2].value); | 2596 EXPECT_EQ(ASCIIToUTF16("777"), response_data5.fields[2].value); |
| 2649 EXPECT_EQ(ASCIIToUTF16("1234"), results5.fields[3].value); | 2597 EXPECT_EQ(ASCIIToUTF16("1234"), response_data5.fields[3].value); |
| 2650 EXPECT_EQ(base::string16(), results5.fields[4].value); | 2598 EXPECT_EQ(base::string16(), response_data5.fields[4].value); |
| 2651 } | 2599 } |
| 2652 | 2600 |
| 2653 // Test that we can still fill a form when a field has been removed from it. | 2601 // Test that we can still fill a form when a field has been removed from it. |
| 2654 TEST_F(AutofillManagerTest, FormChangesRemoveField) { | 2602 TEST_F(AutofillManagerTest, FormChangesRemoveField) { |
| 2655 // Set up our form data. | 2603 // Set up our form data. |
| 2656 FormData form; | 2604 FormData form; |
| 2657 CreateTestAddressFormData(&form); | 2605 test::CreateTestAddressFormData(&form); |
| 2658 | 2606 |
| 2659 // Add a field -- we'll remove it again later. | 2607 // Add a field -- we'll remove it again later. |
| 2660 FormFieldData field; | 2608 FormFieldData field; |
| 2661 test::CreateTestFormField("Some", "field", "", "text", &field); | 2609 test::CreateTestFormField("Some", "field", "", "text", &field); |
| 2662 form.fields.insert(form.fields.begin() + 3, field); | 2610 form.fields.insert(form.fields.begin() + 3, field); |
| 2663 | 2611 |
| 2664 std::vector<FormData> forms(1, form); | 2612 std::vector<FormData> forms(1, form); |
| 2665 FormsSeen(forms); | 2613 FormsSeen(forms); |
| 2666 | 2614 |
| 2667 // Now, after the call to |FormsSeen|, we remove the field before filling. | 2615 // Now, after the call to |FormsSeen|, we remove the field before filling. |
| 2668 form.fields.erase(form.fields.begin() + 3); | 2616 form.fields.erase(form.fields.begin() + 3); |
| 2669 | 2617 |
| 2670 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2618 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2671 GUIDPair empty(std::string(), 0); | 2619 GUIDPair empty(std::string(), 0); |
| 2672 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2620 int response_page_id = 0; |
| 2673 PackGUIDs(empty, guid)); | 2621 FormData response_data; |
| 2674 | 2622 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2675 int page_id = 0; | 2623 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2676 FormData results; | 2624 ExpectFilledAddressFormElvis( |
| 2677 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2625 response_page_id, response_data, kDefaultPageID, false); |
| 2678 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 2679 } | 2626 } |
| 2680 | 2627 |
| 2681 // Test that we can still fill a form when a field has been added to it. | 2628 // Test that we can still fill a form when a field has been added to it. |
| 2682 TEST_F(AutofillManagerTest, FormChangesAddField) { | 2629 TEST_F(AutofillManagerTest, FormChangesAddField) { |
| 2683 // The offset of the phone field in the address form. | 2630 // The offset of the phone field in the address form. |
| 2684 const int kPhoneFieldOffset = 9; | 2631 const int kPhoneFieldOffset = 9; |
| 2685 | 2632 |
| 2686 // Set up our form data. | 2633 // Set up our form data. |
| 2687 FormData form; | 2634 FormData form; |
| 2688 CreateTestAddressFormData(&form); | 2635 test::CreateTestAddressFormData(&form); |
| 2689 | 2636 |
| 2690 // Remove the phone field -- we'll add it back later. | 2637 // Remove the phone field -- we'll add it back later. |
| 2691 std::vector<FormFieldData>::iterator pos = | 2638 std::vector<FormFieldData>::iterator pos = |
| 2692 form.fields.begin() + kPhoneFieldOffset; | 2639 form.fields.begin() + kPhoneFieldOffset; |
| 2693 FormFieldData field = *pos; | 2640 FormFieldData field = *pos; |
| 2694 pos = form.fields.erase(pos); | 2641 pos = form.fields.erase(pos); |
| 2695 | 2642 |
| 2696 std::vector<FormData> forms(1, form); | 2643 std::vector<FormData> forms(1, form); |
| 2697 FormsSeen(forms); | 2644 FormsSeen(forms); |
| 2698 | 2645 |
| 2699 // Now, after the call to |FormsSeen|, we restore the field before filling. | 2646 // Now, after the call to |FormsSeen|, we restore the field before filling. |
| 2700 form.fields.insert(pos, field); | 2647 form.fields.insert(pos, field); |
| 2701 | 2648 |
| 2702 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2649 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2703 GUIDPair empty(std::string(), 0); | 2650 GUIDPair empty(std::string(), 0); |
| 2704 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2651 int response_page_id = 0; |
| 2705 PackGUIDs(empty, guid)); | 2652 FormData response_data; |
| 2706 | 2653 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2707 int page_id = 0; | 2654 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2708 FormData results; | 2655 ExpectFilledAddressFormElvis( |
| 2709 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2656 response_page_id, response_data, kDefaultPageID, false); |
| 2710 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 2711 } | 2657 } |
| 2712 | 2658 |
| 2713 // Test that we are able to save form data when forms are submitted. | 2659 // Test that we are able to save form data when forms are submitted. |
| 2714 TEST_F(AutofillManagerTest, FormSubmitted) { | 2660 TEST_F(AutofillManagerTest, FormSubmitted) { |
| 2715 // Set up our form data. | 2661 // Set up our form data. |
| 2716 FormData form; | 2662 FormData form; |
| 2717 CreateTestAddressFormData(&form); | 2663 test::CreateTestAddressFormData(&form); |
| 2718 std::vector<FormData> forms(1, form); | 2664 std::vector<FormData> forms(1, form); |
| 2719 FormsSeen(forms); | 2665 FormsSeen(forms); |
| 2720 | 2666 |
| 2721 // Fill the form. | 2667 // Fill the form. |
| 2722 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2668 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2723 GUIDPair empty(std::string(), 0); | 2669 GUIDPair empty(std::string(), 0); |
| 2724 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2670 int response_page_id = 0; |
| 2725 PackGUIDs(empty, guid)); | 2671 FormData response_data; |
| 2726 | 2672 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2727 int page_id = 0; | 2673 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2728 FormData results; | 2674 ExpectFilledAddressFormElvis( |
| 2729 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2675 response_page_id, response_data, kDefaultPageID, false); |
| 2730 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 2731 | 2676 |
| 2732 // Simulate form submission. We should call into the PDM to try to save the | 2677 // Simulate form submission. We should call into the PDM to try to save the |
| 2733 // filled data. | 2678 // filled data. |
| 2734 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2679 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2735 FormSubmitted(results); | 2680 FormSubmitted(response_data); |
| 2736 } | 2681 } |
| 2737 | 2682 |
| 2738 // Test that when Autocomplete is enabled and Autofill is disabled, | 2683 // Test that when Autocomplete is enabled and Autofill is disabled, |
| 2739 // form submissions are still received by AutocompleteHistoryManager. | 2684 // form submissions are still received by AutocompleteHistoryManager. |
| 2740 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { | 2685 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { |
| 2741 TestAutofillManagerDelegate delegate; | 2686 TestAutofillManagerDelegate delegate; |
| 2742 autofill_manager_.reset(new TestAutofillManager( | 2687 autofill_manager_.reset(new TestAutofillManager( |
| 2743 autofill_driver_.get(), | 2688 autofill_driver_.get(), |
| 2744 &delegate, | 2689 &delegate, |
| 2745 NULL)); | 2690 NULL)); |
| 2746 autofill_manager_->set_autofill_enabled(false); | 2691 autofill_manager_->set_autofill_enabled(false); |
| 2747 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2692 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
| 2748 autocomplete_history_manager.reset( | 2693 autocomplete_history_manager.reset( |
| 2749 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); | 2694 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); |
| 2750 autofill_manager_->autocomplete_history_manager_ = | 2695 autofill_manager_->autocomplete_history_manager_ = |
| 2751 autocomplete_history_manager.Pass(); | 2696 autocomplete_history_manager.Pass(); |
| 2752 | 2697 |
| 2753 // Set up our form data. | 2698 // Set up our form data. |
| 2754 FormData form; | 2699 FormData form; |
| 2755 CreateTestAddressFormData(&form); | 2700 test::CreateTestAddressFormData(&form); |
| 2756 form.method = ASCIIToUTF16("GET"); | 2701 form.method = ASCIIToUTF16("GET"); |
| 2757 MockAutocompleteHistoryManager* m = static_cast< | 2702 MockAutocompleteHistoryManager* m = static_cast< |
| 2758 MockAutocompleteHistoryManager*>( | 2703 MockAutocompleteHistoryManager*>( |
| 2759 autofill_manager_->autocomplete_history_manager_.get()); | 2704 autofill_manager_->autocomplete_history_manager_.get()); |
| 2760 EXPECT_CALL(*m, | 2705 EXPECT_CALL(*m, |
| 2761 OnFormSubmitted(_)).Times(1); | 2706 OnFormSubmitted(_)).Times(1); |
| 2762 FormSubmitted(form); | 2707 FormSubmitted(form); |
| 2763 } | 2708 } |
| 2764 | 2709 |
| 2765 // Test that when Autocomplete is enabled and Autofill is disabled, | 2710 // Test that when Autocomplete is enabled and Autofill is disabled, |
| 2766 // Autocomplete suggestions are still received. | 2711 // Autocomplete suggestions are still received. |
| 2767 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { | 2712 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { |
| 2768 TestAutofillManagerDelegate delegate; | 2713 TestAutofillManagerDelegate delegate; |
| 2769 autofill_manager_.reset(new TestAutofillManager( | 2714 autofill_manager_.reset(new TestAutofillManager( |
| 2770 autofill_driver_.get(), | 2715 autofill_driver_.get(), |
| 2771 &delegate, | 2716 &delegate, |
| 2772 NULL)); | 2717 NULL)); |
| 2773 autofill_manager_->set_autofill_enabled(false); | 2718 autofill_manager_->set_autofill_enabled(false); |
| 2774 | 2719 |
| 2775 // Set up our form data. | 2720 // Set up our form data. |
| 2776 FormData form; | 2721 FormData form; |
| 2777 CreateTestAddressFormData(&form); | 2722 test::CreateTestAddressFormData(&form); |
| 2778 form.method = ASCIIToUTF16("GET"); | 2723 form.method = ASCIIToUTF16("GET"); |
| 2779 std::vector<FormData> forms(1, form); | 2724 std::vector<FormData> forms(1, form); |
| 2780 FormsSeen(forms); | 2725 FormsSeen(forms); |
| 2781 const FormFieldData& field = form.fields[0]; | 2726 const FormFieldData& field = form.fields[0]; |
| 2782 GetAutofillSuggestions(form, field); | 2727 GetAutofillSuggestions(form, field); |
| 2783 | 2728 |
| 2784 // Add some Autocomplete suggestions. We should return the autocomplete | 2729 // Add some Autocomplete suggestions. We should return the autocomplete |
| 2785 // suggestions, these will be culled by the renderer. | 2730 // suggestions, these will be culled by the renderer. |
| 2786 std::vector<base::string16> suggestions; | 2731 std::vector<base::string16> suggestions; |
| 2787 suggestions.push_back(ASCIIToUTF16("Jay")); | 2732 suggestions.push_back(ASCIIToUTF16("Jay")); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2806 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 2751 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 2807 kDefaultPageID, arraysize(expected_values), expected_values, | 2752 kDefaultPageID, arraysize(expected_values), expected_values, |
| 2808 expected_labels, expected_icons, expected_unique_ids); | 2753 expected_labels, expected_icons, expected_unique_ids); |
| 2809 } | 2754 } |
| 2810 | 2755 |
| 2811 // Test that we are able to save form data when forms are submitted and we only | 2756 // Test that we are able to save form data when forms are submitted and we only |
| 2812 // have server data for the field types. | 2757 // have server data for the field types. |
| 2813 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { | 2758 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { |
| 2814 // Set up our form data. | 2759 // Set up our form data. |
| 2815 FormData form; | 2760 FormData form; |
| 2816 CreateTestAddressFormData(&form); | 2761 test::CreateTestAddressFormData(&form); |
| 2817 | 2762 |
| 2818 // Simulate having seen this form on page load. | 2763 // Simulate having seen this form on page load. |
| 2819 // |form_structure| will be owned by |autofill_manager_|. | 2764 // |form_structure| will be owned by |autofill_manager_|. |
| 2820 TestFormStructure* form_structure = new TestFormStructure(form); | 2765 TestFormStructure* form_structure = new TestFormStructure(form); |
| 2821 AutofillMetrics metrics_logger; // ignored | 2766 AutofillMetrics metrics_logger; // ignored |
| 2822 form_structure->DetermineHeuristicTypes(metrics_logger); | 2767 form_structure->DetermineHeuristicTypes(metrics_logger); |
| 2823 | 2768 |
| 2824 // Clear the heuristic types, and instead set the appropriate server types. | 2769 // Clear the heuristic types, and instead set the appropriate server types. |
| 2825 std::vector<AutofillFieldType> heuristic_types, server_types; | 2770 std::vector<AutofillFieldType> heuristic_types, server_types; |
| 2826 for (size_t i = 0; i < form.fields.size(); ++i) { | 2771 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 2827 heuristic_types.push_back(UNKNOWN_TYPE); | 2772 heuristic_types.push_back(UNKNOWN_TYPE); |
| 2828 server_types.push_back(form_structure->field(i)->type()); | 2773 server_types.push_back(form_structure->field(i)->type()); |
| 2829 } | 2774 } |
| 2830 form_structure->SetFieldTypes(heuristic_types, server_types); | 2775 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 2831 autofill_manager_->AddSeenForm(form_structure); | 2776 autofill_manager_->AddSeenForm(form_structure); |
| 2832 | 2777 |
| 2833 // Fill the form. | 2778 // Fill the form. |
| 2834 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2779 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2835 GUIDPair empty(std::string(), 0); | 2780 GUIDPair empty(std::string(), 0); |
| 2836 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2781 int response_page_id = 0; |
| 2837 PackGUIDs(empty, guid)); | 2782 FormData response_data; |
| 2838 | 2783 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2839 int page_id = 0; | 2784 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2840 FormData results; | 2785 ExpectFilledAddressFormElvis( |
| 2841 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2786 response_page_id, response_data, kDefaultPageID, false); |
| 2842 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
| 2843 | 2787 |
| 2844 // Simulate form submission. We should call into the PDM to try to save the | 2788 // Simulate form submission. We should call into the PDM to try to save the |
| 2845 // filled data. | 2789 // filled data. |
| 2846 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2790 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2847 FormSubmitted(results); | 2791 FormSubmitted(response_data); |
| 2848 } | 2792 } |
| 2849 | 2793 |
| 2850 // Test that the form signature for an uploaded form always matches the form | 2794 // Test that the form signature for an uploaded form always matches the form |
| 2851 // signature from the query. | 2795 // signature from the query. |
| 2852 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { | 2796 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { |
| 2853 // Set up our form data. | 2797 // Set up our form data. |
| 2854 FormData form; | 2798 FormData form; |
| 2855 CreateTestAddressFormData(&form); | 2799 test::CreateTestAddressFormData(&form); |
| 2856 std::vector<FormData> forms(1, form); | 2800 std::vector<FormData> forms(1, form); |
| 2857 FormsSeen(forms); | 2801 FormsSeen(forms); |
| 2858 | 2802 |
| 2859 // Cache the expected form signature. | 2803 // Cache the expected form signature. |
| 2860 std::string signature = FormStructure(form, std::string()).FormSignature(); | 2804 std::string signature = FormStructure(form, std::string()).FormSignature(); |
| 2861 | 2805 |
| 2862 // Change the structure of the form prior to submission. | 2806 // Change the structure of the form prior to submission. |
| 2863 // Websites would typically invoke JavaScript either on page load or on form | 2807 // Websites would typically invoke JavaScript either on page load or on form |
| 2864 // submit to achieve this. | 2808 // submit to achieve this. |
| 2865 form.fields.pop_back(); | 2809 form.fields.pop_back(); |
| 2866 FormFieldData field = form.fields[3]; | 2810 FormFieldData field = form.fields[3]; |
| 2867 form.fields[3] = form.fields[7]; | 2811 form.fields[3] = form.fields[7]; |
| 2868 form.fields[7] = field; | 2812 form.fields[7] = field; |
| 2869 | 2813 |
| 2870 // Simulate form submission. | 2814 // Simulate form submission. |
| 2871 FormSubmitted(form); | 2815 FormSubmitted(form); |
| 2872 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 2816 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 2873 } | 2817 } |
| 2874 | 2818 |
| 2875 // Test that we do not save form data when submitted fields contain default | 2819 // Test that we do not save form data when submitted fields contain default |
| 2876 // values. | 2820 // values. |
| 2877 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { | 2821 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { |
| 2878 // Set up our form data. | 2822 // Set up our form data. |
| 2879 FormData form; | 2823 FormData form; |
| 2880 CreateTestAddressFormData(&form); | 2824 test::CreateTestAddressFormData(&form); |
| 2881 form.fields[3].value = ASCIIToUTF16("Enter your address"); | 2825 form.fields[3].value = ASCIIToUTF16("Enter your address"); |
| 2882 | 2826 |
| 2883 // Convert the state field to a <select> popup, to make sure that we only | 2827 // Convert the state field to a <select> popup, to make sure that we only |
| 2884 // reject default values for text fields. | 2828 // reject default values for text fields. |
| 2885 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); | 2829 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); |
| 2886 form.fields[6].form_control_type = "select-one"; | 2830 form.fields[6].form_control_type = "select-one"; |
| 2887 form.fields[6].value = ASCIIToUTF16("Tennessee"); | 2831 form.fields[6].value = ASCIIToUTF16("Tennessee"); |
| 2888 | 2832 |
| 2889 std::vector<FormData> forms(1, form); | 2833 std::vector<FormData> forms(1, form); |
| 2890 FormsSeen(forms); | 2834 FormsSeen(forms); |
| 2891 | 2835 |
| 2892 // Fill the form. | 2836 // Fill the form. |
| 2893 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2837 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2894 GUIDPair empty(std::string(), 0); | 2838 GUIDPair empty(std::string(), 0); |
| 2895 FillAutofillFormData(kDefaultPageID, form, form.fields[3], | 2839 int response_page_id = 0; |
| 2896 PackGUIDs(empty, guid)); | 2840 FormData response_data; |
| 2897 | 2841 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[3], |
| 2898 int page_id = 0; | 2842 PackGUIDs(empty, guid), &response_page_id, &response_data); |
| 2899 FormData results; | |
| 2900 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | |
| 2901 | 2843 |
| 2902 // Simulate form submission. We should call into the PDM to try to save the | 2844 // Simulate form submission. We should call into the PDM to try to save the |
| 2903 // filled data. | 2845 // filled data. |
| 2904 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2846 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2905 FormSubmitted(results); | 2847 FormSubmitted(response_data); |
| 2906 | 2848 |
| 2907 // Set the address field's value back to the default value. | 2849 // Set the address field's value back to the default value. |
| 2908 results.fields[3].value = ASCIIToUTF16("Enter your address"); | 2850 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); |
| 2909 | 2851 |
| 2910 // Simulate form submission. We should not call into the PDM to try to save | 2852 // Simulate form submission. We should not call into the PDM to try to save |
| 2911 // the filled data, since the filled form is effectively missing an address. | 2853 // the filled data, since the filled form is effectively missing an address. |
| 2912 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); | 2854 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); |
| 2913 FormSubmitted(results); | 2855 FormSubmitted(response_data); |
| 2914 } | 2856 } |
| 2915 | 2857 |
| 2916 // Checks that resetting the auxiliary profile enabled preference does the right | 2858 // Checks that resetting the auxiliary profile enabled preference does the right |
| 2917 // thing on all platforms. | 2859 // thing on all platforms. |
| 2918 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2860 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
| 2919 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); | 2861 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); |
| 2920 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 2862 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
| 2921 // Auxiliary profiles is implemented on Mac and Android only. | 2863 // Auxiliary profiles is implemented on Mac and Android only. |
| 2922 // OSX: enables Mac Address Book integration. | 2864 // OSX: enables Mac Address Book integration. |
| 2923 // Android: enables integration with user's contact profile. | 2865 // Android: enables integration with user's contact profile. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 | 3284 |
| 3343 // Test that Autocheckout bubble is offered when server specifies field types. | 3285 // Test that Autocheckout bubble is offered when server specifies field types. |
| 3344 TEST_F(AutofillManagerTest, TestBubbleShown) { | 3286 TEST_F(AutofillManagerTest, TestBubbleShown) { |
| 3345 MockAutofillManagerDelegate delegate; | 3287 MockAutofillManagerDelegate delegate; |
| 3346 autofill_manager_.reset(new TestAutofillManager( | 3288 autofill_manager_.reset(new TestAutofillManager( |
| 3347 autofill_driver_.get(), &delegate, &personal_data_)); | 3289 autofill_driver_.get(), &delegate, &personal_data_)); |
| 3348 autofill_manager_->set_autofill_enabled(true); | 3290 autofill_manager_->set_autofill_enabled(true); |
| 3349 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3291 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
| 3350 | 3292 |
| 3351 FormData form; | 3293 FormData form; |
| 3352 CreateTestAddressFormData(&form); | 3294 test::CreateTestAddressFormData(&form); |
| 3353 | 3295 |
| 3354 TestFormStructure* form_structure = new TestFormStructure(form); | 3296 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3355 AutofillMetrics metrics_logger; // ignored | 3297 AutofillMetrics metrics_logger; // ignored |
| 3356 form_structure->DetermineHeuristicTypes(metrics_logger); | 3298 form_structure->DetermineHeuristicTypes(metrics_logger); |
| 3357 | 3299 |
| 3358 // Build and add form structure with server data. | 3300 // Build and add form structure with server data. |
| 3359 std::vector<AutofillFieldType> heuristic_types, server_types; | 3301 std::vector<AutofillFieldType> heuristic_types, server_types; |
| 3360 for (size_t i = 0; i < form.fields.size(); ++i) { | 3302 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 3361 heuristic_types.push_back(UNKNOWN_TYPE); | 3303 heuristic_types.push_back(UNKNOWN_TYPE); |
| 3362 server_types.push_back(form_structure->field(i)->type()); | 3304 server_types.push_back(form_structure->field(i)->type()); |
| 3363 } | 3305 } |
| 3364 form_structure->SetFieldTypes(heuristic_types, server_types); | 3306 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 3365 autofill_manager_->AddSeenForm(form_structure); | 3307 autofill_manager_->AddSeenForm(form_structure); |
| 3366 | 3308 |
| 3367 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3309 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
| 3368 | 3310 |
| 3369 EXPECT_TRUE(delegate.autocheckout_bubble_shown()); | 3311 EXPECT_TRUE(delegate.autocheckout_bubble_shown()); |
| 3370 } | 3312 } |
| 3371 | 3313 |
| 3372 // Test that Autocheckout bubble is not offered when server doesn't have data | 3314 // Test that Autocheckout bubble is not offered when server doesn't have data |
| 3373 // for the form. | 3315 // for the form. |
| 3374 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { | 3316 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { |
| 3375 MockAutofillManagerDelegate delegate; | 3317 MockAutofillManagerDelegate delegate; |
| 3376 autofill_manager_.reset(new TestAutofillManager( | 3318 autofill_manager_.reset(new TestAutofillManager( |
| 3377 autofill_driver_.get(), &delegate, &personal_data_)); | 3319 autofill_driver_.get(), &delegate, &personal_data_)); |
| 3378 autofill_manager_->set_autofill_enabled(true); | 3320 autofill_manager_->set_autofill_enabled(true); |
| 3379 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3321 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
| 3380 | 3322 |
| 3381 FormData form; | 3323 FormData form; |
| 3382 CreateTestAddressFormData(&form); | 3324 test::CreateTestAddressFormData(&form); |
| 3383 | 3325 |
| 3384 TestFormStructure* form_structure = new TestFormStructure(form); | 3326 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3385 AutofillMetrics metrics_logger; // ignored | 3327 AutofillMetrics metrics_logger; // ignored |
| 3386 form_structure->DetermineHeuristicTypes(metrics_logger); | 3328 form_structure->DetermineHeuristicTypes(metrics_logger); |
| 3387 | 3329 |
| 3388 // Build form structure without server data. | 3330 // Build form structure without server data. |
| 3389 std::vector<AutofillFieldType> heuristic_types, server_types; | 3331 std::vector<AutofillFieldType> heuristic_types, server_types; |
| 3390 for (size_t i = 0; i < form.fields.size(); ++i) { | 3332 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 3391 heuristic_types.push_back(form_structure->field(i)->type()); | 3333 heuristic_types.push_back(form_structure->field(i)->type()); |
| 3392 server_types.push_back(NO_SERVER_DATA); | 3334 server_types.push_back(NO_SERVER_DATA); |
| 3393 } | 3335 } |
| 3394 form_structure->SetFieldTypes(heuristic_types, server_types); | 3336 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 3395 autofill_manager_->AddSeenForm(form_structure); | 3337 autofill_manager_->AddSeenForm(form_structure); |
| 3396 | 3338 |
| 3397 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3339 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
| 3398 | 3340 |
| 3399 EXPECT_FALSE(delegate.autocheckout_bubble_shown()); | 3341 EXPECT_FALSE(delegate.autocheckout_bubble_shown()); |
| 3400 } | 3342 } |
| 3401 | 3343 |
| 3402 // Test our external delegate is called at the right time. | 3344 // Test our external delegate is called at the right time. |
| 3403 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3345 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| 3404 MockAutofillExternalDelegate external_delegate(web_contents(), | 3346 MockAutofillExternalDelegate external_delegate(web_contents(), |
| 3405 autofill_manager_.get()); | 3347 autofill_manager_.get()); |
| 3406 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); | 3348 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); |
| 3407 autofill_manager_->SetExternalDelegate(&external_delegate); | 3349 autofill_manager_->SetExternalDelegate(&external_delegate); |
| 3408 | 3350 |
| 3409 FormData form; | 3351 FormData form; |
| 3410 CreateTestAddressFormData(&form); | 3352 test::CreateTestAddressFormData(&form); |
| 3411 std::vector<FormData> forms(1, form); | 3353 std::vector<FormData> forms(1, form); |
| 3412 FormsSeen(forms); | 3354 FormsSeen(forms); |
| 3413 const FormFieldData& field = form.fields[0]; | 3355 const FormFieldData& field = form.fields[0]; |
| 3414 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3356 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3415 | 3357 |
| 3416 autofill_manager_->SetExternalDelegate(NULL); | 3358 autofill_manager_->SetExternalDelegate(NULL); |
| 3417 } | 3359 } |
| 3418 | 3360 |
| 3419 // Test that in the case of Autocheckout, forms seen are in order supplied. | 3361 // Test that in the case of Autocheckout, forms seen are in order supplied. |
| 3420 TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) { | 3362 TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) { |
| 3421 MockAutofillManagerDelegate delegate; | 3363 MockAutofillManagerDelegate delegate; |
| 3422 autofill_manager_.reset(new TestAutofillManager( | 3364 autofill_manager_.reset(new TestAutofillManager( |
| 3423 autofill_driver_.get(), &delegate, &personal_data_)); | 3365 autofill_driver_.get(), &delegate, &personal_data_)); |
| 3424 FormData shipping_options; | 3366 FormData shipping_options; |
| 3425 CreateTestShippingOptionsFormData(&shipping_options); | 3367 CreateTestShippingOptionsFormData(&shipping_options); |
| 3426 FormData user_supplied; | 3368 FormData user_supplied; |
| 3427 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 3369 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
| 3428 FormData address; | 3370 FormData address; |
| 3429 CreateTestAddressFormData(&address); | 3371 test::CreateTestAddressFormData(&address); |
| 3430 | 3372 |
| 3431 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 3373 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 3432 // Push address only | 3374 // Push address only |
| 3433 std::vector<FormData> forms; | 3375 std::vector<FormData> forms; |
| 3434 forms.push_back(address); | 3376 forms.push_back(address); |
| 3435 | 3377 |
| 3436 // Build and add form structure with server data. | 3378 // Build and add form structure with server data. |
| 3437 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address)); | 3379 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address)); |
| 3438 std::vector<AutofillFieldType> heuristic_types, server_types; | 3380 std::vector<AutofillFieldType> heuristic_types, server_types; |
| 3439 for (size_t i = 0; i < address.fields.size(); ++i) { | 3381 for (size_t i = 0; i < address.fields.size(); ++i) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3459 forms.push_back(user_supplied); | 3401 forms.push_back(user_supplied); |
| 3460 | 3402 |
| 3461 // FormStructure should contain the same forms as before. | 3403 // FormStructure should contain the same forms as before. |
| 3462 DynamicFormsSeen(forms); | 3404 DynamicFormsSeen(forms); |
| 3463 form_structures = autofill_manager_->GetFormStructures(); | 3405 form_structures = autofill_manager_->GetFormStructures(); |
| 3464 ASSERT_EQ(1U, form_structures.size()); | 3406 ASSERT_EQ(1U, form_structures.size()); |
| 3465 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); | 3407 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); |
| 3466 } | 3408 } |
| 3467 | 3409 |
| 3468 } // namespace autofill | 3410 } // namespace autofill |
| OLD | NEW |