| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
| 8 #include "components/autofill/content/renderer/autofill_agent.h" | 8 #include "components/autofill/content/renderer/autofill_agent.h" |
| 9 #include "components/autofill/content/renderer/form_autofill_util.h" | 9 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 10 #include "components/autofill/content/renderer/password_autofill_agent.h" | 10 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 " <script type='text/javascript'>" | 125 " <script type='text/javascript'>" |
| 126 " function addParagraph() {" | 126 " function addParagraph() {" |
| 127 " var p = document.createElement('p');" | 127 " var p = document.createElement('p');" |
| 128 " document.body.appendChild(p);" | 128 " document.body.appendChild(p);" |
| 129 " }" | 129 " }" |
| 130 " window.onload = addParagraph;" | 130 " window.onload = addParagraph;" |
| 131 " </script>" | 131 " </script>" |
| 132 " </body>" | 132 " </body>" |
| 133 "</html>"; | 133 "</html>"; |
| 134 | 134 |
| 135 const char kAutocompleteOffFormHTML[] = |
| 136 "<FORM name='LoginTestForm' autocomplete='off'>" |
| 137 " <INPUT type='text' id='username'/>" |
| 138 " <INPUT type='password' id='password'/>" |
| 139 " <INPUT type='submit' value='Login'/>" |
| 140 "</FORM>"; |
| 141 |
| 135 const char kJavaScriptClick[] = | 142 const char kJavaScriptClick[] = |
| 136 "var event = new MouseEvent('click', {" | 143 "var event = new MouseEvent('click', {" |
| 137 " 'view': window," | 144 " 'view': window," |
| 138 " 'bubbles': true," | 145 " 'bubbles': true," |
| 139 " 'cancelable': true" | 146 " 'cancelable': true" |
| 140 "});" | 147 "});" |
| 141 "var form = document.getElementById('myform1');" | 148 "var form = document.getElementById('myform1');" |
| 142 "form.dispatchEvent(event);" | 149 "form.dispatchEvent(event);" |
| 143 "console.log('clicked!');"; | 150 "console.log('clicked!');"; |
| 144 | 151 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 "<input type='text' id='username'/>" | 463 "<input type='text' id='username'/>" |
| 457 "<input type='password' id='password'/>"; | 464 "<input type='password' id='password'/>"; |
| 458 LoadHTML(kNoFormInputs); | 465 LoadHTML(kNoFormInputs); |
| 459 | 466 |
| 460 SimulateOnFillPasswordForm(fill_data_); | 467 SimulateOnFillPasswordForm(fill_data_); |
| 461 | 468 |
| 462 // Input elements that aren't in a <form> won't autofill. | 469 // Input elements that aren't in a <form> won't autofill. |
| 463 CheckTextFieldsState(std::string(), false, std::string(), false); | 470 CheckTextFieldsState(std::string(), false, std::string(), false); |
| 464 } | 471 } |
| 465 | 472 |
| 466 // Tests that we do not autofill username/passwords if marked as | 473 // Makes sure that we are ignoring autocomplete="off" on usernames and paswords. |
| 467 // autocomplete="off". | 474 TEST_F(PasswordAutofillAgentTest, IgnoreElementAutocompleteOff) { |
| 468 TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForAutocompleteOff) { | |
| 469 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), | 475 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 470 WebString::fromUTF8("off")); | 476 WebString::fromUTF8("off")); |
| 477 password_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 478 WebString::fromUTF8("off")); |
| 471 | 479 |
| 472 // Simulate the browser sending back the login info, it triggers the | 480 // Simulate the browser sending back the login info, it triggers the |
| 473 // autocomplete. | 481 // autocomplete. |
| 474 SimulateOnFillPasswordForm(fill_data_); | 482 SimulateOnFillPasswordForm(fill_data_); |
| 475 | 483 |
| 476 CheckTextFieldsState(std::string(), false, std::string(), false); | 484 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| 485 } |
| 486 |
| 487 // Makes sure that we are ignoring autocomplete="off" on forms |
| 488 TEST_F(PasswordAutofillAgentTest, IgnoreFormAutocompleteOff) { |
| 489 // We need to set the origin so it matches the frame URL and the action so |
| 490 // it matches the form action, otherwise we won't autocomplete. |
| 491 LoadHTML(kAutocompleteOffFormHTML); |
| 492 |
| 493 // Retrieve the input elements so the test can access them. |
| 494 WebDocument document = GetMainFrame()->document(); |
| 495 WebElement element = |
| 496 document.getElementById(WebString::fromUTF8(kUsernameName)); |
| 497 ASSERT_FALSE(element.isNull()); |
| 498 username_element_ = element.to<blink::WebInputElement>(); |
| 499 element = document.getElementById(WebString::fromUTF8(kPasswordName)); |
| 500 ASSERT_FALSE(element.isNull()); |
| 501 password_element_ = element.to<blink::WebInputElement>(); |
| 502 |
| 503 // Set the expected form origin and action URLs. |
| 504 std::string origin("data:text/html;charset=utf-8,"); |
| 505 origin += kAutocompleteOffFormHTML; |
| 506 fill_data_.basic_data.origin = GURL(origin); |
| 507 fill_data_.basic_data.action = GURL(origin); |
| 508 |
| 509 // Simulate the browser sending back the login info, it triggers the |
| 510 // autocomplete. |
| 511 SimulateOnFillPasswordForm(fill_data_); |
| 512 |
| 513 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| 477 } | 514 } |
| 478 | 515 |
| 479 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForTextFieldPasswords) { | 516 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForTextFieldPasswords) { |
| 480 const char kTextFieldPasswordFormHTML[] = | 517 const char kTextFieldPasswordFormHTML[] = |
| 481 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" | 518 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" |
| 482 " <INPUT type='text' id='username'/>" | 519 " <INPUT type='text' id='username'/>" |
| 483 " <INPUT type='text' id='password'/>" | 520 " <INPUT type='text' id='password'/>" |
| 484 " <INPUT type='submit' value='Login'/>" | 521 " <INPUT type='submit' value='Login'/>" |
| 485 "</FORM>"; | 522 "</FORM>"; |
| 486 LoadHTML(kTextFieldPasswordFormHTML); | 523 LoadHTML(kTextFieldPasswordFormHTML); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 // Verfies that a DOM-activated UI event will not cause an autofill. | 867 // Verfies that a DOM-activated UI event will not cause an autofill. |
| 831 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 868 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
| 832 // Trigger the initial autocomplete. | 869 // Trigger the initial autocomplete. |
| 833 SimulateOnFillPasswordForm(fill_data_); | 870 SimulateOnFillPasswordForm(fill_data_); |
| 834 | 871 |
| 835 ExecuteJavaScript(kJavaScriptClick); | 872 ExecuteJavaScript(kJavaScriptClick); |
| 836 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 873 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
| 837 } | 874 } |
| 838 | 875 |
| 839 } // namespace autofill | 876 } // namespace autofill |
| OLD | NEW |