Index: chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
index 94f2af7ca0b1e92503480bb04e763a16f0a79a61..4ce99d79e13147c96f49b681c777783b107e993c 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -132,6 +132,13 @@ const char kWebpageWithDynamicContent[] = |
" </body>" |
"</html>"; |
+const char kAutocompleteOffFormHTML[] = |
+ "<FORM name='LoginTestForm' autocomplete='off'>" |
+ " <INPUT type='text' id='username'/>" |
+ " <INPUT type='password' id='password'/>" |
+ " <INPUT type='submit' value='Login'/>" |
+ "</FORM>"; |
+ |
const char kJavaScriptClick[] = |
"var event = new MouseEvent('click', {" |
" 'view': window," |
@@ -463,17 +470,47 @@ TEST_F(PasswordAutofillAgentTest, InputWithNoForms) { |
CheckTextFieldsState(std::string(), false, std::string(), false); |
} |
-// Tests that we do not autofill username/passwords if marked as |
-// autocomplete="off". |
-TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) { |
+// Makes sure that we are ignoring autocomplete="off" on usernames and paswords. |
+TEST_F(PasswordAutofillAgentTest, IgnoreElementAutocompleteOff) { |
username_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
WebString::fromUTF8("off")); |
+ password_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
+ WebString::fromUTF8("off")); |
// Simulate the browser sending back the login info, it triggers the |
// autocomplete. |
SimulateOnFillPasswordForm(fill_data_); |
- CheckTextFieldsState(std::string(), false, std::string(), false); |
+ CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
+} |
+ |
+// Makes sure that we are ignoring autocomplete="off" on forms |
+TEST_F(PasswordAutofillAgentTest, IgnoreFormAutocompleteOff) { |
+ // We need to set the origin so it matches the frame URL and the action so |
+ // it matches the form action, otherwise we won't autocomplete. |
+ LoadHTML(kAutocompleteOffFormHTML); |
+ |
+ // 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<blink::WebInputElement>(); |
+ element = document.getElementById(WebString::fromUTF8(kPasswordName)); |
+ ASSERT_FALSE(element.isNull()); |
+ password_element_ = element.to<blink::WebInputElement>(); |
+ |
+ // Set the expected form origin and action URLs. |
+ std::string origin("data:text/html;charset=utf-8,"); |
+ origin += kAutocompleteOffFormHTML; |
+ 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_); |
+ |
+ CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
} |
TEST_F(PasswordAutofillAgentTest, NoAutocompleteForTextFieldPasswords) { |