Chromium Code Reviews| 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 a92c51d4d8c62897ead44b33009472f72f058452..85b8e47db163e3e28b7aff161ae4a2ad1506a6a5 100644 |
| --- a/chrome/renderer/autofill/form_autofill_browsertest.cc |
| +++ b/chrome/renderer/autofill/form_autofill_browsertest.cc |
| @@ -2960,11 +2960,33 @@ TEST_F(FormAutofillTest, ClearFormWithNode) { |
| form_cache.ExtractNewForms(*web_frame, &forms); |
| ASSERT_EQ(1U, forms.size()); |
| - // Set the auto-filled attribute on the firstname element. |
| + // Set the auto-filled attribute. |
| WebInputElement firstname = |
| web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| firstname.setAutofilled(true); |
|
Ilya Sherman
2014/06/16 21:19:37
nit: I'd avoid these blank lines for the various e
Nikhil
2014/06/17 08:59:43
Done.
|
| + WebInputElement lastname = |
| + web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| + lastname.setAutofilled(true); |
| + |
| + WebInputElement no_autocomplete = |
| + web_frame->document().getElementById("noAC").to<WebInputElement>(); |
| + no_autocomplete.setAutofilled(true); |
|
Ilya Sherman
2014/06/16 21:19:37
It doesn't really make sense to set autofilled to
Nikhil
2014/06/17 08:59:43
Right! I've updated the behavior. Since these fiel
|
| + |
| + WebInputElement month = |
| + web_frame->document().getElementById("month").to<WebInputElement>(); |
| + month.setAutofilled(true); |
| + |
| + WebInputElement textarea = |
| + web_frame->document().getElementById("textarea").to<WebInputElement>(); |
| + textarea.setAutofilled(true); |
| + |
| + WebInputElement textarea_no_autocomplete = |
| + web_frame->document() |
| + .getElementById("textarea-noAC") |
| + .to<WebInputElement>(); |
| + textarea_no_autocomplete.setAutofilled(true); |
| + |
| // Set the value of the disabled text input element. |
| WebInputElement notenabled = |
| web_frame->document().getElementById("notenabled").to<WebInputElement>(); |
| @@ -3064,11 +3086,19 @@ TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
| form_cache.ExtractNewForms(*web_frame, &forms); |
| ASSERT_EQ(1U, forms.size()); |
| - // Set the auto-filled attribute on the firstname element. |
| + // Set the auto-filled attribute. |
| WebInputElement firstname = |
| web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| firstname.setAutofilled(true); |
| + WebInputElement lastname = |
| + web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| + lastname.setAutofilled(true); |
| + |
| + WebInputElement state = |
| + web_frame->document().getElementById("state").to<WebInputElement>(); |
| + state.setAutofilled(true); |
| + |
| // Set the value of the select-one. |
| WebSelectElement select_element = |
| web_frame->document().getElementById("state").to<WebSelectElement>(); |
| @@ -3322,6 +3352,58 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
| EXPECT_FALSE(phone.isAutofilled()); |
| } |
| +// Autofill's "Clear Form" should clear only autofilled fields |
| +TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
| + // Load the form. |
| + LoadHTML( |
| + "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| + " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| + " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" |
| + " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>" |
| + " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>" |
| + " <INPUT type=\"submit\" value=\"Send\"/>" |
| + "</FORM>"); |
| + |
| + WebFrame* web_frame = GetMainFrame(); |
| + ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| + |
| + FormCache form_cache; |
| + std::vector<FormData> forms; |
| + form_cache.ExtractNewForms(*web_frame, &forms); |
| + ASSERT_EQ(1U, forms.size()); |
| + |
| + // Set the autofilled attribute. |
| + WebInputElement firstname = |
| + web_frame->document().getElementById("firstname").to<WebInputElement>(); |
| + firstname.setAutofilled(false); |
| + WebInputElement lastname = |
| + web_frame->document().getElementById("lastname").to<WebInputElement>(); |
| + lastname.setAutofilled(true); |
| + WebInputElement email = |
| + web_frame->document().getElementById("email").to<WebInputElement>(); |
| + email.setAutofilled(true); |
| + WebInputElement phone = |
| + web_frame->document().getElementById("phone").to<WebInputElement>(); |
| + phone.setAutofilled(true); |
| + |
| + // Clear the fields. |
| + EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| + |
| + // Verify only autofilled fields are cleared. |
| + EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
| + EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
| + EXPECT_FALSE(firstname.isAutofilled()); |
| + EXPECT_TRUE(lastname.value().isEmpty()); |
| + EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| + EXPECT_FALSE(lastname.isAutofilled()); |
| + EXPECT_TRUE(email.value().isEmpty()); |
| + EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| + EXPECT_FALSE(email.isAutofilled()); |
| + EXPECT_TRUE(phone.value().isEmpty()); |
| + EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| + EXPECT_FALSE(phone.isAutofilled()); |
| +} |
| + |
| TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { |
| LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| @@ -3501,5 +3583,4 @@ TEST_F(FormAutofillTest, SelectOneAsText) { |
| expected.max_length = 0; |
| EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| } |
| - |
| } // namespace autofill |