Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2881033003: [Password Manager] Send a request to the store if user clicks on an undetected password field (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_autofill_agent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_FormWithoutPasswords) { 892 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_FormWithoutPasswords) {
893 fake_driver_.reset_password_forms_calls(); 893 fake_driver_.reset_password_forms_calls();
894 LoadHTML(kFormWithoutPasswordsHTML); 894 LoadHTML(kFormWithoutPasswordsHTML);
895 base::RunLoop().RunUntilIdle(); 895 base::RunLoop().RunUntilIdle();
896 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); 896 EXPECT_FALSE(fake_driver_.called_password_forms_parsed());
897 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); 897 EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
898 ASSERT_TRUE(fake_driver_.password_forms_rendered()); 898 ASSERT_TRUE(fake_driver_.password_forms_rendered());
899 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); 899 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
900 } 900 }
901 901
902 TEST_F(PasswordAutofillAgentTest,
903 SendPasswordFormsTest_UndetectedPasswordField) {
904 fake_driver_.reset_password_forms_calls();
905 LoadHTML(kFormWithoutPasswordsHTML);
906 // Emulate that a password field appears but we don't detect that.
907 std::string script =
908 "document.getElementById('random_field').type = 'password';";
909 ExecuteJavaScriptForTests(script.c_str());
910 base::RunLoop().RunUntilIdle();
911 EXPECT_FALSE(fake_driver_.called_password_forms_parsed());
912
913 // When the user clicks on the field, a request to the store will be sent.
914 EXPECT_TRUE(SimulateElementClick("random_field"));
915 base::RunLoop().RunUntilIdle();
916 EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
917 ASSERT_TRUE(fake_driver_.password_forms_parsed());
918 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
919 }
920
902 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonDisplayedForm) { 921 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonDisplayedForm) {
903 fake_driver_.reset_password_forms_calls(); 922 fake_driver_.reset_password_forms_calls();
904 LoadHTML(kNonDisplayedFormHTML); 923 LoadHTML(kNonDisplayedFormHTML);
905 base::RunLoop().RunUntilIdle(); 924 base::RunLoop().RunUntilIdle();
906 EXPECT_TRUE(fake_driver_.called_password_forms_parsed()); 925 EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
907 ASSERT_TRUE(fake_driver_.password_forms_parsed()); 926 ASSERT_TRUE(fake_driver_.password_forms_parsed());
908 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty()); 927 EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
909 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); 928 EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
910 ASSERT_TRUE(fake_driver_.password_forms_rendered()); 929 ASSERT_TRUE(fake_driver_.password_forms_rendered());
911 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); 930 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2888 2907
2889 // Navigate to another page and click on username field, 2908 // Navigate to another page and click on username field,
2890 // CheckSafeBrowsingReputation() should be triggered again. 2909 // CheckSafeBrowsingReputation() should be triggered again.
2891 LoadHTML(kFormHTML); 2910 LoadHTML(kFormHTML);
2892 SimulateElementClick(kUsernameName); 2911 SimulateElementClick(kUsernameName);
2893 base::RunLoop().RunUntilIdle(); 2912 base::RunLoop().RunUntilIdle();
2894 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt()); 2913 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt());
2895 } 2914 }
2896 #endif 2915 #endif
2897 } // namespace autofill 2916 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_autofill_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698