Chromium Code Reviews| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 | 197 |
| 198 credit_card = new CreditCard; | 198 credit_card = new CreditCard; |
| 199 autofill_test::SetCreditCardInfo(credit_card, "", "", "", ""); | 199 autofill_test::SetCreditCardInfo(credit_card, "", "", "", ""); |
| 200 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 200 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
| 201 credit_cards->push_back(credit_card); | 201 credit_cards->push_back(credit_card); |
| 202 } | 202 } |
| 203 | 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 204 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 // Populates |form| with 3 fields and a field with autocomplete attribute. | |
| 208 void CreateTestFormWithAutocompleteAttribute(FormData* form) { | |
| 209 form->name = ASCIIToUTF16("UserSpecified"); | |
| 210 form->method = ASCIIToUTF16("POST"); | |
| 211 form->origin = GURL("http://myform.com/userspecified.html"); | |
| 212 form->action = GURL("http://myform.com/submit.html"); | |
| 213 form->user_submitted = true; | |
| 214 | |
| 215 FormFieldData field; | |
| 216 autofill_test::CreateTestFormField( | |
| 217 "First Name", "firstname", "", "text", &field); | |
| 218 form->fields.push_back(field); | |
| 219 autofill_test::CreateTestFormField( | |
| 220 "Middle Name", "middlename", "", "text", &field); | |
| 221 form->fields.push_back(field); | |
| 222 autofill_test::CreateTestFormField( | |
| 223 "Last Name", "lastname", "", "text", &field); | |
| 224 form->fields.push_back(field); | |
| 225 field.autocomplete_attribute="cc-type"; | |
| 226 autofill_test::CreateTestFormField( | |
| 227 "cc-type", "cc-type", "", "text", &field); | |
| 228 form->fields.push_back(field); | |
| 229 } | |
| 230 | |
| 231 // Populates |form| with data corresponding to a simple shipping options form. | |
| 232 void CreateTestShippingOptionsFormData(FormData* form) { | |
| 233 form->name = ASCIIToUTF16("Shipping Options"); | |
| 234 form->method = ASCIIToUTF16("POST"); | |
| 235 form->origin = GURL("http://myform.com/shipping.html"); | |
| 236 form->action = GURL("http://myform.com/submit.html"); | |
| 237 form->user_submitted = true; | |
| 238 | |
| 239 FormFieldData field; | |
| 240 autofill_test::CreateTestFormField( | |
| 241 "Shipping1", "option", "option1", "radio", &field); | |
| 242 form->fields.push_back(field); | |
| 243 autofill_test::CreateTestFormField( | |
| 244 "Shipping2", "option", "option2", "radio", &field); | |
| 245 form->fields.push_back(field); | |
| 246 } | |
| 247 | |
| 207 // Populates |form| with data corresponding to a simple address form. | 248 // Populates |form| with data corresponding to a simple address form. |
| 208 // Note that this actually appends fields to the form data, which can be useful | 249 // Note that this actually appends fields to the form data, which can be useful |
| 209 // for building up more complex test forms. | 250 // for building up more complex test forms. |
| 210 void CreateTestAddressFormData(FormData* form) { | 251 void CreateTestAddressFormData(FormData* form) { |
| 211 form->name = ASCIIToUTF16("MyForm"); | 252 form->name = ASCIIToUTF16("MyForm"); |
| 212 form->method = ASCIIToUTF16("POST"); | 253 form->method = ASCIIToUTF16("POST"); |
| 213 form->origin = GURL("http://myform.com/form.html"); | 254 form->origin = GURL("http://myform.com/form.html"); |
| 214 form->action = GURL("http://myform.com/submit.html"); | 255 form->action = GURL("http://myform.com/submit.html"); |
| 215 form->user_submitted = true; | 256 form->user_submitted = true; |
| 216 | 257 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 message_loop_is_running_(false) { | 508 message_loop_is_running_(false) { |
| 468 } | 509 } |
| 469 virtual ~TestAutofillManager() {} | 510 virtual ~TestAutofillManager() {} |
| 470 | 511 |
| 471 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 512 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
| 472 | 513 |
| 473 void set_autofill_enabled(bool autofill_enabled) { | 514 void set_autofill_enabled(bool autofill_enabled) { |
| 474 autofill_enabled_ = autofill_enabled; | 515 autofill_enabled_ = autofill_enabled; |
| 475 } | 516 } |
| 476 | 517 |
| 518 void set_autocheckout_url_prefix(std::string autocheckout_url_prefix) { | |
|
Ilya Sherman
2013/03/15 23:37:18
nit: Pass by const-reference.
Raman Kakilate
2013/03/18 16:14:32
Done.
| |
| 519 autocheckout_url_prefix_ = autocheckout_url_prefix; | |
| 520 } | |
| 521 | |
| 522 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { | |
| 523 return autocheckout_url_prefix_; | |
| 524 } | |
| 525 | |
| 477 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& | 526 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& |
| 478 request_autocomplete_results() const { | 527 request_autocomplete_results() const { |
| 479 return request_autocomplete_results_; | 528 return request_autocomplete_results_; |
| 480 } | 529 } |
| 481 | 530 |
| 482 | 531 |
| 483 void set_expected_submitted_field_types( | 532 void set_expected_submitted_field_types( |
| 484 const std::vector<FieldTypeSet>& expected_types) { | 533 const std::vector<FieldTypeSet>& expected_types) { |
| 485 expected_submitted_field_types_ = expected_types; | 534 expected_submitted_field_types_ = expected_types; |
| 486 } | 535 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 std::string credit_card_guid = | 626 std::string credit_card_guid = |
| 578 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 627 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 579 | 628 |
| 580 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); | 629 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); |
| 581 } | 630 } |
| 582 | 631 |
| 583 void AddSeenForm(FormStructure* form) { | 632 void AddSeenForm(FormStructure* form) { |
| 584 form_structures()->push_back(form); | 633 form_structures()->push_back(form); |
| 585 } | 634 } |
| 586 | 635 |
| 636 void ClearFormStructures() { | |
| 637 form_structures()->clear(); | |
| 638 } | |
| 639 | |
| 587 virtual void ReturnAutocompleteResult( | 640 virtual void ReturnAutocompleteResult( |
| 588 WebFormElement::AutocompleteResult result, | 641 WebFormElement::AutocompleteResult result, |
| 589 const FormData& form_data) OVERRIDE { | 642 const FormData& form_data) OVERRIDE { |
| 590 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); | 643 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); |
| 591 } | 644 } |
| 592 | 645 |
| 593 private: | 646 private: |
| 594 // Weak reference. | 647 // Weak reference. |
| 595 TestPersonalDataManager* personal_data_; | 648 TestPersonalDataManager* personal_data_; |
| 596 | 649 |
| 597 bool autofill_enabled_; | 650 bool autofill_enabled_; |
| 598 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > | 651 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > |
| 599 request_autocomplete_results_; | 652 request_autocomplete_results_; |
| 600 | 653 |
| 601 bool did_finish_async_form_submit_; | 654 bool did_finish_async_form_submit_; |
| 602 bool message_loop_is_running_; | 655 bool message_loop_is_running_; |
| 603 | 656 |
| 657 std::string autocheckout_url_prefix_; | |
| 604 std::string submitted_form_signature_; | 658 std::string submitted_form_signature_; |
| 605 std::vector<FieldTypeSet> expected_submitted_field_types_; | 659 std::vector<FieldTypeSet> expected_submitted_field_types_; |
| 606 std::vector<bool> sent_states_; | 660 std::vector<bool> sent_states_; |
| 607 | 661 |
| 608 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 662 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 609 }; | 663 }; |
| 610 | 664 |
| 611 } // namespace | 665 } // namespace |
| 612 | 666 |
| 613 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { | 667 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 ASCIIToUTF16("3734 Elvis Presley Blvd."), | 889 ASCIIToUTF16("3734 Elvis Presley Blvd."), |
| 836 ASCIIToUTF16("123 Apple St.") | 890 ASCIIToUTF16("123 Apple St.") |
| 837 }; | 891 }; |
| 838 string16 expected_icons[] = {string16(), string16()}; | 892 string16 expected_icons[] = {string16(), string16()}; |
| 839 int expected_unique_ids[] = {1, 2}; | 893 int expected_unique_ids[] = {1, 2}; |
| 840 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 894 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 841 kDefaultPageID, arraysize(expected_values), expected_values, | 895 kDefaultPageID, arraysize(expected_values), expected_values, |
| 842 expected_labels, expected_icons, expected_unique_ids); | 896 expected_labels, expected_icons, expected_unique_ids); |
| 843 } | 897 } |
| 844 | 898 |
| 899 // Test that in the case of Autocheckout, forms seen are in order supplied. | |
| 900 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { | |
| 901 FormData shipping_options; | |
| 902 CreateTestShippingOptionsFormData(&shipping_options); | |
| 903 FormData user_supplied; | |
| 904 CreateTestFormWithAutocompleteAttribute(&user_supplied); | |
| 905 FormData address; | |
| 906 CreateTestAddressFormData(&address); | |
| 907 | |
| 908 // Push user_supplied before address and observe order changing when | |
| 909 // Autocheckout is not enabled.. | |
| 910 std::vector<FormData> forms; | |
| 911 forms.push_back(shipping_options); | |
| 912 forms.push_back(user_supplied); | |
| 913 forms.push_back(address); | |
| 914 | |
| 915 // Test without enabling Autocheckout. FormStructure should only contain | |
| 916 // form1. Shipping Options form will not qualify as parsable form. | |
| 917 FormsSeen(forms); | |
| 918 std::vector<FormStructure*> form_structures; | |
| 919 form_structures = autofill_manager_->GetFormStructures(); | |
| 920 ASSERT_EQ(2U, form_structures.size()); | |
| 921 ASSERT_EQ("/form.html", | |
|
Ilya Sherman
2013/03/15 23:37:18
nit: EXPECT_EQ
Raman Kakilate
2013/03/18 16:14:32
Done.
| |
| 922 form_structures[0]->source_url().path()); | |
|
Ilya Sherman
2013/03/15 23:37:18
nit: Looks like this fits on the previous line. (
Raman Kakilate
2013/03/18 16:14:32
Done.
| |
| 923 ASSERT_EQ("/userspecified.html", | |
|
Ilya Sherman
2013/03/15 23:37:18
nit: EXPECT_EQ
Raman Kakilate
2013/03/18 16:14:32
Done.
| |
| 924 form_structures[1]->source_url().path()); | |
| 925 autofill_manager_->ClearFormStructures(); | |
| 926 | |
| 927 // Test after enabling Autocheckout. Order should be shipping_options, | |
| 928 // userspecified and then address form. | |
| 929 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); | |
| 930 FormsSeen(forms); | |
| 931 form_structures = autofill_manager_->GetFormStructures(); | |
| 932 ASSERT_EQ(3U, form_structures.size()); | |
| 933 ASSERT_EQ("/shipping.html", | |
| 934 form_structures[0]->source_url().path()); | |
| 935 ASSERT_EQ("/userspecified.html", | |
| 936 form_structures[1]->source_url().path()); | |
| 937 ASSERT_EQ("/form.html", | |
| 938 form_structures[2]->source_url().path()); | |
| 939 } | |
| 940 | |
| 845 // Test that we return only matching address profile suggestions when the | 941 // Test that we return only matching address profile suggestions when the |
| 846 // selected form field has been partially filled out. | 942 // selected form field has been partially filled out. |
| 847 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 943 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
| 848 // Set up our form data. | 944 // Set up our form data. |
| 849 FormData form; | 945 FormData form; |
| 850 CreateTestAddressFormData(&form); | 946 CreateTestAddressFormData(&form); |
| 851 std::vector<FormData> forms(1, form); | 947 std::vector<FormData> forms(1, form); |
| 852 FormsSeen(forms); | 948 FormsSeen(forms); |
| 853 | 949 |
| 854 FormFieldData field; | 950 FormFieldData field; |
| (...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3219 | 3315 |
| 3220 FormData form; | 3316 FormData form; |
| 3221 CreateTestAddressFormData(&form); | 3317 CreateTestAddressFormData(&form); |
| 3222 std::vector<FormData> forms(1, form); | 3318 std::vector<FormData> forms(1, form); |
| 3223 FormsSeen(forms); | 3319 FormsSeen(forms); |
| 3224 const FormFieldData& field = form.fields[0]; | 3320 const FormFieldData& field = form.fields[0]; |
| 3225 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3321 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3226 | 3322 |
| 3227 autofill_manager_->SetExternalDelegate(NULL); | 3323 autofill_manager_->SetExternalDelegate(NULL); |
| 3228 } | 3324 } |
| OLD | NEW |