diff options
-rw-r--r-- | chrome/browser/autofill/autofill_browsertest.cc | 100 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_autofill_browsertest.cc | 28 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_autofill_util.cc | 23 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_autofill_util.h | 1 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_cache.cc | 9 |
5 files changed, 103 insertions, 58 deletions
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index f3bbdf5..4c0630d 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -37,31 +37,31 @@ static const char* kTestFormString = "<form action=\"http://www.example.com/\" method=\"POST\">" "<label for=\"firstname\">First name:</label>" " <input type=\"text\" id=\"firstname\"" - " onFocus=\"domAutomationController.send(true)\" /><br />" + " onFocus=\"domAutomationController.send(true)\"><br>" "<label for=\"lastname\">Last name:</label>" - " <input type=\"text\" id=\"lastname\" /><br />" + " <input type=\"text\" id=\"lastname\"><br>" "<label for=\"address1\">Address line 1:</label>" - " <input type=\"text\" id=\"address1\" /><br />" + " <input type=\"text\" id=\"address1\"><br>" "<label for=\"address2\">Address line 2:</label>" - " <input type=\"text\" id=\"address2\" /><br />" + " <input type=\"text\" id=\"address2\"><br>" "<label for=\"city\">City:</label>" - " <input type=\"text\" id=\"city\" /><br />" + " <input type=\"text\" id=\"city\"><br>" "<label for=\"state\">State:</label>" " <select id=\"state\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">California</option>" " <option value=\"TX\">Texas</option>" - " </select><br />" + " </select><br>" "<label for=\"zip\">ZIP code:</label>" - " <input type=\"text\" id=\"zip\" /><br />" + " <input type=\"text\" id=\"zip\"><br>" "<label for=\"country\">Country:</label>" " <select id=\"country\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">Canada</option>" " <option value=\"US\">United States</option>" - " </select><br />" + " </select><br>" "<label for=\"phone\">Phone number:</label>" - " <input type=\"text\" id=\"phone\" /><br />" + " <input type=\"text\" id=\"phone\"><br>" "</form>"; class AutofillTest : public InProcessBrowserTest { @@ -395,34 +395,34 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillFormWithRepeatedField) { "<form action=\"http://www.example.com/\" method=\"POST\">" "<label for=\"firstname\">First name:</label>" " <input type=\"text\" id=\"firstname\"" - " onFocus=\"domAutomationController.send(true)\" /><br />" + " onFocus=\"domAutomationController.send(true)\"><br>" "<label for=\"lastname\">Last name:</label>" - " <input type=\"text\" id=\"lastname\" /><br />" + " <input type=\"text\" id=\"lastname\"><br>" "<label for=\"address1\">Address line 1:</label>" - " <input type=\"text\" id=\"address1\" /><br />" + " <input type=\"text\" id=\"address1\"><br>" "<label for=\"address2\">Address line 2:</label>" - " <input type=\"text\" id=\"address2\" /><br />" + " <input type=\"text\" id=\"address2\"><br>" "<label for=\"city\">City:</label>" - " <input type=\"text\" id=\"city\" /><br />" + " <input type=\"text\" id=\"city\"><br>" "<label for=\"state\">State:</label>" " <select id=\"state\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">California</option>" " <option value=\"TX\">Texas</option>" - " </select><br />" + " </select><br>" "<label for=\"state_freeform\" style=\"display:none\">State:</label>" " <input type=\"text\" id=\"state_freeform\"" - " style=\"display:none\" /><br />" + " style=\"display:none\"><br>" "<label for=\"zip\">ZIP code:</label>" - " <input type=\"text\" id=\"zip\" /><br />" + " <input type=\"text\" id=\"zip\"><br>" "<label for=\"country\">Country:</label>" " <select id=\"country\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">Canada</option>" " <option value=\"US\">United States</option>" - " </select><br />" + " </select><br>" "<label for=\"phone\">Phone number:</label>" - " <input type=\"text\" id=\"phone\" /><br />" + " <input type=\"text\" id=\"phone\"><br>" "</form>"))); // Invoke Autofill. @@ -430,6 +430,50 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillFormWithRepeatedField) { ExpectFieldValue(L"state_freeform", ""); } +// Test that we properly autofill forms with non-autofillable fields. +IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillFormWithNonAutofillableField) { + CreateTestProfile(); + + // Load the test page. + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); + ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), + GURL(std::string(kDataURIPrefix) + + "<form action=\"http://www.example.com/\" method=\"POST\">" + "<label for=\"firstname\">First name:</label>" + " <input type=\"text\" id=\"firstname\"" + " onFocus=\"domAutomationController.send(true)\"><br>" + "<label for=\"middlename\">Middle name:</label>" + " <input type=\"text\" id=\"middlename\" autocomplete=\"off\" /><br>" + "<label for=\"lastname\">Last name:</label>" + " <input type=\"text\" id=\"lastname\"><br>" + "<label for=\"address1\">Address line 1:</label>" + " <input type=\"text\" id=\"address1\"><br>" + "<label for=\"address2\">Address line 2:</label>" + " <input type=\"text\" id=\"address2\"><br>" + "<label for=\"city\">City:</label>" + " <input type=\"text\" id=\"city\"><br>" + "<label for=\"state\">State:</label>" + " <select id=\"state\">" + " <option value=\"\" selected=\"yes\">--</option>" + " <option value=\"CA\">California</option>" + " <option value=\"TX\">Texas</option>" + " </select><br>" + "<label for=\"zip\">ZIP code:</label>" + " <input type=\"text\" id=\"zip\"><br>" + "<label for=\"country\">Country:</label>" + " <select id=\"country\">" + " <option value=\"\" selected=\"yes\">--</option>" + " <option value=\"CA\">Canada</option>" + " <option value=\"US\">United States</option>" + " </select><br>" + "<label for=\"phone\">Phone number:</label>" + " <input type=\"text\" id=\"phone\"><br>" + "</form>"))); + + // Invoke Autofill. + TryBasicFormFill(); +} + // Test that we can Autofill dynamically generated forms. IN_PROC_BROWSER_TEST_F(AutofillTest, DynamicFormFill) { CreateTestProfile(); @@ -565,31 +609,31 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillAfterTranslate) { "<label for=\"fn\">なまえ</label>" " <input type=\"text\" id=\"fn\"" " onFocus=\"domAutomationController.send(true)\"" - " /><br />" + "><br>" "<label for=\"ln\">みょうじ</label>" - " <input type=\"text\" id=\"ln\" /><br />" + " <input type=\"text\" id=\"ln\"><br>" "<label for=\"a1\">Address line 1:</label>" - " <input type=\"text\" id=\"a1\" /><br />" + " <input type=\"text\" id=\"a1\"><br>" "<label for=\"a2\">Address line 2:</label>" - " <input type=\"text\" id=\"a2\" /><br />" + " <input type=\"text\" id=\"a2\"><br>" "<label for=\"ci\">City:</label>" - " <input type=\"text\" id=\"ci\" /><br />" + " <input type=\"text\" id=\"ci\"><br>" "<label for=\"st\">State:</label>" " <select id=\"st\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">California</option>" " <option value=\"TX\">Texas</option>" - " </select><br />" + " </select><br>" "<label for=\"z\">ZIP code:</label>" - " <input type=\"text\" id=\"z\" /><br />" + " <input type=\"text\" id=\"z\"><br>" "<label for=\"co\">Country:</label>" " <select id=\"co\">" " <option value=\"\" selected=\"yes\">--</option>" " <option value=\"CA\">Canada</option>" " <option value=\"US\">United States</option>" - " </select><br />" + " </select><br>" "<label for=\"ph\">Phone number:</label>" - " <input type=\"text\" id=\"ph\" /><br />" + " <input type=\"text\" id=\"ph\"><br>" "</form>"); ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc index f200c87..858164f 100644 --- a/chrome/renderer/autofill/form_autofill_browsertest.cc +++ b/chrome/renderer/autofill/form_autofill_browsertest.cc @@ -785,13 +785,13 @@ TEST_F(FormAutofillTest, FillForm) { FormData form; FormField field; EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, - autofill::REQUIRE_NONE)); + autofill::REQUIRE_AUTOCOMPLETE)); EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); EXPECT_EQ(GURL(web_frame->document().url()), form.origin); EXPECT_EQ(GURL("http://buh.com"), form.action); const std::vector<FormField>& fields = form.fields; - ASSERT_EQ(8U, fields.size()); + ASSERT_EQ(7U, fields.size()); FormField expected; expected.form_control_type = ASCIIToUTF16("text"); @@ -809,25 +809,21 @@ TEST_F(FormAutofillTest, FillForm) { expected.value = ASCIIToUTF16("Hi"); EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); - expected.name = ASCIIToUTF16("noautocomplete"); - expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); - expected.name = ASCIIToUTF16("notenabled"); expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); + EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); expected.name = ASCIIToUTF16("readonly"); expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); + EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); expected.name = ASCIIToUTF16("invisible"); expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[6]); + EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); expected.name = ASCIIToUTF16("displaynone"); expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[7]); + EXPECT_FORM_FIELD_EQUALS(expected, fields[6]); // Fill the form. form.fields[0].value = ASCIIToUTF16("Wyatt"); @@ -837,7 +833,6 @@ TEST_F(FormAutofillTest, FillForm) { form.fields[4].value = ASCIIToUTF16("Gamma"); form.fields[5].value = ASCIIToUTF16("Delta"); form.fields[6].value = ASCIIToUTF16("Epsilon"); - form.fields[7].value = ASCIIToUTF16("Zeta"); FillForm(form, input_element); // Verify the filled elements. @@ -917,13 +912,13 @@ TEST_F(FormAutofillTest, PreviewForm) { FormData form; FormField field; EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, - autofill::REQUIRE_NONE)); + autofill::REQUIRE_AUTOCOMPLETE)); EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); EXPECT_EQ(GURL(web_frame->document().url()), form.origin); EXPECT_EQ(GURL("http://buh.com"), form.action); const std::vector<FormField>& fields = form.fields; - ASSERT_EQ(5U, fields.size()); + ASSERT_EQ(4U, fields.size()); FormField expected; expected.form_control_type = ASCIIToUTF16("text"); @@ -941,20 +936,15 @@ TEST_F(FormAutofillTest, PreviewForm) { expected.value = ASCIIToUTF16("Hi"); EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); - expected.name = ASCIIToUTF16("noautocomplete"); - expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); - expected.name = ASCIIToUTF16("notenabled"); expected.value = string16(); - EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); + EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); // Preview the form. form.fields[0].value = ASCIIToUTF16("Wyatt"); form.fields[1].value = ASCIIToUTF16("Earp"); form.fields[2].value = ASCIIToUTF16("Alpha"); form.fields[3].value = ASCIIToUTF16("Beta"); - form.fields[4].value = ASCIIToUTF16("Gamma"); PreviewForm(form, input_element); // Verify the previewed elements. diff --git a/chrome/renderer/autofill/form_autofill_util.cc b/chrome/renderer/autofill/form_autofill_util.cc index 4f44ffc..4c25669 100644 --- a/chrome/renderer/autofill/form_autofill_util.cc +++ b/chrome/renderer/autofill/form_autofill_util.cc @@ -427,7 +427,8 @@ void ForEachMatchingFormField(const WebFormElement& form_element, const FormData& data, Callback callback) { std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, autofill::REQUIRE_AUTOCOMPLETE, + &control_elements); if (control_elements.size() != data.fields.size()) { // This case should be reachable only for pathological websites, which add @@ -461,11 +462,6 @@ void ForEachMatchingFormField(const WebFormElement& form_element, const WebInputElement* input_element = toWebInputElement(element); if (IsTextInput(input_element)) { - // TODO(jhawkins): WebKit currently doesn't handle the autocomplete - // attribute for select control elements, but it probably should. - if (!input_element->autoComplete()) - continue; - // Only autofill empty fields and the field that initiated the filling, // i.e. the field the user is currently editing and interacting with. if (!is_initiating_element && !input_element->value().isEmpty()) @@ -565,6 +561,7 @@ const string16 GetFormIdentifier(const WebFormElement& form) { // elements in |form_element|. void ExtractAutofillableElements( const WebFormElement& form_element, + RequirementsMask requirements, std::vector<WebFormControlElement>* autofillable_elements) { WebVector<WebFormControlElement> control_elements; form_element.getFormControlElements(control_elements); @@ -575,6 +572,14 @@ void ExtractAutofillableElements( if (!IsAutofillableElement(element)) continue; + if (requirements & REQUIRE_AUTOCOMPLETE) { + // TODO(jhawkins): WebKit currently doesn't handle the autocomplete + // attribute for select control elements, but it probably should. + WebInputElement* input_element = toWebInputElement(&control_elements[i]); + if (IsTextInput(input_element) && !input_element->autoComplete()) + continue; + } + autofillable_elements->push_back(element); } } @@ -831,7 +836,8 @@ bool ClearPreviewedFormWithElement(const WebInputElement& element, return false; std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, + &control_elements); for (size_t i = 0; i < control_elements.size(); ++i) { // Only text input elements can be previewed. WebInputElement* input_element = toWebInputElement(&control_elements[i]); @@ -877,7 +883,8 @@ bool FormWithElementIsAutofilled(const WebInputElement& element) { return false; std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, + &control_elements); for (size_t i = 0; i < control_elements.size(); ++i) { WebInputElement* input_element = toWebInputElement(&control_elements[i]); if (!IsTextInput(input_element)) diff --git a/chrome/renderer/autofill/form_autofill_util.h b/chrome/renderer/autofill/form_autofill_util.h index 8afe0ba..ff51986 100644 --- a/chrome/renderer/autofill/form_autofill_util.h +++ b/chrome/renderer/autofill/form_autofill_util.h @@ -58,6 +58,7 @@ const string16 GetFormIdentifier(const WebKit::WebFormElement& form); // elements in |form_element|. void ExtractAutofillableElements( const WebKit::WebFormElement& form_element, + RequirementsMask requirements, std::vector<WebKit::WebFormControlElement>* autofillable_elements); // Fills out a FormField object from a given WebFormControlElement. diff --git a/chrome/renderer/autofill/form_cache.cc b/chrome/renderer/autofill/form_cache.cc index a1b3999..d4081cb 100644 --- a/chrome/renderer/autofill/form_cache.cc +++ b/chrome/renderer/autofill/form_cache.cc @@ -77,7 +77,8 @@ void FormCache::ExtractForms(const WebFrame& frame, WebFormElement form_element = web_forms[i]; std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, + &control_elements); for (size_t j = 0; j < control_elements.size(); ++j) { WebFormControlElement element = control_elements[j]; @@ -152,7 +153,8 @@ bool FormCache::ClearFormWithElement(const WebInputElement& element) { return false; std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, + &control_elements); for (size_t i = 0; i < control_elements.size(); ++i) { WebFormControlElement control_element = control_elements[i]; WebInputElement* input_element = toWebInputElement(&control_element); @@ -222,7 +224,8 @@ bool FormCache::ShowPredictions(const FormDataPredictions& form) { return false; std::vector<WebFormControlElement> control_elements; - ExtractAutofillableElements(form_element, &control_elements); + ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, + &control_elements); if (control_elements.size() != form.fields.size()) { // Keep things simple. Don't show predictions for forms that were modified // between page load and the server's response to our query. |