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/renderer/autofill/password_generation_test_utils.h" | 7 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
10 #include "components/autofill/content/renderer/autofill_agent.h" | 10 #include "components/autofill/content/renderer/autofill_agent.h" |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // Simulate a user click so that the password field's real value is filled. | 798 // Simulate a user click so that the password field's real value is filled. |
799 SimulateElementClick(kUsernameName); | 799 SimulateElementClick(kUsernameName); |
800 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 800 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
801 } | 801 } |
802 | 802 |
803 // Verfies that a DOM-activated UI event will not cause an autofill. | 803 // Verfies that a DOM-activated UI event will not cause an autofill. |
804 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 804 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
805 // Trigger the initial autocomplete. | 805 // Trigger the initial autocomplete. |
806 SimulateOnFillPasswordForm(fill_data_); | 806 SimulateOnFillPasswordForm(fill_data_); |
807 | 807 |
808 ExecuteJavaScript(kJavaScriptClick); | 808 ExecuteJavaScriptForTests(kJavaScriptClick); |
809 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 809 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
810 } | 810 } |
811 | 811 |
812 // Verifies that password autofill triggers onChange events in JavaScript for | 812 // Verifies that password autofill triggers onChange events in JavaScript for |
813 // forms that are filled on page load. | 813 // forms that are filled on page load. |
814 TEST_F(PasswordAutofillAgentTest, | 814 TEST_F(PasswordAutofillAgentTest, |
815 PasswordAutofillTriggersOnChangeEventsOnLoad) { | 815 PasswordAutofillTriggersOnChangeEventsOnLoad) { |
816 std::string html = std::string(kFormHTML) + kOnChangeDetectionScript; | 816 std::string html = std::string(kFormHTML) + kOnChangeDetectionScript; |
817 LoadHTML(html.c_str()); | 817 LoadHTML(html.c_str()); |
818 UpdateOriginForHTML(html); | 818 UpdateOriginForHTML(html); |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 ->OnMessageReceived(msg); | 1673 ->OnMessageReceived(msg); |
1674 | 1674 |
1675 // The predictions should still match even if the form changes, as long | 1675 // The predictions should still match even if the form changes, as long |
1676 // as the particular elements don't change. | 1676 // as the particular elements don't change. |
1677 std::string add_field_to_form = | 1677 std::string add_field_to_form = |
1678 "var form = document.getElementById('LoginTestForm');" | 1678 "var form = document.getElementById('LoginTestForm');" |
1679 "var new_input = document.createElement('input');" | 1679 "var new_input = document.createElement('input');" |
1680 "new_input.setAttribute('type', 'text');" | 1680 "new_input.setAttribute('type', 'text');" |
1681 "new_input.setAttribute('id', 'other_field');" | 1681 "new_input.setAttribute('id', 'other_field');" |
1682 "form.appendChild(new_input);"; | 1682 "form.appendChild(new_input);"; |
1683 ExecuteJavaScript(add_field_to_form.c_str()); | 1683 ExecuteJavaScriptForTests(add_field_to_form.c_str()); |
1684 | 1684 |
1685 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1685 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1686 ->WillSendSubmitEvent(username_element_.form()); | 1686 ->WillSendSubmitEvent(username_element_.form()); |
1687 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1687 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1688 ->WillSubmitForm(username_element_.form()); | 1688 ->WillSubmitForm(username_element_.form()); |
1689 | 1689 |
1690 // Observe that the PasswordAutofillAgent identifies the first field as | 1690 // Observe that the PasswordAutofillAgent identifies the first field as |
1691 // username. | 1691 // username. |
1692 // TODO(msramek): We should also test that adding another password field | 1692 // TODO(msramek): We should also test that adding another password field |
1693 // won't override the password field prediction either. However, the password | 1693 // won't override the password field prediction either. However, the password |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 // Simulate a user clicking on the password element. This should produce no | 1894 // Simulate a user clicking on the password element. This should produce no |
1895 // message. | 1895 // message. |
1896 render_thread_->sink().ClearMessages(); | 1896 render_thread_->sink().ClearMessages(); |
1897 static_cast<PageClickListener*>(autofill_agent_) | 1897 static_cast<PageClickListener*>(autofill_agent_) |
1898 ->FormControlElementClicked(password_element_, false); | 1898 ->FormControlElementClicked(password_element_, false); |
1899 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1899 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
1900 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 1900 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1901 } | 1901 } |
1902 | 1902 |
1903 } // namespace autofill | 1903 } // namespace autofill |
OLD | NEW |