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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_manager_unittest.cc
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index 56af1b9f0176d839d25b90c67aa4635aa4567a91..de1dc12dbc105edb067f7ed0166c852b4fdcecc6 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -694,7 +694,10 @@ class TestAutofillExternalDelegate : public AutofillExternalDelegate {
suggestion_vector.push_back(suggestion2);
CheckSuggestions(expected_page_id, 3, &suggestion_vector[0]);
}
-
+ void CheckNoSuggestions(int expected_page_id) {
+ EXPECT_TRUE(on_suggestions_returned_seen());
+ CheckSuggestions(expected_page_id, 0, nullptr);
+ }
bool on_query_seen() const {
return on_query_seen_;
@@ -1510,6 +1513,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
// Clear the test credit cards and try again -- we shouldn't return a warning.
personal_data_.ClearCreditCards();
GetAutofillSuggestions(form, field);
+ // Autocomplete suggestions are queried, but not Autofill.
EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
}
@@ -1618,7 +1622,7 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
// Clear the test credit cards and try again -- we shouldn't return a warning.
personal_data_.ClearCreditCards();
GetAutofillSuggestions(form, field);
- EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
+ external_delegate_->CheckNoSuggestions(kDefaultPageID);
}
// Test that we return autocomplete-like suggestions when trying to autofill
@@ -3071,6 +3075,68 @@ TEST_F(AutofillManagerTest, AutocompleteSuggestions_SomeWhenAutofillEmpty) {
GetAutofillSuggestions(form, field);
}
+// Test that when Autofill is disabled and the field is a credit card name
+// field,
+// autocomplete is queried for suggestions.
+TEST_F(AutofillManagerTest,
+ AutocompleteSuggestions_CreditCardNameFieldShouldAutocomplete) {
+ TestAutofillClient client;
+ autofill_manager_.reset(
+ new TestAutofillManager(autofill_driver_.get(), &client, NULL));
+ autofill_manager_->set_autofill_enabled(false);
+ autofill_manager_->SetExternalDelegate(external_delegate_.get());
+
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, false, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+ // The first field is "Name on card", which should autocomplete.
+ FormFieldData field = form.fields[0];
+ field.should_autocomplete = true;
+
+ // Autocomplete manager is not called for suggestions.
+ autofill_manager_->autocomplete_history_manager_.reset(
+ new MockAutocompleteHistoryManager(autofill_driver_.get(),
+ autofill_manager_->client()));
+ MockAutocompleteHistoryManager* m =
+ static_cast<MockAutocompleteHistoryManager*>(
+ autofill_manager_->autocomplete_history_manager_.get());
+ EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _));
+
+ GetAutofillSuggestions(form, field);
+}
+
+// Test that when Autofill is disabled and the field is a credit card number
+// field, autocomplete is not queried for suggestions.
+TEST_F(AutofillManagerTest,
+ AutocompleteSuggestions_CreditCardNumberShouldNotAutocomplete) {
+ TestAutofillClient client;
+ autofill_manager_.reset(
+ new TestAutofillManager(autofill_driver_.get(), &client, NULL));
+ autofill_manager_->set_autofill_enabled(false);
+ autofill_manager_->SetExternalDelegate(external_delegate_.get());
+
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, false, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+ // The second field is "Card Number", which should not autocomplete.
+ FormFieldData field = form.fields[1];
+ field.should_autocomplete = true;
+
+ // Autocomplete manager is not called for suggestions.
+ autofill_manager_->autocomplete_history_manager_.reset(
+ new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
+ MockAutocompleteHistoryManager* m =
+ static_cast<MockAutocompleteHistoryManager*>(
+ autofill_manager_->autocomplete_history_manager_.get());
+ EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0);
+
+ GetAutofillSuggestions(form, field);
+}
+
// Test that we do not query for Autocomplete suggestions when there are no
// Autofill suggestions available, and that the field should not autocomplete.
TEST_F(
@@ -4791,6 +4857,7 @@ TEST_F(AutofillManagerTest, NoCreditCardSuggestionsForNonPrefixTokenMatch) {
test::CreateTestFormField("Name on Card", "nameoncard", "lvis", "text",
&field);
GetAutofillSuggestions(form, field);
+ // Autocomplete suggestions are queried, but not Autofill.
EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
}
« 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