| 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/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/gfx/rect.h" | 42 #include "ui/gfx/rect.h" |
| 43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 44 | 44 |
| 45 using base::ASCIIToUTF16; | 45 using base::ASCIIToUTF16; |
| 46 using base::UTF8ToUTF16; | 46 using base::UTF8ToUTF16; |
| 47 using testing::_; | 47 using testing::_; |
| 48 | 48 |
| 49 namespace autofill { | 49 namespace autofill { |
| 50 | 50 |
| 51 typedef PersonalDataManager::GUIDPair GUIDPair; | |
| 52 | |
| 53 namespace { | 51 namespace { |
| 54 | 52 |
| 55 const int kDefaultPageID = 137; | 53 const int kDefaultPageID = 137; |
| 56 | 54 |
| 57 class TestPersonalDataManager : public PersonalDataManager { | 55 class TestPersonalDataManager : public PersonalDataManager { |
| 58 public: | 56 public: |
| 59 TestPersonalDataManager() : PersonalDataManager("en-US") { | 57 TestPersonalDataManager() : PersonalDataManager("en-US") { |
| 60 CreateTestAutofillProfiles(&web_profiles_); | 58 CreateTestAutofillProfiles(&web_profiles_); |
| 61 CreateTestCreditCards(&credit_cards_); | 59 CreateTestCreditCards(&credit_cards_); |
| 62 } | 60 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 "", "", "", "", "", "", "", "", "", "", "", | 350 "", "", "", "", "", "", "", "", "", "", "", |
| 353 "Miku Hatsune", "4234567890654321", month, year, | 351 "Miku Hatsune", "4234567890654321", month, year, |
| 354 has_address_fields, true, true); | 352 has_address_fields, true, true); |
| 355 } | 353 } |
| 356 | 354 |
| 357 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { | 355 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { |
| 358 public: | 356 public: |
| 359 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) | 357 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) |
| 360 : AutocompleteHistoryManager(driver, client) {} | 358 : AutocompleteHistoryManager(driver, client) {} |
| 361 | 359 |
| 362 MOCK_METHOD8(OnGetAutocompleteSuggestions, void( | 360 MOCK_METHOD5(OnGetAutocompleteSuggestions, void( |
| 363 int query_id, | 361 int query_id, |
| 364 const base::string16& name, | 362 const base::string16& name, |
| 365 const base::string16& prefix, | 363 const base::string16& prefix, |
| 366 const std::string& form_control_type, | 364 const std::string& form_control_type, |
| 367 const std::vector<base::string16>& autofill_values, | 365 const std::vector<Suggestion>& suggestions)); |
| 368 const std::vector<base::string16>& autofill_labels, | |
| 369 const std::vector<base::string16>& autofill_icons, | |
| 370 const std::vector<int>& autofill_unique_ids)); | |
| 371 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); | 366 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); |
| 372 | 367 |
| 373 private: | 368 private: |
| 374 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); | 369 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); |
| 375 }; | 370 }; |
| 376 | 371 |
| 377 class MockAutofillDriver : public TestAutofillDriver { | 372 class MockAutofillDriver : public TestAutofillDriver { |
| 378 public: | 373 public: |
| 379 MockAutofillDriver() {} | 374 MockAutofillDriver() {} |
| 380 | 375 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 466 } |
| 472 | 467 |
| 473 void AddCreditCard(CreditCard* credit_card) { | 468 void AddCreditCard(CreditCard* credit_card) { |
| 474 personal_data_->AddCreditCard(credit_card); | 469 personal_data_->AddCreditCard(credit_card); |
| 475 } | 470 } |
| 476 | 471 |
| 477 int GetPackedCreditCardID(int credit_card_id) { | 472 int GetPackedCreditCardID(int credit_card_id) { |
| 478 std::string credit_card_guid = | 473 std::string credit_card_guid = |
| 479 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 474 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 480 | 475 |
| 481 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); | 476 return MakeFrontendID(SuggestionBackendID(credit_card_guid, 0), |
| 477 SuggestionBackendID()); |
| 482 } | 478 } |
| 483 | 479 |
| 484 void AddSeenForm(FormStructure* form) { | 480 void AddSeenForm(FormStructure* form) { |
| 485 form_structures()->push_back(form); | 481 form_structures()->push_back(form); |
| 486 } | 482 } |
| 487 | 483 |
| 488 void ClearFormStructures() { | 484 void ClearFormStructures() { |
| 489 form_structures()->clear(); | 485 form_structures()->clear(); |
| 490 } | 486 } |
| 491 | 487 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 516 const FormData& form, | 512 const FormData& form, |
| 517 const FormFieldData& field, | 513 const FormFieldData& field, |
| 518 const gfx::RectF& bounds, | 514 const gfx::RectF& bounds, |
| 519 bool display_warning) override { | 515 bool display_warning) override { |
| 520 on_query_seen_ = true; | 516 on_query_seen_ = true; |
| 521 on_suggestions_returned_seen_ = false; | 517 on_suggestions_returned_seen_ = false; |
| 522 } | 518 } |
| 523 | 519 |
| 524 void OnSuggestionsReturned( | 520 void OnSuggestionsReturned( |
| 525 int query_id, | 521 int query_id, |
| 526 const std::vector<base::string16>& autofill_values, | 522 const std::vector<Suggestion>& suggestions) override { |
| 527 const std::vector<base::string16>& autofill_labels, | |
| 528 const std::vector<base::string16>& autofill_icons, | |
| 529 const std::vector<int>& autofill_unique_ids) override { | |
| 530 on_suggestions_returned_seen_ = true; | 523 on_suggestions_returned_seen_ = true; |
| 531 | |
| 532 query_id_ = query_id; | 524 query_id_ = query_id; |
| 533 autofill_values_ = autofill_values; | 525 suggestions_ = suggestions; |
| 534 autofill_labels_ = autofill_labels; | |
| 535 autofill_icons_ = autofill_icons; | |
| 536 autofill_unique_ids_ = autofill_unique_ids; | |
| 537 } | 526 } |
| 538 | 527 |
| 539 void CheckSuggestions(int expected_page_id, | 528 void CheckSuggestions(int expected_page_id, |
| 540 size_t expected_num_suggestions, | 529 size_t expected_num_suggestions, |
| 541 const base::string16 expected_values[], | 530 const Suggestion expected_suggestions[]) { |
| 542 const base::string16 expected_labels[], | |
| 543 const base::string16 expected_icons[], | |
| 544 const int expected_unique_ids[]) { | |
| 545 // Ensure that these results are from the most recent query. | 531 // Ensure that these results are from the most recent query. |
| 546 EXPECT_TRUE(on_suggestions_returned_seen_); | 532 EXPECT_TRUE(on_suggestions_returned_seen_); |
| 547 | 533 |
| 548 EXPECT_EQ(expected_page_id, query_id_); | 534 EXPECT_EQ(expected_page_id, query_id_); |
| 549 ASSERT_EQ(expected_num_suggestions, autofill_values_.size()); | 535 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
| 550 ASSERT_EQ(expected_num_suggestions, autofill_labels_.size()); | |
| 551 ASSERT_EQ(expected_num_suggestions, autofill_icons_.size()); | |
| 552 ASSERT_EQ(expected_num_suggestions, autofill_unique_ids_.size()); | |
| 553 for (size_t i = 0; i < expected_num_suggestions; ++i) { | 536 for (size_t i = 0; i < expected_num_suggestions; ++i) { |
| 554 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | 537 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| 555 EXPECT_EQ(expected_values[i], autofill_values_[i]); | 538 EXPECT_EQ(expected_suggestions[i].value, suggestions_[i].value); |
| 556 EXPECT_EQ(expected_labels[i], autofill_labels_[i]); | 539 EXPECT_EQ(expected_suggestions[i].label, suggestions_[i].label); |
| 557 EXPECT_EQ(expected_icons[i], autofill_icons_[i]); | 540 EXPECT_EQ(expected_suggestions[i].icon, suggestions_[i].icon); |
| 558 EXPECT_EQ(expected_unique_ids[i], autofill_unique_ids_[i]); | 541 EXPECT_EQ(expected_suggestions[i].frontend_id, |
| 542 suggestions_[i].frontend_id); |
| 559 } | 543 } |
| 560 } | 544 } |
| 561 | 545 |
| 546 // Wrappers around the above GetSuggestions call that take a hardcoded number |
| 547 // of expected results so callsites are cleaner. |
| 548 void CheckSuggestions(int expected_page_id, |
| 549 const Suggestion& suggestion0) { |
| 550 std::vector<Suggestion> suggestion_vector; |
| 551 suggestion_vector.push_back(suggestion0); |
| 552 CheckSuggestions(expected_page_id, 1, &suggestion_vector[0]); |
| 553 } |
| 554 void CheckSuggestions(int expected_page_id, |
| 555 const Suggestion& suggestion0, |
| 556 const Suggestion& suggestion1) { |
| 557 std::vector<Suggestion> suggestion_vector; |
| 558 suggestion_vector.push_back(suggestion0); |
| 559 suggestion_vector.push_back(suggestion1); |
| 560 CheckSuggestions(expected_page_id, 2, &suggestion_vector[0]); |
| 561 } |
| 562 void CheckSuggestions(int expected_page_id, |
| 563 const Suggestion& suggestion0, |
| 564 const Suggestion& suggestion1, |
| 565 const Suggestion& suggestion2) { |
| 566 std::vector<Suggestion> suggestion_vector; |
| 567 suggestion_vector.push_back(suggestion0); |
| 568 suggestion_vector.push_back(suggestion1); |
| 569 suggestion_vector.push_back(suggestion2); |
| 570 CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]); |
| 571 } |
| 572 |
| 573 |
| 562 bool on_query_seen() const { | 574 bool on_query_seen() const { |
| 563 return on_query_seen_; | 575 return on_query_seen_; |
| 564 } | 576 } |
| 565 | 577 |
| 566 bool on_suggestions_returned_seen() const { | 578 bool on_suggestions_returned_seen() const { |
| 567 return on_suggestions_returned_seen_; | 579 return on_suggestions_returned_seen_; |
| 568 } | 580 } |
| 569 | 581 |
| 570 private: | 582 private: |
| 571 // Records if OnQuery has been called yet. | 583 // Records if OnQuery has been called yet. |
| 572 bool on_query_seen_; | 584 bool on_query_seen_; |
| 573 | 585 |
| 574 // Records if OnSuggestionsReturned has been called after the most recent | 586 // Records if OnSuggestionsReturned has been called after the most recent |
| 575 // call to OnQuery. | 587 // call to OnQuery. |
| 576 bool on_suggestions_returned_seen_; | 588 bool on_suggestions_returned_seen_; |
| 577 | 589 |
| 578 // The query id of the most recent Autofill query. | 590 // The query id of the most recent Autofill query. |
| 579 int query_id_; | 591 int query_id_; |
| 580 | 592 |
| 581 // The results returned by the most recent Autofill query. | 593 // The results returned by the most recent Autofill query. |
| 582 std::vector<base::string16> autofill_values_; | 594 std::vector<Suggestion> suggestions_; |
| 583 std::vector<base::string16> autofill_labels_; | |
| 584 std::vector<base::string16> autofill_icons_; | |
| 585 std::vector<int> autofill_unique_ids_; | |
| 586 | 595 |
| 587 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); | 596 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); |
| 588 }; | 597 }; |
| 589 | 598 |
| 590 } // namespace | 599 } // namespace |
| 591 | 600 |
| 592 class AutofillManagerTest : public testing::Test { | 601 class AutofillManagerTest : public testing::Test { |
| 593 public: | 602 public: |
| 594 void SetUp() override { | 603 void SetUp() override { |
| 595 autofill_client_.SetPrefs(test::PrefServiceForTesting()); | 604 autofill_client_.SetPrefs(test::PrefServiceForTesting()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 const FormFieldData& input_field, | 675 const FormFieldData& input_field, |
| 667 int unique_id, | 676 int unique_id, |
| 668 int* response_query_id, | 677 int* response_query_id, |
| 669 FormData* response_data) { | 678 FormData* response_data) { |
| 670 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)). | 679 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)). |
| 671 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), | 680 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), |
| 672 testing::SaveArg<2>(response_data)))); | 681 testing::SaveArg<2>(response_data)))); |
| 673 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); | 682 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); |
| 674 } | 683 } |
| 675 | 684 |
| 676 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 685 int MakeFrontendID(const SuggestionBackendID& cc_sid, |
| 677 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 686 const SuggestionBackendID& profile_sid) const { |
| 687 return autofill_manager_->MakeFrontendID(cc_sid, profile_sid); |
| 678 } | 688 } |
| 679 | 689 |
| 680 protected: | 690 protected: |
| 681 base::MessageLoop message_loop_; | 691 base::MessageLoop message_loop_; |
| 682 TestAutofillClient autofill_client_; | 692 TestAutofillClient autofill_client_; |
| 683 scoped_ptr<MockAutofillDriver> autofill_driver_; | 693 scoped_ptr<MockAutofillDriver> autofill_driver_; |
| 684 scoped_ptr<TestAutofillManager> autofill_manager_; | 694 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 685 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | 695 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; |
| 686 TestPersonalDataManager personal_data_; | 696 TestPersonalDataManager personal_data_; |
| 687 }; | 697 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 std::vector<FormData> forms(1, form); | 730 std::vector<FormData> forms(1, form); |
| 721 FormsSeen(forms); | 731 FormsSeen(forms); |
| 722 | 732 |
| 723 const FormFieldData& field = form.fields[0]; | 733 const FormFieldData& field = form.fields[0]; |
| 724 GetAutofillSuggestions(form, field); | 734 GetAutofillSuggestions(form, field); |
| 725 | 735 |
| 726 // No suggestions provided, so send an empty vector as the results. | 736 // No suggestions provided, so send an empty vector as the results. |
| 727 // This triggers the combined message send. | 737 // This triggers the combined message send. |
| 728 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 738 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 729 | 739 |
| 730 // Test that we sent the right values to the external delegate. | 740 // Test that we sent the right values to the external delegate. Inferred |
| 731 base::string16 expected_values[] = { | 741 // labels include full first relevant field, which in this case is the |
| 732 ASCIIToUTF16("Elvis"), | 742 // address line 1. |
| 733 ASCIIToUTF16("Charles") | |
| 734 }; | |
| 735 // Inferred labels include full first relevant field, which in this case is | |
| 736 // the address line 1. | |
| 737 base::string16 expected_labels[] = { | |
| 738 ASCIIToUTF16("3734 Elvis Presley Blvd."), | |
| 739 ASCIIToUTF16("123 Apple St.") | |
| 740 }; | |
| 741 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 742 int expected_unique_ids[] = {1, 2}; | |
| 743 external_delegate_->CheckSuggestions( | 743 external_delegate_->CheckSuggestions( |
| 744 kDefaultPageID, arraysize(expected_values), expected_values, | 744 kDefaultPageID, |
| 745 expected_labels, expected_icons, expected_unique_ids); | 745 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| 746 Suggestion("Charles", "123 Apple St.", "", 2)); |
| 746 } | 747 } |
| 747 | 748 |
| 748 // Test that we return only matching address profile suggestions when the | 749 // Test that we return only matching address profile suggestions when the |
| 749 // selected form field has been partially filled out. | 750 // selected form field has been partially filled out. |
| 750 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 751 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
| 751 // Set up our form data. | 752 // Set up our form data. |
| 752 FormData form; | 753 FormData form; |
| 753 test::CreateTestAddressFormData(&form); | 754 test::CreateTestAddressFormData(&form); |
| 754 std::vector<FormData> forms(1, form); | 755 std::vector<FormData> forms(1, form); |
| 755 FormsSeen(forms); | 756 FormsSeen(forms); |
| 756 | 757 |
| 757 FormFieldData field; | 758 FormFieldData field; |
| 758 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); | 759 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); |
| 759 GetAutofillSuggestions(form, field); | 760 GetAutofillSuggestions(form, field); |
| 760 | 761 |
| 761 // No suggestions provided, so send an empty vector as the results. | 762 // No suggestions provided, so send an empty vector as the results. |
| 762 // This triggers the combined message send. | 763 // This triggers the combined message send. |
| 763 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 764 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 764 | 765 |
| 765 // Test that we sent the right values to the external delegate. | 766 // Test that we sent the right values to the external delegate. |
| 766 base::string16 expected_values[] = {ASCIIToUTF16("Elvis")}; | |
| 767 base::string16 expected_labels[] = {ASCIIToUTF16("3734 Elvis Presley Blvd.")}; | |
| 768 base::string16 expected_icons[] = {base::string16()}; | |
| 769 int expected_unique_ids[] = {1}; | |
| 770 external_delegate_->CheckSuggestions( | 767 external_delegate_->CheckSuggestions( |
| 771 kDefaultPageID, arraysize(expected_values), expected_values, | 768 kDefaultPageID, |
| 772 expected_labels, expected_icons, expected_unique_ids); | 769 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1)); |
| 773 } | 770 } |
| 774 | 771 |
| 775 // Test that we return no suggestions when the form has no relevant fields. | 772 // Test that we return no suggestions when the form has no relevant fields. |
| 776 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { | 773 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { |
| 777 // Set up our form data. | 774 // Set up our form data. |
| 778 FormData form; | 775 FormData form; |
| 779 form.name = ASCIIToUTF16("MyForm"); | 776 form.name = ASCIIToUTF16("MyForm"); |
| 780 form.origin = GURL("http://myform.com/form.html"); | 777 form.origin = GURL("http://myform.com/form.html"); |
| 781 form.action = GURL("http://myform.com/submit.html"); | 778 form.action = GURL("http://myform.com/submit.html"); |
| 782 form.user_submitted = true; | 779 form.user_submitted = true; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 autofill_manager_->AddProfile(duplicate_profile); | 811 autofill_manager_->AddProfile(duplicate_profile); |
| 815 | 812 |
| 816 const FormFieldData& field = form.fields[0]; | 813 const FormFieldData& field = form.fields[0]; |
| 817 GetAutofillSuggestions(form, field); | 814 GetAutofillSuggestions(form, field); |
| 818 | 815 |
| 819 // No suggestions provided, so send an empty vector as the results. | 816 // No suggestions provided, so send an empty vector as the results. |
| 820 // This triggers the combined message send. | 817 // This triggers the combined message send. |
| 821 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 818 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 822 | 819 |
| 823 // Test that we sent the right values to the external delegate. | 820 // Test that we sent the right values to the external delegate. |
| 824 base::string16 expected_values[] = { | |
| 825 ASCIIToUTF16("Elvis"), | |
| 826 ASCIIToUTF16("Charles") | |
| 827 }; | |
| 828 base::string16 expected_labels[] = { | |
| 829 ASCIIToUTF16("3734 Elvis Presley Blvd."), | |
| 830 ASCIIToUTF16("123 Apple St.") | |
| 831 }; | |
| 832 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 833 int expected_unique_ids[] = {1, 2}; | |
| 834 external_delegate_->CheckSuggestions( | 821 external_delegate_->CheckSuggestions( |
| 835 kDefaultPageID, arraysize(expected_values), expected_values, | 822 kDefaultPageID, |
| 836 expected_labels, expected_icons, expected_unique_ids); | 823 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| 824 Suggestion("Charles", "123 Apple St.", "", 2)); |
| 837 } | 825 } |
| 838 | 826 |
| 839 // Test that we return no suggestions when autofill is disabled. | 827 // Test that we return no suggestions when autofill is disabled. |
| 840 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 828 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
| 841 // Set up our form data. | 829 // Set up our form data. |
| 842 FormData form; | 830 FormData form; |
| 843 test::CreateTestAddressFormData(&form); | 831 test::CreateTestAddressFormData(&form); |
| 844 std::vector<FormData> forms(1, form); | 832 std::vector<FormData> forms(1, form); |
| 845 FormsSeen(forms); | 833 FormsSeen(forms); |
| 846 | 834 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 862 FormsSeen(forms); | 850 FormsSeen(forms); |
| 863 | 851 |
| 864 FormFieldData field = form.fields[1]; | 852 FormFieldData field = form.fields[1]; |
| 865 GetAutofillSuggestions(form, field); | 853 GetAutofillSuggestions(form, field); |
| 866 | 854 |
| 867 // No suggestions provided, so send an empty vector as the results. | 855 // No suggestions provided, so send an empty vector as the results. |
| 868 // This triggers the combined message send. | 856 // This triggers the combined message send. |
| 869 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 857 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 870 | 858 |
| 871 // Test that we sent the right values to the external delegate. | 859 // Test that we sent the right values to the external delegate. |
| 872 base::string16 expected_values[] = { | |
| 873 ASCIIToUTF16("************3456"), | |
| 874 ASCIIToUTF16("************8765") | |
| 875 }; | |
| 876 base::string16 expected_labels[] = { ASCIIToUTF16("04/12"), | |
| 877 ASCIIToUTF16("10/14")}; | |
| 878 base::string16 expected_icons[] = { | |
| 879 ASCIIToUTF16(kVisaCard), | |
| 880 ASCIIToUTF16(kMasterCard) | |
| 881 }; | |
| 882 int expected_unique_ids[] = { | |
| 883 autofill_manager_->GetPackedCreditCardID(4), | |
| 884 autofill_manager_->GetPackedCreditCardID(5) | |
| 885 }; | |
| 886 external_delegate_->CheckSuggestions( | 860 external_delegate_->CheckSuggestions( |
| 887 kDefaultPageID, arraysize(expected_values), expected_values, | 861 kDefaultPageID, |
| 888 expected_labels, expected_icons, expected_unique_ids); | 862 Suggestion("************3456", "04/12", kVisaCard, |
| 863 autofill_manager_->GetPackedCreditCardID(4)), |
| 864 Suggestion("************8765", "10/14", kMasterCard, |
| 865 autofill_manager_->GetPackedCreditCardID(5))); |
| 889 } | 866 } |
| 890 | 867 |
| 891 // Test that we return only matching credit card profile suggestions when the | 868 // Test that we return only matching credit card profile suggestions when the |
| 892 // selected form field has been partially filled out. | 869 // selected form field has been partially filled out. |
| 893 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 870 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
| 894 // Set up our form data. | 871 // Set up our form data. |
| 895 FormData form; | 872 FormData form; |
| 896 CreateTestCreditCardFormData(&form, true, false); | 873 CreateTestCreditCardFormData(&form, true, false); |
| 897 std::vector<FormData> forms(1, form); | 874 std::vector<FormData> forms(1, form); |
| 898 FormsSeen(forms); | 875 FormsSeen(forms); |
| 899 | 876 |
| 900 FormFieldData field; | 877 FormFieldData field; |
| 901 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 878 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
| 902 GetAutofillSuggestions(form, field); | 879 GetAutofillSuggestions(form, field); |
| 903 | 880 |
| 904 // No suggestions provided, so send an empty vector as the results. | 881 // No suggestions provided, so send an empty vector as the results. |
| 905 // This triggers the combined message send. | 882 // This triggers the combined message send. |
| 906 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 883 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 907 | 884 |
| 908 // Test that we sent the right values to the external delegate. | 885 // Test that we sent the right values to the external delegate. |
| 909 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | |
| 910 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | |
| 911 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | |
| 912 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; | |
| 913 external_delegate_->CheckSuggestions( | 886 external_delegate_->CheckSuggestions( |
| 914 kDefaultPageID, arraysize(expected_values), expected_values, | 887 kDefaultPageID, |
| 915 expected_labels, expected_icons, expected_unique_ids); | 888 Suggestion("************3456", "04/12", kVisaCard, |
| 889 autofill_manager_->GetPackedCreditCardID(4))); |
| 916 } | 890 } |
| 917 | 891 |
| 918 // Test that we return credit card profile suggestions when the selected form | 892 // Test that we return credit card profile suggestions when the selected form |
| 919 // field is not the credit card number field. | 893 // field is not the credit card number field. |
| 920 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 894 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
| 921 // Set up our form data. | 895 // Set up our form data. |
| 922 FormData form; | 896 FormData form; |
| 923 CreateTestCreditCardFormData(&form, true, false); | 897 CreateTestCreditCardFormData(&form, true, false); |
| 924 std::vector<FormData> forms(1, form); | 898 std::vector<FormData> forms(1, form); |
| 925 FormsSeen(forms); | 899 FormsSeen(forms); |
| 926 | 900 |
| 927 const FormFieldData& field = form.fields[0]; | 901 const FormFieldData& field = form.fields[0]; |
| 928 GetAutofillSuggestions(form, field); | 902 GetAutofillSuggestions(form, field); |
| 929 | 903 |
| 930 // No suggestions provided, so send an empty vector as the results. | 904 // No suggestions provided, so send an empty vector as the results. |
| 931 // This triggers the combined message send. | 905 // This triggers the combined message send. |
| 932 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 906 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 933 | 907 |
| 934 // Test that we sent the right values to the external delegate. | 908 // Test that we sent the right values to the external delegate. |
| 935 base::string16 expected_values[] = { | |
| 936 ASCIIToUTF16("Elvis Presley"), | |
| 937 ASCIIToUTF16("Buddy Holly") | |
| 938 }; | |
| 939 base::string16 expected_labels[] = { ASCIIToUTF16("*3456"), | |
| 940 ASCIIToUTF16("*8765") }; | |
| 941 base::string16 expected_icons[] = { | |
| 942 ASCIIToUTF16(kVisaCard), | |
| 943 ASCIIToUTF16(kMasterCard) | |
| 944 }; | |
| 945 int expected_unique_ids[] = { | |
| 946 autofill_manager_->GetPackedCreditCardID(4), | |
| 947 autofill_manager_->GetPackedCreditCardID(5) | |
| 948 }; | |
| 949 external_delegate_->CheckSuggestions( | 909 external_delegate_->CheckSuggestions( |
| 950 kDefaultPageID, arraysize(expected_values), expected_values, | 910 kDefaultPageID, |
| 951 expected_labels, expected_icons, expected_unique_ids); | 911 Suggestion("Elvis Presley", "*3456", kVisaCard, |
| 912 autofill_manager_->GetPackedCreditCardID(4)), |
| 913 Suggestion("Buddy Holly", "*8765", kMasterCard, |
| 914 autofill_manager_->GetPackedCreditCardID(5))); |
| 952 } | 915 } |
| 953 | 916 |
| 954 // Test that we return a warning explaining that credit card profile suggestions | 917 // Test that we return a warning explaining that credit card profile suggestions |
| 955 // are unavailable when the form is not https. | 918 // are unavailable when the form is not https. |
| 956 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 919 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 957 // Set up our form data. | 920 // Set up our form data. |
| 958 FormData form; | 921 FormData form; |
| 959 CreateTestCreditCardFormData(&form, false, false); | 922 CreateTestCreditCardFormData(&form, false, false); |
| 960 std::vector<FormData> forms(1, form); | 923 std::vector<FormData> forms(1, form); |
| 961 FormsSeen(forms); | 924 FormsSeen(forms); |
| 962 | 925 |
| 963 const FormFieldData& field = form.fields[0]; | 926 const FormFieldData& field = form.fields[0]; |
| 964 GetAutofillSuggestions(form, field); | 927 GetAutofillSuggestions(form, field); |
| 965 | 928 |
| 966 // No suggestions provided, so send an empty vector as the results. | 929 // No suggestions provided, so send an empty vector as the results. |
| 967 // This triggers the combined message send. | 930 // This triggers the combined message send. |
| 968 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 931 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 969 | 932 |
| 970 // Test that we sent the right values to the external delegate. | 933 // Test that we sent the right values to the external delegate. |
| 971 base::string16 expected_values[] = { | |
| 972 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION) | |
| 973 }; | |
| 974 base::string16 expected_labels[] = {base::string16()}; | |
| 975 base::string16 expected_icons[] = {base::string16()}; | |
| 976 int expected_unique_ids[] = {-1}; | |
| 977 external_delegate_->CheckSuggestions( | 934 external_delegate_->CheckSuggestions( |
| 978 kDefaultPageID, arraysize(expected_values), expected_values, | 935 kDefaultPageID, |
| 979 expected_labels, expected_icons, expected_unique_ids); | 936 Suggestion( |
| 937 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 938 "", "", -1)); |
| 980 | 939 |
| 981 // Now add some Autocomplete suggestions. We should show the autocomplete | 940 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 982 // suggestions and the warning. | 941 // suggestions and the warning. |
| 983 const int kPageID2 = 2; | 942 const int kPageID2 = 2; |
| 984 GetAutofillSuggestions(kPageID2, form, field); | 943 GetAutofillSuggestions(kPageID2, form, field); |
| 985 | 944 |
| 986 std::vector<base::string16> suggestions; | 945 std::vector<base::string16> suggestions; |
| 987 suggestions.push_back(ASCIIToUTF16("Jay")); | 946 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 988 suggestions.push_back(ASCIIToUTF16("Jason")); | 947 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 989 AutocompleteSuggestionsReturned(suggestions); | 948 AutocompleteSuggestionsReturned(suggestions); |
| 990 | 949 |
| 991 base::string16 expected_values2[] = { | |
| 992 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | |
| 993 ASCIIToUTF16("Jay"), | |
| 994 ASCIIToUTF16("Jason") | |
| 995 }; | |
| 996 base::string16 expected_labels2[] = { base::string16(), base::string16(), | |
| 997 base::string16() }; | |
| 998 base::string16 expected_icons2[] = { base::string16(), base::string16(), | |
| 999 base::string16() }; | |
| 1000 int expected_unique_ids2[] = {-1, 0, 0}; | |
| 1001 external_delegate_->CheckSuggestions( | 950 external_delegate_->CheckSuggestions( |
| 1002 kPageID2, arraysize(expected_values2), expected_values2, | 951 kPageID2, |
| 1003 expected_labels2, expected_icons2, expected_unique_ids2); | 952 Suggestion( |
| 953 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 954 "", "", -1), |
| 955 Suggestion("Jay", "", "", 0), |
| 956 Suggestion("Jason", "", "", 0)); |
| 1004 | 957 |
| 1005 // Clear the test credit cards and try again -- we shouldn't return a warning. | 958 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1006 personal_data_.ClearCreditCards(); | 959 personal_data_.ClearCreditCards(); |
| 1007 GetAutofillSuggestions(form, field); | 960 GetAutofillSuggestions(form, field); |
| 1008 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 961 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1009 } | 962 } |
| 1010 | 963 |
| 1011 // Test that we return all credit card suggestions in the case that two cards | 964 // Test that we return all credit card suggestions in the case that two cards |
| 1012 // have the same obfuscated number. | 965 // have the same obfuscated number. |
| 1013 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { | 966 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1027 FormsSeen(forms); | 980 FormsSeen(forms); |
| 1028 | 981 |
| 1029 FormFieldData field = form.fields[1]; | 982 FormFieldData field = form.fields[1]; |
| 1030 GetAutofillSuggestions(form, field); | 983 GetAutofillSuggestions(form, field); |
| 1031 | 984 |
| 1032 // No suggestions provided, so send an empty vector as the results. | 985 // No suggestions provided, so send an empty vector as the results. |
| 1033 // This triggers the combined message send. | 986 // This triggers the combined message send. |
| 1034 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 987 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1035 | 988 |
| 1036 // Test that we sent the right values to the external delegate. | 989 // Test that we sent the right values to the external delegate. |
| 1037 base::string16 expected_values[] = { | |
| 1038 ASCIIToUTF16("************3456"), | |
| 1039 ASCIIToUTF16("************8765"), | |
| 1040 ASCIIToUTF16("************3456") | |
| 1041 }; | |
| 1042 base::string16 expected_labels[] = { | |
| 1043 ASCIIToUTF16("04/12"), | |
| 1044 ASCIIToUTF16("10/14"), | |
| 1045 ASCIIToUTF16("05/12"), | |
| 1046 }; | |
| 1047 base::string16 expected_icons[] = { | |
| 1048 ASCIIToUTF16(kVisaCard), | |
| 1049 ASCIIToUTF16(kMasterCard), | |
| 1050 ASCIIToUTF16(kMasterCard) | |
| 1051 }; | |
| 1052 int expected_unique_ids[] = { | |
| 1053 autofill_manager_->GetPackedCreditCardID(4), | |
| 1054 autofill_manager_->GetPackedCreditCardID(5), | |
| 1055 autofill_manager_->GetPackedCreditCardID(7) | |
| 1056 }; | |
| 1057 external_delegate_->CheckSuggestions( | 990 external_delegate_->CheckSuggestions( |
| 1058 kDefaultPageID, arraysize(expected_values), expected_values, | 991 kDefaultPageID, |
| 1059 expected_labels, expected_icons, expected_unique_ids); | 992 Suggestion("************3456", "04/12", kVisaCard, |
| 993 autofill_manager_->GetPackedCreditCardID(4)), |
| 994 Suggestion("************8765", "10/14", kMasterCard, |
| 995 autofill_manager_->GetPackedCreditCardID(5)), |
| 996 Suggestion("************3456", "05/12", kMasterCard, |
| 997 autofill_manager_->GetPackedCreditCardID(7))); |
| 1060 } | 998 } |
| 1061 | 999 |
| 1062 // Test that we return profile and credit card suggestions for combined forms. | 1000 // Test that we return profile and credit card suggestions for combined forms. |
| 1063 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1001 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1064 // Set up our form data. | 1002 // Set up our form data. |
| 1065 FormData form; | 1003 FormData form; |
| 1066 test::CreateTestAddressFormData(&form); | 1004 test::CreateTestAddressFormData(&form); |
| 1067 CreateTestCreditCardFormData(&form, true, false); | 1005 CreateTestCreditCardFormData(&form, true, false); |
| 1068 std::vector<FormData> forms(1, form); | 1006 std::vector<FormData> forms(1, form); |
| 1069 FormsSeen(forms); | 1007 FormsSeen(forms); |
| 1070 | 1008 |
| 1071 FormFieldData field = form.fields[0]; | 1009 FormFieldData field = form.fields[0]; |
| 1072 GetAutofillSuggestions(form, field); | 1010 GetAutofillSuggestions(form, field); |
| 1073 | 1011 |
| 1074 // No suggestions provided, so send an empty vector as the results. | 1012 // No suggestions provided, so send an empty vector as the results. |
| 1075 // This triggers the combined message send. | 1013 // This triggers the combined message send. |
| 1076 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1014 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1077 | 1015 |
| 1078 // Test that we sent the right address suggestions to the external delegate. | 1016 // Test that we sent the right address suggestions to the external delegate. |
| 1079 base::string16 expected_values[] = { | |
| 1080 ASCIIToUTF16("Elvis"), | |
| 1081 ASCIIToUTF16("Charles") | |
| 1082 }; | |
| 1083 base::string16 expected_labels[] = { | |
| 1084 ASCIIToUTF16("3734 Elvis Presley Blvd."), | |
| 1085 ASCIIToUTF16("123 Apple St.") | |
| 1086 }; | |
| 1087 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 1088 int expected_unique_ids[] = {1, 2}; | |
| 1089 external_delegate_->CheckSuggestions( | 1017 external_delegate_->CheckSuggestions( |
| 1090 kDefaultPageID, arraysize(expected_values), expected_values, | 1018 kDefaultPageID, |
| 1091 expected_labels, expected_icons, expected_unique_ids); | 1019 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| 1020 Suggestion("Charles", "123 Apple St.", "", 2)); |
| 1092 | 1021 |
| 1093 const int kPageID2 = 2; | 1022 const int kPageID2 = 2; |
| 1094 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 1023 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 1095 GetAutofillSuggestions(kPageID2, form, field); | 1024 GetAutofillSuggestions(kPageID2, form, field); |
| 1096 | 1025 |
| 1097 // No suggestions provided, so send an empty vector as the results. | 1026 // No suggestions provided, so send an empty vector as the results. |
| 1098 // This triggers the combined message send. | 1027 // This triggers the combined message send. |
| 1099 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1028 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1100 | 1029 |
| 1101 // Test that we sent the credit card suggestions to the external delegate. | 1030 // Test that we sent the credit card suggestions to the external delegate. |
| 1102 base::string16 expected_values2[] = { | |
| 1103 ASCIIToUTF16("************3456"), | |
| 1104 ASCIIToUTF16("************8765") | |
| 1105 }; | |
| 1106 base::string16 expected_labels2[] = { ASCIIToUTF16("04/12"), | |
| 1107 ASCIIToUTF16("10/14")}; | |
| 1108 base::string16 expected_icons2[] = { | |
| 1109 ASCIIToUTF16(kVisaCard), | |
| 1110 ASCIIToUTF16(kMasterCard) | |
| 1111 }; | |
| 1112 int expected_unique_ids2[] = { | |
| 1113 autofill_manager_->GetPackedCreditCardID(4), | |
| 1114 autofill_manager_->GetPackedCreditCardID(5) | |
| 1115 }; | |
| 1116 external_delegate_->CheckSuggestions( | 1031 external_delegate_->CheckSuggestions( |
| 1117 kPageID2, arraysize(expected_values2), expected_values2, | 1032 kPageID2, |
| 1118 expected_labels2, expected_icons2, expected_unique_ids2); | 1033 Suggestion("************3456", "04/12", kVisaCard, |
| 1034 autofill_manager_->GetPackedCreditCardID(4)), |
| 1035 Suggestion("************8765", "10/14", kMasterCard, |
| 1036 autofill_manager_->GetPackedCreditCardID(5))); |
| 1119 } | 1037 } |
| 1120 | 1038 |
| 1121 // Test that for non-https forms with both address and credit card fields, we | 1039 // Test that for non-https forms with both address and credit card fields, we |
| 1122 // only return address suggestions. Instead of credit card suggestions, we | 1040 // only return address suggestions. Instead of credit card suggestions, we |
| 1123 // should return a warning explaining that credit card profile suggestions are | 1041 // should return a warning explaining that credit card profile suggestions are |
| 1124 // unavailable when the form is not https. | 1042 // unavailable when the form is not https. |
| 1125 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1043 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1126 // Set up our form data. | 1044 // Set up our form data. |
| 1127 FormData form; | 1045 FormData form; |
| 1128 test::CreateTestAddressFormData(&form); | 1046 test::CreateTestAddressFormData(&form); |
| 1129 CreateTestCreditCardFormData(&form, false, false); | 1047 CreateTestCreditCardFormData(&form, false, false); |
| 1130 std::vector<FormData> forms(1, form); | 1048 std::vector<FormData> forms(1, form); |
| 1131 FormsSeen(forms); | 1049 FormsSeen(forms); |
| 1132 | 1050 |
| 1133 FormFieldData field = form.fields[0]; | 1051 FormFieldData field = form.fields[0]; |
| 1134 GetAutofillSuggestions(form, field); | 1052 GetAutofillSuggestions(form, field); |
| 1135 | 1053 |
| 1136 // No suggestions provided, so send an empty vector as the results. | 1054 // No suggestions provided, so send an empty vector as the results. |
| 1137 // This triggers the combined message send. | 1055 // This triggers the combined message send. |
| 1138 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1056 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1139 | 1057 |
| 1140 // Test that we sent the right suggestions to the external delegate. | 1058 // Test that we sent the right suggestions to the external delegate. |
| 1141 base::string16 expected_values[] = { | |
| 1142 ASCIIToUTF16("Elvis"), | |
| 1143 ASCIIToUTF16("Charles") | |
| 1144 }; | |
| 1145 base::string16 expected_labels[] = { | |
| 1146 ASCIIToUTF16("3734 Elvis Presley Blvd."), | |
| 1147 ASCIIToUTF16("123 Apple St.") | |
| 1148 }; | |
| 1149 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 1150 int expected_unique_ids[] = {1, 2}; | |
| 1151 external_delegate_->CheckSuggestions( | 1059 external_delegate_->CheckSuggestions( |
| 1152 kDefaultPageID, arraysize(expected_values), expected_values, | 1060 kDefaultPageID, |
| 1153 expected_labels, expected_icons, expected_unique_ids); | 1061 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| 1062 Suggestion("Charles", "123 Apple St.", "", 2)); |
| 1154 | 1063 |
| 1155 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 1064 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 1156 const int kPageID2 = 2; | 1065 const int kPageID2 = 2; |
| 1157 GetAutofillSuggestions(kPageID2, form, field); | 1066 GetAutofillSuggestions(kPageID2, form, field); |
| 1158 | 1067 |
| 1159 // No suggestions provided, so send an empty vector as the results. | 1068 // No suggestions provided, so send an empty vector as the results. |
| 1160 // This triggers the combined message send. | 1069 // This triggers the combined message send. |
| 1161 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1070 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1162 | 1071 |
| 1163 // Test that we sent the right values to the external delegate. | 1072 // Test that we sent the right values to the external delegate. |
| 1164 base::string16 expected_values2[] = { | |
| 1165 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION) | |
| 1166 }; | |
| 1167 base::string16 expected_labels2[] = {base::string16()}; | |
| 1168 base::string16 expected_icons2[] = {base::string16()}; | |
| 1169 int expected_unique_ids2[] = {-1}; | |
| 1170 external_delegate_->CheckSuggestions( | 1073 external_delegate_->CheckSuggestions( |
| 1171 kPageID2, arraysize(expected_values2), expected_values2, | 1074 kPageID2, |
| 1172 expected_labels2, expected_icons2, expected_unique_ids2); | 1075 Suggestion( |
| 1076 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1077 "", "", -1)); |
| 1173 | 1078 |
| 1174 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1079 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1175 personal_data_.ClearCreditCards(); | 1080 personal_data_.ClearCreditCards(); |
| 1176 GetAutofillSuggestions(form, field); | 1081 GetAutofillSuggestions(form, field); |
| 1177 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1082 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1178 } | 1083 } |
| 1179 | 1084 |
| 1180 // Test that we correctly combine autofill and autocomplete suggestions. | 1085 // Test that we correctly combine autofill and autocomplete suggestions. |
| 1181 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { | 1086 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { |
| 1182 // Set up our form data. | 1087 // Set up our form data. |
| 1183 FormData form; | 1088 FormData form; |
| 1184 test::CreateTestAddressFormData(&form); | 1089 test::CreateTestAddressFormData(&form); |
| 1185 std::vector<FormData> forms(1, form); | 1090 std::vector<FormData> forms(1, form); |
| 1186 FormsSeen(forms); | 1091 FormsSeen(forms); |
| 1187 | 1092 |
| 1188 const FormFieldData& field = form.fields[0]; | 1093 const FormFieldData& field = form.fields[0]; |
| 1189 GetAutofillSuggestions(form, field); | 1094 GetAutofillSuggestions(form, field); |
| 1190 | 1095 |
| 1191 // Add some Autocomplete suggestions. | 1096 // Add some Autocomplete suggestions. |
| 1192 // This triggers the combined message send. | 1097 // This triggers the combined message send. |
| 1193 std::vector<base::string16> suggestions; | 1098 std::vector<base::string16> suggestions; |
| 1194 suggestions.push_back(ASCIIToUTF16("Jay")); | 1099 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 1195 // This suggestion is a duplicate, and should be trimmed. | 1100 // This suggestion is a duplicate, and should be trimmed. |
| 1196 suggestions.push_back(ASCIIToUTF16("Elvis")); | 1101 suggestions.push_back(ASCIIToUTF16("Elvis")); |
| 1197 suggestions.push_back(ASCIIToUTF16("Jason")); | 1102 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 1198 AutocompleteSuggestionsReturned(suggestions); | 1103 AutocompleteSuggestionsReturned(suggestions); |
| 1199 | 1104 |
| 1200 // Test that we sent the right values to the external delegate. | 1105 // Test that we sent the right values to the external delegate. |
| 1201 base::string16 expected_values[] = { | 1106 Suggestion expected[] = { |
| 1202 ASCIIToUTF16("Elvis"), | 1107 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1), |
| 1203 ASCIIToUTF16("Charles"), | 1108 Suggestion("Charles", "123 Apple St.", "", 2), |
| 1204 ASCIIToUTF16("Jay"), | 1109 Suggestion("Jay", "", "", 0), |
| 1205 ASCIIToUTF16("Jason") | 1110 Suggestion("Jason", "", "", 0), |
| 1206 }; | 1111 }; |
| 1207 base::string16 expected_labels[] = { | |
| 1208 ASCIIToUTF16("3734 Elvis Presley Blvd."), | |
| 1209 ASCIIToUTF16("123 Apple St."), | |
| 1210 base::string16(), | |
| 1211 base::string16() | |
| 1212 }; | |
| 1213 base::string16 expected_icons[] = { base::string16(), base::string16(), | |
| 1214 base::string16(), base::string16()}; | |
| 1215 int expected_unique_ids[] = {1, 2, 0, 0}; | |
| 1216 external_delegate_->CheckSuggestions( | 1112 external_delegate_->CheckSuggestions( |
| 1217 kDefaultPageID, arraysize(expected_values), expected_values, | 1113 kDefaultPageID, arraysize(expected), expected); |
| 1218 expected_labels, expected_icons, expected_unique_ids); | |
| 1219 } | 1114 } |
| 1220 | 1115 |
| 1221 // Test that we return autocomplete-like suggestions when trying to autofill | 1116 // Test that we return autocomplete-like suggestions when trying to autofill |
| 1222 // already filled forms. | 1117 // already filled forms. |
| 1223 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { | 1118 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { |
| 1224 // Set up our form data. | 1119 // Set up our form data. |
| 1225 FormData form; | 1120 FormData form; |
| 1226 test::CreateTestAddressFormData(&form); | 1121 test::CreateTestAddressFormData(&form); |
| 1227 std::vector<FormData> forms(1, form); | 1122 std::vector<FormData> forms(1, form); |
| 1228 FormsSeen(forms); | 1123 FormsSeen(forms); |
| 1229 | 1124 |
| 1230 // Mark one of the fields as filled. | 1125 // Mark one of the fields as filled. |
| 1231 form.fields[2].is_autofilled = true; | 1126 form.fields[2].is_autofilled = true; |
| 1232 const FormFieldData& field = form.fields[0]; | 1127 const FormFieldData& field = form.fields[0]; |
| 1233 GetAutofillSuggestions(form, field); | 1128 GetAutofillSuggestions(form, field); |
| 1234 | 1129 |
| 1235 // No suggestions provided, so send an empty vector as the results. | 1130 // No suggestions provided, so send an empty vector as the results. |
| 1236 // This triggers the combined message send. | 1131 // This triggers the combined message send. |
| 1237 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1132 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1238 | 1133 |
| 1239 // Test that we sent the right values to the external delegate. | 1134 // Test that we sent the right values to the external delegate. |
| 1240 base::string16 expected_values[] = { | |
| 1241 ASCIIToUTF16("Elvis"), | |
| 1242 ASCIIToUTF16("Charles") | |
| 1243 }; | |
| 1244 base::string16 expected_labels[] = {base::string16(), base::string16()}; | |
| 1245 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 1246 int expected_unique_ids[] = {1, 2}; | |
| 1247 external_delegate_->CheckSuggestions( | 1135 external_delegate_->CheckSuggestions( |
| 1248 kDefaultPageID, arraysize(expected_values), expected_values, | 1136 kDefaultPageID, |
| 1249 expected_labels, expected_icons, expected_unique_ids); | 1137 Suggestion("Elvis", "", "", 1), |
| 1138 Suggestion("Charles", "", "", 2)); |
| 1250 } | 1139 } |
| 1251 | 1140 |
| 1252 // Test that nothing breaks when there are autocomplete suggestions but no | 1141 // Test that nothing breaks when there are autocomplete suggestions but no |
| 1253 // autofill suggestions. | 1142 // autofill suggestions. |
| 1254 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { | 1143 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { |
| 1255 // Set up our form data. | 1144 // Set up our form data. |
| 1256 FormData form; | 1145 FormData form; |
| 1257 test::CreateTestAddressFormData(&form); | 1146 test::CreateTestAddressFormData(&form); |
| 1258 FormFieldData field; | 1147 FormFieldData field; |
| 1259 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); | 1148 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); |
| 1260 form.fields.push_back(field); | 1149 form.fields.push_back(field); |
| 1261 std::vector<FormData> forms(1, form); | 1150 std::vector<FormData> forms(1, form); |
| 1262 FormsSeen(forms); | 1151 FormsSeen(forms); |
| 1263 | 1152 |
| 1264 GetAutofillSuggestions(form, field); | 1153 GetAutofillSuggestions(form, field); |
| 1265 | 1154 |
| 1266 // Add some Autocomplete suggestions. | 1155 // Add some Autocomplete suggestions. |
| 1267 // This triggers the combined message send. | 1156 // This triggers the combined message send. |
| 1268 std::vector<base::string16> suggestions; | 1157 std::vector<base::string16> suggestions; |
| 1269 suggestions.push_back(ASCIIToUTF16("one")); | 1158 suggestions.push_back(ASCIIToUTF16("one")); |
| 1270 suggestions.push_back(ASCIIToUTF16("two")); | 1159 suggestions.push_back(ASCIIToUTF16("two")); |
| 1271 AutocompleteSuggestionsReturned(suggestions); | 1160 AutocompleteSuggestionsReturned(suggestions); |
| 1272 | 1161 |
| 1273 // Test that we sent the right values to the external delegate. | 1162 // Test that we sent the right values to the external delegate. |
| 1274 base::string16 expected_values[] = { | |
| 1275 ASCIIToUTF16("one"), | |
| 1276 ASCIIToUTF16("two") | |
| 1277 }; | |
| 1278 base::string16 expected_labels[] = {base::string16(), base::string16()}; | |
| 1279 base::string16 expected_icons[] = {base::string16(), base::string16()}; | |
| 1280 int expected_unique_ids[] = {0, 0}; | |
| 1281 external_delegate_->CheckSuggestions( | 1163 external_delegate_->CheckSuggestions( |
| 1282 kDefaultPageID, arraysize(expected_values), expected_values, | 1164 kDefaultPageID, |
| 1283 expected_labels, expected_icons, expected_unique_ids); | 1165 Suggestion("one", "", "", 0), |
| 1166 Suggestion("two", "", "", 0)); |
| 1284 } | 1167 } |
| 1285 | 1168 |
| 1286 // Test that we do not return duplicate values drawn from multiple profiles when | 1169 // Test that we do not return duplicate values drawn from multiple profiles when |
| 1287 // filling an already filled field. | 1170 // filling an already filled field. |
| 1288 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 1171 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
| 1289 // Set up our form data. | 1172 // Set up our form data. |
| 1290 FormData form; | 1173 FormData form; |
| 1291 test::CreateTestAddressFormData(&form); | 1174 test::CreateTestAddressFormData(&form); |
| 1292 std::vector<FormData> forms(1, form); | 1175 std::vector<FormData> forms(1, form); |
| 1293 FormsSeen(forms); | 1176 FormsSeen(forms); |
| 1294 | 1177 |
| 1295 // |profile| will be owned by the mock PersonalDataManager. | 1178 // |profile| will be owned by the mock PersonalDataManager. |
| 1296 AutofillProfile* profile = new AutofillProfile; | 1179 AutofillProfile* profile = new AutofillProfile; |
| 1297 test::SetProfileInfo( | 1180 test::SetProfileInfo( |
| 1298 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); | 1181 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); |
| 1299 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1182 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1300 autofill_manager_->AddProfile(profile); | 1183 autofill_manager_->AddProfile(profile); |
| 1301 | 1184 |
| 1302 FormFieldData& field = form.fields[0]; | 1185 FormFieldData& field = form.fields[0]; |
| 1303 field.is_autofilled = true; | 1186 field.is_autofilled = true; |
| 1304 field.value = ASCIIToUTF16("Elvis"); | 1187 field.value = ASCIIToUTF16("Elvis"); |
| 1305 GetAutofillSuggestions(form, field); | 1188 GetAutofillSuggestions(form, field); |
| 1306 | 1189 |
| 1307 // No suggestions provided, so send an empty vector as the results. | 1190 // No suggestions provided, so send an empty vector as the results. |
| 1308 // This triggers the combined message send. | 1191 // This triggers the combined message send. |
| 1309 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1192 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1310 | 1193 |
| 1311 // Test that we sent the right values to the external delegate. | 1194 // Test that we sent the right values to the external delegate. |
| 1312 base::string16 expected_values[] = { ASCIIToUTF16("Elvis") }; | |
| 1313 base::string16 expected_labels[] = { base::string16() }; | |
| 1314 base::string16 expected_icons[] = { base::string16() }; | |
| 1315 int expected_unique_ids[] = { 1 }; | |
| 1316 external_delegate_->CheckSuggestions( | 1195 external_delegate_->CheckSuggestions( |
| 1317 kDefaultPageID, arraysize(expected_values), expected_values, | 1196 kDefaultPageID, |
| 1318 expected_labels, expected_icons, expected_unique_ids); | 1197 Suggestion("Elvis", "", "", 1)); |
| 1319 } | 1198 } |
| 1320 | 1199 |
| 1321 // Test that a non-default value is suggested for multi-valued profile, on an | 1200 // Test that a non-default value is suggested for multi-valued profile, on an |
| 1322 // unfilled form. | 1201 // unfilled form. |
| 1323 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { | 1202 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { |
| 1324 // Set up our form data. | 1203 // Set up our form data. |
| 1325 FormData form; | 1204 FormData form; |
| 1326 test::CreateTestAddressFormData(&form); | 1205 test::CreateTestAddressFormData(&form); |
| 1327 std::vector<FormData> forms(1, form); | 1206 std::vector<FormData> forms(1, form); |
| 1328 FormsSeen(forms); | 1207 FormsSeen(forms); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1347 // Start out with "E", hoping for either "Elvis" or "Elena. | 1226 // Start out with "E", hoping for either "Elvis" or "Elena. |
| 1348 FormFieldData& field = form.fields[0]; | 1227 FormFieldData& field = form.fields[0]; |
| 1349 field.value = ASCIIToUTF16("E"); | 1228 field.value = ASCIIToUTF16("E"); |
| 1350 field.is_autofilled = false; | 1229 field.is_autofilled = false; |
| 1351 GetAutofillSuggestions(form, field); | 1230 GetAutofillSuggestions(form, field); |
| 1352 | 1231 |
| 1353 // Trigger the |Send|. | 1232 // Trigger the |Send|. |
| 1354 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1233 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1355 | 1234 |
| 1356 // Test that we sent the right values to the external delegate. | 1235 // Test that we sent the right values to the external delegate. |
| 1357 base::string16 expected_values[] = { | |
| 1358 ASCIIToUTF16("Elvis"), | |
| 1359 ASCIIToUTF16("Elena") | |
| 1360 }; | |
| 1361 base::string16 expected_labels[] = { | |
| 1362 ASCIIToUTF16("me@x.com"), | |
| 1363 ASCIIToUTF16("me@x.com") | |
| 1364 }; | |
| 1365 base::string16 expected_icons[] = { base::string16(), base::string16() }; | |
| 1366 int expected_unique_ids[] = { 1, 2 }; | |
| 1367 external_delegate_->CheckSuggestions( | 1236 external_delegate_->CheckSuggestions( |
| 1368 kDefaultPageID, arraysize(expected_values), expected_values, | 1237 kDefaultPageID, |
| 1369 expected_labels, expected_icons, expected_unique_ids); | 1238 Suggestion("Elvis", "me@x.com", "", 1), |
| 1239 Suggestion("Elena", "me@x.com", "", 2)); |
| 1370 } | 1240 } |
| 1371 | 1241 |
| 1372 { | 1242 { |
| 1373 // Get the first name field. | 1243 // Get the first name field. |
| 1374 // This time, start out with "Ele", hoping for "Elena". | 1244 // This time, start out with "Ele", hoping for "Elena". |
| 1375 FormFieldData& field = form.fields[0]; | 1245 FormFieldData& field = form.fields[0]; |
| 1376 field.value = ASCIIToUTF16("Ele"); | 1246 field.value = ASCIIToUTF16("Ele"); |
| 1377 field.is_autofilled = false; | 1247 field.is_autofilled = false; |
| 1378 GetAutofillSuggestions(form, field); | 1248 GetAutofillSuggestions(form, field); |
| 1379 | 1249 |
| 1380 // Trigger the |Send|. | 1250 // Trigger the |Send|. |
| 1381 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1251 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1382 | 1252 |
| 1383 // Test that we sent the right values to the external delegate. | 1253 // Test that we sent the right values to the external delegate. |
| 1384 base::string16 expected_values[] = { ASCIIToUTF16("Elena") }; | |
| 1385 base::string16 expected_labels[] = { ASCIIToUTF16("me@x.com") }; | |
| 1386 base::string16 expected_icons[] = { base::string16() }; | |
| 1387 int expected_unique_ids[] = { 2 }; | |
| 1388 external_delegate_->CheckSuggestions( | 1254 external_delegate_->CheckSuggestions( |
| 1389 kDefaultPageID, arraysize(expected_values), expected_values, | 1255 kDefaultPageID, |
| 1390 expected_labels, expected_icons, expected_unique_ids); | 1256 Suggestion("Elena", "me@x.com", "", 2)); |
| 1391 } | 1257 } |
| 1392 } | 1258 } |
| 1393 | 1259 |
| 1394 // Test that all values are suggested for multi-valued profile, on a filled | 1260 // Test that all values are suggested for multi-valued profile, on a filled |
| 1395 // form. This is the per-field "override" case. | 1261 // form. This is the per-field "override" case. |
| 1396 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { | 1262 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { |
| 1397 // Set up our form data. | 1263 // Set up our form data. |
| 1398 FormData form; | 1264 FormData form; |
| 1399 test::CreateTestAddressFormData(&form); | 1265 test::CreateTestAddressFormData(&form); |
| 1400 std::vector<FormData> forms(1, form); | 1266 std::vector<FormData> forms(1, form); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1418 // multi-valued variants as suggestions. | 1284 // multi-valued variants as suggestions. |
| 1419 FormFieldData& field = form.fields[0]; | 1285 FormFieldData& field = form.fields[0]; |
| 1420 field.value = ASCIIToUTF16("Travis"); | 1286 field.value = ASCIIToUTF16("Travis"); |
| 1421 field.is_autofilled = true; | 1287 field.is_autofilled = true; |
| 1422 GetAutofillSuggestions(form, field); | 1288 GetAutofillSuggestions(form, field); |
| 1423 | 1289 |
| 1424 // Trigger the |Send|. | 1290 // Trigger the |Send|. |
| 1425 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1291 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1426 | 1292 |
| 1427 // Test that we sent the right values to the external delegate. | 1293 // Test that we sent the right values to the external delegate. |
| 1428 base::string16 expected_values[] = { | |
| 1429 ASCIIToUTF16("Travis"), | |
| 1430 ASCIIToUTF16("Cynthia"), | |
| 1431 ASCIIToUTF16("Zac") | |
| 1432 }; | |
| 1433 base::string16 expected_labels[] = { base::string16(), base::string16(), | |
| 1434 base::string16() }; | |
| 1435 base::string16 expected_icons[] = { base::string16(), base::string16(), | |
| 1436 base::string16() }; | |
| 1437 int expected_unique_ids[] = { 1, 2, 3 }; | |
| 1438 external_delegate_->CheckSuggestions( | 1294 external_delegate_->CheckSuggestions( |
| 1439 kDefaultPageID, arraysize(expected_values), expected_values, | 1295 kDefaultPageID, |
| 1440 expected_labels, expected_icons, expected_unique_ids); | 1296 Suggestion("Travis", "", "", 1), |
| 1297 Suggestion("Cynthia", "", "", 2), |
| 1298 Suggestion("Zac", "", "", 3)); |
| 1441 } | 1299 } |
| 1442 | 1300 |
| 1443 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { | 1301 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { |
| 1444 // Set up our form data. | 1302 // Set up our form data. |
| 1445 FormData form; | 1303 FormData form; |
| 1446 test::CreateTestAddressFormData(&form); | 1304 test::CreateTestAddressFormData(&form); |
| 1447 std::vector<FormData> forms(1, form); | 1305 std::vector<FormData> forms(1, form); |
| 1448 FormsSeen(forms); | 1306 FormsSeen(forms); |
| 1449 | 1307 |
| 1450 AutofillProfile* profile = new AutofillProfile; | 1308 AutofillProfile* profile = new AutofillProfile; |
| 1451 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1309 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1452 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), | 1310 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 1453 "en-US"); | 1311 "en-US"); |
| 1454 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 1312 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1455 ASCIIToUTF16("1800PRAIRIE")); | 1313 ASCIIToUTF16("1800PRAIRIE")); |
| 1456 autofill_manager_->AddProfile(profile); | 1314 autofill_manager_->AddProfile(profile); |
| 1457 | 1315 |
| 1458 const FormFieldData& field = form.fields[9]; | 1316 const FormFieldData& field = form.fields[9]; |
| 1459 GetAutofillSuggestions(form, field); | 1317 GetAutofillSuggestions(form, field); |
| 1460 | 1318 |
| 1461 // No suggestions provided, so send an empty vector as the results. | 1319 // No suggestions provided, so send an empty vector as the results. |
| 1462 // This triggers the combined message send. | 1320 // This triggers the combined message send. |
| 1463 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1321 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1464 | 1322 |
| 1465 // Test that we sent the right values to the external delegate. | 1323 // Test that we sent the right values to the external delegate. Inferred |
| 1466 base::string16 expected_values[] = { | 1324 // labels include full first relevant field, which in this case is the |
| 1467 ASCIIToUTF16("12345678901"), | 1325 // address line 1. |
| 1468 ASCIIToUTF16("23456789012"), | |
| 1469 ASCIIToUTF16("18007724743"), // 1800PRAIRIE | |
| 1470 }; | |
| 1471 // Inferred labels include full first relevant field, which in this case is | |
| 1472 // the address line 1. | |
| 1473 base::string16 expected_labels[] = { | |
| 1474 ASCIIToUTF16("Elvis Aaron Presley"), | |
| 1475 ASCIIToUTF16("Charles Hardin Holley"), | |
| 1476 ASCIIToUTF16("Natty Bumppo"), | |
| 1477 }; | |
| 1478 base::string16 expected_icons[] = { base::string16(), base::string16(), | |
| 1479 base::string16()}; | |
| 1480 int expected_unique_ids[] = {1, 2, 3}; | |
| 1481 external_delegate_->CheckSuggestions( | 1326 external_delegate_->CheckSuggestions( |
| 1482 kDefaultPageID, arraysize(expected_values), expected_values, | 1327 kDefaultPageID, |
| 1483 expected_labels, expected_icons, expected_unique_ids); | 1328 Suggestion("12345678901", "Elvis Aaron Presley", "", 1), |
| 1329 Suggestion("23456789012", "Charles Hardin Holley", "", 2), |
| 1330 Suggestion("18007724743", "Natty Bumppo", "", 3)); // 1800PRAIRIE |
| 1331 |
| 1484 } | 1332 } |
| 1485 | 1333 |
| 1486 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { | 1334 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { |
| 1487 // Set up our form data. | 1335 // Set up our form data. |
| 1488 FormData form; | 1336 FormData form; |
| 1489 form.name = ASCIIToUTF16("MyForm"); | 1337 form.name = ASCIIToUTF16("MyForm"); |
| 1490 form.origin = GURL("http://myform.com/form.html"); | 1338 form.origin = GURL("http://myform.com/form.html"); |
| 1491 form.action = GURL("http://myform.com/submit.html"); | 1339 form.action = GURL("http://myform.com/submit.html"); |
| 1492 form.user_submitted = true; | 1340 form.user_submitted = true; |
| 1493 | 1341 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1521 multi_values[1] = ASCIIToUTF16("14158889999"); | 1369 multi_values[1] = ASCIIToUTF16("14158889999"); |
| 1522 | 1370 |
| 1523 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); | 1371 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); |
| 1524 personal_data_.ClearAutofillProfiles(); | 1372 personal_data_.ClearAutofillProfiles(); |
| 1525 autofill_manager_->AddProfile(profile); | 1373 autofill_manager_->AddProfile(profile); |
| 1526 | 1374 |
| 1527 const FormFieldData& phone_prefix = form.fields[2]; | 1375 const FormFieldData& phone_prefix = form.fields[2]; |
| 1528 GetAutofillSuggestions(form, phone_prefix); | 1376 GetAutofillSuggestions(form, phone_prefix); |
| 1529 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1377 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1530 // Test that we sent the right prefix values to the external delegate. | 1378 // Test that we sent the right prefix values to the external delegate. |
| 1531 base::string16 expected_prefix_values[] = {ASCIIToUTF16("356"), | 1379 external_delegate_->CheckSuggestions( |
| 1532 ASCIIToUTF16("888")}; | 1380 kDefaultPageID, |
| 1533 base::string16 expected_prefix_labels[] = {ASCIIToUTF16("1"), | 1381 Suggestion("356", "1", "", 1), |
| 1534 ASCIIToUTF16("1")}; | 1382 Suggestion("888", "1", "", 2)); |
| 1535 base::string16 expected_prefix_icons[] = {base::string16(), base::string16()}; | |
| 1536 int expected_unique_ids[] = {1, 2}; | |
| 1537 external_delegate_->CheckSuggestions(kDefaultPageID, | |
| 1538 arraysize(expected_prefix_values), | |
| 1539 expected_prefix_values, | |
| 1540 expected_prefix_labels, | |
| 1541 expected_prefix_icons, | |
| 1542 expected_unique_ids); | |
| 1543 | 1383 |
| 1544 const FormFieldData& phone_suffix = form.fields[3]; | 1384 const FormFieldData& phone_suffix = form.fields[3]; |
| 1545 GetAutofillSuggestions(form, phone_suffix); | 1385 GetAutofillSuggestions(form, phone_suffix); |
| 1546 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1386 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1547 // Test that we sent the right suffix values to the external delegate. | 1387 // Test that we sent the right suffix values to the external delegate. |
| 1548 base::string16 expected_suffix_values[] = {ASCIIToUTF16("9377"), | 1388 external_delegate_->CheckSuggestions( |
| 1549 ASCIIToUTF16("9999")}; | 1389 kDefaultPageID, |
| 1550 base::string16 expected_suffix_labels[] = {ASCIIToUTF16("1"), | 1390 Suggestion("9377", "1", "", 1), |
| 1551 ASCIIToUTF16("1")}; | 1391 Suggestion("9999", "1", "", 2)); |
| 1552 base::string16 expected_suffix_icons[] = {base::string16(), base::string16()}; | |
| 1553 external_delegate_->CheckSuggestions(kDefaultPageID, | |
| 1554 arraysize(expected_suffix_values), | |
| 1555 expected_suffix_values, | |
| 1556 expected_suffix_labels, | |
| 1557 expected_suffix_icons, | |
| 1558 expected_unique_ids); | |
| 1559 } | 1392 } |
| 1560 | 1393 |
| 1561 // Test that we correctly fill an address form. | 1394 // Test that we correctly fill an address form. |
| 1562 TEST_F(AutofillManagerTest, FillAddressForm) { | 1395 TEST_F(AutofillManagerTest, FillAddressForm) { |
| 1563 // Set up our form data. | 1396 // Set up our form data. |
| 1564 FormData form; | 1397 FormData form; |
| 1565 test::CreateTestAddressFormData(&form); | 1398 test::CreateTestAddressFormData(&form); |
| 1566 std::vector<FormData> forms(1, form); | 1399 std::vector<FormData> forms(1, form); |
| 1567 FormsSeen(forms); | 1400 FormsSeen(forms); |
| 1568 | 1401 |
| 1569 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1402 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1570 GUIDPair empty(std::string(), 0); | 1403 SuggestionBackendID empty(std::string(), 0); |
| 1571 int response_page_id = 0; | 1404 int response_page_id = 0; |
| 1572 FormData response_data; | 1405 FormData response_data; |
| 1573 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1406 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1574 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1407 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1575 ExpectFilledAddressFormElvis( | 1408 ExpectFilledAddressFormElvis( |
| 1576 response_page_id, response_data, kDefaultPageID, false); | 1409 response_page_id, response_data, kDefaultPageID, false); |
| 1577 } | 1410 } |
| 1578 | 1411 |
| 1579 // Test that we correctly fill an address form from an auxiliary profile. | 1412 // Test that we correctly fill an address form from an auxiliary profile. |
| 1580 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1413 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
| 1581 personal_data_.ClearAutofillProfiles(); | 1414 personal_data_.ClearAutofillProfiles(); |
| 1582 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1415 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 1583 autofill_client_.GetPrefs()->SetBoolean( | 1416 autofill_client_.GetPrefs()->SetBoolean( |
| 1584 ::autofill::prefs::kAutofillUseMacAddressBook, true); | 1417 ::autofill::prefs::kAutofillUseMacAddressBook, true); |
| 1585 #else | 1418 #else |
| 1586 autofill_client_.GetPrefs()->SetBoolean( | 1419 autofill_client_.GetPrefs()->SetBoolean( |
| 1587 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1420 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); |
| 1588 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1421 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 1589 | 1422 |
| 1590 personal_data_.CreateTestAuxiliaryProfiles(); | 1423 personal_data_.CreateTestAuxiliaryProfiles(); |
| 1591 | 1424 |
| 1592 // Set up our form data. | 1425 // Set up our form data. |
| 1593 FormData form; | 1426 FormData form; |
| 1594 test::CreateTestAddressFormData(&form); | 1427 test::CreateTestAddressFormData(&form); |
| 1595 std::vector<FormData> forms(1, form); | 1428 std::vector<FormData> forms(1, form); |
| 1596 FormsSeen(forms); | 1429 FormsSeen(forms); |
| 1597 | 1430 |
| 1598 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1431 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1599 GUIDPair empty(std::string(), 0); | 1432 SuggestionBackendID empty(std::string(), 0); |
| 1600 int response_page_id = 0; | 1433 int response_page_id = 0; |
| 1601 FormData response_data; | 1434 FormData response_data; |
| 1602 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1435 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1603 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1436 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1604 ExpectFilledAddressFormElvis( | 1437 ExpectFilledAddressFormElvis( |
| 1605 response_page_id, response_data, kDefaultPageID, false); | 1438 response_page_id, response_data, kDefaultPageID, false); |
| 1606 } | 1439 } |
| 1607 | 1440 |
| 1608 // Test that we correctly fill a credit card form. | 1441 // Test that we correctly fill a credit card form. |
| 1609 TEST_F(AutofillManagerTest, FillCreditCardForm) { | 1442 TEST_F(AutofillManagerTest, FillCreditCardForm) { |
| 1610 // Set up our form data. | 1443 // Set up our form data. |
| 1611 FormData form; | 1444 FormData form; |
| 1612 CreateTestCreditCardFormData(&form, true, false); | 1445 CreateTestCreditCardFormData(&form, true, false); |
| 1613 std::vector<FormData> forms(1, form); | 1446 std::vector<FormData> forms(1, form); |
| 1614 FormsSeen(forms); | 1447 FormsSeen(forms); |
| 1615 | 1448 |
| 1616 GUIDPair guid("00000000-0000-0000-0000-000000000004", 0); | 1449 SuggestionBackendID guid("00000000-0000-0000-0000-000000000004", 0); |
| 1617 GUIDPair empty(std::string(), 0); | 1450 SuggestionBackendID empty(std::string(), 0); |
| 1618 int response_page_id = 0; | 1451 int response_page_id = 0; |
| 1619 FormData response_data; | 1452 FormData response_data; |
| 1620 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1453 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1621 PackGUIDs(guid, empty), &response_page_id, &response_data); | 1454 MakeFrontendID(guid, empty), &response_page_id, &response_data); |
| 1622 ExpectFilledCreditCardFormElvis( | 1455 ExpectFilledCreditCardFormElvis( |
| 1623 response_page_id, response_data, kDefaultPageID, false); | 1456 response_page_id, response_data, kDefaultPageID, false); |
| 1624 } | 1457 } |
| 1625 | 1458 |
| 1626 // Test that we correctly fill a credit card form with month input type. | 1459 // Test that we correctly fill a credit card form with month input type. |
| 1627 // 1. year empty, month empty | 1460 // 1. year empty, month empty |
| 1628 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1461 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { |
| 1629 // Same as the SetUp(), but generate 4 credit cards with year month | 1462 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1630 // combination. | 1463 // combination. |
| 1631 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1464 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
| 1632 // Set up our form data. | 1465 // Set up our form data. |
| 1633 FormData form; | 1466 FormData form; |
| 1634 CreateTestCreditCardFormData(&form, true, true); | 1467 CreateTestCreditCardFormData(&form, true, true); |
| 1635 std::vector<FormData> forms(1, form); | 1468 std::vector<FormData> forms(1, form); |
| 1636 FormsSeen(forms); | 1469 FormsSeen(forms); |
| 1637 | 1470 |
| 1638 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 1471 SuggestionBackendID guid("00000000-0000-0000-0000-000000000007", 0); |
| 1639 GUIDPair empty(std::string(), 0); | 1472 SuggestionBackendID empty(std::string(), 0); |
| 1640 int response_page_id = 0; | 1473 int response_page_id = 0; |
| 1641 FormData response_data; | 1474 FormData response_data; |
| 1642 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1475 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1643 PackGUIDs(guid, empty), &response_page_id, &response_data); | 1476 MakeFrontendID(guid, empty), &response_page_id, &response_data); |
| 1644 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1477 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1645 kDefaultPageID, false, "", ""); | 1478 kDefaultPageID, false, "", ""); |
| 1646 } | 1479 } |
| 1647 | 1480 |
| 1648 | 1481 |
| 1649 // Test that we correctly fill a credit card form with month input type. | 1482 // Test that we correctly fill a credit card form with month input type. |
| 1650 // 2. year empty, month non-empty | 1483 // 2. year empty, month non-empty |
| 1651 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { | 1484 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearMonth) { |
| 1652 // Same as the SetUp(), but generate 4 credit cards with year month | 1485 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1653 // combination. | 1486 // combination. |
| 1654 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); | 1487 personal_data_.CreateTestCreditCardsYearAndMonth("", "04"); |
| 1655 // Set up our form data. | 1488 // Set up our form data. |
| 1656 FormData form; | 1489 FormData form; |
| 1657 CreateTestCreditCardFormData(&form, true, true); | 1490 CreateTestCreditCardFormData(&form, true, true); |
| 1658 std::vector<FormData> forms(1, form); | 1491 std::vector<FormData> forms(1, form); |
| 1659 FormsSeen(forms); | 1492 FormsSeen(forms); |
| 1660 | 1493 |
| 1661 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 1494 SuggestionBackendID guid("00000000-0000-0000-0000-000000000007", 0); |
| 1662 GUIDPair empty(std::string(), 0); | 1495 SuggestionBackendID empty(std::string(), 0); |
| 1663 int response_page_id = 0; | 1496 int response_page_id = 0; |
| 1664 FormData response_data; | 1497 FormData response_data; |
| 1665 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1498 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1666 PackGUIDs(guid, empty), &response_page_id, &response_data); | 1499 MakeFrontendID(guid, empty), &response_page_id, &response_data); |
| 1667 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1500 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1668 kDefaultPageID, false, "", "04"); | 1501 kDefaultPageID, false, "", "04"); |
| 1669 } | 1502 } |
| 1670 | 1503 |
| 1671 // Test that we correctly fill a credit card form with month input type. | 1504 // Test that we correctly fill a credit card form with month input type. |
| 1672 // 3. year non-empty, month empty | 1505 // 3. year non-empty, month empty |
| 1673 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { | 1506 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { |
| 1674 // Same as the SetUp(), but generate 4 credit cards with year month | 1507 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1675 // combination. | 1508 // combination. |
| 1676 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); | 1509 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); |
| 1677 // Set up our form data. | 1510 // Set up our form data. |
| 1678 FormData form; | 1511 FormData form; |
| 1679 CreateTestCreditCardFormData(&form, true, true); | 1512 CreateTestCreditCardFormData(&form, true, true); |
| 1680 std::vector<FormData> forms(1, form); | 1513 std::vector<FormData> forms(1, form); |
| 1681 FormsSeen(forms); | 1514 FormsSeen(forms); |
| 1682 | 1515 |
| 1683 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 1516 SuggestionBackendID guid("00000000-0000-0000-0000-000000000007", 0); |
| 1684 GUIDPair empty(std::string(), 0); | 1517 SuggestionBackendID empty(std::string(), 0); |
| 1685 int response_page_id = 0; | 1518 int response_page_id = 0; |
| 1686 FormData response_data; | 1519 FormData response_data; |
| 1687 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1520 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1688 PackGUIDs(guid, empty), &response_page_id, &response_data); | 1521 MakeFrontendID(guid, empty), &response_page_id, &response_data); |
| 1689 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1522 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1690 kDefaultPageID, false, "2012", ""); | 1523 kDefaultPageID, false, "2012", ""); |
| 1691 } | 1524 } |
| 1692 | 1525 |
| 1693 // Test that we correctly fill a credit card form with month input type. | 1526 // Test that we correctly fill a credit card form with month input type. |
| 1694 // 4. year non-empty, month empty | 1527 // 4. year non-empty, month empty |
| 1695 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { | 1528 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { |
| 1696 // Same as the SetUp(), but generate 4 credit cards with year month | 1529 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1697 // combination. | 1530 // combination. |
| 1698 personal_data_.ClearCreditCards(); | 1531 personal_data_.ClearCreditCards(); |
| 1699 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); | 1532 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); |
| 1700 // Set up our form data. | 1533 // Set up our form data. |
| 1701 FormData form; | 1534 FormData form; |
| 1702 CreateTestCreditCardFormData(&form, true, true); | 1535 CreateTestCreditCardFormData(&form, true, true); |
| 1703 std::vector<FormData> forms(1, form); | 1536 std::vector<FormData> forms(1, form); |
| 1704 FormsSeen(forms); | 1537 FormsSeen(forms); |
| 1705 | 1538 |
| 1706 GUIDPair guid("00000000-0000-0000-0000-000000000007", 0); | 1539 SuggestionBackendID guid("00000000-0000-0000-0000-000000000007", 0); |
| 1707 GUIDPair empty(std::string(), 0); | 1540 SuggestionBackendID empty(std::string(), 0); |
| 1708 int response_page_id = 0; | 1541 int response_page_id = 0; |
| 1709 FormData response_data; | 1542 FormData response_data; |
| 1710 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1543 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1711 PackGUIDs(guid, empty), &response_page_id, &response_data); | 1544 MakeFrontendID(guid, empty), &response_page_id, &response_data); |
| 1712 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1545 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1713 kDefaultPageID, false, "2012", "04"); | 1546 kDefaultPageID, false, "2012", "04"); |
| 1714 } | 1547 } |
| 1715 | 1548 |
| 1716 // Test that we correctly fill a combined address and credit card form. | 1549 // Test that we correctly fill a combined address and credit card form. |
| 1717 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { | 1550 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { |
| 1718 // Set up our form data. | 1551 // Set up our form data. |
| 1719 FormData form; | 1552 FormData form; |
| 1720 test::CreateTestAddressFormData(&form); | 1553 test::CreateTestAddressFormData(&form); |
| 1721 CreateTestCreditCardFormData(&form, true, false); | 1554 CreateTestCreditCardFormData(&form, true, false); |
| 1722 std::vector<FormData> forms(1, form); | 1555 std::vector<FormData> forms(1, form); |
| 1723 FormsSeen(forms); | 1556 FormsSeen(forms); |
| 1724 | 1557 |
| 1725 // First fill the address data. | 1558 // First fill the address data. |
| 1726 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1559 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1727 GUIDPair empty(std::string(), 0); | 1560 SuggestionBackendID empty(std::string(), 0); |
| 1728 int response_page_id = 0; | 1561 int response_page_id = 0; |
| 1729 FormData response_data; | 1562 FormData response_data; |
| 1730 { | 1563 { |
| 1731 SCOPED_TRACE("Address"); | 1564 SCOPED_TRACE("Address"); |
| 1732 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1565 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1733 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1566 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1734 ExpectFilledAddressFormElvis( | 1567 ExpectFilledAddressFormElvis( |
| 1735 response_page_id, response_data, kDefaultPageID, true); | 1568 response_page_id, response_data, kDefaultPageID, true); |
| 1736 } | 1569 } |
| 1737 | 1570 |
| 1738 // Now fill the credit card data. | 1571 // Now fill the credit card data. |
| 1739 const int kPageID2 = 2; | 1572 const int kPageID2 = 2; |
| 1740 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); | 1573 SuggestionBackendID guid2("00000000-0000-0000-0000-000000000004", 0); |
| 1741 response_page_id = 0; | 1574 response_page_id = 0; |
| 1742 { | 1575 { |
| 1743 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 1576 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 1744 PackGUIDs(guid2, empty), &response_page_id, &response_data); | 1577 MakeFrontendID(guid2, empty), &response_page_id, &response_data); |
| 1745 SCOPED_TRACE("Credit card"); | 1578 SCOPED_TRACE("Credit card"); |
| 1746 ExpectFilledCreditCardFormElvis( | 1579 ExpectFilledCreditCardFormElvis( |
| 1747 response_page_id, response_data, kPageID2, true); | 1580 response_page_id, response_data, kPageID2, true); |
| 1748 } | 1581 } |
| 1749 } | 1582 } |
| 1750 | 1583 |
| 1751 // Test that non-focusable field is ignored while inferring boundaries between | 1584 // Test that non-focusable field is ignored while inferring boundaries between |
| 1752 // sections: http://crbug.com/231160 | 1585 // sections: http://crbug.com/231160 |
| 1753 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { | 1586 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { |
| 1754 // Create a form with both focusable and non-focusable fields. | 1587 // Create a form with both focusable and non-focusable fields. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1776 field.is_focusable = false; | 1609 field.is_focusable = false; |
| 1777 form.fields.push_back(field); | 1610 form.fields.push_back(field); |
| 1778 | 1611 |
| 1779 test::CreateTestFormField("Country", "country", "", "text", &field); | 1612 test::CreateTestFormField("Country", "country", "", "text", &field); |
| 1780 form.fields.push_back(field); | 1613 form.fields.push_back(field); |
| 1781 | 1614 |
| 1782 std::vector<FormData> forms(1, form); | 1615 std::vector<FormData> forms(1, form); |
| 1783 FormsSeen(forms); | 1616 FormsSeen(forms); |
| 1784 | 1617 |
| 1785 // Fill the form | 1618 // Fill the form |
| 1786 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1619 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1787 GUIDPair empty(std::string(), 0); | 1620 SuggestionBackendID empty(std::string(), 0); |
| 1788 int response_page_id = 0; | 1621 int response_page_id = 0; |
| 1789 FormData response_data; | 1622 FormData response_data; |
| 1790 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1623 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1791 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1624 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1792 | 1625 |
| 1793 // The whole form should be filled as all the fields belong to the same | 1626 // The whole form should be filled as all the fields belong to the same |
| 1794 // logical section. | 1627 // logical section. |
| 1795 ASSERT_EQ(6U, response_data.fields.size()); | 1628 ASSERT_EQ(6U, response_data.fields.size()); |
| 1796 ExpectFilledField("First Name", "firstname", "Elvis", "text", | 1629 ExpectFilledField("First Name", "firstname", "Elvis", "text", |
| 1797 response_data.fields[0]); | 1630 response_data.fields[0]); |
| 1798 ExpectFilledField("", "lastname", "Presley", "text", | 1631 ExpectFilledField("", "lastname", "Presley", "text", |
| 1799 response_data.fields[1]); | 1632 response_data.fields[1]); |
| 1800 ExpectFilledField("", "email", "theking@gmail.com", "text", | 1633 ExpectFilledField("", "email", "theking@gmail.com", "text", |
| 1801 response_data.fields[2]); | 1634 response_data.fields[2]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1816 const size_t kAddressFormSize = form.fields.size(); | 1649 const size_t kAddressFormSize = form.fields.size(); |
| 1817 test::CreateTestAddressFormData(&form); | 1650 test::CreateTestAddressFormData(&form); |
| 1818 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 1651 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
| 1819 // Make sure the fields have distinct names. | 1652 // Make sure the fields have distinct names. |
| 1820 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); | 1653 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); |
| 1821 } | 1654 } |
| 1822 std::vector<FormData> forms(1, form); | 1655 std::vector<FormData> forms(1, form); |
| 1823 FormsSeen(forms); | 1656 FormsSeen(forms); |
| 1824 | 1657 |
| 1825 // Fill the first section. | 1658 // Fill the first section. |
| 1826 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1659 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1827 GUIDPair empty(std::string(), 0); | 1660 SuggestionBackendID empty(std::string(), 0); |
| 1828 int response_page_id = 0; | 1661 int response_page_id = 0; |
| 1829 FormData response_data; | 1662 FormData response_data; |
| 1830 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1663 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 1831 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1664 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1832 { | 1665 { |
| 1833 SCOPED_TRACE("Address 1"); | 1666 SCOPED_TRACE("Address 1"); |
| 1834 // The second address section should be empty. | 1667 // The second address section should be empty. |
| 1835 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); | 1668 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); |
| 1836 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 1669 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
| 1837 EXPECT_EQ(base::string16(), response_data.fields[i].value); | 1670 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 1838 } | 1671 } |
| 1839 | 1672 |
| 1840 // The first address section should be filled with Elvis's data. | 1673 // The first address section should be filled with Elvis's data. |
| 1841 response_data.fields.resize(kAddressFormSize); | 1674 response_data.fields.resize(kAddressFormSize); |
| 1842 ExpectFilledAddressFormElvis( | 1675 ExpectFilledAddressFormElvis( |
| 1843 response_page_id, response_data, kDefaultPageID, false); | 1676 response_page_id, response_data, kDefaultPageID, false); |
| 1844 } | 1677 } |
| 1845 | 1678 |
| 1846 // Fill the second section, with the initiating field somewhere in the middle | 1679 // Fill the second section, with the initiating field somewhere in the middle |
| 1847 // of the section. | 1680 // of the section. |
| 1848 const int kPageID2 = 2; | 1681 const int kPageID2 = 2; |
| 1849 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); | 1682 SuggestionBackendID guid2("00000000-0000-0000-0000-000000000001", 0); |
| 1850 ASSERT_LT(9U, kAddressFormSize); | 1683 ASSERT_LT(9U, kAddressFormSize); |
| 1851 response_page_id = 0; | 1684 response_page_id = 0; |
| 1852 FillAutofillFormDataAndSaveResults( | 1685 FillAutofillFormDataAndSaveResults( |
| 1853 kPageID2, form, form.fields[kAddressFormSize + 9], | 1686 kPageID2, form, form.fields[kAddressFormSize + 9], |
| 1854 PackGUIDs(empty, guid2), &response_page_id, &response_data); | 1687 MakeFrontendID(empty, guid2), &response_page_id, &response_data); |
| 1855 { | 1688 { |
| 1856 SCOPED_TRACE("Address 2"); | 1689 SCOPED_TRACE("Address 2"); |
| 1857 ASSERT_EQ(response_data.fields.size(), form.fields.size()); | 1690 ASSERT_EQ(response_data.fields.size(), form.fields.size()); |
| 1858 | 1691 |
| 1859 // The first address section should be empty. | 1692 // The first address section should be empty. |
| 1860 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); | 1693 ASSERT_EQ(response_data.fields.size(), 2*kAddressFormSize); |
| 1861 for (size_t i = 0; i < kAddressFormSize; ++i) { | 1694 for (size_t i = 0; i < kAddressFormSize; ++i) { |
| 1862 EXPECT_EQ(base::string16(), response_data.fields[i].value); | 1695 EXPECT_EQ(base::string16(), response_data.fields[i].value); |
| 1863 } | 1696 } |
| 1864 | 1697 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 form.fields.push_back(field); | 1764 form.fields.push_back(field); |
| 1932 | 1765 |
| 1933 test::CreateTestFormField("", "email", "", "text", &field); | 1766 test::CreateTestFormField("", "email", "", "text", &field); |
| 1934 field.autocomplete_attribute = "email"; | 1767 field.autocomplete_attribute = "email"; |
| 1935 form.fields.push_back(field); | 1768 form.fields.push_back(field); |
| 1936 | 1769 |
| 1937 std::vector<FormData> forms(1, form); | 1770 std::vector<FormData> forms(1, form); |
| 1938 FormsSeen(forms); | 1771 FormsSeen(forms); |
| 1939 | 1772 |
| 1940 // Fill the unnamed section. | 1773 // Fill the unnamed section. |
| 1941 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1774 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 1942 GUIDPair empty(std::string(), 0); | 1775 SuggestionBackendID empty(std::string(), 0); |
| 1943 int response_page_id = 0; | 1776 int response_page_id = 0; |
| 1944 FormData response_data; | 1777 FormData response_data; |
| 1945 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[1], | 1778 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[1], |
| 1946 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1779 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 1947 { | 1780 { |
| 1948 SCOPED_TRACE("Unnamed section"); | 1781 SCOPED_TRACE("Unnamed section"); |
| 1949 EXPECT_EQ(kDefaultPageID, response_page_id); | 1782 EXPECT_EQ(kDefaultPageID, response_page_id); |
| 1950 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); | 1783 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 1951 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); | 1784 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 1952 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); | 1785 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 1953 EXPECT_TRUE(response_data.user_submitted); | 1786 EXPECT_TRUE(response_data.user_submitted); |
| 1954 ASSERT_EQ(11U, response_data.fields.size()); | 1787 ASSERT_EQ(11U, response_data.fields.size()); |
| 1955 | 1788 |
| 1956 ExpectFilledField("", "country", "", "text", response_data.fields[0]); | 1789 ExpectFilledField("", "country", "", "text", response_data.fields[0]); |
| 1957 ExpectFilledField("", "firstname", "Elvis", "text", | 1790 ExpectFilledField("", "firstname", "Elvis", "text", |
| 1958 response_data.fields[1]); | 1791 response_data.fields[1]); |
| 1959 ExpectFilledField("", "lastname", "Presley", "text", | 1792 ExpectFilledField("", "lastname", "Presley", "text", |
| 1960 response_data.fields[2]); | 1793 response_data.fields[2]); |
| 1961 ExpectFilledField("", "address", "", "text", response_data.fields[3]); | 1794 ExpectFilledField("", "address", "", "text", response_data.fields[3]); |
| 1962 ExpectFilledField("", "city", "", "text", response_data.fields[4]); | 1795 ExpectFilledField("", "city", "", "text", response_data.fields[4]); |
| 1963 ExpectFilledField("", "state", "", "text", response_data.fields[5]); | 1796 ExpectFilledField("", "state", "", "text", response_data.fields[5]); |
| 1964 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); | 1797 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); |
| 1965 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); | 1798 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); |
| 1966 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); | 1799 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); |
| 1967 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); | 1800 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); |
| 1968 ExpectFilledField("", "email", "theking@gmail.com", "text", | 1801 ExpectFilledField("", "email", "theking@gmail.com", "text", |
| 1969 response_data.fields[10]); | 1802 response_data.fields[10]); |
| 1970 } | 1803 } |
| 1971 | 1804 |
| 1972 // Fill the address portion of the billing section. | 1805 // Fill the address portion of the billing section. |
| 1973 const int kPageID2 = 2; | 1806 const int kPageID2 = 2; |
| 1974 GUIDPair guid2("00000000-0000-0000-0000-000000000001", 0); | 1807 SuggestionBackendID guid2("00000000-0000-0000-0000-000000000001", 0); |
| 1975 response_page_id = 0; | 1808 response_page_id = 0; |
| 1976 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], | 1809 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], |
| 1977 PackGUIDs(empty, guid2), &response_page_id, &response_data); | 1810 MakeFrontendID(empty, guid2), &response_page_id, &response_data); |
| 1978 { | 1811 { |
| 1979 SCOPED_TRACE("Billing address"); | 1812 SCOPED_TRACE("Billing address"); |
| 1980 EXPECT_EQ(kPageID2, response_page_id); | 1813 EXPECT_EQ(kPageID2, response_page_id); |
| 1981 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); | 1814 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 1982 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); | 1815 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 1983 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); | 1816 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 1984 EXPECT_TRUE(response_data.user_submitted); | 1817 EXPECT_TRUE(response_data.user_submitted); |
| 1985 ASSERT_EQ(11U, response_data.fields.size()); | 1818 ASSERT_EQ(11U, response_data.fields.size()); |
| 1986 | 1819 |
| 1987 ExpectFilledField("", "country", "US", "text", | 1820 ExpectFilledField("", "country", "US", "text", |
| 1988 response_data.fields[0]); | 1821 response_data.fields[0]); |
| 1989 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); | 1822 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); |
| 1990 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); | 1823 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); |
| 1991 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", | 1824 ExpectFilledField("", "address", "3734 Elvis Presley Blvd.", "text", |
| 1992 response_data.fields[3]); | 1825 response_data.fields[3]); |
| 1993 ExpectFilledField("", "city", "Memphis", "text", response_data.fields[4]); | 1826 ExpectFilledField("", "city", "Memphis", "text", response_data.fields[4]); |
| 1994 ExpectFilledField("", "state", "Tennessee", "text", | 1827 ExpectFilledField("", "state", "Tennessee", "text", |
| 1995 response_data.fields[5]); | 1828 response_data.fields[5]); |
| 1996 ExpectFilledField("", "zip", "38116", "text", response_data.fields[6]); | 1829 ExpectFilledField("", "zip", "38116", "text", response_data.fields[6]); |
| 1997 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); | 1830 ExpectFilledField("", "ccname", "", "text", response_data.fields[7]); |
| 1998 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); | 1831 ExpectFilledField("", "ccnumber", "", "text", response_data.fields[8]); |
| 1999 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); | 1832 ExpectFilledField("", "ccexp", "", "text", response_data.fields[9]); |
| 2000 ExpectFilledField("", "email", "", "text", response_data.fields[10]); | 1833 ExpectFilledField("", "email", "", "text", response_data.fields[10]); |
| 2001 } | 1834 } |
| 2002 | 1835 |
| 2003 // Fill the credit card portion of the billing section. | 1836 // Fill the credit card portion of the billing section. |
| 2004 const int kPageID3 = 3; | 1837 const int kPageID3 = 3; |
| 2005 GUIDPair guid3("00000000-0000-0000-0000-000000000004", 0); | 1838 SuggestionBackendID guid3("00000000-0000-0000-0000-000000000004", 0); |
| 2006 response_page_id = 0; | 1839 response_page_id = 0; |
| 2007 FillAutofillFormDataAndSaveResults( | 1840 FillAutofillFormDataAndSaveResults( |
| 2008 kPageID3, form, form.fields[form.fields.size() - 2], | 1841 kPageID3, form, form.fields[form.fields.size() - 2], |
| 2009 PackGUIDs(guid3, empty), &response_page_id, &response_data); | 1842 MakeFrontendID(guid3, empty), &response_page_id, &response_data); |
| 2010 { | 1843 { |
| 2011 SCOPED_TRACE("Credit card"); | 1844 SCOPED_TRACE("Credit card"); |
| 2012 EXPECT_EQ(kPageID3, response_page_id); | 1845 EXPECT_EQ(kPageID3, response_page_id); |
| 2013 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); | 1846 EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name); |
| 2014 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); | 1847 EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin); |
| 2015 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); | 1848 EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action); |
| 2016 EXPECT_TRUE(response_data.user_submitted); | 1849 EXPECT_TRUE(response_data.user_submitted); |
| 2017 ASSERT_EQ(11U, response_data.fields.size()); | 1850 ASSERT_EQ(11U, response_data.fields.size()); |
| 2018 | 1851 |
| 2019 ExpectFilledField("", "country", "", "text", response_data.fields[0]); | 1852 ExpectFilledField("", "country", "", "text", response_data.fields[0]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2039 FormData form; | 1872 FormData form; |
| 2040 test::CreateTestAddressFormData(&form); | 1873 test::CreateTestAddressFormData(&form); |
| 2041 FormFieldData field; | 1874 FormFieldData field; |
| 2042 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); | 1875 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); |
| 2043 form.fields.push_back(field); | 1876 form.fields.push_back(field); |
| 2044 | 1877 |
| 2045 std::vector<FormData> forms(1, form); | 1878 std::vector<FormData> forms(1, form); |
| 2046 FormsSeen(forms); | 1879 FormsSeen(forms); |
| 2047 | 1880 |
| 2048 // Fill the form. | 1881 // Fill the form. |
| 2049 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1882 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2050 GUIDPair empty(std::string(), 0); | 1883 SuggestionBackendID empty(std::string(), 0); |
| 2051 int response_page_id = 0; | 1884 int response_page_id = 0; |
| 2052 FormData response_data; | 1885 FormData response_data; |
| 2053 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1886 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2054 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1887 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2055 | 1888 |
| 2056 // The second email address should be filled. | 1889 // The second email address should be filled. |
| 2057 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), | 1890 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), |
| 2058 response_data.fields.back().value); | 1891 response_data.fields.back().value); |
| 2059 | 1892 |
| 2060 // The remainder of the form should be filled as usual. | 1893 // The remainder of the form should be filled as usual. |
| 2061 response_data.fields.pop_back(); | 1894 response_data.fields.pop_back(); |
| 2062 ExpectFilledAddressFormElvis( | 1895 ExpectFilledAddressFormElvis( |
| 2063 response_page_id, response_data, kDefaultPageID, false); | 1896 response_page_id, response_data, kDefaultPageID, false); |
| 2064 } | 1897 } |
| 2065 | 1898 |
| 2066 // Test that we correctly fill a previously auto-filled form. | 1899 // Test that we correctly fill a previously auto-filled form. |
| 2067 TEST_F(AutofillManagerTest, FillAutofilledForm) { | 1900 TEST_F(AutofillManagerTest, FillAutofilledForm) { |
| 2068 // Set up our form data. | 1901 // Set up our form data. |
| 2069 FormData form; | 1902 FormData form; |
| 2070 test::CreateTestAddressFormData(&form); | 1903 test::CreateTestAddressFormData(&form); |
| 2071 // Mark one of the address fields as autofilled. | 1904 // Mark one of the address fields as autofilled. |
| 2072 form.fields[4].is_autofilled = true; | 1905 form.fields[4].is_autofilled = true; |
| 2073 CreateTestCreditCardFormData(&form, true, false); | 1906 CreateTestCreditCardFormData(&form, true, false); |
| 2074 std::vector<FormData> forms(1, form); | 1907 std::vector<FormData> forms(1, form); |
| 2075 FormsSeen(forms); | 1908 FormsSeen(forms); |
| 2076 | 1909 |
| 2077 // First fill the address data. | 1910 // First fill the address data. |
| 2078 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1911 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2079 GUIDPair empty(std::string(), 0); | 1912 SuggestionBackendID empty(std::string(), 0); |
| 2080 int response_page_id = 0; | 1913 int response_page_id = 0; |
| 2081 FormData response_data; | 1914 FormData response_data; |
| 2082 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1915 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2083 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1916 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2084 { | 1917 { |
| 2085 SCOPED_TRACE("Address"); | 1918 SCOPED_TRACE("Address"); |
| 2086 ExpectFilledForm(response_page_id, response_data, kDefaultPageID, | 1919 ExpectFilledForm(response_page_id, response_data, kDefaultPageID, |
| 2087 "Elvis", "", "", "", "", "", "", "", "", "", "", "", "", | 1920 "Elvis", "", "", "", "", "", "", "", "", "", "", "", "", |
| 2088 "", "", true, true, false); | 1921 "", "", true, true, false); |
| 2089 } | 1922 } |
| 2090 | 1923 |
| 2091 // Now fill the credit card data. | 1924 // Now fill the credit card data. |
| 2092 const int kPageID2 = 2; | 1925 const int kPageID2 = 2; |
| 2093 GUIDPair guid2("00000000-0000-0000-0000-000000000004", 0); | 1926 SuggestionBackendID guid2("00000000-0000-0000-0000-000000000004", 0); |
| 2094 response_page_id = 0; | 1927 response_page_id = 0; |
| 2095 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 1928 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
| 2096 PackGUIDs(guid2, empty), &response_page_id, &response_data); | 1929 MakeFrontendID(guid2, empty), &response_page_id, &response_data); |
| 2097 { | 1930 { |
| 2098 SCOPED_TRACE("Credit card 1"); | 1931 SCOPED_TRACE("Credit card 1"); |
| 2099 ExpectFilledCreditCardFormElvis( | 1932 ExpectFilledCreditCardFormElvis( |
| 2100 response_page_id, response_data, kPageID2, true); | 1933 response_page_id, response_data, kPageID2, true); |
| 2101 } | 1934 } |
| 2102 | 1935 |
| 2103 // Now set the credit card fields to also be auto-filled, and try again to | 1936 // Now set the credit card fields to also be auto-filled, and try again to |
| 2104 // fill the credit card data | 1937 // fill the credit card data |
| 2105 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); | 1938 for (std::vector<FormFieldData>::iterator iter = form.fields.begin(); |
| 2106 iter != form.fields.end(); | 1939 iter != form.fields.end(); |
| 2107 ++iter) { | 1940 ++iter) { |
| 2108 iter->is_autofilled = true; | 1941 iter->is_autofilled = true; |
| 2109 } | 1942 } |
| 2110 | 1943 |
| 2111 const int kPageID3 = 3; | 1944 const int kPageID3 = 3; |
| 2112 response_page_id = 0; | 1945 response_page_id = 0; |
| 2113 FillAutofillFormDataAndSaveResults(kPageID3, form, *form.fields.rbegin(), | 1946 FillAutofillFormDataAndSaveResults(kPageID3, form, *form.fields.rbegin(), |
| 2114 PackGUIDs(guid2, empty), &response_page_id, &response_data); | 1947 MakeFrontendID(guid2, empty), &response_page_id, &response_data); |
| 2115 { | 1948 { |
| 2116 SCOPED_TRACE("Credit card 2"); | 1949 SCOPED_TRACE("Credit card 2"); |
| 2117 ExpectFilledForm(response_page_id, response_data, kPageID3, | 1950 ExpectFilledForm(response_page_id, response_data, kPageID3, |
| 2118 "", "", "", "", "", "", "", "", "", "", "", "", "", "", | 1951 "", "", "", "", "", "", "", "", "", "", "", "", "", "", |
| 2119 "2012", true, true, false); | 1952 "2012", true, true, false); |
| 2120 } | 1953 } |
| 2121 } | 1954 } |
| 2122 | 1955 |
| 2123 // Test that we correctly fill an address form with a non-default variant for a | 1956 // Test that we correctly fill an address form with a non-default variant for a |
| 2124 // multi-valued field. | 1957 // multi-valued field. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2141 name_variants.clear(); | 1974 name_variants.clear(); |
| 2142 name_variants.push_back(ASCIIToUTF16("Other")); | 1975 name_variants.push_back(ASCIIToUTF16("Other")); |
| 2143 name_variants.push_back(profile->GetRawInfo(NAME_MIDDLE)); | 1976 name_variants.push_back(profile->GetRawInfo(NAME_MIDDLE)); |
| 2144 profile->SetRawMultiInfo(NAME_MIDDLE, name_variants); | 1977 profile->SetRawMultiInfo(NAME_MIDDLE, name_variants); |
| 2145 | 1978 |
| 2146 name_variants.clear(); | 1979 name_variants.clear(); |
| 2147 name_variants.push_back(ASCIIToUTF16("Guy")); | 1980 name_variants.push_back(ASCIIToUTF16("Guy")); |
| 2148 name_variants.push_back(profile->GetRawInfo(NAME_LAST)); | 1981 name_variants.push_back(profile->GetRawInfo(NAME_LAST)); |
| 2149 profile->SetRawMultiInfo(NAME_LAST, name_variants); | 1982 profile->SetRawMultiInfo(NAME_LAST, name_variants); |
| 2150 | 1983 |
| 2151 GUIDPair guid(profile->guid(), 1); | 1984 SuggestionBackendID guid(profile->guid(), 1); |
| 2152 GUIDPair empty(std::string(), 0); | 1985 SuggestionBackendID empty(std::string(), 0); |
| 2153 int response_page_id = 0; | 1986 int response_page_id = 0; |
| 2154 FormData response_data1; | 1987 FormData response_data1; |
| 2155 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1988 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2156 PackGUIDs(empty, guid), &response_page_id, &response_data1); | 1989 MakeFrontendID(empty, guid), &response_page_id, &response_data1); |
| 2157 { | 1990 { |
| 2158 SCOPED_TRACE("Valid variant"); | 1991 SCOPED_TRACE("Valid variant"); |
| 2159 ExpectFilledAddressFormElvis( | 1992 ExpectFilledAddressFormElvis( |
| 2160 response_page_id, response_data1, kDefaultPageID, false); | 1993 response_page_id, response_data1, kDefaultPageID, false); |
| 2161 } | 1994 } |
| 2162 | 1995 |
| 2163 // Try filling with a variant that doesn't exist. The fields to which this | 1996 // Try filling with a variant that doesn't exist. The fields to which this |
| 2164 // variant would normally apply should not be filled. | 1997 // variant would normally apply should not be filled. |
| 2165 const int kPageID2 = 2; | 1998 const int kPageID2 = 2; |
| 2166 GUIDPair guid2(profile->guid(), 2); | 1999 SuggestionBackendID guid2(profile->guid(), 2); |
| 2167 response_page_id = 0; | 2000 response_page_id = 0; |
| 2168 FormData response_data2; | 2001 FormData response_data2; |
| 2169 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], | 2002 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields[0], |
| 2170 PackGUIDs(empty, guid2), &response_page_id, &response_data2); | 2003 MakeFrontendID(empty, guid2), &response_page_id, &response_data2); |
| 2171 { | 2004 { |
| 2172 SCOPED_TRACE("Invalid variant"); | 2005 SCOPED_TRACE("Invalid variant"); |
| 2173 ExpectFilledForm(response_page_id, response_data2, kPageID2, "", "", "", | 2006 ExpectFilledForm(response_page_id, response_data2, kPageID2, "", "", "", |
| 2174 "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 2007 "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
| 2175 "Tennessee", "38116", "United States", "12345678901", | 2008 "Tennessee", "38116", "United States", "12345678901", |
| 2176 "theking@gmail.com", "", "", "", "", true, false, false); | 2009 "theking@gmail.com", "", "", "", "", true, false, false); |
| 2177 } | 2010 } |
| 2178 } | 2011 } |
| 2179 | 2012 |
| 2180 // Test that we correctly fill a phone number split across multiple fields. | 2013 // Test that we correctly fill a phone number split across multiple fields. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 forms.push_back(form_with_autocompletetype); | 2054 forms.push_back(form_with_autocompletetype); |
| 2222 FormsSeen(forms); | 2055 FormsSeen(forms); |
| 2223 | 2056 |
| 2224 // We should be able to fill prefix and suffix fields for US numbers. | 2057 // We should be able to fill prefix and suffix fields for US numbers. |
| 2225 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( | 2058 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( |
| 2226 "00000000-0000-0000-0000-000000000002"); | 2059 "00000000-0000-0000-0000-000000000002"); |
| 2227 ASSERT_TRUE(work_profile != NULL); | 2060 ASSERT_TRUE(work_profile != NULL); |
| 2228 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 2061 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 2229 ASCIIToUTF16("16505554567")); | 2062 ASCIIToUTF16("16505554567")); |
| 2230 | 2063 |
| 2231 GUIDPair guid(work_profile->guid(), 0); | 2064 SuggestionBackendID guid(work_profile->guid(), 0); |
| 2232 GUIDPair empty(std::string(), 0); | 2065 SuggestionBackendID empty(std::string(), 0); |
| 2233 int page_id = 1; | 2066 int page_id = 1; |
| 2234 int response_page_id = 0; | 2067 int response_page_id = 0; |
| 2235 FormData response_data1; | 2068 FormData response_data1; |
| 2236 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, | 2069 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2237 *form_with_maxlength.fields.begin(), | 2070 *form_with_maxlength.fields.begin(), |
| 2238 PackGUIDs(empty, guid), &response_page_id, &response_data1); | 2071 MakeFrontendID(empty, guid), &response_page_id, &response_data1); |
| 2239 EXPECT_EQ(1, response_page_id); | 2072 EXPECT_EQ(1, response_page_id); |
| 2240 | 2073 |
| 2241 ASSERT_EQ(5U, response_data1.fields.size()); | 2074 ASSERT_EQ(5U, response_data1.fields.size()); |
| 2242 EXPECT_EQ(ASCIIToUTF16("1"), response_data1.fields[0].value); | 2075 EXPECT_EQ(ASCIIToUTF16("1"), response_data1.fields[0].value); |
| 2243 EXPECT_EQ(ASCIIToUTF16("650"), response_data1.fields[1].value); | 2076 EXPECT_EQ(ASCIIToUTF16("650"), response_data1.fields[1].value); |
| 2244 EXPECT_EQ(ASCIIToUTF16("555"), response_data1.fields[2].value); | 2077 EXPECT_EQ(ASCIIToUTF16("555"), response_data1.fields[2].value); |
| 2245 EXPECT_EQ(ASCIIToUTF16("4567"), response_data1.fields[3].value); | 2078 EXPECT_EQ(ASCIIToUTF16("4567"), response_data1.fields[3].value); |
| 2246 EXPECT_EQ(base::string16(), response_data1.fields[4].value); | 2079 EXPECT_EQ(base::string16(), response_data1.fields[4].value); |
| 2247 | 2080 |
| 2248 page_id = 2; | 2081 page_id = 2; |
| 2249 response_page_id = 0; | 2082 response_page_id = 0; |
| 2250 FormData response_data2; | 2083 FormData response_data2; |
| 2251 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, | 2084 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, |
| 2252 *form_with_autocompletetype.fields.begin(), | 2085 *form_with_autocompletetype.fields.begin(), |
| 2253 PackGUIDs(empty, guid), &response_page_id, &response_data2); | 2086 MakeFrontendID(empty, guid), &response_page_id, &response_data2); |
| 2254 EXPECT_EQ(2, response_page_id); | 2087 EXPECT_EQ(2, response_page_id); |
| 2255 | 2088 |
| 2256 ASSERT_EQ(5U, response_data2.fields.size()); | 2089 ASSERT_EQ(5U, response_data2.fields.size()); |
| 2257 EXPECT_EQ(ASCIIToUTF16("1"), response_data2.fields[0].value); | 2090 EXPECT_EQ(ASCIIToUTF16("1"), response_data2.fields[0].value); |
| 2258 EXPECT_EQ(ASCIIToUTF16("650"), response_data2.fields[1].value); | 2091 EXPECT_EQ(ASCIIToUTF16("650"), response_data2.fields[1].value); |
| 2259 EXPECT_EQ(ASCIIToUTF16("555"), response_data2.fields[2].value); | 2092 EXPECT_EQ(ASCIIToUTF16("555"), response_data2.fields[2].value); |
| 2260 EXPECT_EQ(ASCIIToUTF16("4567"), response_data2.fields[3].value); | 2093 EXPECT_EQ(ASCIIToUTF16("4567"), response_data2.fields[3].value); |
| 2261 EXPECT_EQ(base::string16(), response_data2.fields[4].value); | 2094 EXPECT_EQ(base::string16(), response_data2.fields[4].value); |
| 2262 | 2095 |
| 2263 // We should not be able to fill prefix and suffix fields for international | 2096 // We should not be able to fill prefix and suffix fields for international |
| 2264 // numbers. | 2097 // numbers. |
| 2265 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); | 2098 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); |
| 2266 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 2099 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 2267 ASCIIToUTF16("447700954321")); | 2100 ASCIIToUTF16("447700954321")); |
| 2268 page_id = 3; | 2101 page_id = 3; |
| 2269 response_page_id = 0; | 2102 response_page_id = 0; |
| 2270 FormData response_data3; | 2103 FormData response_data3; |
| 2271 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, | 2104 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2272 *form_with_maxlength.fields.begin(), | 2105 *form_with_maxlength.fields.begin(), |
| 2273 PackGUIDs(empty, guid), &response_page_id, &response_data3); | 2106 MakeFrontendID(empty, guid), &response_page_id, &response_data3); |
| 2274 EXPECT_EQ(3, response_page_id); | 2107 EXPECT_EQ(3, response_page_id); |
| 2275 | 2108 |
| 2276 ASSERT_EQ(5U, response_data3.fields.size()); | 2109 ASSERT_EQ(5U, response_data3.fields.size()); |
| 2277 EXPECT_EQ(ASCIIToUTF16("44"), response_data3.fields[0].value); | 2110 EXPECT_EQ(ASCIIToUTF16("44"), response_data3.fields[0].value); |
| 2278 EXPECT_EQ(ASCIIToUTF16("7700"), response_data3.fields[1].value); | 2111 EXPECT_EQ(ASCIIToUTF16("7700"), response_data3.fields[1].value); |
| 2279 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[2].value); | 2112 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[2].value); |
| 2280 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[3].value); | 2113 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[3].value); |
| 2281 EXPECT_EQ(base::string16(), response_data3.fields[4].value); | 2114 EXPECT_EQ(base::string16(), response_data3.fields[4].value); |
| 2282 | 2115 |
| 2283 page_id = 4; | 2116 page_id = 4; |
| 2284 response_page_id = 0; | 2117 response_page_id = 0; |
| 2285 FormData response_data4; | 2118 FormData response_data4; |
| 2286 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, | 2119 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, |
| 2287 *form_with_autocompletetype.fields.begin(), | 2120 *form_with_autocompletetype.fields.begin(), |
| 2288 PackGUIDs(empty, guid), &response_page_id, &response_data4); | 2121 MakeFrontendID(empty, guid), &response_page_id, &response_data4); |
| 2289 EXPECT_EQ(4, response_page_id); | 2122 EXPECT_EQ(4, response_page_id); |
| 2290 | 2123 |
| 2291 ASSERT_EQ(5U, response_data4.fields.size()); | 2124 ASSERT_EQ(5U, response_data4.fields.size()); |
| 2292 EXPECT_EQ(ASCIIToUTF16("44"), response_data4.fields[0].value); | 2125 EXPECT_EQ(ASCIIToUTF16("44"), response_data4.fields[0].value); |
| 2293 EXPECT_EQ(ASCIIToUTF16("7700"), response_data4.fields[1].value); | 2126 EXPECT_EQ(ASCIIToUTF16("7700"), response_data4.fields[1].value); |
| 2294 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[2].value); | 2127 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[2].value); |
| 2295 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[3].value); | 2128 EXPECT_EQ(ASCIIToUTF16("954321"), response_data4.fields[3].value); |
| 2296 EXPECT_EQ(base::string16(), response_data4.fields[4].value); | 2129 EXPECT_EQ(base::string16(), response_data4.fields[4].value); |
| 2297 | 2130 |
| 2298 // We should fill all phone fields with the same phone number variant. | 2131 // We should fill all phone fields with the same phone number variant. |
| 2299 std::vector<base::string16> phone_variants; | 2132 std::vector<base::string16> phone_variants; |
| 2300 phone_variants.push_back(ASCIIToUTF16("16505554567")); | 2133 phone_variants.push_back(ASCIIToUTF16("16505554567")); |
| 2301 phone_variants.push_back(ASCIIToUTF16("18887771234")); | 2134 phone_variants.push_back(ASCIIToUTF16("18887771234")); |
| 2302 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 2135 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 2303 work_profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_variants); | 2136 work_profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_variants); |
| 2304 | 2137 |
| 2305 page_id = 5; | 2138 page_id = 5; |
| 2306 response_page_id = 0; | 2139 response_page_id = 0; |
| 2307 FormData response_data5; | 2140 FormData response_data5; |
| 2308 GUIDPair variant_guid(work_profile->guid(), 1); | 2141 SuggestionBackendID variant_guid(work_profile->guid(), 1); |
| 2309 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, | 2142 FillAutofillFormDataAndSaveResults(page_id, form_with_maxlength, |
| 2310 *form_with_maxlength.fields.begin(), | 2143 *form_with_maxlength.fields.begin(), |
| 2311 PackGUIDs(empty, variant_guid), &response_page_id, &response_data5); | 2144 MakeFrontendID(empty, variant_guid), &response_page_id, &response_data5); |
| 2312 EXPECT_EQ(5, response_page_id); | 2145 EXPECT_EQ(5, response_page_id); |
| 2313 | 2146 |
| 2314 ASSERT_EQ(5U, response_data5.fields.size()); | 2147 ASSERT_EQ(5U, response_data5.fields.size()); |
| 2315 EXPECT_EQ(ASCIIToUTF16("1"), response_data5.fields[0].value); | 2148 EXPECT_EQ(ASCIIToUTF16("1"), response_data5.fields[0].value); |
| 2316 EXPECT_EQ(ASCIIToUTF16("888"), response_data5.fields[1].value); | 2149 EXPECT_EQ(ASCIIToUTF16("888"), response_data5.fields[1].value); |
| 2317 EXPECT_EQ(ASCIIToUTF16("777"), response_data5.fields[2].value); | 2150 EXPECT_EQ(ASCIIToUTF16("777"), response_data5.fields[2].value); |
| 2318 EXPECT_EQ(ASCIIToUTF16("1234"), response_data5.fields[3].value); | 2151 EXPECT_EQ(ASCIIToUTF16("1234"), response_data5.fields[3].value); |
| 2319 EXPECT_EQ(base::string16(), response_data5.fields[4].value); | 2152 EXPECT_EQ(base::string16(), response_data5.fields[4].value); |
| 2320 } | 2153 } |
| 2321 | 2154 |
| 2322 // Test that we can still fill a form when a field has been removed from it. | 2155 // Test that we can still fill a form when a field has been removed from it. |
| 2323 TEST_F(AutofillManagerTest, FormChangesRemoveField) { | 2156 TEST_F(AutofillManagerTest, FormChangesRemoveField) { |
| 2324 // Set up our form data. | 2157 // Set up our form data. |
| 2325 FormData form; | 2158 FormData form; |
| 2326 test::CreateTestAddressFormData(&form); | 2159 test::CreateTestAddressFormData(&form); |
| 2327 | 2160 |
| 2328 // Add a field -- we'll remove it again later. | 2161 // Add a field -- we'll remove it again later. |
| 2329 FormFieldData field; | 2162 FormFieldData field; |
| 2330 test::CreateTestFormField("Some", "field", "", "text", &field); | 2163 test::CreateTestFormField("Some", "field", "", "text", &field); |
| 2331 form.fields.insert(form.fields.begin() + 3, field); | 2164 form.fields.insert(form.fields.begin() + 3, field); |
| 2332 | 2165 |
| 2333 std::vector<FormData> forms(1, form); | 2166 std::vector<FormData> forms(1, form); |
| 2334 FormsSeen(forms); | 2167 FormsSeen(forms); |
| 2335 | 2168 |
| 2336 // Now, after the call to |FormsSeen|, we remove the field before filling. | 2169 // Now, after the call to |FormsSeen|, we remove the field before filling. |
| 2337 form.fields.erase(form.fields.begin() + 3); | 2170 form.fields.erase(form.fields.begin() + 3); |
| 2338 | 2171 |
| 2339 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2172 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2340 GUIDPair empty(std::string(), 0); | 2173 SuggestionBackendID empty(std::string(), 0); |
| 2341 int response_page_id = 0; | 2174 int response_page_id = 0; |
| 2342 FormData response_data; | 2175 FormData response_data; |
| 2343 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2176 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2344 PackGUIDs(empty, guid), &response_page_id, &response_data); | 2177 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2345 ExpectFilledAddressFormElvis( | 2178 ExpectFilledAddressFormElvis( |
| 2346 response_page_id, response_data, kDefaultPageID, false); | 2179 response_page_id, response_data, kDefaultPageID, false); |
| 2347 } | 2180 } |
| 2348 | 2181 |
| 2349 // Test that we can still fill a form when a field has been added to it. | 2182 // Test that we can still fill a form when a field has been added to it. |
| 2350 TEST_F(AutofillManagerTest, FormChangesAddField) { | 2183 TEST_F(AutofillManagerTest, FormChangesAddField) { |
| 2351 // The offset of the phone field in the address form. | 2184 // The offset of the phone field in the address form. |
| 2352 const int kPhoneFieldOffset = 9; | 2185 const int kPhoneFieldOffset = 9; |
| 2353 | 2186 |
| 2354 // Set up our form data. | 2187 // Set up our form data. |
| 2355 FormData form; | 2188 FormData form; |
| 2356 test::CreateTestAddressFormData(&form); | 2189 test::CreateTestAddressFormData(&form); |
| 2357 | 2190 |
| 2358 // Remove the phone field -- we'll add it back later. | 2191 // Remove the phone field -- we'll add it back later. |
| 2359 std::vector<FormFieldData>::iterator pos = | 2192 std::vector<FormFieldData>::iterator pos = |
| 2360 form.fields.begin() + kPhoneFieldOffset; | 2193 form.fields.begin() + kPhoneFieldOffset; |
| 2361 FormFieldData field = *pos; | 2194 FormFieldData field = *pos; |
| 2362 pos = form.fields.erase(pos); | 2195 pos = form.fields.erase(pos); |
| 2363 | 2196 |
| 2364 std::vector<FormData> forms(1, form); | 2197 std::vector<FormData> forms(1, form); |
| 2365 FormsSeen(forms); | 2198 FormsSeen(forms); |
| 2366 | 2199 |
| 2367 // Now, after the call to |FormsSeen|, we restore the field before filling. | 2200 // Now, after the call to |FormsSeen|, we restore the field before filling. |
| 2368 form.fields.insert(pos, field); | 2201 form.fields.insert(pos, field); |
| 2369 | 2202 |
| 2370 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2203 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2371 GUIDPair empty(std::string(), 0); | 2204 SuggestionBackendID empty(std::string(), 0); |
| 2372 int response_page_id = 0; | 2205 int response_page_id = 0; |
| 2373 FormData response_data; | 2206 FormData response_data; |
| 2374 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2207 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2375 PackGUIDs(empty, guid), &response_page_id, &response_data); | 2208 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2376 ExpectFilledAddressFormElvis( | 2209 ExpectFilledAddressFormElvis( |
| 2377 response_page_id, response_data, kDefaultPageID, false); | 2210 response_page_id, response_data, kDefaultPageID, false); |
| 2378 } | 2211 } |
| 2379 | 2212 |
| 2380 // Test that we are able to save form data when forms are submitted. | 2213 // Test that we are able to save form data when forms are submitted. |
| 2381 TEST_F(AutofillManagerTest, FormSubmitted) { | 2214 TEST_F(AutofillManagerTest, FormSubmitted) { |
| 2382 // Set up our form data. | 2215 // Set up our form data. |
| 2383 FormData form; | 2216 FormData form; |
| 2384 test::CreateTestAddressFormData(&form); | 2217 test::CreateTestAddressFormData(&form); |
| 2385 std::vector<FormData> forms(1, form); | 2218 std::vector<FormData> forms(1, form); |
| 2386 FormsSeen(forms); | 2219 FormsSeen(forms); |
| 2387 | 2220 |
| 2388 // Fill the form. | 2221 // Fill the form. |
| 2389 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2222 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2390 GUIDPair empty(std::string(), 0); | 2223 SuggestionBackendID empty(std::string(), 0); |
| 2391 int response_page_id = 0; | 2224 int response_page_id = 0; |
| 2392 FormData response_data; | 2225 FormData response_data; |
| 2393 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2226 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2394 PackGUIDs(empty, guid), &response_page_id, &response_data); | 2227 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2395 ExpectFilledAddressFormElvis( | 2228 ExpectFilledAddressFormElvis( |
| 2396 response_page_id, response_data, kDefaultPageID, false); | 2229 response_page_id, response_data, kDefaultPageID, false); |
| 2397 | 2230 |
| 2398 // Simulate form submission. We should call into the PDM to try to save the | 2231 // Simulate form submission. We should call into the PDM to try to save the |
| 2399 // filled data. | 2232 // filled data. |
| 2400 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2233 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2401 FormSubmitted(response_data); | 2234 FormSubmitted(response_data); |
| 2402 } | 2235 } |
| 2403 | 2236 |
| 2404 // Test that when Autocomplete is enabled and Autofill is disabled, | 2237 // Test that when Autocomplete is enabled and Autofill is disabled, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2442 const FormFieldData& field = form.fields[0]; | 2275 const FormFieldData& field = form.fields[0]; |
| 2443 GetAutofillSuggestions(form, field); | 2276 GetAutofillSuggestions(form, field); |
| 2444 | 2277 |
| 2445 // Add some Autocomplete suggestions. We should return the autocomplete | 2278 // Add some Autocomplete suggestions. We should return the autocomplete |
| 2446 // suggestions, these will be culled by the renderer. | 2279 // suggestions, these will be culled by the renderer. |
| 2447 std::vector<base::string16> suggestions; | 2280 std::vector<base::string16> suggestions; |
| 2448 suggestions.push_back(ASCIIToUTF16("Jay")); | 2281 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 2449 suggestions.push_back(ASCIIToUTF16("Jason")); | 2282 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 2450 AutocompleteSuggestionsReturned(suggestions); | 2283 AutocompleteSuggestionsReturned(suggestions); |
| 2451 | 2284 |
| 2452 base::string16 expected_values[] = { | |
| 2453 ASCIIToUTF16("Jay"), | |
| 2454 ASCIIToUTF16("Jason") | |
| 2455 }; | |
| 2456 base::string16 expected_labels[] = { base::string16(), base::string16()}; | |
| 2457 base::string16 expected_icons[] = { base::string16(), base::string16()}; | |
| 2458 int expected_unique_ids[] = {0, 0}; | |
| 2459 external_delegate_->CheckSuggestions( | 2285 external_delegate_->CheckSuggestions( |
| 2460 kDefaultPageID, arraysize(expected_values), expected_values, | 2286 kDefaultPageID, |
| 2461 expected_labels, expected_icons, expected_unique_ids); | 2287 Suggestion("Jay", "", "", 0), |
| 2288 Suggestion("Jason", "", "", 0)); |
| 2462 } | 2289 } |
| 2463 | 2290 |
| 2464 // Duplicate of the below test with the respect-autocomplete-off-autofill | 2291 // Duplicate of the below test with the respect-autocomplete-off-autofill |
| 2465 // switch. | 2292 // switch. |
| 2466 TEST_F(AutofillManagerTest, AutocompleteOffRespected) { | 2293 TEST_F(AutofillManagerTest, AutocompleteOffRespected) { |
| 2467 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2294 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2468 switches::kRespectAutocompleteOffForAutofill); | 2295 switches::kRespectAutocompleteOffForAutofill); |
| 2469 | 2296 |
| 2470 TestAutofillClient client; | 2297 TestAutofillClient client; |
| 2471 autofill_manager_.reset( | 2298 autofill_manager_.reset( |
| 2472 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 2299 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 2473 autofill_manager_->set_autofill_enabled(false); | 2300 autofill_manager_->set_autofill_enabled(false); |
| 2474 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 2301 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 2475 | 2302 |
| 2476 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2303 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
| 2477 autocomplete_history_manager.reset( | 2304 autocomplete_history_manager.reset( |
| 2478 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 2305 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); |
| 2479 autofill_manager_->autocomplete_history_manager_ = | 2306 autofill_manager_->autocomplete_history_manager_ = |
| 2480 autocomplete_history_manager.Pass(); | 2307 autocomplete_history_manager.Pass(); |
| 2481 MockAutocompleteHistoryManager* m = static_cast< | 2308 MockAutocompleteHistoryManager* m = static_cast< |
| 2482 MockAutocompleteHistoryManager*>( | 2309 MockAutocompleteHistoryManager*>( |
| 2483 autofill_manager_->autocomplete_history_manager_.get()); | 2310 autofill_manager_->autocomplete_history_manager_.get()); |
| 2484 EXPECT_CALL(*m, | 2311 EXPECT_CALL(*m, |
| 2485 OnGetAutocompleteSuggestions(_, _, _, _, _, _, _, _)).Times(0); | 2312 OnGetAutocompleteSuggestions(_, _, _, _, _)).Times(0); |
| 2486 | 2313 |
| 2487 // Set up our form data. | 2314 // Set up our form data. |
| 2488 FormData form; | 2315 FormData form; |
| 2489 test::CreateTestAddressFormData(&form); | 2316 test::CreateTestAddressFormData(&form); |
| 2490 std::vector<FormData> forms(1, form); | 2317 std::vector<FormData> forms(1, form); |
| 2491 FormsSeen(forms); | 2318 FormsSeen(forms); |
| 2492 FormFieldData* field = &form.fields[0]; | 2319 FormFieldData* field = &form.fields[0]; |
| 2493 field->should_autocomplete = false; | 2320 field->should_autocomplete = false; |
| 2494 GetAutofillSuggestions(form, *field); | 2321 GetAutofillSuggestions(form, *field); |
| 2495 } | 2322 } |
| 2496 | 2323 |
| 2497 TEST_F(AutofillManagerTest, AutocompleteOffRespectedWithFlag) { | 2324 TEST_F(AutofillManagerTest, AutocompleteOffRespectedWithFlag) { |
| 2498 TestAutofillClient client; | 2325 TestAutofillClient client; |
| 2499 autofill_manager_.reset( | 2326 autofill_manager_.reset( |
| 2500 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 2327 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 2501 autofill_manager_->set_autofill_enabled(false); | 2328 autofill_manager_->set_autofill_enabled(false); |
| 2502 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 2329 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 2503 | 2330 |
| 2504 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2331 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
| 2505 autocomplete_history_manager.reset( | 2332 autocomplete_history_manager.reset( |
| 2506 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 2333 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); |
| 2507 autofill_manager_->autocomplete_history_manager_ = | 2334 autofill_manager_->autocomplete_history_manager_ = |
| 2508 autocomplete_history_manager.Pass(); | 2335 autocomplete_history_manager.Pass(); |
| 2509 MockAutocompleteHistoryManager* m = static_cast< | 2336 MockAutocompleteHistoryManager* m = static_cast< |
| 2510 MockAutocompleteHistoryManager*>( | 2337 MockAutocompleteHistoryManager*>( |
| 2511 autofill_manager_->autocomplete_history_manager_.get()); | 2338 autofill_manager_->autocomplete_history_manager_.get()); |
| 2512 EXPECT_CALL(*m, | 2339 EXPECT_CALL(*m, |
| 2513 OnGetAutocompleteSuggestions(_, _, _, _, _, _, _, _)).Times(0); | 2340 OnGetAutocompleteSuggestions(_, _, _, _, _)).Times(0); |
| 2514 | 2341 |
| 2515 // Set up our form data. | 2342 // Set up our form data. |
| 2516 FormData form; | 2343 FormData form; |
| 2517 test::CreateTestAddressFormData(&form); | 2344 test::CreateTestAddressFormData(&form); |
| 2518 std::vector<FormData> forms(1, form); | 2345 std::vector<FormData> forms(1, form); |
| 2519 FormsSeen(forms); | 2346 FormsSeen(forms); |
| 2520 FormFieldData* field = &form.fields[0]; | 2347 FormFieldData* field = &form.fields[0]; |
| 2521 field->should_autocomplete = false; | 2348 field->should_autocomplete = false; |
| 2522 GetAutofillSuggestions(form, *field); | 2349 GetAutofillSuggestions(form, *field); |
| 2523 } | 2350 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2538 // Clear the heuristic types, and instead set the appropriate server types. | 2365 // Clear the heuristic types, and instead set the appropriate server types. |
| 2539 std::vector<ServerFieldType> heuristic_types, server_types; | 2366 std::vector<ServerFieldType> heuristic_types, server_types; |
| 2540 for (size_t i = 0; i < form.fields.size(); ++i) { | 2367 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 2541 heuristic_types.push_back(UNKNOWN_TYPE); | 2368 heuristic_types.push_back(UNKNOWN_TYPE); |
| 2542 server_types.push_back(form_structure->field(i)->heuristic_type()); | 2369 server_types.push_back(form_structure->field(i)->heuristic_type()); |
| 2543 } | 2370 } |
| 2544 form_structure->SetFieldTypes(heuristic_types, server_types); | 2371 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 2545 autofill_manager_->AddSeenForm(form_structure); | 2372 autofill_manager_->AddSeenForm(form_structure); |
| 2546 | 2373 |
| 2547 // Fill the form. | 2374 // Fill the form. |
| 2548 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2375 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2549 GUIDPair empty(std::string(), 0); | 2376 SuggestionBackendID empty(std::string(), 0); |
| 2550 int response_page_id = 0; | 2377 int response_page_id = 0; |
| 2551 FormData response_data; | 2378 FormData response_data; |
| 2552 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2379 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2553 PackGUIDs(empty, guid), &response_page_id, &response_data); | 2380 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2554 ExpectFilledAddressFormElvis( | 2381 ExpectFilledAddressFormElvis( |
| 2555 response_page_id, response_data, kDefaultPageID, false); | 2382 response_page_id, response_data, kDefaultPageID, false); |
| 2556 | 2383 |
| 2557 // Simulate form submission. We should call into the PDM to try to save the | 2384 // Simulate form submission. We should call into the PDM to try to save the |
| 2558 // filled data. | 2385 // filled data. |
| 2559 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2386 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2560 FormSubmitted(response_data); | 2387 FormSubmitted(response_data); |
| 2561 } | 2388 } |
| 2562 | 2389 |
| 2563 // Test that the form signature for an uploaded form always matches the form | 2390 // Test that the form signature for an uploaded form always matches the form |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 // Convert the state field to a <select> popup, to make sure that we only | 2423 // Convert the state field to a <select> popup, to make sure that we only |
| 2597 // reject default values for text fields. | 2424 // reject default values for text fields. |
| 2598 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); | 2425 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); |
| 2599 form.fields[6].form_control_type = "select-one"; | 2426 form.fields[6].form_control_type = "select-one"; |
| 2600 form.fields[6].value = ASCIIToUTF16("Tennessee"); | 2427 form.fields[6].value = ASCIIToUTF16("Tennessee"); |
| 2601 | 2428 |
| 2602 std::vector<FormData> forms(1, form); | 2429 std::vector<FormData> forms(1, form); |
| 2603 FormsSeen(forms); | 2430 FormsSeen(forms); |
| 2604 | 2431 |
| 2605 // Fill the form. | 2432 // Fill the form. |
| 2606 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2433 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001", 0); |
| 2607 GUIDPair empty(std::string(), 0); | 2434 SuggestionBackendID empty(std::string(), 0); |
| 2608 int response_page_id = 0; | 2435 int response_page_id = 0; |
| 2609 FormData response_data; | 2436 FormData response_data; |
| 2610 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[3], | 2437 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[3], |
| 2611 PackGUIDs(empty, guid), &response_page_id, &response_data); | 2438 MakeFrontendID(empty, guid), &response_page_id, &response_data); |
| 2612 | 2439 |
| 2613 // Simulate form submission. We should call into the PDM to try to save the | 2440 // Simulate form submission. We should call into the PDM to try to save the |
| 2614 // filled data. | 2441 // filled data. |
| 2615 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2442 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2616 FormSubmitted(response_data); | 2443 FormSubmitted(response_data); |
| 2617 | 2444 |
| 2618 // Set the address field's value back to the default value. | 2445 // Set the address field's value back to the default value. |
| 2619 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); | 2446 response_data.fields[3].value = ASCIIToUTF16("Enter your address"); |
| 2620 | 2447 |
| 2621 // Simulate form submission. We should not call into the PDM to try to save | 2448 // Simulate form submission. We should not call into the PDM to try to save |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2932 FormSubmitted(form); | 2759 FormSubmitted(form); |
| 2933 } | 2760 } |
| 2934 | 2761 |
| 2935 TEST_F(AutofillManagerTest, RemoveProfile) { | 2762 TEST_F(AutofillManagerTest, RemoveProfile) { |
| 2936 // Add and remove an Autofill profile. | 2763 // Add and remove an Autofill profile. |
| 2937 AutofillProfile* profile = new AutofillProfile; | 2764 AutofillProfile* profile = new AutofillProfile; |
| 2938 std::string guid = "00000000-0000-0000-0000-000000000102"; | 2765 std::string guid = "00000000-0000-0000-0000-000000000102"; |
| 2939 profile->set_guid(guid.c_str()); | 2766 profile->set_guid(guid.c_str()); |
| 2940 autofill_manager_->AddProfile(profile); | 2767 autofill_manager_->AddProfile(profile); |
| 2941 | 2768 |
| 2942 GUIDPair guid_pair(guid, 0); | 2769 SuggestionBackendID guid_pair(guid, 0); |
| 2943 GUIDPair empty(std::string(), 0); | 2770 SuggestionBackendID empty(std::string(), 0); |
| 2944 int id = PackGUIDs(empty, guid_pair); | 2771 int id = MakeFrontendID(empty, guid_pair); |
| 2945 | 2772 |
| 2946 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 2773 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 2947 | 2774 |
| 2948 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 2775 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
| 2949 } | 2776 } |
| 2950 | 2777 |
| 2951 TEST_F(AutofillManagerTest, RemoveCreditCard){ | 2778 TEST_F(AutofillManagerTest, RemoveCreditCard){ |
| 2952 // Add and remove an Autofill credit card. | 2779 // Add and remove an Autofill credit card. |
| 2953 CreditCard* credit_card = new CreditCard; | 2780 CreditCard* credit_card = new CreditCard; |
| 2954 std::string guid = "00000000-0000-0000-0000-000000100007"; | 2781 std::string guid = "00000000-0000-0000-0000-000000100007"; |
| 2955 credit_card->set_guid(guid.c_str()); | 2782 credit_card->set_guid(guid.c_str()); |
| 2956 autofill_manager_->AddCreditCard(credit_card); | 2783 autofill_manager_->AddCreditCard(credit_card); |
| 2957 | 2784 |
| 2958 GUIDPair guid_pair(guid, 0); | 2785 SuggestionBackendID guid_pair(guid, 0); |
| 2959 GUIDPair empty(std::string(), 0); | 2786 SuggestionBackendID empty(std::string(), 0); |
| 2960 int id = PackGUIDs(guid_pair, empty); | 2787 int id = MakeFrontendID(guid_pair, empty); |
| 2961 | 2788 |
| 2962 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 2789 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 2963 | 2790 |
| 2964 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str())); | 2791 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str())); |
| 2965 } | 2792 } |
| 2966 | 2793 |
| 2967 TEST_F(AutofillManagerTest, RemoveProfileVariant) { | 2794 TEST_F(AutofillManagerTest, RemoveProfileVariant) { |
| 2968 // Add and remove an Autofill profile. | 2795 // Add and remove an Autofill profile. |
| 2969 AutofillProfile* profile = new AutofillProfile; | 2796 AutofillProfile* profile = new AutofillProfile; |
| 2970 std::string guid = "00000000-0000-0000-0000-000000000102"; | 2797 std::string guid = "00000000-0000-0000-0000-000000000102"; |
| 2971 profile->set_guid(guid.c_str()); | 2798 profile->set_guid(guid.c_str()); |
| 2972 autofill_manager_->AddProfile(profile); | 2799 autofill_manager_->AddProfile(profile); |
| 2973 | 2800 |
| 2974 GUIDPair guid_pair(guid, 1); | 2801 SuggestionBackendID guid_pair(guid, 1); |
| 2975 GUIDPair empty(std::string(), 0); | 2802 SuggestionBackendID empty(std::string(), 0); |
| 2976 int id = PackGUIDs(empty, guid_pair); | 2803 int id = MakeFrontendID(empty, guid_pair); |
| 2977 | 2804 |
| 2978 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 2805 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 2979 | 2806 |
| 2980 // TODO(csharp): Currently variants should not be deleted, but once they are | 2807 // TODO(csharp): Currently variants should not be deleted, but once they are |
| 2981 // update these expectations. | 2808 // update these expectations. |
| 2982 // http://crbug.com/124211 | 2809 // http://crbug.com/124211 |
| 2983 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 2810 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
| 2984 } | 2811 } |
| 2985 | 2812 |
| 2986 #if defined(OS_MACOSX) && !defined(OS_IOS) | 2813 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3095 FormFieldData number_field = form.fields[3]; | 2922 FormFieldData number_field = form.fields[3]; |
| 3096 number_field.value = ASCIIToUTF16("901"); | 2923 number_field.value = ASCIIToUTF16("901"); |
| 3097 | 2924 |
| 3098 // Get the suggestions for already filled credit card |number_field|. | 2925 // Get the suggestions for already filled credit card |number_field|. |
| 3099 GetAutofillSuggestions(form, number_field); | 2926 GetAutofillSuggestions(form, number_field); |
| 3100 | 2927 |
| 3101 // No autocomplete suggestions provided, so send an empty vector as the | 2928 // No autocomplete suggestions provided, so send an empty vector as the |
| 3102 // results. This triggers the combined message send. | 2929 // results. This triggers the combined message send. |
| 3103 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 2930 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 3104 | 2931 |
| 3105 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | |
| 3106 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | |
| 3107 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | |
| 3108 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; | |
| 3109 external_delegate_->CheckSuggestions( | 2932 external_delegate_->CheckSuggestions( |
| 3110 kDefaultPageID, arraysize(expected_values), expected_values, | 2933 kDefaultPageID, |
| 3111 expected_labels, expected_icons, expected_unique_ids); | 2934 Suggestion("************3456", "04/12", kVisaCard, |
| 2935 autofill_manager_->GetPackedCreditCardID(4))); |
| 3112 } | 2936 } |
| 3113 | 2937 |
| 3114 } // namespace autofill | 2938 } // namespace autofill |
| OLD | NEW |