Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 int expected_page_id, | 473 int expected_page_id, |
| 474 bool has_address_fields, | 474 bool has_address_fields, |
| 475 const char* year, | 475 const char* year, |
| 476 const char* month) { | 476 const char* month) { |
| 477 ExpectFilledForm(page_id, filled_form, expected_page_id, | 477 ExpectFilledForm(page_id, filled_form, expected_page_id, |
| 478 "", "", "", "", "", "", "", "", "", "", "", | 478 "", "", "", "", "", "", "", "", "", "", "", |
| 479 "Miku Hatsune", "4234567890654321", month, year, | 479 "Miku Hatsune", "4234567890654321", month, year, |
| 480 has_address_fields, true, true); | 480 has_address_fields, true, true); |
| 481 } | 481 } |
| 482 | 482 |
| 483 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { | |
| 484 public: | |
| 485 MockAutocompleteHistoryManager(AutofillDriver* driver, | |
| 486 AutofillManagerDelegate* delegate) | |
| 487 : AutocompleteHistoryManager(driver, delegate) {} | |
| 488 | |
| 489 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); | |
| 490 | |
| 491 private: | |
| 492 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); | |
| 493 }; | |
| 494 | |
| 483 class TestAutofillManager : public AutofillManager { | 495 class TestAutofillManager : public AutofillManager { |
| 484 public: | 496 public: |
| 485 TestAutofillManager(AutofillDriver* driver, | 497 TestAutofillManager(AutofillDriver* driver, |
| 486 autofill::AutofillManagerDelegate* delegate, | 498 autofill::AutofillManagerDelegate* delegate, |
| 487 TestPersonalDataManager* personal_data) | 499 TestPersonalDataManager* personal_data) |
| 488 : AutofillManager(driver, delegate, personal_data), | 500 : AutofillManager(driver, delegate, personal_data), |
| 489 personal_data_(personal_data), | 501 personal_data_(personal_data), |
| 490 autofill_enabled_(true) {} | 502 autofill_enabled_(true) {} |
| 491 virtual ~TestAutofillManager() {} | 503 virtual ~TestAutofillManager() {} |
| 492 | 504 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 false); | 708 false); |
| 697 } | 709 } |
| 698 | 710 |
| 699 void GetAutofillSuggestions(const FormData& form, | 711 void GetAutofillSuggestions(const FormData& form, |
| 700 const FormFieldData& field) { | 712 const FormFieldData& field) { |
| 701 GetAutofillSuggestions(kDefaultPageID, form, field); | 713 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 702 } | 714 } |
| 703 | 715 |
| 704 void AutocompleteSuggestionsReturned( | 716 void AutocompleteSuggestionsReturned( |
| 705 const std::vector<base::string16>& result) { | 717 const std::vector<base::string16>& result) { |
| 706 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); | 718 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
| 707 } | 719 } |
| 708 | 720 |
| 709 void FormsSeen(const std::vector<FormData>& forms) { | 721 void FormsSeen(const std::vector<FormData>& forms) { |
| 710 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), | 722 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 711 autofill::NO_SPECIAL_FORMS_SEEN); | 723 autofill::NO_SPECIAL_FORMS_SEEN); |
| 712 } | 724 } |
| 713 | 725 |
| 714 void PartialFormsSeen(const std::vector<FormData>& forms) { | 726 void PartialFormsSeen(const std::vector<FormData>& forms) { |
| 715 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), | 727 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 716 autofill::PARTIAL_FORMS_SEEN); | 728 autofill::PARTIAL_FORMS_SEEN); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 *page_id = autofill_param.a; | 767 *page_id = autofill_param.a; |
| 756 if (values) | 768 if (values) |
| 757 *values = autofill_param.b; | 769 *values = autofill_param.b; |
| 758 if (labels) | 770 if (labels) |
| 759 *labels = autofill_param.c; | 771 *labels = autofill_param.c; |
| 760 if (icons) | 772 if (icons) |
| 761 *icons = autofill_param.d; | 773 *icons = autofill_param.d; |
| 762 if (unique_ids) | 774 if (unique_ids) |
| 763 *unique_ids = autofill_param.e; | 775 *unique_ids = autofill_param.e; |
| 764 | 776 |
| 765 autofill_manager_->autocomplete_history_manager_.CancelPendingQuery(); | 777 autofill_manager_->autocomplete_history_manager_->CancelPendingQuery(); |
| 766 process()->sink().ClearMessages(); | 778 process()->sink().ClearMessages(); |
| 767 return true; | 779 return true; |
| 768 } | 780 } |
| 769 | 781 |
| 770 bool HasSeenAutofillGetAllFormsMessage() { | 782 bool HasSeenAutofillGetAllFormsMessage() { |
| 771 const uint32 kMsgID = AutofillMsg_GetAllForms::ID; | 783 const uint32 kMsgID = AutofillMsg_GetAllForms::ID; |
| 772 const IPC::Message* message = | 784 const IPC::Message* message = |
| 773 process()->sink().GetFirstMessageMatching(kMsgID); | 785 process()->sink().GetFirstMessageMatching(kMsgID); |
| 774 return message != NULL; | 786 return message != NULL; |
| 775 } | 787 } |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2702 FormData results; | 2714 FormData results; |
| 2703 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2715 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 2704 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2716 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
| 2705 | 2717 |
| 2706 // Simulate form submission. We should call into the PDM to try to save the | 2718 // Simulate form submission. We should call into the PDM to try to save the |
| 2707 // filled data. | 2719 // filled data. |
| 2708 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2720 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
| 2709 FormSubmitted(results); | 2721 FormSubmitted(results); |
| 2710 } | 2722 } |
| 2711 | 2723 |
| 2724 // Test that when Autocomplete is enabled and Autofill is disabled, | |
| 2725 // form submissions are still received by AutocompleteHistoryManager. | |
| 2726 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { | |
| 2727 TestAutofillManagerDelegate delegate; | |
| 2728 autofill_manager_.reset(new TestAutofillManager( | |
| 2729 autofill_driver_.get(), | |
| 2730 &delegate, | |
| 2731 NULL)); | |
| 2732 autofill_manager_->set_autofill_enabled(false); | |
| 2733 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | |
| 2734 autocomplete_history_manager.reset( | |
| 2735 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); | |
| 2736 autofill_manager_->autocomplete_history_manager_.reset( | |
| 2737 autocomplete_history_manager.get()); | |
|
Ilya Sherman
2013/06/19 23:19:55
Pretty sure this needs to be .Pass(), or else you'
sgurun-gerrit only
2013/06/20 15:18:44
You are right. thanks.
On 2013/06/19 23:19:55, Il
| |
| 2738 | |
| 2739 // Set up our form data. | |
| 2740 FormData form; | |
| 2741 CreateTestAddressFormData(&form); | |
| 2742 form.method = ASCIIToUTF16("GET"); | |
| 2743 FormSubmitted(form); | |
| 2744 EXPECT_CALL(*(autocomplete_history_manager.get()), | |
| 2745 OnFormSubmitted(_)).Times(1); | |
|
Ilya Sherman
2013/06/19 23:19:55
I'm pretty sure this is supposed to go *before* th
sgurun-gerrit only
2013/06/20 15:18:44
Done.
| |
| 2746 } | |
| 2747 | |
| 2748 // Test that when Autocomplete is enabled and Autofill is disabled, | |
| 2749 // Autocomplete suggestions are still received. | |
| 2750 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { | |
| 2751 TestAutofillManagerDelegate delegate; | |
| 2752 autofill_manager_.reset(new TestAutofillManager( | |
| 2753 autofill_driver_.get(), | |
| 2754 &delegate, | |
| 2755 NULL)); | |
| 2756 autofill_manager_->set_autofill_enabled(false); | |
| 2757 | |
| 2758 // Set up our form data. | |
| 2759 FormData form; | |
| 2760 CreateTestAddressFormData(&form); | |
| 2761 form.method = ASCIIToUTF16("GET"); | |
| 2762 std::vector<FormData> forms(1, form); | |
| 2763 FormsSeen(forms); | |
| 2764 const FormFieldData& field = form.fields[0]; | |
| 2765 GetAutofillSuggestions(form, field); | |
| 2766 | |
| 2767 // Add some Autocomplete suggestions. We should return the autocomplete | |
| 2768 // suggestions, these will be culled by the renderer. | |
| 2769 std::vector<base::string16> suggestions; | |
| 2770 suggestions.push_back(ASCIIToUTF16("Jay")); | |
| 2771 suggestions.push_back(ASCIIToUTF16("Jason")); | |
| 2772 AutocompleteSuggestionsReturned(suggestions); | |
| 2773 | |
| 2774 int page_id = 0; | |
| 2775 std::vector<base::string16> values; | |
| 2776 std::vector<base::string16> labels; | |
| 2777 std::vector<base::string16> icons; | |
| 2778 std::vector<int> unique_ids; | |
| 2779 EXPECT_TRUE(GetAutofillSuggestionsMessage(&page_id, &values, &labels, &icons, | |
| 2780 &unique_ids)); | |
| 2781 | |
| 2782 base::string16 expected_values[] = { | |
| 2783 ASCIIToUTF16("Jay"), | |
| 2784 ASCIIToUTF16("Jason") | |
| 2785 }; | |
| 2786 base::string16 expected_labels[] = { base::string16(), base::string16()}; | |
| 2787 base::string16 expected_icons[] = { base::string16(), base::string16()}; | |
| 2788 int expected_unique_ids[] = {0, 0}; | |
| 2789 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | |
| 2790 kDefaultPageID, arraysize(expected_values), expected_values, | |
| 2791 expected_labels, expected_icons, expected_unique_ids); | |
| 2792 } | |
| 2793 | |
| 2712 // Test that we are able to save form data when forms are submitted and we only | 2794 // Test that we are able to save form data when forms are submitted and we only |
| 2713 // have server data for the field types. | 2795 // have server data for the field types. |
| 2714 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { | 2796 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { |
| 2715 // Set up our form data. | 2797 // Set up our form data. |
| 2716 FormData form; | 2798 FormData form; |
| 2717 CreateTestAddressFormData(&form); | 2799 CreateTestAddressFormData(&form); |
| 2718 | 2800 |
| 2719 // Simulate having seen this form on page load. | 2801 // Simulate having seen this form on page load. |
| 2720 // |form_structure| will be owned by |autofill_manager_|. | 2802 // |form_structure| will be owned by |autofill_manager_|. |
| 2721 TestFormStructure* form_structure = new TestFormStructure(form); | 2803 TestFormStructure* form_structure = new TestFormStructure(form); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3284 CreateTestAddressFormData(&form); | 3366 CreateTestAddressFormData(&form); |
| 3285 std::vector<FormData> forms(1, form); | 3367 std::vector<FormData> forms(1, form); |
| 3286 FormsSeen(forms); | 3368 FormsSeen(forms); |
| 3287 const FormFieldData& field = form.fields[0]; | 3369 const FormFieldData& field = form.fields[0]; |
| 3288 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3370 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3289 | 3371 |
| 3290 autofill_manager_->SetExternalDelegate(NULL); | 3372 autofill_manager_->SetExternalDelegate(NULL); |
| 3291 } | 3373 } |
| 3292 | 3374 |
| 3293 } // namespace autofill | 3375 } // namespace autofill |
| OLD | NEW |