Index: chrome/renderer/autofill/form_autofill_browsertest.cc |
diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc |
index 7d5e4db39ce98372bde73f8605d6848a505d1c33..31ce3b89d7e4699e7788a5e892e4e4bd9a2e8594 100644 |
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc |
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc |
@@ -51,7 +51,8 @@ struct AutofillFieldCase { |
const char* const initial_value; |
const char* const autocomplete_attribute; // The autocomplete attribute of |
// the element. |
- bool should_be_autofilled; // Whether the filed should be autofilled. |
+ bool is_autofilled; // Whether the FormFieldData field is autofilled. |
+ bool should_be_autofilled; // Whether the filed should be autofilled. |
const char* const autofill_value; // The value being used to fill the field. |
const char* const expected_value; // The expected value after Autofill |
// or Preview. |
@@ -80,6 +81,10 @@ static const char kFormHtml[] = |
" <OPTION value=\"CA\" selected>California</OPTION>" |
" <OPTION value=\"TX\">Texas</OPTION>" |
" </SELECT>" |
+ " <SELECT id=\"select-nonewsuggestion\">" |
+ " <OPTION value=\"CA\" selected>California</OPTION>" |
+ " <OPTION value=\"TX\">Texas</OPTION>" |
+ " </SELECT>" |
" <TEXTAREA id=\"textarea\"></TEXTAREA>" |
" <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>" |
" <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
@@ -215,6 +220,10 @@ 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 "select-one" field. |
+ std::string form_control_type = field_cases[i].form_control_type; |
+ if (form_control_type == "select-one") |
+ form_data.fields[i].is_autofilled = field_cases[i].is_autofilled; |
} |
// Autofill the form using the given fill form function. |
@@ -1328,35 +1337,41 @@ TEST_F(FormAutofillTest, FillForm) { |
// should_be_autofilled, autofill_value, expected_value |
// Regular empty fields (firstname & lastname) should be autofilled. |
- {"text", "firstname", "", "", true, "filled firstname", |
+ {"text", "firstname", "", "", false, true, "filled firstname", |
"filled firstname"}, |
- {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
+ {"text", "lastname", "", "", false, true, "filled lastname", |
+ "filled lastname"}, |
// hidden fields should not be extracted to form_data. |
// Non empty fields should not be autofilled. |
- {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, |
+ {"text", "notempty", "Hi", "", false, false, "filled notempty", "Hi"}, |
// "noautocomplete" should not be extracted to form_data. |
// Disabled fields should not be autofilled. |
- {"text", "notenabled", "", "", false, "filled notenabled", ""}, |
+ {"text", "notenabled", "", "", false, false, "filled notenabled", ""}, |
// Readonly fields should not be autofilled. |
- {"text", "readonly", "", "", false, "filled readonly", ""}, |
+ {"text", "readonly", "", "", false, false, "filled readonly", ""}, |
// Fields with "visibility: hidden" should not be autofilled. |
- {"text", "invisible", "", "", false, "filled invisible", ""}, |
+ {"text", "invisible", "", "", false, false, "filled invisible", ""}, |
// Fields with "display:none" should not be autofilled. |
- {"text", "displaynone", "", "", false, "filled displaynone", ""}, |
+ {"text", "displaynone", "", "", false, false, "filled displaynone", ""}, |
// Regular <input type="month"> should be autofilled. |
- {"month", "month", "", "", true, "2017-11", "2017-11"}, |
+ {"month", "month", "", "", false, true, "2017-11", "2017-11"}, |
// Non-empty <input type="month"> should not be autofilled. |
- {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, |
+ {"month", "month-nonempty", "2011-12", "", false, false, "2017-11", |
+ "2011-12"}, |
// Regular select fields should be autofilled. |
- {"select-one", "select", "", "", true, "TX", "TX"}, |
+ {"select-one", "select", "", "", true, true, "TX", "TX"}, |
// Select fields should be autofilled even if they already have a |
// non-empty value. |
- {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, |
+ {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
+ // Select fields should be autofilled with the existing value if |
+ // no new value is passed from autofill profile. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, true, "CA", |
+ "CA"}, |
// Regular textarea elements should be autofilled. |
- {"textarea", "textarea", "", "", true, "some multi-\nline value", |
+ {"textarea", "textarea", "", "", false, true, "some multi-\nline value", |
"some multi-\nline value"}, |
// Non-empty textarea elements should not be autofilled. |
- {"textarea", "textarea-nonempty", "Go\naway!", "", false, |
+ {"textarea", "textarea-nonempty", "Go\naway!", "", false, false, |
"some multi-\nline value", "Go\naway!"}, |
}; |
TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
@@ -1374,38 +1389,44 @@ TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
// should_be_autofilled, autofill_value, expected_value |
// Regular empty fields (firstname & lastname) should be autofilled. |
- {"text", "firstname", "", "", true, "filled firstname", |
+ {"text", "firstname", "", "", false, true, "filled firstname", |
"filled firstname"}, |
- {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
+ {"text", "lastname", "", "", false, true, "filled lastname", |
+ "filled lastname"}, |
// hidden fields should not be extracted to form_data. |
// Non empty fields should be overriden. |
- {"text", "notempty", "Hi", "", true, "filled notempty", |
+ {"text", "notempty", "Hi", "", false, true, "filled notempty", |
"filled notempty"}, |
// "noautocomplete" should not be extracted to form_data. |
// Disabled fields should not be autofilled. |
- {"text", "notenabled", "", "", false, "filled notenabled", ""}, |
+ {"text", "notenabled", "", "", false, false, "filled notenabled", ""}, |
// Readonly fields should not be autofilled. |
- {"text", "readonly", "", "", false, "filled readonly", ""}, |
+ {"text", "readonly", "", "", false, false, "filled readonly", ""}, |
// Fields with "visibility: hidden" should also be autofilled. |
- {"text", "invisible", "", "", true, "filled invisible", |
+ {"text", "invisible", "", "", false, true, "filled invisible", |
"filled invisible"}, |
// Fields with "display:none" should also be autofilled. |
- {"text", "displaynone", "", "", true, "filled displaynone", |
+ {"text", "displaynone", "", "", false, true, "filled displaynone", |
"filled displaynone"}, |
// Regular <input type="month"> should be autofilled. |
- {"month", "month", "", "", true, "2017-11", "2017-11"}, |
+ {"month", "month", "", "", false, true, "2017-11", "2017-11"}, |
// Non-empty <input type="month"> should be overridden. |
- {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"}, |
+ {"month", "month-nonempty", "2011-12", "", false, true, "2017-11", |
+ "2017-11"}, |
// Regular select fields should be autofilled. |
- {"select-one", "select", "", "", true, "TX", "TX"}, |
+ {"select-one", "select", "", "", true, true, "TX", "TX"}, |
// Select fields should be autofilled even if they already have a |
// non-empty value. |
- {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, |
+ {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
+ // Select fields should be autofilled with the existing value if |
+ // no new value is passed from autofill profile. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, true, "CA", |
+ "CA"}, |
// Regular textarea elements should be autofilled. |
- {"textarea", "textarea", "", "", true, "some multi-\nline value", |
+ {"textarea", "textarea", "", "", false, true, "some multi-\nline value", |
"some multi-\nline value"}, |
// Nonempty textarea elements should be overridden. |
- {"textarea", "textarea-nonempty", "Go\naway!", "", true, |
+ {"textarea", "textarea-nonempty", "Go\naway!", "", false, true, |
"some multi-\nline value", "some multi-\nline value"}, |
}; |
TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
@@ -1416,38 +1437,42 @@ TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
TEST_F(FormAutofillTest, PreviewForm) { |
static const AutofillFieldCase field_cases[] = { |
// Normal empty fields should be previewed. |
- {"text", "firstname", "", "", true, "suggested firstname", |
+ {"text", "firstname", "", "", false, true, "suggested firstname", |
"suggested firstname"}, |
- {"text", "lastname", "", "", true, "suggested lastname", |
+ {"text", "lastname", "", "", false, true, "suggested lastname", |
"suggested lastname"}, |
// Hidden fields should not be extracted to form_data. |
// Non empty fields should not be previewed. |
- {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, |
+ {"text", "notempty", "Hi", "", false, false, "suggested notempty", ""}, |
// "noautocomplete" should not be extracted to form_data. |
// Disabled fields should not be previewed. |
- {"text", "notenabled", "", "", false, "suggested notenabled", ""}, |
+ {"text", "notenabled", "", "", false, false, "suggested notenabled", ""}, |
// Readonly fields should not be previewed. |
- {"text", "readonly", "", "", false, "suggested readonly", ""}, |
+ {"text", "readonly", "", "", false, false, "suggested readonly", ""}, |
// Fields with "visibility: hidden" should not be previewed. |
- {"text", "invisible", "", "", false, "suggested invisible", |
+ {"text", "invisible", "", "", false, false, "suggested invisible", |
""}, |
// Fields with "display:none" should not previewed. |
- {"text", "displaynone", "", "", false, "suggested displaynone", |
+ {"text", "displaynone", "", "", false, false, "suggested displaynone", |
""}, |
// Regular <input type="month"> should be previewed. |
- {"month", "month", "", "", true, "2017-11", "2017-11"}, |
+ {"month", "month", "", "", false, true, "2017-11", "2017-11"}, |
// Non-empty <input type="month"> should not be previewed. |
- {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, |
+ {"month", "month-nonempty", "2011-12", "", false, false, "2017-11", ""}, |
// Regular select fields should be previewed. |
- {"select-one", "select", "", "", true, "TX", "TX"}, |
+ {"select-one", "select", "", "", true, true, "TX", "TX"}, |
// Select fields should be previewed even if they already have a |
// non-empty value. |
- {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, |
+ {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
+ // Select fields autofilled property should be set as false when |
+ // no value is suggested from autofill profile. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, false, "CA", |
+ "CA"}, |
// Normal textarea elements should be previewed. |
- {"textarea", "textarea", "", "", true, "suggested multi-\nline value", |
- "suggested multi-\nline value"}, |
+ {"textarea", "textarea", "", "", false, true, |
+ "suggested multi-\nline value", "suggested multi-\nline value"}, |
// Nonempty textarea elements should not be previewed. |
- {"textarea", "textarea-nonempty", "Go\naway!", "", false, |
+ {"textarea", "textarea-nonempty", "Go\naway!", "", false, false, |
"suggested multi-\nline value", ""}, |
}; |
TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |