Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: components/autofill/browser/autofill_manager_unittest.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: rebased for IPC changes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 form_submissions(0) { }
Ilya Sherman 2013/06/19 00:38:27 nit: No space between the curlies.
sgurun-gerrit only 2013/06/19 17:56:23 Done.
489
490 void OnFormSubmitted(const FormData& form) {
Ilya Sherman 2013/06/19 00:38:27 nit: virtual, OVERRIDE
Ilya Sherman 2013/06/19 00:38:27 nit: This seems like a good function to just mock
sgurun-gerrit only 2013/06/19 17:56:23 Done.
sgurun-gerrit only 2013/06/19 17:56:23 Done.
491 form_submissions++;
Ilya Sherman 2013/06/19 00:38:27 nit: ++form_submissions;
sgurun-gerrit only 2013/06/19 17:56:23 Done.
492 }
Ilya Sherman 2013/06/19 00:38:27 nit: Leave a blank line below this one.
sgurun-gerrit only 2013/06/19 17:56:23 Done.
493 int get_form_submissions() {
494 return form_submissions;
495 }
Ilya Sherman 2013/06/19 00:38:27 nit: Leave a blank line below this one.
sgurun-gerrit only 2013/06/19 17:56:23 Done.
496 private:
497 int form_submissions;
498 };
499
483 class TestAutofillManager : public AutofillManager { 500 class TestAutofillManager : public AutofillManager {
484 public: 501 public:
485 TestAutofillManager(AutofillDriver* driver, 502 TestAutofillManager(AutofillDriver* driver,
486 autofill::AutofillManagerDelegate* delegate, 503 autofill::AutofillManagerDelegate* delegate,
487 TestPersonalDataManager* personal_data) 504 TestPersonalDataManager* personal_data)
488 : AutofillManager(driver, delegate, personal_data), 505 : AutofillManager(driver, delegate, personal_data),
489 personal_data_(personal_data), 506 personal_data_(personal_data),
490 autofill_enabled_(true) {} 507 autofill_enabled_(true) {}
491 virtual ~TestAutofillManager() {} 508 virtual ~TestAutofillManager() {}
492 509
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 false); 713 false);
697 } 714 }
698 715
699 void GetAutofillSuggestions(const FormData& form, 716 void GetAutofillSuggestions(const FormData& form,
700 const FormFieldData& field) { 717 const FormFieldData& field) {
701 GetAutofillSuggestions(kDefaultPageID, form, field); 718 GetAutofillSuggestions(kDefaultPageID, form, field);
702 } 719 }
703 720
704 void AutocompleteSuggestionsReturned( 721 void AutocompleteSuggestionsReturned(
705 const std::vector<base::string16>& result) { 722 const std::vector<base::string16>& result) {
706 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); 723 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result);
707 } 724 }
708 725
709 void FormsSeen(const std::vector<FormData>& forms) { 726 void FormsSeen(const std::vector<FormData>& forms) {
710 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), 727 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
711 autofill::NO_SPECIAL_FORMS_SEEN); 728 autofill::NO_SPECIAL_FORMS_SEEN);
712 } 729 }
713 730
714 void PartialFormsSeen(const std::vector<FormData>& forms) { 731 void PartialFormsSeen(const std::vector<FormData>& forms) {
715 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), 732 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
716 autofill::PARTIAL_FORMS_SEEN); 733 autofill::PARTIAL_FORMS_SEEN);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 *page_id = autofill_param.a; 772 *page_id = autofill_param.a;
756 if (values) 773 if (values)
757 *values = autofill_param.b; 774 *values = autofill_param.b;
758 if (labels) 775 if (labels)
759 *labels = autofill_param.c; 776 *labels = autofill_param.c;
760 if (icons) 777 if (icons)
761 *icons = autofill_param.d; 778 *icons = autofill_param.d;
762 if (unique_ids) 779 if (unique_ids)
763 *unique_ids = autofill_param.e; 780 *unique_ids = autofill_param.e;
764 781
765 autofill_manager_->autocomplete_history_manager_.CancelPendingQuery(); 782 autofill_manager_->autocomplete_history_manager_->CancelPendingQuery();
766 process()->sink().ClearMessages(); 783 process()->sink().ClearMessages();
767 return true; 784 return true;
768 } 785 }
769 786
770 bool HasSeenAutofillGetAllFormsMessage() { 787 bool HasSeenAutofillGetAllFormsMessage() {
771 const uint32 kMsgID = AutofillMsg_GetAllForms::ID; 788 const uint32 kMsgID = AutofillMsg_GetAllForms::ID;
772 const IPC::Message* message = 789 const IPC::Message* message =
773 process()->sink().GetFirstMessageMatching(kMsgID); 790 process()->sink().GetFirstMessageMatching(kMsgID);
774 return message != NULL; 791 return message != NULL;
775 } 792 }
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 FormData results; 2719 FormData results;
2703 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); 2720 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results));
2704 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); 2721 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
2705 2722
2706 // Simulate form submission. We should call into the PDM to try to save the 2723 // Simulate form submission. We should call into the PDM to try to save the
2707 // filled data. 2724 // filled data.
2708 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); 2725 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1);
2709 FormSubmitted(results); 2726 FormSubmitted(results);
2710 } 2727 }
2711 2728
2729 // Test that when Autocomplete is enabled and Autofill is disabled,
2730 // form submissions are still received by AutocompleteHistoryManager.
2731 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) {
2732 TestAutofillManagerDelegate delegate;
2733 autofill_manager_.reset(new TestAutofillManager(
2734 autofill_driver_.get(),
2735 &delegate,
2736 NULL));
2737 autofill_manager_->set_autofill_enabled(false);
2738 MockAutocompleteHistoryManager* mock_autocomplete_history_manager =
2739 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate);
Ilya Sherman 2013/06/19 00:38:27 nit: Please declare this as a scoped_ptr.
sgurun-gerrit only 2013/06/19 17:56:23 Done.
2740 autofill_manager_->autocomplete_history_manager_.reset(
2741 mock_autocomplete_history_manager);
2742
2743 // Set up our form data.
2744 FormData form;
2745 CreateTestAddressFormData(&form);
2746 form.method = ASCIIToUTF16("GET");
2747 FormSubmitted(form);
2748 EXPECT_EQ(1, mock_autocomplete_history_manager->get_form_submissions());
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698