| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <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/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 29 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 30 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 31 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 32 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | 32 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 33 #include "chrome/common/autofill_messages.h" | 33 #include "chrome/common/autofill_messages.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/form_data.h" |
| 36 #include "chrome/common/form_field_data.h" |
| 35 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/test/base/testing_profile.h" | 38 #include "chrome/test/base/testing_profile.h" |
| 37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/test/mock_render_process_host.h" | 40 #include "content/public/test/mock_render_process_host.h" |
| 39 #include "content/public/test/test_browser_thread.h" | 41 #include "content/public/test/test_browser_thread.h" |
| 40 #include "googleurl/src/gurl.h" | 42 #include "googleurl/src/gurl.h" |
| 41 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 42 #include "ipc/ipc_test_sink.h" | 44 #include "ipc/ipc_test_sink.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/gfx/rect.h" | 49 #include "ui/gfx/rect.h" |
| 48 #include "webkit/forms/form_data.h" | |
| 49 #include "webkit/forms/form_field.h" | |
| 50 | 50 |
| 51 using content::BrowserThread; | 51 using content::BrowserThread; |
| 52 using content::WebContents; | 52 using content::WebContents; |
| 53 using testing::_; | 53 using testing::_; |
| 54 using webkit::forms::FormData; | |
| 55 using webkit::forms::FormField; | |
| 56 | 54 |
| 57 namespace { | 55 namespace { |
| 58 | 56 |
| 59 // The page ID sent to the AutofillManager from the RenderView, used to send | 57 // The page ID sent to the AutofillManager from the RenderView, used to send |
| 60 // an IPC message back to the renderer. | 58 // an IPC message back to the renderer. |
| 61 const int kDefaultPageID = 137; | 59 const int kDefaultPageID = 137; |
| 62 | 60 |
| 63 typedef Tuple5<int, | 61 typedef Tuple5<int, |
| 64 std::vector<string16>, | 62 std::vector<string16>, |
| 65 std::vector<string16>, | 63 std::vector<string16>, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Populates |form| with data corresponding to a simple address form. | 189 // Populates |form| with data corresponding to a simple address form. |
| 192 // Note that this actually appends fields to the form data, which can be useful | 190 // Note that this actually appends fields to the form data, which can be useful |
| 193 // for building up more complex test forms. | 191 // for building up more complex test forms. |
| 194 void CreateTestAddressFormData(FormData* form) { | 192 void CreateTestAddressFormData(FormData* form) { |
| 195 form->name = ASCIIToUTF16("MyForm"); | 193 form->name = ASCIIToUTF16("MyForm"); |
| 196 form->method = ASCIIToUTF16("POST"); | 194 form->method = ASCIIToUTF16("POST"); |
| 197 form->origin = GURL("http://myform.com/form.html"); | 195 form->origin = GURL("http://myform.com/form.html"); |
| 198 form->action = GURL("http://myform.com/submit.html"); | 196 form->action = GURL("http://myform.com/submit.html"); |
| 199 form->user_submitted = true; | 197 form->user_submitted = true; |
| 200 | 198 |
| 201 FormField field; | 199 FormFieldData field; |
| 202 autofill_test::CreateTestFormField( | 200 autofill_test::CreateTestFormField( |
| 203 "First Name", "firstname", "", "text", &field); | 201 "First Name", "firstname", "", "text", &field); |
| 204 form->fields.push_back(field); | 202 form->fields.push_back(field); |
| 205 autofill_test::CreateTestFormField( | 203 autofill_test::CreateTestFormField( |
| 206 "Middle Name", "middlename", "", "text", &field); | 204 "Middle Name", "middlename", "", "text", &field); |
| 207 form->fields.push_back(field); | 205 form->fields.push_back(field); |
| 208 autofill_test::CreateTestFormField( | 206 autofill_test::CreateTestFormField( |
| 209 "Last Name", "lastname", "", "text", &field); | 207 "Last Name", "lastname", "", "text", &field); |
| 210 form->fields.push_back(field); | 208 form->fields.push_back(field); |
| 211 autofill_test::CreateTestFormField( | 209 autofill_test::CreateTestFormField( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 form->method = ASCIIToUTF16("POST"); | 242 form->method = ASCIIToUTF16("POST"); |
| 245 if (is_https) { | 243 if (is_https) { |
| 246 form->origin = GURL("https://myform.com/form.html"); | 244 form->origin = GURL("https://myform.com/form.html"); |
| 247 form->action = GURL("https://myform.com/submit.html"); | 245 form->action = GURL("https://myform.com/submit.html"); |
| 248 } else { | 246 } else { |
| 249 form->origin = GURL("http://myform.com/form.html"); | 247 form->origin = GURL("http://myform.com/form.html"); |
| 250 form->action = GURL("http://myform.com/submit.html"); | 248 form->action = GURL("http://myform.com/submit.html"); |
| 251 } | 249 } |
| 252 form->user_submitted = true; | 250 form->user_submitted = true; |
| 253 | 251 |
| 254 FormField field; | 252 FormFieldData field; |
| 255 autofill_test::CreateTestFormField( | 253 autofill_test::CreateTestFormField( |
| 256 "Name on Card", "nameoncard", "", "text", &field); | 254 "Name on Card", "nameoncard", "", "text", &field); |
| 257 form->fields.push_back(field); | 255 form->fields.push_back(field); |
| 258 autofill_test::CreateTestFormField( | 256 autofill_test::CreateTestFormField( |
| 259 "Card Number", "cardnumber", "", "text", &field); | 257 "Card Number", "cardnumber", "", "text", &field); |
| 260 form->fields.push_back(field); | 258 form->fields.push_back(field); |
| 261 if (use_month_type) { | 259 if (use_month_type) { |
| 262 autofill_test::CreateTestFormField( | 260 autofill_test::CreateTestFormField( |
| 263 "Expiration Date", "ccmonth", "", "month", &field); | 261 "Expiration Date", "ccmonth", "", "month", &field); |
| 264 form->fields.push_back(field); | 262 form->fields.push_back(field); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 294 EXPECT_EQ(expected_labels[i], labels[i]); | 292 EXPECT_EQ(expected_labels[i], labels[i]); |
| 295 EXPECT_EQ(expected_icons[i], icons[i]); | 293 EXPECT_EQ(expected_icons[i], icons[i]); |
| 296 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); | 294 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); |
| 297 } | 295 } |
| 298 } | 296 } |
| 299 | 297 |
| 300 void ExpectFilledField(const char* expected_label, | 298 void ExpectFilledField(const char* expected_label, |
| 301 const char* expected_name, | 299 const char* expected_name, |
| 302 const char* expected_value, | 300 const char* expected_value, |
| 303 const char* expected_form_control_type, | 301 const char* expected_form_control_type, |
| 304 const webkit::forms::FormField& field) { | 302 const FormFieldData& field) { |
| 305 SCOPED_TRACE(expected_label); | 303 SCOPED_TRACE(expected_label); |
| 306 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 304 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
| 307 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 305 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
| 308 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 306 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
| 309 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); | 307 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); |
| 310 } | 308 } |
| 311 | 309 |
| 312 // Verifies that the |filled_form| has been filled with the given data. | 310 // Verifies that the |filled_form| has been filled with the given data. |
| 313 // Verifies address fields if |has_address_fields| is true, and verifies | 311 // Verifies address fields if |has_address_fields| is true, and verifies |
| 314 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 312 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 virtual void TearDown() OVERRIDE { | 614 virtual void TearDown() OVERRIDE { |
| 617 file_thread_.Stop(); | 615 file_thread_.Stop(); |
| 618 TabContentsTestHarness::TearDown(); | 616 TabContentsTestHarness::TearDown(); |
| 619 } | 617 } |
| 620 | 618 |
| 621 void UpdatePasswordGenerationState(bool new_renderer) { | 619 void UpdatePasswordGenerationState(bool new_renderer) { |
| 622 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 620 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 623 } | 621 } |
| 624 | 622 |
| 625 void GetAutofillSuggestions(int query_id, | 623 void GetAutofillSuggestions(int query_id, |
| 626 const webkit::forms::FormData& form, | 624 const FormData& form, |
| 627 const webkit::forms::FormField& field) { | 625 const FormFieldData& field) { |
| 628 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 626 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 629 form, | 627 form, |
| 630 field, | 628 field, |
| 631 gfx::Rect(), | 629 gfx::Rect(), |
| 632 false); | 630 false); |
| 633 } | 631 } |
| 634 | 632 |
| 635 void GetAutofillSuggestions(const webkit::forms::FormData& form, | 633 void GetAutofillSuggestions(const FormData& form, |
| 636 const webkit::forms::FormField& field) { | 634 const FormFieldData& field) { |
| 637 GetAutofillSuggestions(kDefaultPageID, form, field); | 635 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 638 } | 636 } |
| 639 | 637 |
| 640 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 638 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
| 641 AutocompleteHistoryManager::FromWebContents(web_contents())-> | 639 AutocompleteHistoryManager::FromWebContents(web_contents())-> |
| 642 SendSuggestions(&result); | 640 SendSuggestions(&result); |
| 643 } | 641 } |
| 644 | 642 |
| 645 void FormsSeen(const std::vector<webkit::forms::FormData>& forms) { | 643 void FormsSeen(const std::vector<FormData>& forms) { |
| 646 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 644 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
| 647 } | 645 } |
| 648 | 646 |
| 649 void FormSubmitted(const FormData& form) { | 647 void FormSubmitted(const FormData& form) { |
| 650 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 648 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
| 651 autofill_manager_->WaitForAsyncFormSubmit(); | 649 autofill_manager_->WaitForAsyncFormSubmit(); |
| 652 } | 650 } |
| 653 | 651 |
| 654 void FillAutofillFormData(int query_id, | 652 void FillAutofillFormData(int query_id, |
| 655 const webkit::forms::FormData& form, | 653 const FormData& form, |
| 656 const webkit::forms::FormField& field, | 654 const FormFieldData& field, |
| 657 int unique_id) { | 655 int unique_id) { |
| 658 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 656 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
| 659 } | 657 } |
| 660 | 658 |
| 661 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 659 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { |
| 662 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 660 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); |
| 663 } | 661 } |
| 664 | 662 |
| 665 bool GetAutofillSuggestionsMessage(int* page_id, | 663 bool GetAutofillSuggestionsMessage(int* page_id, |
| 666 std::vector<string16>* values, | 664 std::vector<string16>* values, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 749 |
| 752 // Test that we return all address profile suggestions when all form fields are | 750 // Test that we return all address profile suggestions when all form fields are |
| 753 // empty. | 751 // empty. |
| 754 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 752 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
| 755 // Set up our form data. | 753 // Set up our form data. |
| 756 FormData form; | 754 FormData form; |
| 757 CreateTestAddressFormData(&form); | 755 CreateTestAddressFormData(&form); |
| 758 std::vector<FormData> forms(1, form); | 756 std::vector<FormData> forms(1, form); |
| 759 FormsSeen(forms); | 757 FormsSeen(forms); |
| 760 | 758 |
| 761 const FormField& field = form.fields[0]; | 759 const FormFieldData& field = form.fields[0]; |
| 762 GetAutofillSuggestions(form, field); | 760 GetAutofillSuggestions(form, field); |
| 763 | 761 |
| 764 // No suggestions provided, so send an empty vector as the results. | 762 // No suggestions provided, so send an empty vector as the results. |
| 765 // This triggers the combined message send. | 763 // This triggers the combined message send. |
| 766 AutocompleteSuggestionsReturned(std::vector<string16>()); | 764 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 767 | 765 |
| 768 // Test that we sent the right message to the renderer. | 766 // Test that we sent the right message to the renderer. |
| 769 int page_id = 0; | 767 int page_id = 0; |
| 770 std::vector<string16> values; | 768 std::vector<string16> values; |
| 771 std::vector<string16> labels; | 769 std::vector<string16> labels; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 793 | 791 |
| 794 // Test that we return only matching address profile suggestions when the | 792 // Test that we return only matching address profile suggestions when the |
| 795 // selected form field has been partially filled out. | 793 // selected form field has been partially filled out. |
| 796 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 794 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
| 797 // Set up our form data. | 795 // Set up our form data. |
| 798 FormData form; | 796 FormData form; |
| 799 CreateTestAddressFormData(&form); | 797 CreateTestAddressFormData(&form); |
| 800 std::vector<FormData> forms(1, form); | 798 std::vector<FormData> forms(1, form); |
| 801 FormsSeen(forms); | 799 FormsSeen(forms); |
| 802 | 800 |
| 803 FormField field; | 801 FormFieldData field; |
| 804 autofill_test::CreateTestFormField("First Name", "firstname", "E", "text", | 802 autofill_test::CreateTestFormField("First Name", "firstname", "E", "text", |
| 805 &field); | 803 &field); |
| 806 GetAutofillSuggestions(form, field); | 804 GetAutofillSuggestions(form, field); |
| 807 | 805 |
| 808 // No suggestions provided, so send an empty vector as the results. | 806 // No suggestions provided, so send an empty vector as the results. |
| 809 // This triggers the combined message send. | 807 // This triggers the combined message send. |
| 810 AutocompleteSuggestionsReturned(std::vector<string16>()); | 808 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 811 | 809 |
| 812 // Test that we sent the right message to the renderer. | 810 // Test that we sent the right message to the renderer. |
| 813 int page_id = 0; | 811 int page_id = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 830 // Test that we return no suggestions when the form has no relevant fields. | 828 // Test that we return no suggestions when the form has no relevant fields. |
| 831 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { | 829 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { |
| 832 // Set up our form data. | 830 // Set up our form data. |
| 833 FormData form; | 831 FormData form; |
| 834 form.name = ASCIIToUTF16("MyForm"); | 832 form.name = ASCIIToUTF16("MyForm"); |
| 835 form.method = ASCIIToUTF16("POST"); | 833 form.method = ASCIIToUTF16("POST"); |
| 836 form.origin = GURL("http://myform.com/form.html"); | 834 form.origin = GURL("http://myform.com/form.html"); |
| 837 form.action = GURL("http://myform.com/submit.html"); | 835 form.action = GURL("http://myform.com/submit.html"); |
| 838 form.user_submitted = true; | 836 form.user_submitted = true; |
| 839 | 837 |
| 840 FormField field; | 838 FormFieldData field; |
| 841 autofill_test::CreateTestFormField("Username", "username", "", "text", | 839 autofill_test::CreateTestFormField("Username", "username", "", "text", |
| 842 &field); | 840 &field); |
| 843 form.fields.push_back(field); | 841 form.fields.push_back(field); |
| 844 autofill_test::CreateTestFormField("Password", "password", "", "password", | 842 autofill_test::CreateTestFormField("Password", "password", "", "password", |
| 845 &field); | 843 &field); |
| 846 form.fields.push_back(field); | 844 form.fields.push_back(field); |
| 847 autofill_test::CreateTestFormField("Quest", "quest", "", "quest", &field); | 845 autofill_test::CreateTestFormField("Quest", "quest", "", "quest", &field); |
| 848 form.fields.push_back(field); | 846 form.fields.push_back(field); |
| 849 autofill_test::CreateTestFormField("Color", "color", "", "text", &field); | 847 autofill_test::CreateTestFormField("Color", "color", "", "text", &field); |
| 850 form.fields.push_back(field); | 848 form.fields.push_back(field); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 864 std::vector<FormData> forms(1, form); | 862 std::vector<FormData> forms(1, form); |
| 865 FormsSeen(forms); | 863 FormsSeen(forms); |
| 866 | 864 |
| 867 // Add a duplicate profile. | 865 // Add a duplicate profile. |
| 868 AutofillProfile* duplicate_profile = | 866 AutofillProfile* duplicate_profile = |
| 869 new AutofillProfile( | 867 new AutofillProfile( |
| 870 *(autofill_manager_->GetProfileWithGUID( | 868 *(autofill_manager_->GetProfileWithGUID( |
| 871 "00000000-0000-0000-0000-000000000001"))); | 869 "00000000-0000-0000-0000-000000000001"))); |
| 872 autofill_manager_->AddProfile(duplicate_profile); | 870 autofill_manager_->AddProfile(duplicate_profile); |
| 873 | 871 |
| 874 const FormField& field = form.fields[0]; | 872 const FormFieldData& field = form.fields[0]; |
| 875 GetAutofillSuggestions(form, field); | 873 GetAutofillSuggestions(form, field); |
| 876 | 874 |
| 877 // No suggestions provided, so send an empty vector as the results. | 875 // No suggestions provided, so send an empty vector as the results. |
| 878 // This triggers the combined message send. | 876 // This triggers the combined message send. |
| 879 AutocompleteSuggestionsReturned(std::vector<string16>()); | 877 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 880 | 878 |
| 881 // Test that we sent the right message to the renderer. | 879 // Test that we sent the right message to the renderer. |
| 882 int page_id = 0; | 880 int page_id = 0; |
| 883 std::vector<string16> values; | 881 std::vector<string16> values; |
| 884 std::vector<string16> labels; | 882 std::vector<string16> labels; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 906 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 904 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
| 907 // Set up our form data. | 905 // Set up our form data. |
| 908 FormData form; | 906 FormData form; |
| 909 CreateTestAddressFormData(&form); | 907 CreateTestAddressFormData(&form); |
| 910 std::vector<FormData> forms(1, form); | 908 std::vector<FormData> forms(1, form); |
| 911 FormsSeen(forms); | 909 FormsSeen(forms); |
| 912 | 910 |
| 913 // Disable Autofill. | 911 // Disable Autofill. |
| 914 autofill_manager_->set_autofill_enabled(false); | 912 autofill_manager_->set_autofill_enabled(false); |
| 915 | 913 |
| 916 const FormField& field = form.fields[0]; | 914 const FormFieldData& field = form.fields[0]; |
| 917 GetAutofillSuggestions(form, field); | 915 GetAutofillSuggestions(form, field); |
| 918 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 916 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
| 919 } | 917 } |
| 920 | 918 |
| 921 // Test that we return a warning explaining that autofill suggestions are | 919 // Test that we return a warning explaining that autofill suggestions are |
| 922 // unavailable when the form method is GET rather than POST. | 920 // unavailable when the form method is GET rather than POST. |
| 923 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { | 921 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { |
| 924 // Set up our form data. | 922 // Set up our form data. |
| 925 FormData form; | 923 FormData form; |
| 926 CreateTestAddressFormData(&form); | 924 CreateTestAddressFormData(&form); |
| 927 form.method = ASCIIToUTF16("GET"); | 925 form.method = ASCIIToUTF16("GET"); |
| 928 std::vector<FormData> forms(1, form); | 926 std::vector<FormData> forms(1, form); |
| 929 FormsSeen(forms); | 927 FormsSeen(forms); |
| 930 | 928 |
| 931 const FormField& field = form.fields[0]; | 929 const FormFieldData& field = form.fields[0]; |
| 932 GetAutofillSuggestions(form, field); | 930 GetAutofillSuggestions(form, field); |
| 933 | 931 |
| 934 // No suggestions provided, so send an empty vector as the results. | 932 // No suggestions provided, so send an empty vector as the results. |
| 935 // This triggers the combined message send. | 933 // This triggers the combined message send. |
| 936 AutocompleteSuggestionsReturned(std::vector<string16>()); | 934 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 937 | 935 |
| 938 // Test that we sent the right message to the renderer. | 936 // Test that we sent the right message to the renderer. |
| 939 int page_id = 0; | 937 int page_id = 0; |
| 940 std::vector<string16> values; | 938 std::vector<string16> values; |
| 941 std::vector<string16> labels; | 939 std::vector<string16> labels; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 | 986 |
| 989 // Test that we return all credit card profile suggestions when all form fields | 987 // Test that we return all credit card profile suggestions when all form fields |
| 990 // are empty. | 988 // are empty. |
| 991 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 989 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
| 992 // Set up our form data. | 990 // Set up our form data. |
| 993 FormData form; | 991 FormData form; |
| 994 CreateTestCreditCardFormData(&form, true, false); | 992 CreateTestCreditCardFormData(&form, true, false); |
| 995 std::vector<FormData> forms(1, form); | 993 std::vector<FormData> forms(1, form); |
| 996 FormsSeen(forms); | 994 FormsSeen(forms); |
| 997 | 995 |
| 998 FormField field = form.fields[1]; | 996 FormFieldData field = form.fields[1]; |
| 999 GetAutofillSuggestions(form, field); | 997 GetAutofillSuggestions(form, field); |
| 1000 | 998 |
| 1001 // No suggestions provided, so send an empty vector as the results. | 999 // No suggestions provided, so send an empty vector as the results. |
| 1002 // This triggers the combined message send. | 1000 // This triggers the combined message send. |
| 1003 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1001 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1004 | 1002 |
| 1005 // Test that we sent the right message to the renderer. | 1003 // Test that we sent the right message to the renderer. |
| 1006 int page_id = 0; | 1004 int page_id = 0; |
| 1007 std::vector<string16> values; | 1005 std::vector<string16> values; |
| 1008 std::vector<string16> labels; | 1006 std::vector<string16> labels; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1031 | 1029 |
| 1032 // Test that we return only matching credit card profile suggestions when the | 1030 // Test that we return only matching credit card profile suggestions when the |
| 1033 // selected form field has been partially filled out. | 1031 // selected form field has been partially filled out. |
| 1034 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 1032 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
| 1035 // Set up our form data. | 1033 // Set up our form data. |
| 1036 FormData form; | 1034 FormData form; |
| 1037 CreateTestCreditCardFormData(&form, true, false); | 1035 CreateTestCreditCardFormData(&form, true, false); |
| 1038 std::vector<FormData> forms(1, form); | 1036 std::vector<FormData> forms(1, form); |
| 1039 FormsSeen(forms); | 1037 FormsSeen(forms); |
| 1040 | 1038 |
| 1041 FormField field; | 1039 FormFieldData field; |
| 1042 autofill_test::CreateTestFormField( | 1040 autofill_test::CreateTestFormField( |
| 1043 "Card Number", "cardnumber", "4", "text", &field); | 1041 "Card Number", "cardnumber", "4", "text", &field); |
| 1044 GetAutofillSuggestions(form, field); | 1042 GetAutofillSuggestions(form, field); |
| 1045 | 1043 |
| 1046 // No suggestions provided, so send an empty vector as the results. | 1044 // No suggestions provided, so send an empty vector as the results. |
| 1047 // This triggers the combined message send. | 1045 // This triggers the combined message send. |
| 1048 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1046 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1049 | 1047 |
| 1050 // Test that we sent the right message to the renderer. | 1048 // Test that we sent the right message to the renderer. |
| 1051 int page_id = 0; | 1049 int page_id = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1067 | 1065 |
| 1068 // Test that we return credit card profile suggestions when the selected form | 1066 // Test that we return credit card profile suggestions when the selected form |
| 1069 // field is not the credit card number field. | 1067 // field is not the credit card number field. |
| 1070 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 1068 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
| 1071 // Set up our form data. | 1069 // Set up our form data. |
| 1072 FormData form; | 1070 FormData form; |
| 1073 CreateTestCreditCardFormData(&form, true, false); | 1071 CreateTestCreditCardFormData(&form, true, false); |
| 1074 std::vector<FormData> forms(1, form); | 1072 std::vector<FormData> forms(1, form); |
| 1075 FormsSeen(forms); | 1073 FormsSeen(forms); |
| 1076 | 1074 |
| 1077 const FormField& field = form.fields[0]; | 1075 const FormFieldData& field = form.fields[0]; |
| 1078 GetAutofillSuggestions(form, field); | 1076 GetAutofillSuggestions(form, field); |
| 1079 | 1077 |
| 1080 // No suggestions provided, so send an empty vector as the results. | 1078 // No suggestions provided, so send an empty vector as the results. |
| 1081 // This triggers the combined message send. | 1079 // This triggers the combined message send. |
| 1082 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1080 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1083 | 1081 |
| 1084 // Test that we sent the right message to the renderer. | 1082 // Test that we sent the right message to the renderer. |
| 1085 int page_id = 0; | 1083 int page_id = 0; |
| 1086 std::vector<string16> values; | 1084 std::vector<string16> values; |
| 1087 std::vector<string16> labels; | 1085 std::vector<string16> labels; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1110 | 1108 |
| 1111 // Test that we return a warning explaining that credit card profile suggestions | 1109 // Test that we return a warning explaining that credit card profile suggestions |
| 1112 // are unavailable when the form is not https. | 1110 // are unavailable when the form is not https. |
| 1113 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 1111 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 1114 // Set up our form data. | 1112 // Set up our form data. |
| 1115 FormData form; | 1113 FormData form; |
| 1116 CreateTestCreditCardFormData(&form, false, false); | 1114 CreateTestCreditCardFormData(&form, false, false); |
| 1117 std::vector<FormData> forms(1, form); | 1115 std::vector<FormData> forms(1, form); |
| 1118 FormsSeen(forms); | 1116 FormsSeen(forms); |
| 1119 | 1117 |
| 1120 const FormField& field = form.fields[0]; | 1118 const FormFieldData& field = form.fields[0]; |
| 1121 GetAutofillSuggestions(form, field); | 1119 GetAutofillSuggestions(form, field); |
| 1122 | 1120 |
| 1123 // No suggestions provided, so send an empty vector as the results. | 1121 // No suggestions provided, so send an empty vector as the results. |
| 1124 // This triggers the combined message send. | 1122 // This triggers the combined message send. |
| 1125 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1123 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1126 | 1124 |
| 1127 // Test that we sent the right message to the renderer. | 1125 // Test that we sent the right message to the renderer. |
| 1128 int page_id = 0; | 1126 int page_id = 0; |
| 1129 std::vector<string16> values; | 1127 std::vector<string16> values; |
| 1130 std::vector<string16> labels; | 1128 std::vector<string16> labels; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 "04", "2012"); | 1182 "04", "2012"); |
| 1185 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1183 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1186 autofill_manager_->AddCreditCard(credit_card); | 1184 autofill_manager_->AddCreditCard(credit_card); |
| 1187 | 1185 |
| 1188 // Set up our form data. | 1186 // Set up our form data. |
| 1189 FormData form; | 1187 FormData form; |
| 1190 CreateTestCreditCardFormData(&form, true, false); | 1188 CreateTestCreditCardFormData(&form, true, false); |
| 1191 std::vector<FormData> forms(1, form); | 1189 std::vector<FormData> forms(1, form); |
| 1192 FormsSeen(forms); | 1190 FormsSeen(forms); |
| 1193 | 1191 |
| 1194 FormField field = form.fields[1]; | 1192 FormFieldData field = form.fields[1]; |
| 1195 GetAutofillSuggestions(form, field); | 1193 GetAutofillSuggestions(form, field); |
| 1196 | 1194 |
| 1197 // No suggestions provided, so send an empty vector as the results. | 1195 // No suggestions provided, so send an empty vector as the results. |
| 1198 // This triggers the combined message send. | 1196 // This triggers the combined message send. |
| 1199 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1197 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1200 | 1198 |
| 1201 // Test that we sent the right message to the renderer. | 1199 // Test that we sent the right message to the renderer. |
| 1202 int page_id = 0; | 1200 int page_id = 0; |
| 1203 std::vector<string16> values; | 1201 std::vector<string16> values; |
| 1204 std::vector<string16> labels; | 1202 std::vector<string16> labels; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1234 | 1232 |
| 1235 // Test that we return profile and credit card suggestions for combined forms. | 1233 // Test that we return profile and credit card suggestions for combined forms. |
| 1236 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1234 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1237 // Set up our form data. | 1235 // Set up our form data. |
| 1238 FormData form; | 1236 FormData form; |
| 1239 CreateTestAddressFormData(&form); | 1237 CreateTestAddressFormData(&form); |
| 1240 CreateTestCreditCardFormData(&form, true, false); | 1238 CreateTestCreditCardFormData(&form, true, false); |
| 1241 std::vector<FormData> forms(1, form); | 1239 std::vector<FormData> forms(1, form); |
| 1242 FormsSeen(forms); | 1240 FormsSeen(forms); |
| 1243 | 1241 |
| 1244 FormField field = form.fields[0]; | 1242 FormFieldData field = form.fields[0]; |
| 1245 GetAutofillSuggestions(form, field); | 1243 GetAutofillSuggestions(form, field); |
| 1246 | 1244 |
| 1247 // No suggestions provided, so send an empty vector as the results. | 1245 // No suggestions provided, so send an empty vector as the results. |
| 1248 // This triggers the combined message send. | 1246 // This triggers the combined message send. |
| 1249 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1247 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1250 | 1248 |
| 1251 // Test that we sent the right address suggestions to the renderer. | 1249 // Test that we sent the right address suggestions to the renderer. |
| 1252 int page_id = 0; | 1250 int page_id = 0; |
| 1253 std::vector<string16> values; | 1251 std::vector<string16> values; |
| 1254 std::vector<string16> labels; | 1252 std::vector<string16> labels; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 // should return a warning explaining that credit card profile suggestions are | 1306 // should return a warning explaining that credit card profile suggestions are |
| 1309 // unavailable when the form is not https. | 1307 // unavailable when the form is not https. |
| 1310 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1308 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1311 // Set up our form data. | 1309 // Set up our form data. |
| 1312 FormData form; | 1310 FormData form; |
| 1313 CreateTestAddressFormData(&form); | 1311 CreateTestAddressFormData(&form); |
| 1314 CreateTestCreditCardFormData(&form, false, false); | 1312 CreateTestCreditCardFormData(&form, false, false); |
| 1315 std::vector<FormData> forms(1, form); | 1313 std::vector<FormData> forms(1, form); |
| 1316 FormsSeen(forms); | 1314 FormsSeen(forms); |
| 1317 | 1315 |
| 1318 FormField field = form.fields[0]; | 1316 FormFieldData field = form.fields[0]; |
| 1319 GetAutofillSuggestions(form, field); | 1317 GetAutofillSuggestions(form, field); |
| 1320 | 1318 |
| 1321 // No suggestions provided, so send an empty vector as the results. | 1319 // No suggestions provided, so send an empty vector as the results. |
| 1322 // This triggers the combined message send. | 1320 // This triggers the combined message send. |
| 1323 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1321 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1324 | 1322 |
| 1325 // Test that we sent the right address suggestions to the renderer. | 1323 // Test that we sent the right address suggestions to the renderer. |
| 1326 int page_id = 0; | 1324 int page_id = 0; |
| 1327 std::vector<string16> values; | 1325 std::vector<string16> values; |
| 1328 std::vector<string16> labels; | 1326 std::vector<string16> labels; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 } | 1373 } |
| 1376 | 1374 |
| 1377 // Test that we correctly combine autofill and autocomplete suggestions. | 1375 // Test that we correctly combine autofill and autocomplete suggestions. |
| 1378 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { | 1376 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { |
| 1379 // Set up our form data. | 1377 // Set up our form data. |
| 1380 FormData form; | 1378 FormData form; |
| 1381 CreateTestAddressFormData(&form); | 1379 CreateTestAddressFormData(&form); |
| 1382 std::vector<FormData> forms(1, form); | 1380 std::vector<FormData> forms(1, form); |
| 1383 FormsSeen(forms); | 1381 FormsSeen(forms); |
| 1384 | 1382 |
| 1385 const FormField& field = form.fields[0]; | 1383 const FormFieldData& field = form.fields[0]; |
| 1386 GetAutofillSuggestions(form, field); | 1384 GetAutofillSuggestions(form, field); |
| 1387 | 1385 |
| 1388 // Add some Autocomplete suggestions. | 1386 // Add some Autocomplete suggestions. |
| 1389 // This triggers the combined message send. | 1387 // This triggers the combined message send. |
| 1390 std::vector<string16> suggestions; | 1388 std::vector<string16> suggestions; |
| 1391 suggestions.push_back(ASCIIToUTF16("Jay")); | 1389 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 1392 // This suggestion is a duplicate, and should be trimmed. | 1390 // This suggestion is a duplicate, and should be trimmed. |
| 1393 suggestions.push_back(ASCIIToUTF16("Elvis")); | 1391 suggestions.push_back(ASCIIToUTF16("Elvis")); |
| 1394 suggestions.push_back(ASCIIToUTF16("Jason")); | 1392 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 1395 AutocompleteSuggestionsReturned(suggestions); | 1393 AutocompleteSuggestionsReturned(suggestions); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1426 // already filled forms. | 1424 // already filled forms. |
| 1427 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { | 1425 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { |
| 1428 // Set up our form data. | 1426 // Set up our form data. |
| 1429 FormData form; | 1427 FormData form; |
| 1430 CreateTestAddressFormData(&form); | 1428 CreateTestAddressFormData(&form); |
| 1431 std::vector<FormData> forms(1, form); | 1429 std::vector<FormData> forms(1, form); |
| 1432 FormsSeen(forms); | 1430 FormsSeen(forms); |
| 1433 | 1431 |
| 1434 // Mark one of the fields as filled. | 1432 // Mark one of the fields as filled. |
| 1435 form.fields[2].is_autofilled = true; | 1433 form.fields[2].is_autofilled = true; |
| 1436 const FormField& field = form.fields[0]; | 1434 const FormFieldData& field = form.fields[0]; |
| 1437 GetAutofillSuggestions(form, field); | 1435 GetAutofillSuggestions(form, field); |
| 1438 | 1436 |
| 1439 // No suggestions provided, so send an empty vector as the results. | 1437 // No suggestions provided, so send an empty vector as the results. |
| 1440 // This triggers the combined message send. | 1438 // This triggers the combined message send. |
| 1441 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1439 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1442 | 1440 |
| 1443 // Test that we sent the right message to the renderer. | 1441 // Test that we sent the right message to the renderer. |
| 1444 int page_id = 0; | 1442 int page_id = 0; |
| 1445 std::vector<string16> values; | 1443 std::vector<string16> values; |
| 1446 std::vector<string16> labels; | 1444 std::vector<string16> labels; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1459 kDefaultPageID, arraysize(expected_values), expected_values, | 1457 kDefaultPageID, arraysize(expected_values), expected_values, |
| 1460 expected_labels, expected_icons, expected_unique_ids); | 1458 expected_labels, expected_icons, expected_unique_ids); |
| 1461 } | 1459 } |
| 1462 | 1460 |
| 1463 // Test that nothing breaks when there are autocomplete suggestions but no | 1461 // Test that nothing breaks when there are autocomplete suggestions but no |
| 1464 // autofill suggestions. | 1462 // autofill suggestions. |
| 1465 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { | 1463 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { |
| 1466 // Set up our form data. | 1464 // Set up our form data. |
| 1467 FormData form; | 1465 FormData form; |
| 1468 CreateTestAddressFormData(&form); | 1466 CreateTestAddressFormData(&form); |
| 1469 FormField field; | 1467 FormFieldData field; |
| 1470 autofill_test::CreateTestFormField( | 1468 autofill_test::CreateTestFormField( |
| 1471 "Some Field", "somefield", "", "text", &field); | 1469 "Some Field", "somefield", "", "text", &field); |
| 1472 form.fields.push_back(field); | 1470 form.fields.push_back(field); |
| 1473 std::vector<FormData> forms(1, form); | 1471 std::vector<FormData> forms(1, form); |
| 1474 FormsSeen(forms); | 1472 FormsSeen(forms); |
| 1475 | 1473 |
| 1476 GetAutofillSuggestions(form, field); | 1474 GetAutofillSuggestions(form, field); |
| 1477 | 1475 |
| 1478 // Add some Autocomplete suggestions. | 1476 // Add some Autocomplete suggestions. |
| 1479 // This triggers the combined message send. | 1477 // This triggers the combined message send. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 std::vector<FormData> forms(1, form); | 1510 std::vector<FormData> forms(1, form); |
| 1513 FormsSeen(forms); | 1511 FormsSeen(forms); |
| 1514 | 1512 |
| 1515 // |profile| will be owned by the mock PersonalDataManager. | 1513 // |profile| will be owned by the mock PersonalDataManager. |
| 1516 AutofillProfile* profile = new AutofillProfile; | 1514 AutofillProfile* profile = new AutofillProfile; |
| 1517 autofill_test::SetProfileInfo(profile, "Elvis", "", "", "", "", "", "", "", | 1515 autofill_test::SetProfileInfo(profile, "Elvis", "", "", "", "", "", "", "", |
| 1518 "", "", "", ""); | 1516 "", "", "", ""); |
| 1519 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1517 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1520 autofill_manager_->AddProfile(profile); | 1518 autofill_manager_->AddProfile(profile); |
| 1521 | 1519 |
| 1522 FormField& field = form.fields[0]; | 1520 FormFieldData& field = form.fields[0]; |
| 1523 field.is_autofilled = true; | 1521 field.is_autofilled = true; |
| 1524 field.value = ASCIIToUTF16("Elvis"); | 1522 field.value = ASCIIToUTF16("Elvis"); |
| 1525 GetAutofillSuggestions(form, field); | 1523 GetAutofillSuggestions(form, field); |
| 1526 | 1524 |
| 1527 // No suggestions provided, so send an empty vector as the results. | 1525 // No suggestions provided, so send an empty vector as the results. |
| 1528 // This triggers the combined message send. | 1526 // This triggers the combined message send. |
| 1529 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1527 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1530 | 1528 |
| 1531 // Test that we sent the right message to the renderer. | 1529 // Test that we sent the right message to the renderer. |
| 1532 int page_id = 0; | 1530 int page_id = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1563 std::vector<string16> multi_values(2); | 1561 std::vector<string16> multi_values(2); |
| 1564 multi_values[0] = ASCIIToUTF16("Elvis Presley"); | 1562 multi_values[0] = ASCIIToUTF16("Elvis Presley"); |
| 1565 multi_values[1] = ASCIIToUTF16("Elena Love"); | 1563 multi_values[1] = ASCIIToUTF16("Elena Love"); |
| 1566 profile->SetMultiInfo(NAME_FULL, multi_values); | 1564 profile->SetMultiInfo(NAME_FULL, multi_values); |
| 1567 personal_data_.ClearAutofillProfiles(); | 1565 personal_data_.ClearAutofillProfiles(); |
| 1568 autofill_manager_->AddProfile(profile); | 1566 autofill_manager_->AddProfile(profile); |
| 1569 | 1567 |
| 1570 { | 1568 { |
| 1571 // Get the first name field. | 1569 // Get the first name field. |
| 1572 // Start out with "E", hoping for either "Elvis" or "Elena. | 1570 // Start out with "E", hoping for either "Elvis" or "Elena. |
| 1573 FormField& field = form.fields[0]; | 1571 FormFieldData& field = form.fields[0]; |
| 1574 field.value = ASCIIToUTF16("E"); | 1572 field.value = ASCIIToUTF16("E"); |
| 1575 field.is_autofilled = false; | 1573 field.is_autofilled = false; |
| 1576 GetAutofillSuggestions(form, field); | 1574 GetAutofillSuggestions(form, field); |
| 1577 | 1575 |
| 1578 // Trigger the |Send|. | 1576 // Trigger the |Send|. |
| 1579 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1577 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1580 | 1578 |
| 1581 // Test that we sent the right message to the renderer. | 1579 // Test that we sent the right message to the renderer. |
| 1582 int page_id = 0; | 1580 int page_id = 0; |
| 1583 std::vector<string16> values; | 1581 std::vector<string16> values; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1598 int expected_unique_ids[] = { 1, 2 }; | 1596 int expected_unique_ids[] = { 1, 2 }; |
| 1599 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1597 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 1600 kDefaultPageID, arraysize(expected_values), | 1598 kDefaultPageID, arraysize(expected_values), |
| 1601 expected_values, expected_labels, expected_icons, | 1599 expected_values, expected_labels, expected_icons, |
| 1602 expected_unique_ids); | 1600 expected_unique_ids); |
| 1603 } | 1601 } |
| 1604 | 1602 |
| 1605 { | 1603 { |
| 1606 // Get the first name field. | 1604 // Get the first name field. |
| 1607 // This time, start out with "Ele", hoping for "Elena". | 1605 // This time, start out with "Ele", hoping for "Elena". |
| 1608 FormField& field = form.fields[0]; | 1606 FormFieldData& field = form.fields[0]; |
| 1609 field.value = ASCIIToUTF16("Ele"); | 1607 field.value = ASCIIToUTF16("Ele"); |
| 1610 field.is_autofilled = false; | 1608 field.is_autofilled = false; |
| 1611 GetAutofillSuggestions(form, field); | 1609 GetAutofillSuggestions(form, field); |
| 1612 | 1610 |
| 1613 // Trigger the |Send|. | 1611 // Trigger the |Send|. |
| 1614 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1612 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1615 | 1613 |
| 1616 // Test that we sent the right message to the renderer. | 1614 // Test that we sent the right message to the renderer. |
| 1617 int page_id = 0; | 1615 int page_id = 0; |
| 1618 std::vector<string16> values; | 1616 std::vector<string16> values; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1647 profile->set_guid("00000000-0000-0000-0000-000000000102"); | 1645 profile->set_guid("00000000-0000-0000-0000-000000000102"); |
| 1648 std::vector<string16> multi_values(3); | 1646 std::vector<string16> multi_values(3); |
| 1649 multi_values[0] = ASCIIToUTF16("Travis Smith"); | 1647 multi_values[0] = ASCIIToUTF16("Travis Smith"); |
| 1650 multi_values[1] = ASCIIToUTF16("Cynthia Love"); | 1648 multi_values[1] = ASCIIToUTF16("Cynthia Love"); |
| 1651 multi_values[2] = ASCIIToUTF16("Zac Mango"); | 1649 multi_values[2] = ASCIIToUTF16("Zac Mango"); |
| 1652 profile->SetMultiInfo(NAME_FULL, multi_values); | 1650 profile->SetMultiInfo(NAME_FULL, multi_values); |
| 1653 autofill_manager_->AddProfile(profile); | 1651 autofill_manager_->AddProfile(profile); |
| 1654 | 1652 |
| 1655 // Get the first name field. And start out with "Travis", hoping for all the | 1653 // Get the first name field. And start out with "Travis", hoping for all the |
| 1656 // multi-valued variants as suggestions. | 1654 // multi-valued variants as suggestions. |
| 1657 FormField& field = form.fields[0]; | 1655 FormFieldData& field = form.fields[0]; |
| 1658 field.value = ASCIIToUTF16("Travis"); | 1656 field.value = ASCIIToUTF16("Travis"); |
| 1659 field.is_autofilled = true; | 1657 field.is_autofilled = true; |
| 1660 GetAutofillSuggestions(form, field); | 1658 GetAutofillSuggestions(form, field); |
| 1661 | 1659 |
| 1662 // Trigger the |Send|. | 1660 // Trigger the |Send|. |
| 1663 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1661 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1664 | 1662 |
| 1665 // Test that we sent the right message to the renderer. | 1663 // Test that we sent the right message to the renderer. |
| 1666 int page_id = 0; | 1664 int page_id = 0; |
| 1667 std::vector<string16> values; | 1665 std::vector<string16> values; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1693 | 1691 |
| 1694 AutofillProfile* profile = new AutofillProfile; | 1692 AutofillProfile* profile = new AutofillProfile; |
| 1695 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1693 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1696 std::vector<string16> multi_values(1); | 1694 std::vector<string16> multi_values(1); |
| 1697 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); | 1695 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); |
| 1698 profile->SetMultiInfo(NAME_FULL, multi_values); | 1696 profile->SetMultiInfo(NAME_FULL, multi_values); |
| 1699 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); | 1697 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); |
| 1700 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); | 1698 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); |
| 1701 autofill_manager_->AddProfile(profile); | 1699 autofill_manager_->AddProfile(profile); |
| 1702 | 1700 |
| 1703 const FormField& field = form.fields[9]; | 1701 const FormFieldData& field = form.fields[9]; |
| 1704 GetAutofillSuggestions(form, field); | 1702 GetAutofillSuggestions(form, field); |
| 1705 | 1703 |
| 1706 // No suggestions provided, so send an empty vector as the results. | 1704 // No suggestions provided, so send an empty vector as the results. |
| 1707 // This triggers the combined message send. | 1705 // This triggers the combined message send. |
| 1708 AutocompleteSuggestionsReturned(std::vector<string16>()); | 1706 AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 1709 | 1707 |
| 1710 // Test that we sent the right message to the renderer. | 1708 // Test that we sent the right message to the renderer. |
| 1711 int page_id = 0; | 1709 int page_id = 0; |
| 1712 std::vector<string16> values; | 1710 std::vector<string16> values; |
| 1713 std::vector<string16> labels; | 1711 std::vector<string16> labels; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) { | 1983 TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) { |
| 1986 // Create a form with a billing section and an unnamed section, interleaved. | 1984 // Create a form with a billing section and an unnamed section, interleaved. |
| 1987 // The billing section includes both address and credit card fields. | 1985 // The billing section includes both address and credit card fields. |
| 1988 FormData form; | 1986 FormData form; |
| 1989 form.name = ASCIIToUTF16("MyForm"); | 1987 form.name = ASCIIToUTF16("MyForm"); |
| 1990 form.method = ASCIIToUTF16("POST"); | 1988 form.method = ASCIIToUTF16("POST"); |
| 1991 form.origin = GURL("https://myform.com/form.html"); | 1989 form.origin = GURL("https://myform.com/form.html"); |
| 1992 form.action = GURL("https://myform.com/submit.html"); | 1990 form.action = GURL("https://myform.com/submit.html"); |
| 1993 form.user_submitted = true; | 1991 form.user_submitted = true; |
| 1994 | 1992 |
| 1995 FormField field; | 1993 FormFieldData field; |
| 1996 | 1994 |
| 1997 autofill_test::CreateTestFormField("", "country", "", "text", &field); | 1995 autofill_test::CreateTestFormField("", "country", "", "text", &field); |
| 1998 field.autocomplete_type = ASCIIToUTF16("section-billing country"); | 1996 field.autocomplete_type = ASCIIToUTF16("section-billing country"); |
| 1999 form.fields.push_back(field); | 1997 form.fields.push_back(field); |
| 2000 | 1998 |
| 2001 autofill_test::CreateTestFormField("", "firstname", "", "text", &field); | 1999 autofill_test::CreateTestFormField("", "firstname", "", "text", &field); |
| 2002 field.autocomplete_type = ASCIIToUTF16("given-name"); | 2000 field.autocomplete_type = ASCIIToUTF16("given-name"); |
| 2003 form.fields.push_back(field); | 2001 form.fields.push_back(field); |
| 2004 | 2002 |
| 2005 autofill_test::CreateTestFormField("", "lastname", "", "text", &field); | 2003 autofill_test::CreateTestFormField("", "lastname", "", "text", &field); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 ExpectFilledField("", "email", "", "text", results.fields[10]); | 2137 ExpectFilledField("", "email", "", "text", results.fields[10]); |
| 2140 } | 2138 } |
| 2141 } | 2139 } |
| 2142 | 2140 |
| 2143 // Test that we correctly fill a form that has a single logical section with | 2141 // Test that we correctly fill a form that has a single logical section with |
| 2144 // multiple email address fields. | 2142 // multiple email address fields. |
| 2145 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { | 2143 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { |
| 2146 // Set up our form data. | 2144 // Set up our form data. |
| 2147 FormData form; | 2145 FormData form; |
| 2148 CreateTestAddressFormData(&form); | 2146 CreateTestAddressFormData(&form); |
| 2149 FormField field; | 2147 FormFieldData field; |
| 2150 autofill_test::CreateTestFormField( | 2148 autofill_test::CreateTestFormField( |
| 2151 "Confirm email", "email2", "", "text", &field); | 2149 "Confirm email", "email2", "", "text", &field); |
| 2152 form.fields.push_back(field); | 2150 form.fields.push_back(field); |
| 2153 | 2151 |
| 2154 std::vector<FormData> forms(1, form); | 2152 std::vector<FormData> forms(1, form); |
| 2155 FormsSeen(forms); | 2153 FormsSeen(forms); |
| 2156 | 2154 |
| 2157 // Fill the form. | 2155 // Fill the form. |
| 2158 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2156 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2159 GUIDPair empty(std::string(), 0); | 2157 GUIDPair empty(std::string(), 0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 | 2205 |
| 2208 page_id = 0; | 2206 page_id = 0; |
| 2209 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2207 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 2210 { | 2208 { |
| 2211 SCOPED_TRACE("Credit card 1"); | 2209 SCOPED_TRACE("Credit card 1"); |
| 2212 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 2210 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); |
| 2213 } | 2211 } |
| 2214 | 2212 |
| 2215 // Now set the credit card fields to also be auto-filled, and try again to | 2213 // Now set the credit card fields to also be auto-filled, and try again to |
| 2216 // fill the credit card data | 2214 // fill the credit card data |
| 2217 for (std::vector<FormField>::iterator iter = form.fields.begin(); | 2215 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); |
| 2218 iter != form.fields.end(); | 2216 iter != form.fields.end(); |
| 2219 ++iter) { | 2217 ++iter) { |
| 2220 iter->is_autofilled = true; | 2218 iter->is_autofilled = true; |
| 2221 } | 2219 } |
| 2222 | 2220 |
| 2223 const int kPageID3 = 3; | 2221 const int kPageID3 = 3; |
| 2224 FillAutofillFormData(kPageID3, form, *form.fields.rbegin(), | 2222 FillAutofillFormData(kPageID3, form, *form.fields.rbegin(), |
| 2225 PackGUIDs(guid2, empty)); | 2223 PackGUIDs(guid2, empty)); |
| 2226 | 2224 |
| 2227 page_id = 0; | 2225 page_id = 0; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 size_t max_length; | 2302 size_t max_length; |
| 2305 const char* autocomplete_type; | 2303 const char* autocomplete_type; |
| 2306 } test_fields[] = { | 2304 } test_fields[] = { |
| 2307 { "country code", "country_code", 1, "phone-country-code" }, | 2305 { "country code", "country_code", 1, "phone-country-code" }, |
| 2308 { "area code", "area_code", 3, "phone-area-code" }, | 2306 { "area code", "area_code", 3, "phone-area-code" }, |
| 2309 { "phone", "phone_prefix", 3, "phone-local-prefix" }, | 2307 { "phone", "phone_prefix", 3, "phone-local-prefix" }, |
| 2310 { "-", "phone_suffix", 4, "phone-local-suffix" }, | 2308 { "-", "phone_suffix", 4, "phone-local-suffix" }, |
| 2311 { "Phone Extension", "ext", 3, "phone-extension" } | 2309 { "Phone Extension", "ext", 3, "phone-extension" } |
| 2312 }; | 2310 }; |
| 2313 | 2311 |
| 2314 FormField field; | 2312 FormFieldData field; |
| 2315 const size_t default_max_length = field.max_length; | 2313 const size_t default_max_length = field.max_length; |
| 2316 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_fields); ++i) { | 2314 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_fields); ++i) { |
| 2317 autofill_test::CreateTestFormField( | 2315 autofill_test::CreateTestFormField( |
| 2318 test_fields[i].label, test_fields[i].name, "", "text", &field); | 2316 test_fields[i].label, test_fields[i].name, "", "text", &field); |
| 2319 field.max_length = test_fields[i].max_length; | 2317 field.max_length = test_fields[i].max_length; |
| 2320 field.autocomplete_type = string16(); | 2318 field.autocomplete_type = string16(); |
| 2321 form_with_maxlength.fields.push_back(field); | 2319 form_with_maxlength.fields.push_back(field); |
| 2322 | 2320 |
| 2323 field.max_length = default_max_length; | 2321 field.max_length = default_max_length; |
| 2324 field.autocomplete_type = ASCIIToUTF16(test_fields[i].autocomplete_type); | 2322 field.autocomplete_type = ASCIIToUTF16(test_fields[i].autocomplete_type); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 EXPECT_EQ(string16(), results5.fields[4].value); | 2430 EXPECT_EQ(string16(), results5.fields[4].value); |
| 2433 } | 2431 } |
| 2434 | 2432 |
| 2435 // Test that we can still fill a form when a field has been removed from it. | 2433 // Test that we can still fill a form when a field has been removed from it. |
| 2436 TEST_F(AutofillManagerTest, FormChangesRemoveField) { | 2434 TEST_F(AutofillManagerTest, FormChangesRemoveField) { |
| 2437 // Set up our form data. | 2435 // Set up our form data. |
| 2438 FormData form; | 2436 FormData form; |
| 2439 CreateTestAddressFormData(&form); | 2437 CreateTestAddressFormData(&form); |
| 2440 | 2438 |
| 2441 // Add a field -- we'll remove it again later. | 2439 // Add a field -- we'll remove it again later. |
| 2442 FormField field; | 2440 FormFieldData field; |
| 2443 autofill_test::CreateTestFormField("Some", "field", "", "text", &field); | 2441 autofill_test::CreateTestFormField("Some", "field", "", "text", &field); |
| 2444 form.fields.insert(form.fields.begin() + 3, field); | 2442 form.fields.insert(form.fields.begin() + 3, field); |
| 2445 | 2443 |
| 2446 std::vector<FormData> forms(1, form); | 2444 std::vector<FormData> forms(1, form); |
| 2447 FormsSeen(forms); | 2445 FormsSeen(forms); |
| 2448 | 2446 |
| 2449 // Now, after the call to |FormsSeen|, we remove the field before filling. | 2447 // Now, after the call to |FormsSeen|, we remove the field before filling. |
| 2450 form.fields.erase(form.fields.begin() + 3); | 2448 form.fields.erase(form.fields.begin() + 3); |
| 2451 | 2449 |
| 2452 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2450 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2463 // Test that we can still fill a form when a field has been added to it. | 2461 // Test that we can still fill a form when a field has been added to it. |
| 2464 TEST_F(AutofillManagerTest, FormChangesAddField) { | 2462 TEST_F(AutofillManagerTest, FormChangesAddField) { |
| 2465 // The offset of the phone field in the address form. | 2463 // The offset of the phone field in the address form. |
| 2466 const int kPhoneFieldOffset = 9; | 2464 const int kPhoneFieldOffset = 9; |
| 2467 | 2465 |
| 2468 // Set up our form data. | 2466 // Set up our form data. |
| 2469 FormData form; | 2467 FormData form; |
| 2470 CreateTestAddressFormData(&form); | 2468 CreateTestAddressFormData(&form); |
| 2471 | 2469 |
| 2472 // Remove the phone field -- we'll add it back later. | 2470 // Remove the phone field -- we'll add it back later. |
| 2473 std::vector<FormField>::iterator pos = | 2471 std::vector<FormFieldData>::iterator pos = |
| 2474 form.fields.begin() + kPhoneFieldOffset; | 2472 form.fields.begin() + kPhoneFieldOffset; |
| 2475 FormField field = *pos; | 2473 FormFieldData field = *pos; |
| 2476 pos = form.fields.erase(pos); | 2474 pos = form.fields.erase(pos); |
| 2477 | 2475 |
| 2478 std::vector<FormData> forms(1, form); | 2476 std::vector<FormData> forms(1, form); |
| 2479 FormsSeen(forms); | 2477 FormsSeen(forms); |
| 2480 | 2478 |
| 2481 // Now, after the call to |FormsSeen|, we restore the field before filling. | 2479 // Now, after the call to |FormsSeen|, we restore the field before filling. |
| 2482 form.fields.insert(pos, field); | 2480 form.fields.insert(pos, field); |
| 2483 | 2481 |
| 2484 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2482 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2485 GUIDPair empty(std::string(), 0); | 2483 GUIDPair empty(std::string(), 0); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2564 std::vector<FormData> forms(1, form); | 2562 std::vector<FormData> forms(1, form); |
| 2565 FormsSeen(forms); | 2563 FormsSeen(forms); |
| 2566 | 2564 |
| 2567 // Cache the expected form signature. | 2565 // Cache the expected form signature. |
| 2568 std::string signature = FormStructure(form).FormSignature(); | 2566 std::string signature = FormStructure(form).FormSignature(); |
| 2569 | 2567 |
| 2570 // Change the structure of the form prior to submission. | 2568 // Change the structure of the form prior to submission. |
| 2571 // Websites would typically invoke JavaScript either on page load or on form | 2569 // Websites would typically invoke JavaScript either on page load or on form |
| 2572 // submit to achieve this. | 2570 // submit to achieve this. |
| 2573 form.fields.pop_back(); | 2571 form.fields.pop_back(); |
| 2574 FormField field = form.fields[3]; | 2572 FormFieldData field = form.fields[3]; |
| 2575 form.fields[3] = form.fields[7]; | 2573 form.fields[3] = form.fields[7]; |
| 2576 form.fields[7] = field; | 2574 form.fields[7] = field; |
| 2577 | 2575 |
| 2578 // Simulate form submission. | 2576 // Simulate form submission. |
| 2579 FormSubmitted(form); | 2577 FormSubmitted(form); |
| 2580 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 2578 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 2581 } | 2579 } |
| 2582 | 2580 |
| 2583 // Test that we do not save form data when submitted fields contain default | 2581 // Test that we do not save form data when submitted fields contain default |
| 2584 // values. | 2582 // values. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2644 FormData form; | 2642 FormData form; |
| 2645 form.name = ASCIIToUTF16("MyForm"); | 2643 form.name = ASCIIToUTF16("MyForm"); |
| 2646 form.method = ASCIIToUTF16("POST"); | 2644 form.method = ASCIIToUTF16("POST"); |
| 2647 form.origin = GURL("http://myform.com/form.html"); | 2645 form.origin = GURL("http://myform.com/form.html"); |
| 2648 form.action = GURL("http://myform.com/submit.html"); | 2646 form.action = GURL("http://myform.com/submit.html"); |
| 2649 form.user_submitted = true; | 2647 form.user_submitted = true; |
| 2650 | 2648 |
| 2651 std::vector<FieldTypeSet> expected_types; | 2649 std::vector<FieldTypeSet> expected_types; |
| 2652 | 2650 |
| 2653 // These fields should all match. | 2651 // These fields should all match. |
| 2654 FormField field; | 2652 FormFieldData field; |
| 2655 FieldTypeSet types; | 2653 FieldTypeSet types; |
| 2656 autofill_test::CreateTestFormField("", "1", "Elvis", "text", &field); | 2654 autofill_test::CreateTestFormField("", "1", "Elvis", "text", &field); |
| 2657 types.clear(); | 2655 types.clear(); |
| 2658 types.insert(NAME_FIRST); | 2656 types.insert(NAME_FIRST); |
| 2659 form.fields.push_back(field); | 2657 form.fields.push_back(field); |
| 2660 expected_types.push_back(types); | 2658 expected_types.push_back(types); |
| 2661 | 2659 |
| 2662 autofill_test::CreateTestFormField("", "2", "Aaron", "text", &field); | 2660 autofill_test::CreateTestFormField("", "2", "Aaron", "text", &field); |
| 2663 types.clear(); | 2661 types.clear(); |
| 2664 types.insert(NAME_MIDDLE); | 2662 types.insert(NAME_MIDDLE); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 namespace { | 3074 namespace { |
| 3077 | 3075 |
| 3078 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 3076 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 3079 public: | 3077 public: |
| 3080 explicit MockAutofillExternalDelegate(TabContents* tab_contents, | 3078 explicit MockAutofillExternalDelegate(TabContents* tab_contents, |
| 3081 AutofillManager* autofill_manager) | 3079 AutofillManager* autofill_manager) |
| 3082 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {} | 3080 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {} |
| 3083 virtual ~MockAutofillExternalDelegate() {} | 3081 virtual ~MockAutofillExternalDelegate() {} |
| 3084 | 3082 |
| 3085 MOCK_METHOD5(OnQuery, void(int query_id, | 3083 MOCK_METHOD5(OnQuery, void(int query_id, |
| 3086 const webkit::forms::FormData& form, | 3084 const FormData& form, |
| 3087 const webkit::forms::FormField& field, | 3085 const FormFieldData& field, |
| 3088 const gfx::Rect& bounds, | 3086 const gfx::Rect& bounds, |
| 3089 bool display_warning)); | 3087 bool display_warning)); |
| 3090 | 3088 |
| 3091 virtual void OnQueryPlatformSpecific(int query_id, | 3089 virtual void OnQueryPlatformSpecific(int query_id, |
| 3092 const webkit::forms::FormData& form, | 3090 const FormData& form, |
| 3093 const webkit::forms::FormField& field, | 3091 const FormFieldData& field, |
| 3094 const gfx::Rect& bounds) OVERRIDE {} | 3092 const gfx::Rect& bounds) OVERRIDE {} |
| 3095 | 3093 |
| 3096 private: | 3094 private: |
| 3097 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 3095 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 3098 }; | 3096 }; |
| 3099 | 3097 |
| 3100 } // namespace | 3098 } // namespace |
| 3101 | 3099 |
| 3102 // Test our external delegate is called at the right time. | 3100 // Test our external delegate is called at the right time. |
| 3103 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3101 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| 3104 MockAutofillExternalDelegate external_delegate(tab_contents(), | 3102 MockAutofillExternalDelegate external_delegate(tab_contents(), |
| 3105 autofill_manager_); | 3103 autofill_manager_); |
| 3106 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); | 3104 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); |
| 3107 autofill_manager_->SetExternalDelegate(&external_delegate); | 3105 autofill_manager_->SetExternalDelegate(&external_delegate); |
| 3108 | 3106 |
| 3109 FormData form; | 3107 FormData form; |
| 3110 CreateTestAddressFormData(&form); | 3108 CreateTestAddressFormData(&form); |
| 3111 std::vector<FormData> forms(1, form); | 3109 std::vector<FormData> forms(1, form); |
| 3112 FormsSeen(forms); | 3110 FormsSeen(forms); |
| 3113 const FormField& field = form.fields[0]; | 3111 const FormFieldData& field = form.fields[0]; |
| 3114 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3112 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3115 | 3113 |
| 3116 autofill_manager_->SetExternalDelegate(NULL); | 3114 autofill_manager_->SetExternalDelegate(NULL); |
| 3117 } | 3115 } |
| 3118 | 3116 |
| 3119 #if defined(OS_ANDROID) || defined(TOOLKIT_GTK) | 3117 #if defined(OS_ANDROID) || defined(TOOLKIT_GTK) |
| 3120 // OS_ANDROID defines an external delegate, but prerequisites for | 3118 // OS_ANDROID defines an external delegate, but prerequisites for |
| 3121 // landing autofill_external_delegate_android.cc in the Chromium tree | 3119 // landing autofill_external_delegate_android.cc in the Chromium tree |
| 3122 // have not themselves landed. | 3120 // have not themselves landed. |
| 3123 | 3121 |
| 3124 // Turn on the external delegate. Recreate a WebContents. Make sure | 3122 // Turn on the external delegate. Recreate a WebContents. Make sure |
| 3125 // an external delegate was set in the proper structures. | 3123 // an external delegate was set in the proper structures. |
| 3126 TEST_F(AutofillManagerTest, TestTabContentsWithExternalDelegate) { | 3124 TEST_F(AutofillManagerTest, TestTabContentsWithExternalDelegate) { |
| 3127 CommandLine::ForCurrentProcess()->AppendSwitch( | 3125 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3128 switches::kExternalAutofillPopup); | 3126 switches::kExternalAutofillPopup); |
| 3129 | 3127 |
| 3130 // Setting the contents creates a new TabContents. | 3128 // Setting the contents creates a new TabContents. |
| 3131 WebContents* contents = CreateTestWebContents(); | 3129 WebContents* contents = CreateTestWebContents(); |
| 3132 SetContents(contents); | 3130 SetContents(contents); |
| 3133 | 3131 |
| 3134 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); | 3132 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); |
| 3135 EXPECT_TRUE(autofill_manager->external_delegate()); | 3133 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3136 | 3134 |
| 3137 AutocompleteHistoryManager* autocomplete_history_manager = | 3135 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3138 AutocompleteHistoryManager::FromWebContents(web_contents()); | 3136 AutocompleteHistoryManager::FromWebContents(web_contents()); |
| 3139 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3137 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3140 } | 3138 } |
| 3141 | 3139 |
| 3142 #endif // OS_ANDROID | 3140 #endif // OS_ANDROID |
| OLD | NEW |