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..47d92b189e7ce0c51e159cbc7f99ab8335a67573 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. |
Ilya Sherman
2014/06/03 20:39:31
It seems like this is always identical to should_b
|
+ 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\">" |
Ilya Sherman
2014/06/03 20:39:31
nit: Perhaps "select-unchanged"?
|
+ " <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,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].is_autofilled; |
} |
// Autofill the form using the given fill form function. |
@@ -1324,39 +1331,46 @@ TEST_F(FormAutofillTest, FindFormForTextAreaElement) { |
// Test regular FillForm function. |
TEST_F(FormAutofillTest, FillForm) { |
static const AutofillFieldCase field_cases[] = { |
- // fields: form_control_type, name, initial_value, autocomplete_attribute, |
- // should_be_autofilled, autofill_value, expected_value |
+ // fields: form_control_type, name, initial_value, |
+ // autocomplete_attribute, is_autofilled, should_be_autofilled, |
+ // autofill_value, expected_value |
// Regular empty fields (firstname & lastname) should be autofilled. |
- {"text", "firstname", "", "", true, "filled firstname", |
+ {"text", "firstname", "", "", true, true, "filled firstname", |
"filled firstname"}, |
- {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
+ {"text", "lastname", "", "", true, 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", "", "", true, 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 not be autofilled if no new value is passed from |
+ // autofill profile. The existing value should not be overriden. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, false, "CA", |
+ "CA"}, |
// Regular textarea elements should be autofilled. |
- {"textarea", "textarea", "", "", true, "some multi-\nline value", |
+ {"textarea", "textarea", "", "", true, 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), |
@@ -1370,42 +1384,49 @@ TEST_F(FormAutofillTest, FillForm) { |
TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
static const AutofillFieldCase field_cases[] = { |
- // fields: form_control_type, name, initial_value, autocomplete_attribute, |
- // should_be_autofilled, autofill_value, expected_value |
+ // fields: form_control_type, name, initial_value, |
+ // autocomplete_attribute, is_autofilled, should_be_autofilled, |
+ // autofill_value, expected_value |
// Regular empty fields (firstname & lastname) should be autofilled. |
- {"text", "firstname", "", "", true, "filled firstname", |
+ {"text", "firstname", "", "", true, true, "filled firstname", |
"filled firstname"}, |
- {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
+ {"text", "lastname", "", "", true, 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", "", true, 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", "", "", true, true, "filled invisible", |
"filled invisible"}, |
// Fields with "display:none" should also be autofilled. |
- {"text", "displaynone", "", "", true, "filled displaynone", |
+ {"text", "displaynone", "", "", true, true, "filled displaynone", |
"filled displaynone"}, |
// Regular <input type="month"> should be autofilled. |
- {"month", "month", "", "", true, "2017-11", "2017-11"}, |
+ {"month", "month", "", "", true, 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", "", true, 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 not be autofilled if no new value is passed from |
+ // autofill profile. The existing value should not be overriden. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, false, "CA", |
+ "CA"}, |
// Regular textarea elements should be autofilled. |
- {"textarea", "textarea", "", "", true, "some multi-\nline value", |
+ {"textarea", "textarea", "", "", true, 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!", "", true, 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", "", "", true, true, "suggested firstname", |
"suggested firstname"}, |
- {"text", "lastname", "", "", true, "suggested lastname", |
+ {"text", "lastname", "", "", true, 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", "", "", true, 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 should not be previewed if no suggestion is passed from |
+ // autofill profile. |
+ {"select-one", "select-nonewsuggestion", "CA", "", false, false, "", |
+ ""}, |
// Normal textarea elements should be previewed. |
- {"textarea", "textarea", "", "", true, "suggested multi-\nline value", |
- "suggested multi-\nline value"}, |
+ {"textarea", "textarea", "", "", true, 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), |
@@ -2376,6 +2401,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 +2670,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 +2899,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()); |