| 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/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return element.to<blink::WebInputElement>(); | 356 return element.to<blink::WebInputElement>(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void ClearUsernameAndPasswordFields() { | 359 void ClearUsernameAndPasswordFields() { |
| 360 username_element_.setValue(""); | 360 username_element_.setValue(""); |
| 361 username_element_.setAutofilled(false); | 361 username_element_.setAutofilled(false); |
| 362 password_element_.setValue(""); | 362 password_element_.setValue(""); |
| 363 password_element_.setAutofilled(false); | 363 password_element_.setAutofilled(false); |
| 364 } | 364 } |
| 365 | 365 |
| 366 void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) { | |
| 367 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
| 368 ->textFieldDidEndEditing(input); | |
| 369 } | |
| 370 | |
| 371 void SimulateSuggestionChoice(WebInputElement& username_input) { | 366 void SimulateSuggestionChoice(WebInputElement& username_input) { |
| 372 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); | 367 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); |
| 373 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); | 368 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); |
| 374 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, | 369 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, |
| 375 password); | 370 password); |
| 376 } | 371 } |
| 377 | 372 |
| 378 void SimulateSuggestionChoiceOfUsernameAndPassword( | 373 void SimulateSuggestionChoiceOfUsernameAndPassword( |
| 379 WebInputElement& input, | 374 WebInputElement& input, |
| 380 const base::string16& username, | 375 const base::string16& username, |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // autocomplete. | 743 // autocomplete. |
| 749 SimulateOnFillPasswordForm(fill_data_); | 744 SimulateOnFillPasswordForm(fill_data_); |
| 750 | 745 |
| 751 // Simulate the user changing the username to some unknown username. | 746 // Simulate the user changing the username to some unknown username. |
| 752 SimulateUsernameChange("alicia"); | 747 SimulateUsernameChange("alicia"); |
| 753 | 748 |
| 754 // The password should not have been cleared. | 749 // The password should not have been cleared. |
| 755 CheckTextFieldsDOMState("alicia", false, kAlicePassword, true); | 750 CheckTextFieldsDOMState("alicia", false, kAlicePassword, true); |
| 756 } | 751 } |
| 757 | 752 |
| 758 // Tests that we only autocomplete on focus lost and with a full username match | 753 // Tests that lost focus does not trigger filling when |wait_for_username| is |
| 759 // when |wait_for_username| is true. | 754 // true. |
| 760 TEST_F(PasswordAutofillAgentTest, WaitUsername) { | 755 TEST_F(PasswordAutofillAgentTest, WaitUsername) { |
| 761 // Simulate the browser sending back the login info. | 756 // Simulate the browser sending back the login info. |
| 762 fill_data_.wait_for_username = true; | 757 fill_data_.wait_for_username = true; |
| 763 SimulateOnFillPasswordForm(fill_data_); | 758 SimulateOnFillPasswordForm(fill_data_); |
| 764 | 759 |
| 765 // No auto-fill should have taken place. | 760 // No auto-fill should have taken place. |
| 766 CheckTextFieldsState(std::string(), false, std::string(), false); | 761 CheckTextFieldsState(std::string(), false, std::string(), false); |
| 767 | 762 |
| 763 SimulateUsernameChange(kAliceUsername); |
| 764 // Change focus in between to make sure blur events don't trigger filling. |
| 765 SetFocused(password_element_); |
| 766 SetFocused(username_element_); |
| 768 // No autocomplete should happen when text is entered in the username. | 767 // No autocomplete should happen when text is entered in the username. |
| 769 SimulateUsernameChange("a"); | |
| 770 CheckTextFieldsState("a", false, std::string(), false); | |
| 771 SimulateUsernameChange("al"); | |
| 772 CheckTextFieldsState("al", false, std::string(), false); | |
| 773 SimulateUsernameChange(kAliceUsername); | |
| 774 CheckTextFieldsState(kAliceUsername, false, std::string(), false); | 768 CheckTextFieldsState(kAliceUsername, false, std::string(), false); |
| 775 | |
| 776 // Autocomplete should happen only when the username textfield is blurred with | |
| 777 // a full match. | |
| 778 SimulateUsernameChange("a"); | |
| 779 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
| 780 ->textFieldDidEndEditing(username_element_); | |
| 781 CheckTextFieldsState("a", false, std::string(), false); | |
| 782 SimulateUsernameChange("al"); | |
| 783 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
| 784 ->textFieldDidEndEditing(username_element_); | |
| 785 CheckTextFieldsState("al", false, std::string(), false); | |
| 786 SimulateUsernameChange("alices"); | |
| 787 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
| 788 ->textFieldDidEndEditing(username_element_); | |
| 789 CheckTextFieldsState("alices", false, std::string(), false); | |
| 790 SimulateUsernameChange(kAliceUsername); | |
| 791 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
| 792 ->textFieldDidEndEditing(username_element_); | |
| 793 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | |
| 794 } | 769 } |
| 795 | 770 |
| 796 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { | 771 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { |
| 797 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; | 772 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; |
| 798 blink::WebFrame* frame; | 773 blink::WebFrame* frame; |
| 799 | 774 |
| 800 LoadHTML(kVisibleFormWithNoUsernameHTML); | 775 LoadHTML(kVisibleFormWithNoUsernameHTML); |
| 801 frame = GetMainFrame(); | 776 frame = GetMainFrame(); |
| 802 frame->document().forms(forms1); | 777 frame->document().forms(forms1); |
| 803 ASSERT_EQ(1u, forms1.size()); | 778 ASSERT_EQ(1u, forms1.size()); |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 password_element_.setValue(WebString()); | 1436 password_element_.setValue(WebString()); |
| 1462 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1437 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1463 ->WillSubmitForm(username_element_.form()); | 1438 ->WillSubmitForm(username_element_.form()); |
| 1464 | 1439 |
| 1465 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1440 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
| 1466 // password and sent that to the browser. | 1441 // password and sent that to the browser. |
| 1467 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random"); | 1442 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random"); |
| 1468 } | 1443 } |
| 1469 | 1444 |
| 1470 // The user first accepts a suggestion, but then overwrites the password. This | 1445 // The user first accepts a suggestion, but then overwrites the password. This |
| 1471 // test checks that the overwritten password is not reverted back if the user | 1446 // test checks that the overwritten password is not reverted back. |
| 1472 // triggers autofill through focusing (but not changing) the username again. | |
| 1473 TEST_F(PasswordAutofillAgentTest, | 1447 TEST_F(PasswordAutofillAgentTest, |
| 1474 NoopEditingDoesNotOverwriteManuallyEditedPassword) { | 1448 NoopEditingDoesNotOverwriteManuallyEditedPassword) { |
| 1475 // Simulate having credentials which needed to wait until the user starts | |
| 1476 // typing the username to be filled (e.g., PSL-matched credentials). Those are | |
| 1477 // the ones which can be filled as a result of TextFieldDidEndEditing. | |
| 1478 fill_data_.wait_for_username = true; | 1449 fill_data_.wait_for_username = true; |
| 1450 SimulateUsernameChange(kAliceUsername); |
| 1479 SimulateOnFillPasswordForm(fill_data_); | 1451 SimulateOnFillPasswordForm(fill_data_); |
| 1480 // Simulate that the user typed their name to make the autofill work. | 1452 SimulateSuggestionChoice(username_element_); |
| 1481 SimulateUsernameChange(kAliceUsername); | |
| 1482 SimulateDidEndEditing(GetMainFrame(), username_element_); | |
| 1483 const std::string old_username(username_element_.value().utf8()); | 1453 const std::string old_username(username_element_.value().utf8()); |
| 1484 const std::string old_password(password_element_.value().utf8()); | 1454 const std::string old_password(password_element_.value().utf8()); |
| 1485 const std::string new_password(old_password + "modify"); | 1455 const std::string new_password(old_password + "modify"); |
| 1486 | 1456 |
| 1487 // The user changes the password. | 1457 // The user changes the password. |
| 1488 SimulatePasswordChange(new_password); | 1458 SimulatePasswordChange(new_password); |
| 1489 | 1459 |
| 1490 // The user switches back into the username field, but leaves that without | 1460 // Change focus in between to make sure blur events don't trigger filling. |
| 1491 // changes. | 1461 SetFocused(password_element_); |
| 1492 SimulateDidEndEditing(GetMainFrame(), username_element_); | 1462 SetFocused(username_element_); |
| 1493 | 1463 |
| 1494 // The password should have stayed as the user changed it. | 1464 // The password should have stayed as the user changed it. |
| 1495 CheckTextFieldsDOMState(old_username, true, new_password, false); | 1465 CheckTextFieldsDOMState(old_username, true, new_password, false); |
| 1496 // The password should not have a suggested value. | 1466 // The password should not have a suggested value. |
| 1497 CheckTextFieldsState(old_username, true, std::string(), false); | 1467 CheckTextFieldsState(old_username, true, std::string(), false); |
| 1498 } | 1468 } |
| 1499 | 1469 |
| 1500 // The user types in a username and a password, but then just before sending | 1470 // The user types in a username and a password, but then just before sending |
| 1501 // the form off, a script changes them. This test checks that | 1471 // the form off, a script changes them. This test checks that |
| 1502 // PasswordAutofillAgent can still remember the username and the password | 1472 // PasswordAutofillAgent can still remember the username and the password |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2417 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 2448 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 2418 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 2449 | 2419 |
| 2450 // But when the user clicks on the autofilled password field again it should | 2420 // But when the user clicks on the autofilled password field again it should |
| 2451 // still produce a suggestion dropdown. | 2421 // still produce a suggestion dropdown. |
| 2452 SimulateElementClick("password"); | 2422 SimulateElementClick("password"); |
| 2453 CheckSuggestions("", false); | 2423 CheckSuggestions("", false); |
| 2454 } | 2424 } |
| 2455 | 2425 |
| 2456 } // namespace autofill | 2426 } // namespace autofill |
| OLD | NEW |