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

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

Issue 1920863006: [Autofill] Do not show Autocomplete suggestions for credit card fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no autocomplete on cc number, exp or cvc Created 4 years, 7 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
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 void CheckSuggestions(int expected_page_id, 687 void CheckSuggestions(int expected_page_id,
688 const Suggestion& suggestion0, 688 const Suggestion& suggestion0,
689 const Suggestion& suggestion1, 689 const Suggestion& suggestion1,
690 const Suggestion& suggestion2) { 690 const Suggestion& suggestion2) {
691 std::vector<Suggestion> suggestion_vector; 691 std::vector<Suggestion> suggestion_vector;
692 suggestion_vector.push_back(suggestion0); 692 suggestion_vector.push_back(suggestion0);
693 suggestion_vector.push_back(suggestion1); 693 suggestion_vector.push_back(suggestion1);
694 suggestion_vector.push_back(suggestion2); 694 suggestion_vector.push_back(suggestion2);
695 CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]); 695 CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]);
696 } 696 }
697 697 void CheckNoSuggestions(int expected_page_id) {
698 EXPECT_TRUE(on_suggestions_returned_seen());
699 CheckSuggestions(expected_page_id, 0, nullptr);
700 }
698 701
699 bool on_query_seen() const { 702 bool on_query_seen() const {
700 return on_query_seen_; 703 return on_query_seen_;
701 } 704 }
702 705
703 bool on_suggestions_returned_seen() const { 706 bool on_suggestions_returned_seen() const {
704 return on_suggestions_returned_seen_; 707 return on_suggestions_returned_seen_;
705 } 708 }
706 709
707 private: 710 private:
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 // Test that we sent the right values to the external delegate. 1506 // Test that we sent the right values to the external delegate.
1504 external_delegate_->CheckSuggestions( 1507 external_delegate_->CheckSuggestions(
1505 kDefaultPageID, 1508 kDefaultPageID,
1506 Suggestion( 1509 Suggestion(
1507 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1510 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1508 "", "", -1)); 1511 "", "", -1));
1509 1512
1510 // Clear the test credit cards and try again -- we shouldn't return a warning. 1513 // Clear the test credit cards and try again -- we shouldn't return a warning.
1511 personal_data_.ClearCreditCards(); 1514 personal_data_.ClearCreditCards();
1512 GetAutofillSuggestions(form, field); 1515 GetAutofillSuggestions(form, field);
1516 // Autocomplete suggestions are queried, but not Autofill.
1513 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1517 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
1514 } 1518 }
1515 1519
1516 // Test that we return all credit card suggestions in the case that two cards 1520 // Test that we return all credit card suggestions in the case that two cards
1517 // have the same obfuscated number. 1521 // have the same obfuscated number.
1518 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { 1522 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
1519 // Add a credit card with the same obfuscated number as Elvis's. 1523 // Add a credit card with the same obfuscated number as Elvis's.
1520 // |credit_card| will be owned by the mock PersonalDataManager. 1524 // |credit_card| will be owned by the mock PersonalDataManager.
1521 CreditCard* credit_card = new CreditCard; 1525 CreditCard* credit_card = new CreditCard;
1522 test::SetCreditCardInfo(credit_card, "Elvis Presley", 1526 test::SetCreditCardInfo(credit_card, "Elvis Presley",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 // Test that we sent the right values to the external delegate. 1615 // Test that we sent the right values to the external delegate.
1612 external_delegate_->CheckSuggestions( 1616 external_delegate_->CheckSuggestions(
1613 kPageID2, 1617 kPageID2,
1614 Suggestion( 1618 Suggestion(
1615 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1619 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1616 "", "", -1)); 1620 "", "", -1));
1617 1621
1618 // Clear the test credit cards and try again -- we shouldn't return a warning. 1622 // Clear the test credit cards and try again -- we shouldn't return a warning.
1619 personal_data_.ClearCreditCards(); 1623 personal_data_.ClearCreditCards();
1620 GetAutofillSuggestions(form, field); 1624 GetAutofillSuggestions(form, field);
1621 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1625 external_delegate_->CheckNoSuggestions(kDefaultPageID);
1622 } 1626 }
1623 1627
1624 // Test that we return autocomplete-like suggestions when trying to autofill 1628 // Test that we return autocomplete-like suggestions when trying to autofill
1625 // already filled forms. 1629 // already filled forms.
1626 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { 1630 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) {
1627 // Set up our form data. 1631 // Set up our form data.
1628 FormData form; 1632 FormData form;
1629 test::CreateTestAddressFormData(&form); 1633 test::CreateTestAddressFormData(&form);
1630 std::vector<FormData> forms(1, form); 1634 std::vector<FormData> forms(1, form);
1631 FormsSeen(forms); 1635 FormsSeen(forms);
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3064 autofill_manager_->client())); 3068 autofill_manager_->client()));
3065 MockAutocompleteHistoryManager* m = static_cast< 3069 MockAutocompleteHistoryManager* m = static_cast<
3066 MockAutocompleteHistoryManager*>( 3070 MockAutocompleteHistoryManager*>(
3067 autofill_manager_->autocomplete_history_manager_.get()); 3071 autofill_manager_->autocomplete_history_manager_.get());
3068 EXPECT_CALL(*m, 3072 EXPECT_CALL(*m,
3069 OnGetAutocompleteSuggestions(_, _, _, _)); 3073 OnGetAutocompleteSuggestions(_, _, _, _));
3070 3074
3071 GetAutofillSuggestions(form, field); 3075 GetAutofillSuggestions(form, field);
3072 } 3076 }
3073 3077
3078 // Test that when Autofill is disabled and the field is a credit card name
3079 // field,
3080 // autocomplete is queried for suggestions.
3081 TEST_F(AutofillManagerTest,
3082 AutocompleteSuggestions_CreditCardNameFieldShouldAutocomplete) {
3083 TestAutofillClient client;
3084 autofill_manager_.reset(
3085 new TestAutofillManager(autofill_driver_.get(), &client, NULL));
3086 autofill_manager_->set_autofill_enabled(false);
3087 autofill_manager_->SetExternalDelegate(external_delegate_.get());
3088
3089 // Set up our form data.
3090 FormData form;
3091 CreateTestCreditCardFormData(&form, false, false);
3092 std::vector<FormData> forms(1, form);
3093 FormsSeen(forms);
3094 // The first field is "Name on card", which should autocomplete.
3095 FormFieldData field = form.fields[0];
3096 field.should_autocomplete = true;
3097
3098 // Autocomplete manager is not called for suggestions.
3099 autofill_manager_->autocomplete_history_manager_.reset(
3100 new MockAutocompleteHistoryManager(autofill_driver_.get(),
3101 autofill_manager_->client()));
3102 MockAutocompleteHistoryManager* m =
3103 static_cast<MockAutocompleteHistoryManager*>(
3104 autofill_manager_->autocomplete_history_manager_.get());
3105 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _));
3106
3107 GetAutofillSuggestions(form, field);
3108 }
3109
3110 // Test that when Autofill is disabled and the field is a credit card number
3111 // field, autocomplete is not queried for suggestions.
3112 TEST_F(AutofillManagerTest,
3113 AutocompleteSuggestions_CreditCardNumberShouldNotAutocomplete) {
3114 TestAutofillClient client;
3115 autofill_manager_.reset(
3116 new TestAutofillManager(autofill_driver_.get(), &client, NULL));
3117 autofill_manager_->set_autofill_enabled(false);
3118 autofill_manager_->SetExternalDelegate(external_delegate_.get());
3119
3120 // Set up our form data.
3121 FormData form;
3122 CreateTestCreditCardFormData(&form, false, false);
3123 std::vector<FormData> forms(1, form);
3124 FormsSeen(forms);
3125 // The second field is "Card Number", which should not autocomplete.
3126 FormFieldData field = form.fields[1];
3127 field.should_autocomplete = true;
3128
3129 // Autocomplete manager is not called for suggestions.
3130 autofill_manager_->autocomplete_history_manager_.reset(
3131 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
3132 MockAutocompleteHistoryManager* m =
3133 static_cast<MockAutocompleteHistoryManager*>(
3134 autofill_manager_->autocomplete_history_manager_.get());
3135 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0);
3136
3137 GetAutofillSuggestions(form, field);
3138 }
3139
3074 // Test that we do not query for Autocomplete suggestions when there are no 3140 // Test that we do not query for Autocomplete suggestions when there are no
3075 // Autofill suggestions available, and that the field should not autocomplete. 3141 // Autofill suggestions available, and that the field should not autocomplete.
3076 TEST_F( 3142 TEST_F(
3077 AutofillManagerTest, 3143 AutofillManagerTest,
3078 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) { 3144 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) {
3079 // Set up our form data. 3145 // Set up our form data.
3080 FormData form; 3146 FormData form;
3081 test::CreateTestAddressFormData(&form); 3147 test::CreateTestAddressFormData(&form);
3082 std::vector<FormData> forms(1, form); 3148 std::vector<FormData> forms(1, form);
3083 FormsSeen(forms); 3149 FormsSeen(forms);
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
4784 // Set up our form data. 4850 // Set up our form data.
4785 FormData form; 4851 FormData form;
4786 CreateTestCreditCardFormData(&form, true, false); 4852 CreateTestCreditCardFormData(&form, true, false);
4787 std::vector<FormData> forms(1, form); 4853 std::vector<FormData> forms(1, form);
4788 FormsSeen(forms); 4854 FormsSeen(forms);
4789 4855
4790 FormFieldData field; 4856 FormFieldData field;
4791 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", 4857 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
4792 &field); 4858 &field);
4793 GetAutofillSuggestions(form, field); 4859 GetAutofillSuggestions(form, field);
4860 // Autocomplete suggestions are queried, but not Autofill.
4794 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 4861 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
4795 } 4862 }
4796 4863
4797 // Verify that typing "S" into the middle name field will match and order middle 4864 // Verify that typing "S" into the middle name field will match and order middle
4798 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by 4865 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by
4799 // substring matched. 4866 // substring matched.
4800 TEST_F(AutofillManagerTest, 4867 TEST_F(AutofillManagerTest,
4801 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { 4868 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
4802 // Token matching is currently behind a flag. 4869 // Token matching is currently behind a flag.
4803 base::CommandLine::ForCurrentProcess()->AppendSwitch( 4870 base::CommandLine::ForCurrentProcess()->AppendSwitch(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 FormsSeen(mixed_forms); 5030 FormsSeen(mixed_forms);
4964 5031
4965 // Suggestions should always be displayed. 5032 // Suggestions should always be displayed.
4966 for (const FormFieldData& field : mixed_form.fields) { 5033 for (const FormFieldData& field : mixed_form.fields) {
4967 GetAutofillSuggestions(mixed_form, field); 5034 GetAutofillSuggestions(mixed_form, field);
4968 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 5035 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4969 } 5036 }
4970 } 5037 }
4971 5038
4972 } // namespace autofill 5039 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698