Chromium Code Reviews| 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( |
| 485 UTF16ToUTF8(username1_), true, UTF16ToUTF8(password1_), true); | |
|
Garrett Casto
2013/12/04 18:32:17
Nit: Generally this file just checks against kAlic
jww
2013/12/04 20:00:57
Done.
| |
| 486 } | |
| 487 | |
| 488 // Makes sure that we are ignoring autocomplete="off" on forms | |
| 489 TEST_F(PasswordAutofillAgentTest, IgnoreFormAutocompleteOff) { | |
| 490 // We need to set the origin so it matches the frame URL and the action so | |
| 491 // it matches the form action, otherwise we won't autocomplete. | |
| 492 LoadHTML(kAutocompleteOffFormHTML); | |
| 493 | |
| 494 // Retrieve the input elements so the test can access them. | |
| 495 WebDocument document = GetMainFrame()->document(); | |
| 496 WebElement element = | |
| 497 document.getElementById(WebString::fromUTF8(kUsernameName)); | |
| 498 ASSERT_FALSE(element.isNull()); | |
| 499 username_element_ = element.to<blink::WebInputElement>(); | |
| 500 element = document.getElementById(WebString::fromUTF8(kPasswordName)); | |
| 501 ASSERT_FALSE(element.isNull()); | |
| 502 password_element_ = element.to<blink::WebInputElement>(); | |
| 503 | |
| 504 // Set the expected form origin and action URLs. | |
| 505 std::string origin("data:text/html;charset=utf-8,"); | |
| 506 origin += kAutocompleteOffFormHTML; | |
| 507 fill_data_.basic_data.origin = GURL(origin); | |
| 508 fill_data_.basic_data.action = GURL(origin); | |
| 509 | |
| 510 // Simulate the browser sending back the login info, it triggers the | |
| 511 // autocomplete. | |
| 512 SimulateOnFillPasswordForm(fill_data_); | |
| 513 | |
| 514 CheckTextFieldsState( | |
| 515 UTF16ToUTF8(username1_), true, UTF16ToUTF8(password1_), true); | |
| 477 } | 516 } |
| 478 | 517 |
| 479 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForTextFieldPasswords) { | 518 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForTextFieldPasswords) { |
| 480 const char kTextFieldPasswordFormHTML[] = | 519 const char kTextFieldPasswordFormHTML[] = |
| 481 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" | 520 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" |
| 482 " <INPUT type='text' id='username'/>" | 521 " <INPUT type='text' id='username'/>" |
| 483 " <INPUT type='text' id='password'/>" | 522 " <INPUT type='text' id='password'/>" |
| 484 " <INPUT type='submit' value='Login'/>" | 523 " <INPUT type='submit' value='Login'/>" |
| 485 "</FORM>"; | 524 "</FORM>"; |
| 486 LoadHTML(kTextFieldPasswordFormHTML); | 525 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. | 869 // Verfies that a DOM-activated UI event will not cause an autofill. |
| 831 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 870 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
| 832 // Trigger the initial autocomplete. | 871 // Trigger the initial autocomplete. |
| 833 SimulateOnFillPasswordForm(fill_data_); | 872 SimulateOnFillPasswordForm(fill_data_); |
| 834 | 873 |
| 835 ExecuteJavaScript(kJavaScriptClick); | 874 ExecuteJavaScript(kJavaScriptClick); |
| 836 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 875 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
| 837 } | 876 } |
| 838 | 877 |
| 839 } // namespace autofill | 878 } // namespace autofill |
| OLD | NEW |