Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9609)

Unified Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 316853006: Autofill's "Clear Form" should clear only autofilled fields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated test case Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f76ee97fd465deb7e0fde8bb50a0b54e9c8f70b2 100644
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc
@@ -2960,10 +2960,19 @@ 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);
+ WebInputElement lastname =
+ web_frame->document().getElementById("lastname").to<WebInputElement>();
+ lastname.setAutofilled(true);
+ WebInputElement month =
+ web_frame->document().getElementById("month").to<WebInputElement>();
+ month.setAutofilled(true);
+ WebInputElement textarea =
+ web_frame->document().getElementById("textarea").to<WebInputElement>();
+ textarea.setAutofilled(true);
// Set the value of the disabled text input element.
WebInputElement notenabled =
@@ -3003,7 +3012,7 @@ TEST_F(FormAutofillTest, ClearFormWithNode) {
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
expected.name = ASCIIToUTF16("noAC");
- expected.value = base::string16();
+ expected.value = ASCIIToUTF16("one");
expected.autocomplete_attribute = "off";
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
expected.autocomplete_attribute = std::string(); // reset
@@ -3032,7 +3041,7 @@ TEST_F(FormAutofillTest, ClearFormWithNode) {
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]);
expected.name = ASCIIToUTF16("textarea-noAC");
- expected.value = base::string16();
+ expected.value = ASCIIToUTF16("Carrot?");
expected.autocomplete_attribute = "off";
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]);
expected.autocomplete_attribute = std::string(); // reset
@@ -3064,10 +3073,16 @@ 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 =
@@ -3322,6 +3337,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 +3568,4 @@ TEST_F(FormAutofillTest, SelectOneAsText) {
expected.max_length = 0;
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
}
-
} // namespace autofill
« no previous file with comments | « no previous file | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698