OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 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_ = |
| 2737 autocomplete_history_manager.Pass(); |
| 2738 |
| 2739 // Set up our form data. |
| 2740 FormData form; |
| 2741 CreateTestAddressFormData(&form); |
| 2742 form.method = ASCIIToUTF16("GET"); |
| 2743 MockAutocompleteHistoryManager* m = static_cast< |
| 2744 MockAutocompleteHistoryManager*>( |
| 2745 autofill_manager_->autocomplete_history_manager_.get()); |
| 2746 EXPECT_CALL(*m, |
| 2747 OnFormSubmitted(_)).Times(1); |
| 2748 FormSubmitted(form); |
| 2749 } |
| 2750 |
| 2751 // Test that when Autocomplete is enabled and Autofill is disabled, |
| 2752 // Autocomplete suggestions are still received. |
| 2753 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { |
| 2754 TestAutofillManagerDelegate delegate; |
| 2755 autofill_manager_.reset(new TestAutofillManager( |
| 2756 autofill_driver_.get(), |
| 2757 &delegate, |
| 2758 NULL)); |
| 2759 autofill_manager_->set_autofill_enabled(false); |
| 2760 |
| 2761 // Set up our form data. |
| 2762 FormData form; |
| 2763 CreateTestAddressFormData(&form); |
| 2764 form.method = ASCIIToUTF16("GET"); |
| 2765 std::vector<FormData> forms(1, form); |
| 2766 FormsSeen(forms); |
| 2767 const FormFieldData& field = form.fields[0]; |
| 2768 GetAutofillSuggestions(form, field); |
| 2769 |
| 2770 // Add some Autocomplete suggestions. We should return the autocomplete |
| 2771 // suggestions, these will be culled by the renderer. |
| 2772 std::vector<base::string16> suggestions; |
| 2773 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 2774 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 2775 AutocompleteSuggestionsReturned(suggestions); |
| 2776 |
| 2777 int page_id = 0; |
| 2778 std::vector<base::string16> values; |
| 2779 std::vector<base::string16> labels; |
| 2780 std::vector<base::string16> icons; |
| 2781 std::vector<int> unique_ids; |
| 2782 EXPECT_TRUE(GetAutofillSuggestionsMessage(&page_id, &values, &labels, &icons, |
| 2783 &unique_ids)); |
| 2784 |
| 2785 base::string16 expected_values[] = { |
| 2786 ASCIIToUTF16("Jay"), |
| 2787 ASCIIToUTF16("Jason") |
| 2788 }; |
| 2789 base::string16 expected_labels[] = { base::string16(), base::string16()}; |
| 2790 base::string16 expected_icons[] = { base::string16(), base::string16()}; |
| 2791 int expected_unique_ids[] = {0, 0}; |
| 2792 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 2793 kDefaultPageID, arraysize(expected_values), expected_values, |
| 2794 expected_labels, expected_icons, expected_unique_ids); |
| 2795 } |
| 2796 |
2712 // Test that we are able to save form data when forms are submitted and we only | 2797 // Test that we are able to save form data when forms are submitted and we only |
2713 // have server data for the field types. | 2798 // have server data for the field types. |
2714 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { | 2799 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { |
2715 // Set up our form data. | 2800 // Set up our form data. |
2716 FormData form; | 2801 FormData form; |
2717 CreateTestAddressFormData(&form); | 2802 CreateTestAddressFormData(&form); |
2718 | 2803 |
2719 // Simulate having seen this form on page load. | 2804 // Simulate having seen this form on page load. |
2720 // |form_structure| will be owned by |autofill_manager_|. | 2805 // |form_structure| will be owned by |autofill_manager_|. |
2721 TestFormStructure* form_structure = new TestFormStructure(form); | 2806 TestFormStructure* form_structure = new TestFormStructure(form); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3284 CreateTestAddressFormData(&form); | 3369 CreateTestAddressFormData(&form); |
3285 std::vector<FormData> forms(1, form); | 3370 std::vector<FormData> forms(1, form); |
3286 FormsSeen(forms); | 3371 FormsSeen(forms); |
3287 const FormFieldData& field = form.fields[0]; | 3372 const FormFieldData& field = form.fields[0]; |
3288 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3373 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3289 | 3374 |
3290 autofill_manager_->SetExternalDelegate(NULL); | 3375 autofill_manager_->SetExternalDelegate(NULL); |
3291 } | 3376 } |
3292 | 3377 |
3293 } // namespace autofill | 3378 } // namespace autofill |
OLD | NEW |