Commit 8474014d authored by ziran.sun@samsung.com's avatar ziran.sun@samsung.com

Do not autofill element when there is no autofill suggestion from profile.

R=isherman@chromium.org
BUG=377705

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275417 0039d316-1c4b-4281-b951-d872f2087c98
parent 2b9e772c
......@@ -80,6 +80,10 @@ static const char kFormHtml[] =
" <OPTION value=\"CA\" selected>California</OPTION>"
" <OPTION value=\"TX\">Texas</OPTION>"
" </SELECT>"
" <SELECT id=\"select-unchanged\">"
" <OPTION value=\"CA\" selected>California</OPTION>"
" <OPTION value=\"TX\">Texas</OPTION>"
" </SELECT>"
" <TEXTAREA id=\"textarea\"></TEXTAREA>"
" <TEXTAREA id=\"textarea-nonempty\">Go&#10;away!</TEXTAREA>"
" <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
......@@ -215,6 +219,8 @@ class FormAutofillTest : public ChromeRenderViewTest {
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]);
// Fill the form_data for the field.
form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value);
// Set the is_autofilled property for the field.
form_data.fields[i].is_autofilled = field_cases[i].should_be_autofilled;
}
// Autofill the form using the given fill form function.
......@@ -1352,6 +1358,9 @@ TEST_F(FormAutofillTest, FillForm) {
// Select fields should be autofilled even if they already have a
// non-empty value.
{"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
// Select fields should not be autofilled if no new value is passed from
// autofill profile. The existing value should not be overriden.
{"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
// Regular textarea elements should be autofilled.
{"textarea", "textarea", "", "", true, "some multi-\nline value",
"some multi-\nline value"},
......@@ -1401,6 +1410,9 @@ TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) {
// Select fields should be autofilled even if they already have a
// non-empty value.
{"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
// Select fields should not be autofilled if no new value is passed from
// autofill profile. The existing value should not be overriden.
{"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
// Regular textarea elements should be autofilled.
{"textarea", "textarea", "", "", true, "some multi-\nline value",
"some multi-\nline value"},
......@@ -1443,6 +1455,9 @@ TEST_F(FormAutofillTest, PreviewForm) {
// Select fields should be previewed even if they already have a
// non-empty value.
{"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
// Select fields should not be previewed if no suggestion is passed from
// autofill profile.
{"select-one", "select-unchanged", "CA", "", false, "", ""},
// Normal textarea elements should be previewed.
{"textarea", "textarea", "", "", true, "suggested multi-\nline value",
"suggested multi-\nline value"},
......@@ -2376,6 +2391,9 @@ TEST_F(FormAutofillTest, FillFormMaxLength) {
form.fields[0].value = ASCIIToUTF16("Brother");
form.fields[1].value = ASCIIToUTF16("Jonathan");
form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
form.fields[0].is_autofilled = true;
form.fields[1].is_autofilled = true;
form.fields[2].is_autofilled = true;
FillForm(form, input_element);
// Find the newly-filled form that contains the input element.
......@@ -2642,6 +2660,9 @@ TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
form.fields[0].value = ASCIIToUTF16("Red");
form.fields[1].value = ASCIIToUTF16("Yellow");
form.fields[2].value = ASCIIToUTF16("Also Yellow");
form.fields[0].is_autofilled = true;
form.fields[1].is_autofilled = true;
form.fields[2].is_autofilled = true;
FillForm(form, input_element);
// Find the newly-filled form that contains the input element.
......@@ -2868,6 +2889,9 @@ TEST_F(FormAutofillTest, FillFormNonEmptyField) {
form.fields[0].value = ASCIIToUTF16("Wyatt");
form.fields[1].value = ASCIIToUTF16("Earp");
form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
form.fields[0].is_autofilled = true;
form.fields[1].is_autofilled = true;
form.fields[2].is_autofilled = true;
PreviewForm(form, input_element);
EXPECT_EQ(2, input_element.selectionStart());
EXPECT_EQ(5, input_element.selectionEnd());
......
......@@ -76,11 +76,20 @@ void RequestAutocompleteManager::ReturnAutocompleteResult(
if (!host)
return;
FormData form_data;
if (form_structure) {
form_data = form_structure->ToFormData();
for (size_t i = 0; i < form_data.fields.size(); ++i) {
if(!form_data.fields[i].value.empty())
form_data.fields[i].is_autofilled = true;
}
}
host->Send(new AutofillMsg_RequestAutocompleteResult(
host->GetRoutingID(),
ToWebkitAutocompleteResult(result),
debug_message,
form_structure ? form_structure->ToFormData() : FormData()));
form_data));
}
void RequestAutocompleteManager::ShowRequestAutocompleteDialog(
......
......@@ -537,6 +537,9 @@ void FillFormField(const FormFieldData& data,
if (data.value.empty())
return;
if (!data.is_autofilled)
return;
field->setAutofilled(true);
WebInputElement* input_element = toWebInputElement(field);
......@@ -571,6 +574,9 @@ void PreviewFormField(const FormFieldData& data,
if (data.value.empty())
return;
if (!data.is_autofilled)
return;
// Preview input, textarea and select fields. For input fields, excludes
// checkboxes and radio buttons, as there is no provision for
// setSuggestedCheckedValue in WebInputElement.
......
......@@ -623,6 +623,11 @@ void AutofillManager::FillOrPreviewForm(
// user edits an autofilled field (for metrics).
form_structure->field(i)->is_autofilled = true;
// Mark the field as autofilled when a non-empty value is assigned to
// it. This allows the renderer to distinguish autofilled fields from
// fields with non-empty values, such as select-one fields.
result.fields[i].is_autofilled = true;
if (should_notify)
manager_delegate_->DidFillOrPreviewField(value, profile_full_name);
}
......
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