Commit 504d780c authored by pritam.nikam's avatar pritam.nikam Committed by Commit bot

[Autofill] Autofill fails to show suggestions for suggested input for forms...

[Autofill] Autofill fails to show suggestions for suggested input for forms having credit card number split across multiple fields.

BUG=420323

Review URL: https://codereview.chromium.org/622773002

Cr-Commit-Position: refs/heads/master@{#302703}
parent e201af8f
......@@ -15,6 +15,7 @@
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
......@@ -898,7 +899,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
FormsSeen(forms);
FormFieldData field;
test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field);
test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field);
GetAutofillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
......@@ -2988,4 +2989,67 @@ TEST_F(AutofillManagerTest, TestExternalDelegate) {
EXPECT_TRUE(external_delegate_->on_query_seen());
}
// Test to verify suggestions appears for forms having credit card number split
// across fields.
TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) {
// Set up our form data with credit card number split across fields.
FormData form;
form.name = ASCIIToUTF16("MyForm");
form.origin = GURL("https://myform.com/form.html");
form.action = GURL("https://myform.com/submit.html");
form.user_submitted = true;
FormFieldData name_field;
test::CreateTestFormField("Name on Card", "nameoncard", "", "text",
&name_field);
form.fields.push_back(name_field);
// Add new 4 |card_number_field|s to the |form|.
FormFieldData card_number_field;
card_number_field.max_length = 4;
test::CreateTestFormField("Card Number", "cardnumber_1", "", "text",
&card_number_field);
form.fields.push_back(card_number_field);
test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field);
form.fields.push_back(card_number_field);
test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field);
form.fields.push_back(card_number_field);
test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field);
form.fields.push_back(card_number_field);
FormFieldData exp_field;
test::CreateTestFormField("Expiration Date", "ccmonth", "", "text",
&exp_field);
form.fields.push_back(exp_field);
test::CreateTestFormField("", "ccyear", "", "text", &exp_field);
form.fields.push_back(exp_field);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
// Verify whether suggestions are populated correctly for one of the middle
// credit card number fields when filled partially.
FormFieldData number_field = form.fields[3];
number_field.value = ASCIIToUTF16("901");
// Get the suggestions for already filled credit card |number_field|.
GetAutofillSuggestions(form, number_field);
// No autocomplete suggestions provided, so send an empty vector as the
// results. This triggers the combined message send.
AutocompleteSuggestionsReturned(std::vector<base::string16>());
base::string16 expected_values[] = {ASCIIToUTF16("************3456")};
base::string16 expected_labels[] = {ASCIIToUTF16("04/12")};
base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)};
int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)};
external_delegate_->CheckSuggestions(
kDefaultPageID, arraysize(expected_values), expected_values,
expected_labels, expected_icons, expected_unique_ids);
}
} // namespace autofill
......@@ -673,15 +673,16 @@ void PersonalDataManager::GetCreditCardSuggestions(
base::string16 creditcard_field_value =
credit_card->GetInfo(type, app_locale_);
if (!creditcard_field_value.empty() &&
StartsWith(creditcard_field_value, field_contents, false)) {
if (type.GetStorableType() == CREDIT_CARD_NUMBER)
creditcard_field_value = credit_card->ObfuscatedNumber();
(StartsWith(creditcard_field_value, field_contents, false) ||
(type.GetStorableType() == CREDIT_CARD_NUMBER &&
base::string16::npos !=
creditcard_field_value.find(field_contents)))) {
// If the value is the card number, the label is the expiration date.
// Otherwise the label is the card number, or if that is empty the
// cardholder name. The label should never repeat the value.
base::string16 label;
if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
creditcard_field_value = credit_card->ObfuscatedNumber();
label = credit_card->GetInfo(
AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_);
} else if (credit_card->number().empty()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment