diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 19:53:07 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 19:53:07 +0000 |
commit | 399092645ed91a419c53310ad45ca2a68c9a74f5 (patch) | |
tree | 3edae02b6695fcc5f70695778a6e5a3c723c4a5c | |
parent | 126a39cfe316baa94d0fa5278df5770c7c3b0a30 (diff) | |
download | chromium_src-399092645ed91a419c53310ad45ca2a68c9a74f5.zip chromium_src-399092645ed91a419c53310ad45ca2a68c9a74f5.tar.gz chromium_src-399092645ed91a419c53310ad45ca2a68c9a74f5.tar.bz2 |
Enable password filling for forms with no action URL specified.
BUG=78237
TEST=unit_tests --gtest_filter=PasswordAutofillManagerTest.InitialAutocompleteForEmptyAction
Review URL: http://codereview.chromium.org/6800010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80677 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/autofill/password_autofill_manager.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/autofill/password_autofill_manager_unittest.cc | 34 |
2 files changed, 41 insertions, 1 deletions
diff --git a/chrome/renderer/autofill/password_autofill_manager.cc b/chrome/renderer/autofill/password_autofill_manager.cc index 978ca2a..172ef5e 100644 --- a/chrome/renderer/autofill/password_autofill_manager.cc +++ b/chrome/renderer/autofill/password_autofill_manager.cc @@ -120,8 +120,14 @@ void FindFormElements(WebKit::WebView* view, for (size_t i = 0; i < forms.size(); ++i) { WebKit::WebFormElement fe = forms[i]; - // Action URL must match. + GURL full_action(f->document().completeURL(fe.action())); + if (full_action.is_empty()) { + // The default action URL is the form's origin. + full_action = full_origin; + } + + // Action URL must match. if (data.action != full_action.ReplaceComponents(rep)) continue; diff --git a/chrome/renderer/autofill/password_autofill_manager_unittest.cc b/chrome/renderer/autofill/password_autofill_manager_unittest.cc index ac79404..5d56c79 100644 --- a/chrome/renderer/autofill/password_autofill_manager_unittest.cc +++ b/chrome/renderer/autofill/password_autofill_manager_unittest.cc @@ -203,6 +203,40 @@ TEST_F(PasswordAutofillManagerTest, InitialAutocomplete) { CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); } +// Tests that having a non-empty username precludes the autocomplete. +TEST_F(PasswordAutofillManagerTest, InitialAutocompleteForEmptyAction) { + const char kEmptyActionFormHTML[] = + "<FORM name='LoginTestForm'>" + " <INPUT type='text' id='username'/>" + " <INPUT type='password' id='password'/>" + " <INPUT type='submit' value='Login'/>" + "</FORM>"; + LoadHTML(kEmptyActionFormHTML); + + // Retrieve the input elements so the test can access them. + WebDocument document = GetMainFrame()->document(); + WebElement element = + document.getElementById(WebString::fromUTF8(kUsernameName)); + ASSERT_FALSE(element.isNull()); + username_element_ = element.to<WebKit::WebInputElement>(); + element = document.getElementById(WebString::fromUTF8(kPasswordName)); + ASSERT_FALSE(element.isNull()); + password_element_ = element.to<WebKit::WebInputElement>(); + + // Set the expected form origin and action URLs. + std::string origin("data:text/html;charset=utf-8,"); + origin += kEmptyActionFormHTML; + fill_data_.basic_data.origin = GURL(origin); + fill_data_.basic_data.action = GURL(origin); + + // Simulate the browser sending back the login info, it triggers the + // autocomplete. + SimulateOnFillPasswordForm(fill_data_); + + // The username and password should have been autocompleted. + CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); +} + // Tests that changing the username does not fill a read-only password field. TEST_F(PasswordAutofillManagerTest, NoInitialAutocompleteForReadOnly) { password_element_.setAttribute(WebString::fromUTF8("readonly"), |