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

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: arrays... Created 4 years, 8 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 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);
1513 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1516 external_delegate_->CheckNoSuggestions(kDefaultPageID);
1514 } 1517 }
1515 1518
1516 // Test that we return all credit card suggestions in the case that two cards 1519 // Test that we return all credit card suggestions in the case that two cards
1517 // have the same obfuscated number. 1520 // have the same obfuscated number.
1518 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { 1521 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
1519 // Add a credit card with the same obfuscated number as Elvis's. 1522 // Add a credit card with the same obfuscated number as Elvis's.
1520 // |credit_card| will be owned by the mock PersonalDataManager. 1523 // |credit_card| will be owned by the mock PersonalDataManager.
1521 CreditCard* credit_card = new CreditCard; 1524 CreditCard* credit_card = new CreditCard;
1522 test::SetCreditCardInfo(credit_card, "Elvis Presley", 1525 test::SetCreditCardInfo(credit_card, "Elvis Presley",
1523 "5231567890123456", // Mastercard 1526 "5231567890123456", // Mastercard
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 // Test that we sent the right values to the external delegate. 1614 // Test that we sent the right values to the external delegate.
1612 external_delegate_->CheckSuggestions( 1615 external_delegate_->CheckSuggestions(
1613 kPageID2, 1616 kPageID2,
1614 Suggestion( 1617 Suggestion(
1615 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1618 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1616 "", "", -1)); 1619 "", "", -1));
1617 1620
1618 // Clear the test credit cards and try again -- we shouldn't return a warning. 1621 // Clear the test credit cards and try again -- we shouldn't return a warning.
1619 personal_data_.ClearCreditCards(); 1622 personal_data_.ClearCreditCards();
1620 GetAutofillSuggestions(form, field); 1623 GetAutofillSuggestions(form, field);
1621 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1624 external_delegate_->CheckNoSuggestions(kDefaultPageID);
1622 } 1625 }
1623 1626
1624 // Test that we return autocomplete-like suggestions when trying to autofill 1627 // Test that we return autocomplete-like suggestions when trying to autofill
1625 // already filled forms. 1628 // already filled forms.
1626 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { 1629 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) {
1627 // Set up our form data. 1630 // Set up our form data.
1628 FormData form; 1631 FormData form;
1629 test::CreateTestAddressFormData(&form); 1632 test::CreateTestAddressFormData(&form);
1630 std::vector<FormData> forms(1, form); 1633 std::vector<FormData> forms(1, form);
1631 FormsSeen(forms); 1634 FormsSeen(forms);
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3064 autofill_manager_->client())); 3067 autofill_manager_->client()));
3065 MockAutocompleteHistoryManager* m = static_cast< 3068 MockAutocompleteHistoryManager* m = static_cast<
3066 MockAutocompleteHistoryManager*>( 3069 MockAutocompleteHistoryManager*>(
3067 autofill_manager_->autocomplete_history_manager_.get()); 3070 autofill_manager_->autocomplete_history_manager_.get());
3068 EXPECT_CALL(*m, 3071 EXPECT_CALL(*m,
3069 OnGetAutocompleteSuggestions(_, _, _, _)); 3072 OnGetAutocompleteSuggestions(_, _, _, _));
3070 3073
3071 GetAutofillSuggestions(form, field); 3074 GetAutofillSuggestions(form, field);
3072 } 3075 }
3073 3076
3077 // Test that when Autofill is disabled and the field is a credit card field,
3078 // autocomplete is not queried for suggestions.
3079 TEST_F(AutofillManagerTest,
3080 AutocompleteSuggestions_CreditCardFieldShouldNotAutocomplete) {
3081 TestAutofillClient client;
3082 autofill_manager_.reset(
3083 new TestAutofillManager(autofill_driver_.get(), &client, NULL));
3084 autofill_manager_->set_autofill_enabled(false);
3085 autofill_manager_->SetExternalDelegate(external_delegate_.get());
3086
3087 // Set up our form data.
3088 FormData form;
3089 CreateTestCreditCardFormData(&form, false, false);
3090 std::vector<FormData> forms(1, form);
3091 FormsSeen(forms);
3092 FormFieldData field = form.fields[0];
3093 field.should_autocomplete = true;
3094
3095 // Autocomplete manager is not called for suggestions.
3096 autofill_manager_->autocomplete_history_manager_.reset(
3097 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
3098 MockAutocompleteHistoryManager* m =
3099 static_cast<MockAutocompleteHistoryManager*>(
3100 autofill_manager_->autocomplete_history_manager_.get());
3101 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0);
3102
3103 GetAutofillSuggestions(form, field);
3104 }
3105
3074 // Test that we do not query for Autocomplete suggestions when there are no 3106 // Test that we do not query for Autocomplete suggestions when there are no
3075 // Autofill suggestions available, and that the field should not autocomplete. 3107 // Autofill suggestions available, and that the field should not autocomplete.
3076 TEST_F( 3108 TEST_F(
3077 AutofillManagerTest, 3109 AutofillManagerTest,
3078 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) { 3110 AutocompleteSuggestions_NoneWhenAutofillEmptyFieldShouldNotAutocomplete) {
3079 // Set up our form data. 3111 // Set up our form data.
3080 FormData form; 3112 FormData form;
3081 test::CreateTestAddressFormData(&form); 3113 test::CreateTestAddressFormData(&form);
3082 std::vector<FormData> forms(1, form); 3114 std::vector<FormData> forms(1, form);
3083 FormsSeen(forms); 3115 FormsSeen(forms);
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
4784 // Set up our form data. 4816 // Set up our form data.
4785 FormData form; 4817 FormData form;
4786 CreateTestCreditCardFormData(&form, true, false); 4818 CreateTestCreditCardFormData(&form, true, false);
4787 std::vector<FormData> forms(1, form); 4819 std::vector<FormData> forms(1, form);
4788 FormsSeen(forms); 4820 FormsSeen(forms);
4789 4821
4790 FormFieldData field; 4822 FormFieldData field;
4791 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text", 4823 test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
4792 &field); 4824 &field);
4793 GetAutofillSuggestions(form, field); 4825 GetAutofillSuggestions(form, field);
4794 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 4826 external_delegate_->CheckNoSuggestions(kDefaultPageID);
4795 } 4827 }
4796 4828
4797 // Verify that typing "S" into the middle name field will match and order middle 4829 // 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 4830 // names "Shawn Smith" followed by "Adam Smith" i.e. prefix matched followed by
4799 // substring matched. 4831 // substring matched.
4800 TEST_F(AutofillManagerTest, 4832 TEST_F(AutofillManagerTest,
4801 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { 4833 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
4802 // Token matching is currently behind a flag. 4834 // Token matching is currently behind a flag.
4803 base::CommandLine::ForCurrentProcess()->AppendSwitch( 4835 base::CommandLine::ForCurrentProcess()->AppendSwitch(
4804 switches::kEnableSuggestionsWithSubstringMatch); 4836 switches::kEnableSuggestionsWithSubstringMatch);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 FormsSeen(mixed_forms); 4995 FormsSeen(mixed_forms);
4964 4996
4965 // Suggestions should always be displayed. 4997 // Suggestions should always be displayed.
4966 for (const FormFieldData& field : mixed_form.fields) { 4998 for (const FormFieldData& field : mixed_form.fields) {
4967 GetAutofillSuggestions(mixed_form, field); 4999 GetAutofillSuggestions(mixed_form, field);
4968 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 5000 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4969 } 5001 }
4970 } 5002 }
4971 5003
4972 } // namespace autofill 5004 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698