| 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/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
| 10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 LoadHTML(kSimpleWebpage); | 810 LoadHTML(kSimpleWebpage); |
| 811 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 811 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 812 AutofillHostMsg_PasswordFormsRendered::ID)); | 812 AutofillHostMsg_PasswordFormsRendered::ID)); |
| 813 | 813 |
| 814 render_thread_->sink().ClearMessages(); | 814 render_thread_->sink().ClearMessages(); |
| 815 LoadHTML(kWebpageWithDynamicContent); | 815 LoadHTML(kWebpageWithDynamicContent); |
| 816 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 816 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 817 AutofillHostMsg_PasswordFormsRendered::ID)); | 817 AutofillHostMsg_PasswordFormsRendered::ID)); |
| 818 } | 818 } |
| 819 | 819 |
| 820 // Tests that a password form in an iframe will not be filled in until a user | |
| 821 // interaction with the form. | |
| 822 TEST_F(PasswordAutofillAgentTest, IframeNoFillTest) { | |
| 823 const char kIframeName[] = "iframe"; | |
| 824 const char kWebpageWithIframeStart[] = | |
| 825 "<html>" | |
| 826 " <head>" | |
| 827 " <meta charset='utf-8' />" | |
| 828 " <title>Title</title>" | |
| 829 " </head>" | |
| 830 " <body>" | |
| 831 " <iframe name='iframe' src=\""; | |
| 832 const char kWebpageWithIframeEnd[] = | |
| 833 "\"></iframe>" | |
| 834 " </body>" | |
| 835 "</html>"; | |
| 836 | |
| 837 std::string origin("data:text/html;charset=utf-8,"); | |
| 838 origin += kSimpleWebpage; | |
| 839 | |
| 840 std::string page_html(kWebpageWithIframeStart); | |
| 841 page_html += origin; | |
| 842 page_html += kWebpageWithIframeEnd; | |
| 843 | |
| 844 LoadHTML(page_html.c_str()); | |
| 845 | |
| 846 // Set the expected form origin and action URLs. | |
| 847 fill_data_.origin = GURL(origin); | |
| 848 fill_data_.action = GURL(origin); | |
| 849 | |
| 850 // Retrieve the input elements from the iframe since that is where we want to | |
| 851 // test the autofill. | |
| 852 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName); | |
| 853 ASSERT_TRUE(iframe); | |
| 854 | |
| 855 SimulateOnFillPasswordFormForFrame(iframe, fill_data_); | |
| 856 | |
| 857 WebDocument document = iframe->document(); | |
| 858 | |
| 859 WebElement username_element = document.getElementById(kUsernameName); | |
| 860 WebElement password_element = document.getElementById(kPasswordName); | |
| 861 ASSERT_FALSE(username_element.isNull()); | |
| 862 ASSERT_FALSE(password_element.isNull()); | |
| 863 | |
| 864 WebInputElement username_input = username_element.to<WebInputElement>(); | |
| 865 WebInputElement password_input = password_element.to<WebInputElement>(); | |
| 866 ASSERT_FALSE(username_element.isNull()); | |
| 867 | |
| 868 CheckTextFieldsStateForElements( | |
| 869 username_input, "", false, password_input, "", false, false); | |
| 870 | |
| 871 // Simulate the user typing in the username in the iframe which should cause | |
| 872 // an autofill. | |
| 873 content::RenderFrame::FromWebFrame(iframe) | |
| 874 ->OnMessageReceived(AutofillMsg_FirstUserGestureObservedInTab(0)); | |
| 875 SimulateUserInputChangeForElement(&username_input, kAliceUsername); | |
| 876 | |
| 877 CheckTextFieldsStateForElements(username_input, | |
| 878 kAliceUsername, | |
| 879 true, | |
| 880 password_input, | |
| 881 kAlicePassword, | |
| 882 true, | |
| 883 false); | |
| 884 } | |
| 885 | |
| 886 // Tests that a password will only be filled as a suggested and will not be | 820 // Tests that a password will only be filled as a suggested and will not be |
| 887 // accessible by the DOM until a user gesture has occurred. | 821 // accessible by the DOM until a user gesture has occurred. |
| 888 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { | 822 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { |
| 889 // Trigger the initial autocomplete. | 823 // Trigger the initial autocomplete. |
| 890 SimulateOnFillPasswordForm(fill_data_); | 824 SimulateOnFillPasswordForm(fill_data_); |
| 891 | 825 |
| 892 // The username and password should have been autocompleted. | 826 // The username and password should have been autocompleted. |
| 893 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 827 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| 894 | 828 |
| 895 // However, it should only have completed with the suggested value, as tested | 829 // However, it should only have completed with the suggested value, as tested |
| (...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 ->WillSendSubmitEvent(username_element_.form()); | 1787 ->WillSendSubmitEvent(username_element_.form()); |
| 1854 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1788 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1855 ->WillSubmitForm(username_element_.form()); | 1789 ->WillSubmitForm(username_element_.form()); |
| 1856 | 1790 |
| 1857 // Observe that the PasswordAutofillAgent identifies the first field as | 1791 // Observe that the PasswordAutofillAgent identifies the first field as |
| 1858 // username. | 1792 // username. |
| 1859 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); | 1793 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
| 1860 } | 1794 } |
| 1861 | 1795 |
| 1862 } // namespace autofill | 1796 } // namespace autofill |
| OLD | NEW |