| 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 <tuple> | 5 #include <tuple> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 10 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 // clicking on the username element. This should also produce a message with | 1267 // clicking on the username element. This should also produce a message with |
| 1268 // all the usernames. | 1268 // all the usernames. |
| 1269 SimulateUsernameChange("baz"); | 1269 SimulateUsernameChange("baz"); |
| 1270 render_thread_->sink().ClearMessages(); | 1270 render_thread_->sink().ClearMessages(); |
| 1271 static_cast<PageClickListener*>(autofill_agent_) | 1271 static_cast<PageClickListener*>(autofill_agent_) |
| 1272 ->FormControlElementClicked(username_element_, true); | 1272 ->FormControlElementClicked(username_element_, true); |
| 1273 CheckSuggestions("baz", true); | 1273 CheckSuggestions("baz", true); |
| 1274 ClearUsernameAndPasswordFields(); | 1274 ClearUsernameAndPasswordFields(); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 // Tests that there are no autosuggestions from the password manager when the | 1277 // Tests that there is an autosuggestion from the password manager when the |
| 1278 // user clicks on the password field and the username field is editable when | 1278 // user clicks on the password field when FillOnAccountSelect is enabled. |
| 1279 // FillOnAccountSelect is enabled. | |
| 1280 TEST_F(PasswordAutofillAgentTest, | 1279 TEST_F(PasswordAutofillAgentTest, |
| 1281 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1280 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
| 1282 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1281 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1283 autofill::switches::kEnableFillOnAccountSelect); | 1282 autofill::switches::kEnableFillOnAccountSelect); |
| 1284 | 1283 |
| 1285 // Simulate the browser sending back the login info. | 1284 // Simulate the browser sending back the login info. |
| 1286 SimulateOnFillPasswordForm(fill_data_); | 1285 SimulateOnFillPasswordForm(fill_data_); |
| 1287 | 1286 |
| 1288 // Clear the text fields to start fresh. | 1287 // Clear the text fields to start fresh. |
| 1289 ClearUsernameAndPasswordFields(); | 1288 ClearUsernameAndPasswordFields(); |
| 1290 | 1289 |
| 1291 // Call SimulateElementClick() to produce a user gesture on the page so | 1290 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1292 // autofill will actually fill. | 1291 // autofill will actually fill. |
| 1293 SimulateElementClick(kUsernameName); | 1292 SimulateElementClick(kUsernameName); |
| 1294 | 1293 |
| 1295 // Simulate a user clicking on the password element. This should produce no | 1294 // Simulate a user clicking on the password element. This should produce no |
| 1296 // message. | 1295 // message. |
| 1297 render_thread_->sink().ClearMessages(); | 1296 render_thread_->sink().ClearMessages(); |
| 1298 static_cast<PageClickListener*>(autofill_agent_) | 1297 static_cast<PageClickListener*>(autofill_agent_) |
| 1299 ->FormControlElementClicked(password_element_, false); | 1298 ->FormControlElementClicked(password_element_, false); |
| 1300 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1299 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1301 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 1300 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 1302 } | 1301 } |
| 1303 | 1302 |
| 1304 // Tests the autosuggestions that are given when a password element is clicked, | 1303 // Tests the autosuggestions that are given when a password element is clicked, |
| 1305 // the username element is not editable, and FillOnAccountSelect is enabled. | 1304 // the username element is not editable, and FillOnAccountSelect is enabled. |
| 1306 // Specifically, tests when the user clicks on the password element after page | 1305 // Specifically, tests when the user clicks on the password element after page |
| 1307 // load, and the corresponding username element is readonly (and thus | 1306 // load, and the corresponding username element is readonly (and thus |
| 1308 // uneditable), that the credentials for the already-filled username are | 1307 // uneditable), that the credentials for the already-filled username are |
| 1309 // suggested. | 1308 // suggested. |
| 1310 TEST_F(PasswordAutofillAgentTest, | 1309 TEST_F(PasswordAutofillAgentTest, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1321 // Simulate the page loading with a prefilled username element that is | 1320 // Simulate the page loading with a prefilled username element that is |
| 1322 // uneditable. | 1321 // uneditable. |
| 1323 username_element_.setValue("alicia"); | 1322 username_element_.setValue("alicia"); |
| 1324 SetElementReadOnly(username_element_, true); | 1323 SetElementReadOnly(username_element_, true); |
| 1325 | 1324 |
| 1326 // Call SimulateElementClick() to produce a user gesture on the page so | 1325 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1327 // autofill will actually fill. | 1326 // autofill will actually fill. |
| 1328 SimulateElementClick(kUsernameName); | 1327 SimulateElementClick(kUsernameName); |
| 1329 | 1328 |
| 1330 // Simulate a user clicking on the password element. This should produce a | 1329 // Simulate a user clicking on the password element. This should produce a |
| 1331 // message with "alicia" suggested as the credential. | 1330 // dropdown with suggestion of all available usernames and so username |
| 1331 // filter will be the empty string. |
| 1332 render_thread_->sink().ClearMessages(); | 1332 render_thread_->sink().ClearMessages(); |
| 1333 static_cast<PageClickListener*>(autofill_agent_) | 1333 static_cast<PageClickListener*>(autofill_agent_) |
| 1334 ->FormControlElementClicked(password_element_, false); | 1334 ->FormControlElementClicked(password_element_, false); |
| 1335 CheckSuggestions("alicia", false); | 1335 CheckSuggestions("", false); |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 // Tests that there are no autosuggestions from the password manager when the | 1338 // Tests that there is an autosuggestion from the password manager when the |
| 1339 // user clicks on the password field (not the username field). | 1339 // user clicks on the password field. |
| 1340 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { | 1340 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { |
| 1341 // Simulate the browser sending back the login info. | 1341 // Simulate the browser sending back the login info. |
| 1342 SimulateOnFillPasswordForm(fill_data_); | 1342 SimulateOnFillPasswordForm(fill_data_); |
| 1343 | 1343 |
| 1344 // Clear the text fields to start fresh. | 1344 // Clear the text fields to start fresh. |
| 1345 ClearUsernameAndPasswordFields(); | 1345 ClearUsernameAndPasswordFields(); |
| 1346 | 1346 |
| 1347 // Call SimulateElementClick() to produce a user gesture on the page so | 1347 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1348 // autofill will actually fill. | 1348 // autofill will actually fill. |
| 1349 SimulateElementClick(kUsernameName); | 1349 SimulateElementClick(kUsernameName); |
| 1350 | 1350 |
| 1351 // Simulate a user clicking on the password element. This should produce no | 1351 // Simulate a user clicking on the password element. This should produce no |
| 1352 // message. | 1352 // message. |
| 1353 render_thread_->sink().ClearMessages(); | 1353 render_thread_->sink().ClearMessages(); |
| 1354 static_cast<PageClickListener*>(autofill_agent_) | 1354 static_cast<PageClickListener*>(autofill_agent_) |
| 1355 ->FormControlElementClicked(password_element_, false); | 1355 ->FormControlElementClicked(password_element_, false); |
| 1356 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1356 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1357 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 1357 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 // The user types in a username and a password, but then just before sending | 1360 // The user types in a username and a password, but then just before sending |
| 1361 // the form off, a script clears them. This test checks that | 1361 // the form off, a script clears them. This test checks that |
| 1362 // PasswordAutofillAgent can still remember the username and the password | 1362 // PasswordAutofillAgent can still remember the username and the password |
| 1363 // typed by the user. | 1363 // typed by the user. |
| 1364 TEST_F(PasswordAutofillAgentTest, | 1364 TEST_F(PasswordAutofillAgentTest, |
| 1365 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1365 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
| 1366 SimulateUsernameChange("temp"); | 1366 SimulateUsernameChange("temp"); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 fill_data_.is_possible_change_password_form = true; | 1972 fill_data_.is_possible_change_password_form = true; |
| 1973 SimulateOnFillPasswordForm(fill_data_); | 1973 SimulateOnFillPasswordForm(fill_data_); |
| 1974 // Simulate a user clicking on the password element. This should produce a | 1974 // Simulate a user clicking on the password element. This should produce a |
| 1975 // message. | 1975 // message. |
| 1976 render_thread_->sink().ClearMessages(); | 1976 render_thread_->sink().ClearMessages(); |
| 1977 static_cast<PageClickListener*>(autofill_agent_) | 1977 static_cast<PageClickListener*>(autofill_agent_) |
| 1978 ->FormControlElementClicked(password_element_, true); | 1978 ->FormControlElementClicked(password_element_, true); |
| 1979 CheckSuggestions("", false); | 1979 CheckSuggestions("", false); |
| 1980 } | 1980 } |
| 1981 | 1981 |
| 1982 // Tests that there are no autosuggestions from the password manager when the | |
| 1983 // user clicks on the password field of change password form after the user | |
| 1984 // typed in the username field. | |
| 1985 TEST_F(PasswordAutofillAgentTest, | |
| 1986 NoSuggestionsOnPasswordFieldOfChangePasswordFormAfterUsernameTyping) { | |
| 1987 LoadHTML(kPasswordChangeFormHTML); | |
| 1988 UpdateOriginForHTML(kPasswordChangeFormHTML); | |
| 1989 UpdateUsernameAndPasswordElements(); | |
| 1990 | |
| 1991 ClearUsernameAndPasswordFields(); | |
| 1992 fill_data_.wait_for_username = true; | |
| 1993 fill_data_.is_possible_change_password_form = true; | |
| 1994 SimulateOnFillPasswordForm(fill_data_); | |
| 1995 | |
| 1996 // Clear the text fields to start fresh. | |
| 1997 SimulateUsernameChange("temp"); | |
| 1998 | |
| 1999 // Simulate a user clicking on the password element. This should produce no | |
| 2000 // message. | |
| 2001 render_thread_->sink().ClearMessages(); | |
| 2002 static_cast<PageClickListener*>(autofill_agent_) | |
| 2003 ->FormControlElementClicked(password_element_, false); | |
| 2004 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | |
| 2005 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 2006 } | |
| 2007 | |
| 2008 // Tests that NOT_PASSWORD field predictions are followed so that no password | 1982 // Tests that NOT_PASSWORD field predictions are followed so that no password |
| 2009 // form is submitted. | 1983 // form is submitted. |
| 2010 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { | 1984 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
| 2011 LoadHTML(kCreditCardFormHTML); | 1985 LoadHTML(kCreditCardFormHTML); |
| 2012 blink::WebInputElement credit_card_owner_element = | 1986 blink::WebInputElement credit_card_owner_element = |
| 2013 GetInputElementByID(kCreditCardOwnerName); | 1987 GetInputElementByID(kCreditCardOwnerName); |
| 2014 blink::WebInputElement credit_card_number_element = | 1988 blink::WebInputElement credit_card_number_element = |
| 2015 GetInputElementByID(kCreditCardNumberName); | 1989 GetInputElementByID(kCreditCardNumberName); |
| 2016 blink::WebInputElement credit_card_verification_element = | 1990 blink::WebInputElement credit_card_verification_element = |
| 2017 GetInputElementByID(kCreditCardVerificationName); | 1991 GetInputElementByID(kCreditCardVerificationName); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2320 SimulateUsernameChange("Alice"); | 2294 SimulateUsernameChange("Alice"); |
| 2321 | 2295 |
| 2322 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2296 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2323 ->WillSendSubmitEvent(username_element_.form()); | 2297 ->WillSendSubmitEvent(username_element_.form()); |
| 2324 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2298 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2325 ->WillSubmitForm(username_element_.form()); | 2299 ->WillSubmitForm(username_element_.form()); |
| 2326 | 2300 |
| 2327 ExpectFormSubmittedWithUsernameAndPasswords("Alice", "mypassword", ""); | 2301 ExpectFormSubmittedWithUsernameAndPasswords("Alice", "mypassword", ""); |
| 2328 } | 2302 } |
| 2329 | 2303 |
| 2304 // Tests that a suggestion dropdown is shown on a password field even if a |
| 2305 // username field is present. |
| 2306 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { |
| 2307 // Simulate the browser sending back the login info. |
| 2308 SimulateOnFillPasswordForm(fill_data_); |
| 2309 |
| 2310 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2311 // autofill will actually fill. |
| 2312 SimulateElementClick(kUsernameName); |
| 2313 |
| 2314 // Simulate a user clicking on the password element. This should produce a |
| 2315 // dropdown with suggestion of all available usernames. |
| 2316 render_thread_->sink().ClearMessages(); |
| 2317 static_cast<PageClickListener*>(autofill_agent_) |
| 2318 ->FormControlElementClicked(password_element_, false); |
| 2319 CheckSuggestions("", false); |
| 2320 } |
| 2321 |
| 2322 // Tests that a suggestion dropdown is shown on each password field. But when a |
| 2323 // user chose one of the fields to autofill, a suggestion dropdown will be shown |
| 2324 // only on this field. |
| 2325 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { |
| 2326 LoadHTML(kPasswordChangeFormHTML); |
| 2327 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2328 UpdateUsernameAndPasswordElements(); |
| 2329 |
| 2330 // Simulate the browser sending back the login info. |
| 2331 SimulateOnFillPasswordForm(fill_data_); |
| 2332 |
| 2333 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2334 // autofill will actually fill. |
| 2335 SimulateElementClick(kUsernameName); |
| 2336 |
| 2337 // Simulate a user clicking on the password elements. This should produce |
| 2338 // dropdowns with suggestion of all available usernames. |
| 2339 render_thread_->sink().ClearMessages(); |
| 2340 SimulateElementClick("password"); |
| 2341 CheckSuggestions("", false); |
| 2342 |
| 2343 SimulateElementClick("newpassword"); |
| 2344 CheckSuggestions("", false); |
| 2345 |
| 2346 SimulateElementClick("confirmpassword"); |
| 2347 CheckSuggestions("", false); |
| 2348 |
| 2349 // The user chooses to autofill the current password field. |
| 2350 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
| 2351 password_element_, kAliceUsername, kAlicePassword)); |
| 2352 |
| 2353 // Simulate a user clicking on not autofilled password fields. This should |
| 2354 // produce |
| 2355 // no suggestion dropdowns. |
| 2356 render_thread_->sink().ClearMessages(); |
| 2357 SimulateElementClick("newpassword"); |
| 2358 SimulateElementClick("confirmpassword"); |
| 2359 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 2360 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 2361 |
| 2362 // But when the user clicks on the autofilled password field again it should |
| 2363 // still produce a suggestion dropdown. |
| 2364 SimulateElementClick("password"); |
| 2365 CheckSuggestions("", false); |
| 2366 } |
| 2367 |
| 2330 } // namespace autofill | 2368 } // namespace autofill |
| OLD | NEW |