| 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 "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 " </div>" | 90 " </div>" |
| 91 " </form>" | 91 " </form>" |
| 92 "</body>"; | 92 "</body>"; |
| 93 | 93 |
| 94 const char kEmptyFormHTML[] = | 94 const char kEmptyFormHTML[] = |
| 95 "<head> <style> form {display: inline;} </style> </head>" | 95 "<head> <style> form {display: inline;} </style> </head>" |
| 96 "<body> <form> </form> </body>"; | 96 "<body> <form> </form> </body>"; |
| 97 | 97 |
| 98 const char kFormWithoutPasswordsHTML[] = | 98 const char kFormWithoutPasswordsHTML[] = |
| 99 "<FORM>" | 99 "<FORM>" |
| 100 " <INPUT type='text' id='username'/>" |
| 100 " <INPUT type='text' id='random_field'/>" | 101 " <INPUT type='text' id='random_field'/>" |
| 101 " <INPUT type='text' id='username'/>" | |
| 102 "</FORM>"; | 102 "</FORM>"; |
| 103 | 103 |
| 104 const char kNonVisibleFormHTML[] = | 104 const char kNonVisibleFormHTML[] = |
| 105 "<head> <style> form {visibility: hidden;} </style> </head>" | 105 "<head> <style> form {visibility: hidden;} </style> </head>" |
| 106 "<body>" | 106 "<body>" |
| 107 " <form>" | 107 " <form>" |
| 108 " <div>" | 108 " <div>" |
| 109 " <input type='password' id='password'/>" | 109 " <input type='password' id='password'/>" |
| 110 " </div>" | 110 " </div>" |
| 111 " </form>" | 111 " </form>" |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_FormWithoutPasswords) { | 893 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_FormWithoutPasswords) { |
| 894 fake_driver_.reset_password_forms_calls(); | 894 fake_driver_.reset_password_forms_calls(); |
| 895 LoadHTML(kFormWithoutPasswordsHTML); | 895 LoadHTML(kFormWithoutPasswordsHTML); |
| 896 base::RunLoop().RunUntilIdle(); | 896 base::RunLoop().RunUntilIdle(); |
| 897 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); | 897 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); |
| 898 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 898 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 899 ASSERT_TRUE(fake_driver_.password_forms_rendered()); | 899 ASSERT_TRUE(fake_driver_.password_forms_rendered()); |
| 900 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); | 900 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); |
| 901 } | 901 } |
| 902 | 902 |
| 903 TEST_F(PasswordAutofillAgentTest, |
| 904 SendPasswordFormsTest_UndetectedPasswordField) { |
| 905 fake_driver_.reset_password_forms_calls(); |
| 906 LoadHTML(kFormWithoutPasswordsHTML); |
| 907 // Emulate that a password field appears but we don't detect that. |
| 908 std::string script = |
| 909 "document.getElementById('random_field').type = 'password';"; |
| 910 ExecuteJavaScriptForTests(script.c_str()); |
| 911 base::RunLoop().RunUntilIdle(); |
| 912 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); |
| 913 |
| 914 // When the user click on the field, a request to the store will be sent. |
| 915 EXPECT_TRUE(SimulateElementClick("random_field")); |
| 916 base::RunLoop().RunUntilIdle(); |
| 917 EXPECT_TRUE(fake_driver_.called_password_forms_parsed()); |
| 918 ASSERT_TRUE(fake_driver_.password_forms_parsed()); |
| 919 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty()); |
| 920 } |
| 921 |
| 903 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonDisplayedForm) { | 922 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonDisplayedForm) { |
| 904 fake_driver_.reset_password_forms_calls(); | 923 fake_driver_.reset_password_forms_calls(); |
| 905 LoadHTML(kNonDisplayedFormHTML); | 924 LoadHTML(kNonDisplayedFormHTML); |
| 906 base::RunLoop().RunUntilIdle(); | 925 base::RunLoop().RunUntilIdle(); |
| 907 EXPECT_TRUE(fake_driver_.called_password_forms_parsed()); | 926 EXPECT_TRUE(fake_driver_.called_password_forms_parsed()); |
| 908 ASSERT_TRUE(fake_driver_.password_forms_parsed()); | 927 ASSERT_TRUE(fake_driver_.password_forms_parsed()); |
| 909 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty()); | 928 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty()); |
| 910 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 929 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 911 ASSERT_TRUE(fake_driver_.password_forms_rendered()); | 930 ASSERT_TRUE(fake_driver_.password_forms_rendered()); |
| 912 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); | 931 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); |
| (...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2889 | 2908 |
| 2890 // Navigate to another page and click on username field, | 2909 // Navigate to another page and click on username field, |
| 2891 // CheckSafeBrowsingReputation() should be triggered again. | 2910 // CheckSafeBrowsingReputation() should be triggered again. |
| 2892 LoadHTML(kFormHTML); | 2911 LoadHTML(kFormHTML); |
| 2893 SimulateElementClick(kUsernameName); | 2912 SimulateElementClick(kUsernameName); |
| 2894 base::RunLoop().RunUntilIdle(); | 2913 base::RunLoop().RunUntilIdle(); |
| 2895 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt()); | 2914 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt()); |
| 2896 } | 2915 } |
| 2897 #endif | 2916 #endif |
| 2898 } // namespace autofill | 2917 } // namespace autofill |
| OLD | NEW |