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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 username_element_.setAutofilled(false); | 290 username_element_.setAutofilled(false); |
291 password_element_.setValue(""); | 291 password_element_.setValue(""); |
292 password_element_.setAutofilled(false); | 292 password_element_.setAutofilled(false); |
293 } | 293 } |
294 | 294 |
295 void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) { | 295 void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) { |
296 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 296 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
297 ->textFieldDidEndEditing(input); | 297 ->textFieldDidEndEditing(input); |
298 } | 298 } |
299 | 299 |
300 void SimulateInputChangeForElement(const std::string& new_value, | |
301 bool move_caret_to_end, | |
302 WebFrame* input_frame, | |
303 WebInputElement& input, | |
304 bool is_user_input) { | |
305 input.setValue(WebString::fromUTF8(new_value), is_user_input); | |
306 // The field must have focus or AutofillAgent will think the | |
307 // change should be ignored. | |
308 while (!input.focused()) | |
309 input_frame->document().frame()->view()->advanceFocus(false); | |
310 if (move_caret_to_end) | |
311 input.setSelectionRange(new_value.length(), new_value.length()); | |
312 if (is_user_input) { | |
313 AutofillMsg_FirstUserGestureObservedInTab msg(0); | |
314 content::RenderFrame::FromWebFrame(input_frame)->OnMessageReceived(msg); | |
315 | |
316 // Also pass the message to the testing object. | |
317 if (input_frame == GetMainFrame()) | |
318 password_autofill_agent_->FirstUserGestureObserved(); | |
319 } | |
320 input_frame->toWebLocalFrame()->autofillClient()->textFieldDidChange(input); | |
321 // Processing is delayed because of a Blink bug: | |
322 // https://bugs.webkit.org/show_bug.cgi?id=16976 | |
323 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. | |
324 | |
325 // Autocomplete will trigger a style recalculation when we put up the next | |
326 // frame, but we don't want to wait that long. Instead, trigger a style | |
327 // recalcuation manually after TextFieldDidChangeImpl runs. | |
328 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
329 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); | |
330 | |
331 base::MessageLoop::current()->RunUntilIdle(); | |
332 } | |
333 | |
334 void SimulateSuggestionChoice(WebInputElement& username_input) { | 300 void SimulateSuggestionChoice(WebInputElement& username_input) { |
335 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); | 301 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); |
336 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); | 302 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); |
337 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, | 303 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, |
338 password); | 304 password); |
339 } | 305 } |
340 | 306 |
341 void SimulateSuggestionChoiceOfUsernameAndPassword( | 307 void SimulateSuggestionChoiceOfUsernameAndPassword( |
342 WebInputElement& input, | 308 WebInputElement& input, |
343 const base::string16& username, | 309 const base::string16& username, |
344 const base::string16& password) { | 310 const base::string16& password) { |
345 // This call is necessary to setup the autofill agent appropriate for the | 311 // This call is necessary to setup the autofill agent appropriate for the |
346 // user selection; simulates the menu actually popping up. | 312 // user selection; simulates the menu actually popping up. |
347 render_thread_->sink().ClearMessages(); | 313 render_thread_->sink().ClearMessages(); |
348 static_cast<autofill::PageClickListener*>(autofill_agent_) | 314 static_cast<autofill::PageClickListener*>(autofill_agent_) |
349 ->FormControlElementClicked(input, false); | 315 ->FormControlElementClicked(input, false); |
350 | 316 |
351 AutofillMsg_FillPasswordSuggestion msg(0, username, password); | 317 AutofillMsg_FillPasswordSuggestion msg(0, username, password); |
352 static_cast<content::RenderFrameObserver*>(autofill_agent_) | 318 static_cast<content::RenderFrameObserver*>(autofill_agent_) |
353 ->OnMessageReceived(msg); | 319 ->OnMessageReceived(msg); |
354 } | 320 } |
355 | 321 |
356 void LayoutMainFrame() { | 322 void SimulateUsernameChange(const std::string& username) { |
357 GetMainFrame()->view()->layout(); | 323 SimulateUserInputChangeForElement(&username_element_, username); |
358 } | 324 } |
359 | 325 |
360 void SimulateUsernameChange(const std::string& username, | 326 void SimulatePasswordChange(const std::string& password) { |
361 bool move_caret_to_end, | 327 SimulateUserInputChangeForElement(&password_element_, password); |
362 bool is_user_input = false) { | |
363 SimulateInputChangeForElement(username, | |
364 move_caret_to_end, | |
365 GetMainFrame(), | |
366 username_element_, | |
367 is_user_input); | |
368 } | |
369 | |
370 void SimulateKeyDownEvent(const WebInputElement& element, | |
371 ui::KeyboardCode key_code) { | |
372 blink::WebKeyboardEvent key_event; | |
373 key_event.windowsKeyCode = key_code; | |
374 static_cast<blink::WebAutofillClient*>(autofill_agent_) | |
375 ->textFieldDidReceiveKeyDown(element, key_event); | |
376 } | 328 } |
377 | 329 |
378 void CheckTextFieldsStateForElements(const WebInputElement& username_element, | 330 void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
379 const std::string& username, | 331 const std::string& username, |
380 bool username_autofilled, | 332 bool username_autofilled, |
381 const WebInputElement& password_element, | 333 const WebInputElement& password_element, |
382 const std::string& password, | 334 const std::string& password, |
383 bool password_autofilled, | 335 bool password_autofilled, |
384 bool checkSuggestedValue) { | 336 bool checkSuggestedValue) { |
385 EXPECT_EQ(username, | 337 EXPECT_EQ(username, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 633 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
682 } | 634 } |
683 | 635 |
684 // Tests that editing the password clears the autocompleted password field. | 636 // Tests that editing the password clears the autocompleted password field. |
685 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { | 637 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { |
686 // Simulate the browser sending back the login info, it triggers the | 638 // Simulate the browser sending back the login info, it triggers the |
687 // autocomplete. | 639 // autocomplete. |
688 SimulateOnFillPasswordForm(fill_data_); | 640 SimulateOnFillPasswordForm(fill_data_); |
689 | 641 |
690 // Simulate the user changing the username to some unknown username. | 642 // Simulate the user changing the username to some unknown username. |
691 SimulateUsernameChange("alicia", true); | 643 SimulateUsernameChange("alicia"); |
692 | 644 |
693 // The password should have been cleared. | 645 // The password should have been cleared. |
694 CheckTextFieldsState("alicia", false, std::string(), false); | 646 CheckTextFieldsState("alicia", false, std::string(), false); |
695 } | 647 } |
696 | 648 |
697 // Tests that we only autocomplete on focus lost and with a full username match | 649 // Tests that we only autocomplete on focus lost and with a full username match |
698 // when |wait_for_username| is true. | 650 // when |wait_for_username| is true. |
699 TEST_F(PasswordAutofillAgentTest, WaitUsername) { | 651 TEST_F(PasswordAutofillAgentTest, WaitUsername) { |
700 // Simulate the browser sending back the login info. | 652 // Simulate the browser sending back the login info. |
701 fill_data_.wait_for_username = true; | 653 fill_data_.wait_for_username = true; |
702 SimulateOnFillPasswordForm(fill_data_); | 654 SimulateOnFillPasswordForm(fill_data_); |
703 | 655 |
704 // No auto-fill should have taken place. | 656 // No auto-fill should have taken place. |
705 CheckTextFieldsState(std::string(), false, std::string(), false); | 657 CheckTextFieldsState(std::string(), false, std::string(), false); |
706 | 658 |
707 // No autocomplete should happen when text is entered in the username. | 659 // No autocomplete should happen when text is entered in the username. |
708 SimulateUsernameChange("a", true); | 660 SimulateUsernameChange("a"); |
709 CheckTextFieldsState("a", false, std::string(), false); | 661 CheckTextFieldsState("a", false, std::string(), false); |
710 SimulateUsernameChange("al", true); | 662 SimulateUsernameChange("al"); |
711 CheckTextFieldsState("al", false, std::string(), false); | 663 CheckTextFieldsState("al", false, std::string(), false); |
712 SimulateUsernameChange(kAliceUsername, true); | 664 SimulateUsernameChange(kAliceUsername); |
713 CheckTextFieldsState(kAliceUsername, false, std::string(), false); | 665 CheckTextFieldsState(kAliceUsername, false, std::string(), false); |
714 | 666 |
715 // Autocomplete should happen only when the username textfield is blurred with | 667 // Autocomplete should happen only when the username textfield is blurred with |
716 // a full match. | 668 // a full match. |
717 username_element_.setValue("a"); | 669 SimulateUsernameChange("a"); |
718 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 670 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
719 ->textFieldDidEndEditing(username_element_); | 671 ->textFieldDidEndEditing(username_element_); |
720 CheckTextFieldsState("a", false, std::string(), false); | 672 CheckTextFieldsState("a", false, std::string(), false); |
721 username_element_.setValue("al"); | 673 SimulateUsernameChange("al"); |
722 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 674 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
723 ->textFieldDidEndEditing(username_element_); | 675 ->textFieldDidEndEditing(username_element_); |
724 CheckTextFieldsState("al", false, std::string(), false); | 676 CheckTextFieldsState("al", false, std::string(), false); |
725 username_element_.setValue("alices"); | 677 SimulateUsernameChange("alices"); |
726 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 678 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
727 ->textFieldDidEndEditing(username_element_); | 679 ->textFieldDidEndEditing(username_element_); |
728 CheckTextFieldsState("alices", false, std::string(), false); | 680 CheckTextFieldsState("alices", false, std::string(), false); |
729 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 681 SimulateUsernameChange(kAliceUsername); |
730 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 682 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
731 ->textFieldDidEndEditing(username_element_); | 683 ->textFieldDidEndEditing(username_element_); |
732 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 684 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
733 } | 685 } |
734 | 686 |
735 // Tests that inline autocompletion works properly. | 687 // Tests that inline autocompletion works properly. |
736 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { | 688 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { |
737 // Simulate the browser sending back the login info. | 689 // Simulate the browser sending back the login info. |
738 SimulateOnFillPasswordForm(fill_data_); | 690 SimulateOnFillPasswordForm(fill_data_); |
739 | 691 |
740 ClearUsernameAndPasswordFields(); | 692 ClearUsernameAndPasswordFields(); |
741 | 693 |
742 // Simulate the user typing in the first letter of 'alice', a stored | 694 // Simulate the user typing in the first letter of 'alice', a stored |
743 // username. | 695 // username. |
744 SimulateUsernameChange("a", true); | 696 SimulateUsernameChange("a"); |
745 // Both the username and password text fields should reflect selection of the | 697 // Both the username and password text fields should reflect selection of the |
746 // stored login. | 698 // stored login. |
747 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 699 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
748 // And the selection should have been set to 'lice', the last 4 letters. | 700 // And the selection should have been set to 'lice', the last 4 letters. |
749 CheckUsernameSelection(1, 5); | 701 CheckUsernameSelection(1, 5); |
750 | 702 |
751 // Now the user types the next letter of the same username, 'l'. | 703 // Now the user types the next letter of the same username, 'l'. |
752 SimulateUsernameChange("al", true); | 704 SimulateUserTypingASCIICharacter('l', true); |
753 // Now the fields should have the same value, but the selection should have a | 705 // Now the fields should have the same value, but the selection should have a |
754 // different start value. | 706 // different start value. |
755 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 707 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
756 CheckUsernameSelection(2, 5); | 708 CheckUsernameSelection(2, 5); |
757 | 709 |
758 // Test that deleting does not trigger autocomplete. | 710 // Test that backspace will erase the selection and will stop autocompletion. |
759 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); | 711 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true); |
760 SimulateUsernameChange("alic", true); | 712 CheckTextFieldsState("al", false, std::string(), false); |
761 CheckTextFieldsState("alic", false, std::string(), false); | 713 CheckUsernameSelection(2, 2); // No selection. |
762 CheckUsernameSelection(4, 4); // No selection. | |
763 // Reset the last pressed key to something other than backspace. | |
764 SimulateKeyDownEvent(username_element_, ui::VKEY_A); | |
765 | 714 |
766 // Now lets say the user goes astray from the stored username and types the | 715 // Now lets say the user goes astray from the stored username and types the |
767 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in | 716 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
768 // practice the username should no longer be 'alice' and the selected range | 717 // practice the username should no longer be 'alice' and the selected range |
769 // should be empty. | 718 // should be empty. |
770 SimulateUsernameChange("alf", true); | 719 SimulateUserTypingASCIICharacter('f', true); |
771 CheckTextFieldsState("alf", false, std::string(), false); | 720 CheckTextFieldsState("alf", false, std::string(), false); |
772 CheckUsernameSelection(3, 3); // No selection. | 721 CheckUsernameSelection(3, 3); // No selection. |
773 | 722 |
774 // Ok, so now the user removes all the text and enters the letter 'b'. | 723 // Ok, so now the user removes all the text and enters the letter 'b'. |
775 SimulateUsernameChange("b", true); | 724 SimulateUsernameChange("b"); |
776 // The username and password fields should match the 'bob' entry. | 725 // The username and password fields should match the 'bob' entry. |
777 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); | 726 CheckTextFieldsDOMState(kBobUsername, true, kBobPassword, true); |
778 CheckUsernameSelection(1, 3); | 727 CheckUsernameSelection(1, 3); |
779 | 728 |
780 // Then, the user again removes all the text and types an uppercase 'C'. | 729 // Then, the user again removes all the text and types an uppercase 'C'. |
781 SimulateUsernameChange("C", true); | 730 SimulateUsernameChange("C"); |
782 // The username and password fields should match the 'Carol' entry. | 731 // The username and password fields should match the 'Carol' entry. |
783 CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); | 732 CheckTextFieldsDOMState(kCarolUsername, true, kCarolPassword, true); |
784 CheckUsernameSelection(1, 5); | 733 CheckUsernameSelection(1, 5); |
| 734 |
785 // The user removes all the text and types a lowercase 'c'. We only | 735 // The user removes all the text and types a lowercase 'c'. We only |
786 // want case-sensitive autocompletion, so the username and the selected range | 736 // want case-sensitive autocompletion, so the username and the selected range |
787 // should be empty. | 737 // should be empty. |
788 SimulateUsernameChange("c", true); | 738 SimulateUsernameChange("c"); |
789 CheckTextFieldsState("c", false, std::string(), false); | 739 CheckTextFieldsState("c", false, std::string(), false); |
790 CheckUsernameSelection(1, 1); | 740 CheckUsernameSelection(1, 1); |
791 | 741 |
792 // Check that we complete other_possible_usernames as well. | 742 // Check that we complete other_possible_usernames as well. |
793 SimulateUsernameChange("R", true); | 743 SimulateUsernameChange("R"); |
794 CheckTextFieldsState(kCarolAlternateUsername, true, kCarolPassword, true); | 744 CheckTextFieldsDOMState(kCarolAlternateUsername, true, kCarolPassword, true); |
795 CheckUsernameSelection(1, 17); | 745 CheckUsernameSelection(1, 17); |
796 } | 746 } |
797 | 747 |
798 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { | 748 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { |
799 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; | 749 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; |
800 blink::WebFrame* frame; | 750 blink::WebFrame* frame; |
801 | 751 |
802 LoadHTML(kVisibleFormWithNoUsernameHTML); | 752 LoadHTML(kVisibleFormWithNoUsernameHTML); |
803 frame = GetMainFrame(); | 753 frame = GetMainFrame(); |
804 frame->document().forms(forms1); | 754 frame->document().forms(forms1); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 | 863 |
914 WebInputElement username_input = username_element.to<WebInputElement>(); | 864 WebInputElement username_input = username_element.to<WebInputElement>(); |
915 WebInputElement password_input = password_element.to<WebInputElement>(); | 865 WebInputElement password_input = password_element.to<WebInputElement>(); |
916 ASSERT_FALSE(username_element.isNull()); | 866 ASSERT_FALSE(username_element.isNull()); |
917 | 867 |
918 CheckTextFieldsStateForElements( | 868 CheckTextFieldsStateForElements( |
919 username_input, "", false, password_input, "", false, false); | 869 username_input, "", false, password_input, "", false, false); |
920 | 870 |
921 // Simulate the user typing in the username in the iframe which should cause | 871 // Simulate the user typing in the username in the iframe which should cause |
922 // an autofill. | 872 // an autofill. |
923 SimulateInputChangeForElement( | 873 content::RenderFrame::FromWebFrame(iframe) |
924 kAliceUsername, true, iframe, username_input, true); | 874 ->OnMessageReceived(AutofillMsg_FirstUserGestureObservedInTab(0)); |
| 875 SimulateUserInputChangeForElement(&username_input, kAliceUsername); |
925 | 876 |
926 CheckTextFieldsStateForElements(username_input, | 877 CheckTextFieldsStateForElements(username_input, |
927 kAliceUsername, | 878 kAliceUsername, |
928 true, | 879 true, |
929 password_input, | 880 password_input, |
930 kAlicePassword, | 881 kAlicePassword, |
931 true, | 882 true, |
932 false); | 883 false); |
933 } | 884 } |
934 | 885 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 fill_data_.wait_for_username = true; | 973 fill_data_.wait_for_username = true; |
1023 SimulateOnFillPasswordForm(fill_data_); | 974 SimulateOnFillPasswordForm(fill_data_); |
1024 | 975 |
1025 // The username and password should not yet have been autocompleted. | 976 // The username and password should not yet have been autocompleted. |
1026 CheckTextFieldsState(std::string(), false, std::string(), false); | 977 CheckTextFieldsState(std::string(), false, std::string(), false); |
1027 | 978 |
1028 // Simulate a click just to force a user gesture, since the username value is | 979 // Simulate a click just to force a user gesture, since the username value is |
1029 // set directly. | 980 // set directly. |
1030 SimulateElementClick(kUsernameName); | 981 SimulateElementClick(kUsernameName); |
1031 | 982 |
1032 // Simulate the user entering her username and selecting the matching autofill | 983 // Simulate the user entering the first letter of her username and selecting |
1033 // from the dropdown. | 984 // the matching autofill from the dropdown. |
1034 SimulateUsernameChange(kAliceUsername, true, true); | 985 SimulateUsernameChange("a"); |
1035 SimulateSuggestionChoice(username_element_); | 986 SimulateSuggestionChoice(username_element_); |
1036 | 987 |
1037 // The username and password should now have been autocompleted. | 988 // The username and password should now have been autocompleted. |
1038 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 989 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1039 | 990 |
1040 // JavaScript onChange events should have been triggered both for the username | 991 // JavaScript onChange events should have been triggered both for the username |
1041 // and for the password. | 992 // and for the password. |
1042 int username_onchange_called = -1; | 993 int username_onchange_called = -1; |
1043 int password_onchange_called = -1; | 994 int password_onchange_called = -1; |
1044 ASSERT_TRUE( | 995 ASSERT_TRUE( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 // Tests that |ClearPreview| properly restores the original selection range of | 1233 // Tests that |ClearPreview| properly restores the original selection range of |
1283 // username field that has initially been filled by inline autocomplete. | 1234 // username field that has initially been filled by inline autocomplete. |
1284 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { | 1235 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { |
1285 // Simulate the browser sending back the login info. | 1236 // Simulate the browser sending back the login info. |
1286 SimulateOnFillPasswordForm(fill_data_); | 1237 SimulateOnFillPasswordForm(fill_data_); |
1287 | 1238 |
1288 // Clear the text fields to start fresh. | 1239 // Clear the text fields to start fresh. |
1289 ClearUsernameAndPasswordFields(); | 1240 ClearUsernameAndPasswordFields(); |
1290 | 1241 |
1291 // Simulate the user typing in the first letter of 'alice', a stored username. | 1242 // Simulate the user typing in the first letter of 'alice', a stored username. |
1292 SimulateUsernameChange("a", true); | 1243 SimulateUsernameChange("a"); |
1293 // Both the username and password text fields should reflect selection of the | 1244 // Both the username and password text fields should reflect selection of the |
1294 // stored login. | 1245 // stored login. |
1295 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 1246 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1296 // The selection should have been set to 'lice', the last 4 letters. | 1247 // The selection should have been set to 'lice', the last 4 letters. |
1297 CheckUsernameSelection(1, 5); | 1248 CheckUsernameSelection(1, 5); |
1298 | 1249 |
1299 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( | 1250 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( |
1300 username_element_, "alicia", "secret")); | 1251 username_element_, "alicia", "secret")); |
1301 EXPECT_EQ( | 1252 EXPECT_EQ( |
1302 "alicia", | 1253 "alicia", |
1303 static_cast<std::string>(username_element_.suggestedValue().utf8())); | 1254 static_cast<std::string>(username_element_.suggestedValue().utf8())); |
1304 EXPECT_TRUE(username_element_.isAutofilled()); | 1255 EXPECT_TRUE(username_element_.isAutofilled()); |
1305 EXPECT_EQ( | 1256 EXPECT_EQ( |
1306 "secret", | 1257 "secret", |
1307 static_cast<std::string>(password_element_.suggestedValue().utf8())); | 1258 static_cast<std::string>(password_element_.suggestedValue().utf8())); |
1308 EXPECT_TRUE(password_element_.isAutofilled()); | 1259 EXPECT_TRUE(password_element_.isAutofilled()); |
1309 CheckUsernameSelection(1, 6); | 1260 CheckUsernameSelection(1, 6); |
1310 | 1261 |
1311 EXPECT_TRUE( | 1262 EXPECT_TRUE( |
1312 password_autofill_agent_->DidClearAutofillSelection(username_element_)); | 1263 password_autofill_agent_->DidClearAutofillSelection(username_element_)); |
1313 | 1264 |
1314 EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); | 1265 EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); |
1315 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); | 1266 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
1316 EXPECT_TRUE(username_element_.isAutofilled()); | 1267 EXPECT_TRUE(username_element_.isAutofilled()); |
1317 EXPECT_TRUE(password_element_.value().isEmpty()); | 1268 EXPECT_EQ(kAlicePassword, password_element_.value().utf8()); |
1318 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1269 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
1319 EXPECT_TRUE(password_element_.isAutofilled()); | 1270 EXPECT_TRUE(password_element_.isAutofilled()); |
1320 CheckUsernameSelection(1, 5); | 1271 CheckUsernameSelection(1, 5); |
1321 } | 1272 } |
1322 | 1273 |
1323 // Tests that logging is off by default. | 1274 // Tests that logging is off by default. |
1324 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { | 1275 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
1325 render_thread_->sink().ClearMessages(); | 1276 render_thread_->sink().ClearMessages(); |
1326 SendVisiblePasswordForms(); | 1277 SendVisiblePasswordForms(); |
1327 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1278 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 // Simulate a user clicking on the username element. This should produce a | 1358 // Simulate a user clicking on the username element. This should produce a |
1408 // message with all the usernames. | 1359 // message with all the usernames. |
1409 render_thread_->sink().ClearMessages(); | 1360 render_thread_->sink().ClearMessages(); |
1410 static_cast<PageClickListener*>(autofill_agent_) | 1361 static_cast<PageClickListener*>(autofill_agent_) |
1411 ->FormControlElementClicked(username_element_, false); | 1362 ->FormControlElementClicked(username_element_, false); |
1412 CheckSuggestions(std::string(), false); | 1363 CheckSuggestions(std::string(), false); |
1413 | 1364 |
1414 // Now simulate a user typing in an unrecognized username and then | 1365 // Now simulate a user typing in an unrecognized username and then |
1415 // clicking on the username element. This should also produce a message with | 1366 // clicking on the username element. This should also produce a message with |
1416 // all the usernames. | 1367 // all the usernames. |
1417 SimulateUsernameChange("baz", true); | 1368 SimulateUsernameChange("baz"); |
1418 render_thread_->sink().ClearMessages(); | 1369 render_thread_->sink().ClearMessages(); |
1419 static_cast<PageClickListener*>(autofill_agent_) | 1370 static_cast<PageClickListener*>(autofill_agent_) |
1420 ->FormControlElementClicked(username_element_, true); | 1371 ->FormControlElementClicked(username_element_, true); |
1421 CheckSuggestions("baz", true); | 1372 CheckSuggestions("baz", true); |
| 1373 ClearUsernameAndPasswordFields(); |
1422 | 1374 |
1423 // Now simulate a user typing in the first letter of the username and then | 1375 // Now simulate a user typing in the first letter of the username and then |
1424 // clicking on the username element. While the typing of the first letter will | 1376 // clicking on the username element. While the typing of the first letter will |
1425 // inline autocomplete, clicking on the element should still produce a full | 1377 // inline autocomplete, clicking on the element should still produce a full |
1426 // suggestion list. | 1378 // suggestion list. |
1427 SimulateUsernameChange("a", true); | 1379 SimulateUsernameChange("a"); |
1428 render_thread_->sink().ClearMessages(); | 1380 render_thread_->sink().ClearMessages(); |
1429 static_cast<PageClickListener*>(autofill_agent_) | 1381 static_cast<PageClickListener*>(autofill_agent_) |
1430 ->FormControlElementClicked(username_element_, true); | 1382 ->FormControlElementClicked(username_element_, true); |
1431 CheckSuggestions(kAliceUsername, true); | 1383 CheckSuggestions(kAliceUsername, true); |
1432 } | 1384 } |
1433 | 1385 |
1434 // Tests that there are no autosuggestions from the password manager when the | 1386 // Tests that there are no autosuggestions from the password manager when the |
1435 // user clicks on the password field and the username field is editable when | 1387 // user clicks on the password field and the username field is editable when |
1436 // FillOnAccountSelect is enabled. | 1388 // FillOnAccountSelect is enabled. |
1437 TEST_F(PasswordAutofillAgentTest, | 1389 TEST_F(PasswordAutofillAgentTest, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1465 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
1514 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 1466 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1515 } | 1467 } |
1516 | 1468 |
1517 // The user types in a username and a password, but then just before sending | 1469 // The user types in a username and a password, but then just before sending |
1518 // the form off, a script clears them. This test checks that | 1470 // the form off, a script clears them. This test checks that |
1519 // PasswordAutofillAgent can still remember the username and the password | 1471 // PasswordAutofillAgent can still remember the username and the password |
1520 // typed by the user. | 1472 // typed by the user. |
1521 TEST_F(PasswordAutofillAgentTest, | 1473 TEST_F(PasswordAutofillAgentTest, |
1522 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1474 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
1523 SimulateInputChangeForElement( | 1475 SimulateUsernameChange("temp"); |
1524 "temp", true, GetMainFrame(), username_element_, true); | 1476 SimulatePasswordChange("random"); |
1525 SimulateInputChangeForElement( | |
1526 "random", true, GetMainFrame(), password_element_, true); | |
1527 | 1477 |
1528 // Simulate that the username and the password value was cleared by the | 1478 // Simulate that the username and the password value was cleared by the |
1529 // site's JavaScript before submit. | 1479 // site's JavaScript before submit. |
1530 username_element_.setValue(WebString()); | 1480 username_element_.setValue(WebString()); |
1531 password_element_.setValue(WebString()); | 1481 password_element_.setValue(WebString()); |
1532 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1482 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1533 ->WillSubmitForm(username_element_.form()); | 1483 ->WillSubmitForm(username_element_.form()); |
1534 | 1484 |
1535 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1485 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1536 // username and password and sent that to the browser. | 1486 // username and password and sent that to the browser. |
1537 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); | 1487 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
1538 } | 1488 } |
1539 | 1489 |
1540 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time | 1490 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time |
1541 // it's the user who clears the username and the password. This test checks | 1491 // it's the user who clears the username and the password. This test checks |
1542 // that in that case, the last non-empty username and password are not | 1492 // that in that case, the last non-empty username and password are not |
1543 // remembered. | 1493 // remembered. |
1544 TEST_F(PasswordAutofillAgentTest, | 1494 TEST_F(PasswordAutofillAgentTest, |
1545 RememberLastNonEmptyUsernameAndPasswordOnSubmit_UserCleared) { | 1495 RememberLastNonEmptyUsernameAndPasswordOnSubmit_UserCleared) { |
1546 SimulateInputChangeForElement( | 1496 SimulateUsernameChange("temp"); |
1547 "temp", true, GetMainFrame(), username_element_, true); | 1497 SimulatePasswordChange("random"); |
1548 SimulateInputChangeForElement( | |
1549 "random", true, GetMainFrame(), password_element_, true); | |
1550 | 1498 |
1551 // Simulate that the user actually cleared the username and password again. | 1499 // Simulate that the user actually cleared the username and password again. |
1552 SimulateInputChangeForElement("", true, GetMainFrame(), username_element_, | 1500 SimulateUsernameChange(""); |
1553 true); | 1501 SimulatePasswordChange(""); |
1554 SimulateInputChangeForElement( | |
1555 "", true, GetMainFrame(), password_element_, true); | |
1556 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1502 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1557 ->WillSubmitForm(username_element_.form()); | 1503 ->WillSubmitForm(username_element_.form()); |
1558 | 1504 |
1559 // Observe that the PasswordAutofillAgent respects the user having cleared the | 1505 // Observe that the PasswordAutofillAgent respects the user having cleared the |
1560 // password. | 1506 // password. |
1561 ExpectFormSubmittedWithUsernameAndPasswords("", "", ""); | 1507 ExpectFormSubmittedWithUsernameAndPasswords("", "", ""); |
1562 } | 1508 } |
1563 | 1509 |
1564 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the | 1510 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the |
1565 // new password instead of the current password. | 1511 // new password instead of the current password. |
1566 TEST_F(PasswordAutofillAgentTest, | 1512 TEST_F(PasswordAutofillAgentTest, |
1567 RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) { | 1513 RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) { |
1568 const char kNewPasswordFormHTML[] = | 1514 const char kNewPasswordFormHTML[] = |
1569 "<FORM name='LoginTestForm'>" | 1515 "<FORM name='LoginTestForm'>" |
1570 " <INPUT type='text' id='username' autocomplete='username'/>" | 1516 " <INPUT type='text' id='username' autocomplete='username'/>" |
1571 " <INPUT type='password' id='password' autocomplete='new-password'/>" | 1517 " <INPUT type='password' id='password' autocomplete='new-password'/>" |
1572 " <INPUT type='submit' value='Login'/>" | 1518 " <INPUT type='submit' value='Login'/>" |
1573 "</FORM>"; | 1519 "</FORM>"; |
1574 LoadHTML(kNewPasswordFormHTML); | 1520 LoadHTML(kNewPasswordFormHTML); |
1575 UpdateUsernameAndPasswordElements(); | 1521 UpdateUsernameAndPasswordElements(); |
1576 | 1522 |
1577 SimulateInputChangeForElement( | 1523 SimulateUsernameChange("temp"); |
1578 "temp", true, GetMainFrame(), username_element_, true); | 1524 SimulatePasswordChange("random"); |
1579 SimulateInputChangeForElement( | |
1580 "random", true, GetMainFrame(), password_element_, true); | |
1581 | 1525 |
1582 // Simulate that the username and the password value was cleared by | 1526 // Simulate that the username and the password value was cleared by |
1583 // the site's JavaScript before submit. | 1527 // the site's JavaScript before submit. |
1584 username_element_.setValue(WebString()); | 1528 username_element_.setValue(WebString()); |
1585 password_element_.setValue(WebString()); | 1529 password_element_.setValue(WebString()); |
1586 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1530 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1587 ->WillSubmitForm(username_element_.form()); | 1531 ->WillSubmitForm(username_element_.form()); |
1588 | 1532 |
1589 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1533 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1590 // password and sent that to the browser. | 1534 // password and sent that to the browser. |
1591 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random"); | 1535 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random"); |
1592 } | 1536 } |
1593 | 1537 |
1594 // The user first accepts a suggestion, but then overwrites the password. This | 1538 // The user first accepts a suggestion, but then overwrites the password. This |
1595 // test checks that the overwritten password is not reverted back if the user | 1539 // test checks that the overwritten password is not reverted back if the user |
1596 // triggers autofill through focusing (but not changing) the username again. | 1540 // triggers autofill through focusing (but not changing) the username again. |
1597 TEST_F(PasswordAutofillAgentTest, | 1541 TEST_F(PasswordAutofillAgentTest, |
1598 NoopEditingDoesNotOverwriteManuallyEditedPassword) { | 1542 NoopEditingDoesNotOverwriteManuallyEditedPassword) { |
1599 // Simulate having credentials which needed to wait until the user starts | 1543 // Simulate having credentials which needed to wait until the user starts |
1600 // typing the username to be filled (e.g., PSL-matched credentials). Those are | 1544 // typing the username to be filled (e.g., PSL-matched credentials). Those are |
1601 // the ones which can be filled as a result of TextFieldDidEndEditing. | 1545 // the ones which can be filled as a result of TextFieldDidEndEditing. |
1602 fill_data_.wait_for_username = true; | 1546 fill_data_.wait_for_username = true; |
1603 SimulateOnFillPasswordForm(fill_data_); | 1547 SimulateOnFillPasswordForm(fill_data_); |
1604 // Simulate that the user typed her name to make the autofill work. | 1548 // Simulate that the user typed her name to make the autofill work. |
1605 SimulateInputChangeForElement(kAliceUsername, | 1549 SimulateUsernameChange(kAliceUsername); |
1606 /*move_caret_to_end=*/true, | |
1607 GetMainFrame(), | |
1608 username_element_, | |
1609 /*is_user_input=*/true); | |
1610 SimulateDidEndEditing(GetMainFrame(), username_element_); | 1550 SimulateDidEndEditing(GetMainFrame(), username_element_); |
1611 const std::string old_username(username_element_.value().utf8()); | 1551 const std::string old_username(username_element_.value().utf8()); |
1612 const std::string old_password(password_element_.value().utf8()); | 1552 const std::string old_password(password_element_.value().utf8()); |
1613 const std::string new_password(old_password + "modify"); | 1553 const std::string new_password(old_password + "modify"); |
1614 | 1554 |
1615 // The user changes the password. | 1555 // The user changes the password. |
1616 SimulateInputChangeForElement(new_password, | 1556 SimulatePasswordChange(new_password); |
1617 /*move_caret_to_end=*/true, | |
1618 GetMainFrame(), | |
1619 password_element_, | |
1620 /*is_user_input=*/true); | |
1621 | 1557 |
1622 // The user switches back into the username field, but leaves that without | 1558 // The user switches back into the username field, but leaves that without |
1623 // changes. | 1559 // changes. |
1624 SimulateDidEndEditing(GetMainFrame(), username_element_); | 1560 SimulateDidEndEditing(GetMainFrame(), username_element_); |
1625 | 1561 |
1626 // The password should have stayed as the user changed it. | 1562 // The password should have stayed as the user changed it. |
1627 CheckTextFieldsDOMState(old_username, true, new_password, false); | 1563 CheckTextFieldsDOMState(old_username, true, new_password, false); |
1628 // The password should not have a suggested value. | 1564 // The password should not have a suggested value. |
1629 CheckTextFieldsState(old_username, true, std::string(), false); | 1565 CheckTextFieldsState(old_username, true, std::string(), false); |
1630 } | 1566 } |
1631 | 1567 |
1632 TEST_F(PasswordAutofillAgentTest, | 1568 TEST_F(PasswordAutofillAgentTest, |
1633 InlineAutocompleteOverwritesManuallyEditedPassword) { | 1569 InlineAutocompleteOverwritesManuallyEditedPassword) { |
1634 // Simulate the browser sending back the login info. | 1570 // Simulate the browser sending back the login info. |
1635 SimulateOnFillPasswordForm(fill_data_); | 1571 SimulateOnFillPasswordForm(fill_data_); |
1636 | 1572 |
1637 ClearUsernameAndPasswordFields(); | 1573 ClearUsernameAndPasswordFields(); |
1638 | 1574 |
1639 // The user enters a password | 1575 // The user enters a password |
1640 SimulateInputChangeForElement("someOtherPassword", | 1576 SimulatePasswordChange("someOtherPassword"); |
1641 /*move_caret_to_end=*/true, | |
1642 GetMainFrame(), | |
1643 password_element_, | |
1644 /*is_user_input=*/true); | |
1645 | 1577 |
1646 // Simulate the user typing a stored username. | 1578 // Simulate the user typing a stored username. |
1647 SimulateUsernameChange(kAliceUsername, true); | 1579 SimulateUsernameChange(kAliceUsername); |
1648 // The autofileld password should replace the typed one. | 1580 // The autofileld password should replace the typed one. |
1649 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1581 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1650 } | 1582 } |
1651 | 1583 |
1652 // The user types in a username and a password, but then just before sending | 1584 // The user types in a username and a password, but then just before sending |
1653 // the form off, a script changes them. This test checks that | 1585 // the form off, a script changes them. This test checks that |
1654 // PasswordAutofillAgent can still remember the username and the password | 1586 // PasswordAutofillAgent can still remember the username and the password |
1655 // typed by the user. | 1587 // typed by the user. |
1656 TEST_F(PasswordAutofillAgentTest, | 1588 TEST_F(PasswordAutofillAgentTest, |
1657 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) { | 1589 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) { |
1658 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, | 1590 SimulateUsernameChange("temp"); |
1659 true); | 1591 SimulatePasswordChange("random"); |
1660 SimulateInputChangeForElement("random", true, GetMainFrame(), | |
1661 password_element_, true); | |
1662 | 1592 |
1663 // Simulate that the username and the password value was changed by the | 1593 // Simulate that the username and the password value was changed by the |
1664 // site's JavaScript before submit. | 1594 // site's JavaScript before submit. |
1665 username_element_.setValue(WebString("new username")); | 1595 username_element_.setValue(WebString("new username")); |
1666 password_element_.setValue(WebString("new password")); | 1596 password_element_.setValue(WebString("new password")); |
1667 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1597 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1668 ->WillSendSubmitEvent(username_element_.form()); | 1598 ->WillSendSubmitEvent(username_element_.form()); |
1669 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1599 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1670 ->WillSubmitForm(username_element_.form()); | 1600 ->WillSubmitForm(username_element_.form()); |
1671 | 1601 |
(...skipping 26 matching lines...) Expand all Loading... |
1698 | 1628 |
1699 // The username/password is autofilled by password manager then user types in a | 1629 // The username/password is autofilled by password manager then user types in a |
1700 // username and a password. Then just before sending the form off, a script | 1630 // username and a password. Then just before sending the form off, a script |
1701 // changes them. This test checks that PasswordAutofillAgent can still remember | 1631 // changes them. This test checks that PasswordAutofillAgent can still remember |
1702 // the username and the password typed by the user. | 1632 // the username and the password typed by the user. |
1703 TEST_F( | 1633 TEST_F( |
1704 PasswordAutofillAgentTest, | 1634 PasswordAutofillAgentTest, |
1705 RememberLastTypedAfterAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { | 1635 RememberLastTypedAfterAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { |
1706 SimulateOnFillPasswordForm(fill_data_); | 1636 SimulateOnFillPasswordForm(fill_data_); |
1707 | 1637 |
1708 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, | 1638 SimulateUsernameChange("temp"); |
1709 true); | 1639 SimulatePasswordChange("random"); |
1710 SimulateInputChangeForElement("random", true, GetMainFrame(), | |
1711 password_element_, true); | |
1712 | 1640 |
1713 // Simulate that the username and the password value was changed by the | 1641 // Simulate that the username and the password value was changed by the |
1714 // site's JavaScript before submit. | 1642 // site's JavaScript before submit. |
1715 username_element_.setValue(WebString("new username")); | 1643 username_element_.setValue(WebString("new username")); |
1716 password_element_.setValue(WebString("new password")); | 1644 password_element_.setValue(WebString("new password")); |
1717 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1645 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1718 ->WillSendSubmitEvent(username_element_.form()); | 1646 ->WillSendSubmitEvent(username_element_.form()); |
1719 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1647 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1720 ->WillSubmitForm(username_element_.form()); | 1648 ->WillSubmitForm(username_element_.form()); |
1721 | 1649 |
1722 // Observe that the PasswordAutofillAgent still remembered the last typed | 1650 // Observe that the PasswordAutofillAgent still remembered the last typed |
1723 // username and password and sent that to the browser. | 1651 // username and password and sent that to the browser. |
1724 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); | 1652 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
1725 } | 1653 } |
1726 | 1654 |
1727 // The user starts typing username then it is autofilled. | 1655 // The user starts typing username then it is autofilled. |
1728 // PasswordAutofillAgent should remember the username that was autofilled, | 1656 // PasswordAutofillAgent should remember the username that was autofilled, |
1729 // not last typed. | 1657 // not last typed. |
1730 TEST_F(PasswordAutofillAgentTest, RememberAutofilledUsername) { | 1658 TEST_F(PasswordAutofillAgentTest, RememberAutofilledUsername) { |
1731 SimulateInputChangeForElement("Te", true, GetMainFrame(), username_element_, | 1659 SimulateUsernameChange("Te"); |
1732 true); | |
1733 // Simulate that the username was changed by autofilling. | 1660 // Simulate that the username was changed by autofilling. |
1734 username_element_.setValue(WebString("temp")); | 1661 username_element_.setValue(WebString("temp")); |
1735 SimulateInputChangeForElement("random", true, GetMainFrame(), | 1662 SimulatePasswordChange("random"); |
1736 password_element_, true); | |
1737 | 1663 |
1738 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1664 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1739 ->WillSendSubmitEvent(username_element_.form()); | 1665 ->WillSendSubmitEvent(username_element_.form()); |
1740 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1666 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1741 ->WillSubmitForm(username_element_.form()); | 1667 ->WillSubmitForm(username_element_.form()); |
1742 | 1668 |
1743 // Observe that the PasswordAutofillAgent still remembered the last typed | 1669 // Observe that the PasswordAutofillAgent still remembered the last typed |
1744 // username and password and sent that to the browser. | 1670 // username and password and sent that to the browser. |
1745 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); | 1671 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
1746 } | 1672 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 | 1797 |
1872 CheckTextFieldsState(std::string("foobar"), false, std::string(), false); | 1798 CheckTextFieldsState(std::string("foobar"), false, std::string(), false); |
1873 } | 1799 } |
1874 | 1800 |
1875 // Test that the last plain text field before a password field is chosen as a | 1801 // Test that the last plain text field before a password field is chosen as a |
1876 // username, in a form with 2 plain text fields without username predictions. | 1802 // username, in a form with 2 plain text fields without username predictions. |
1877 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithoutAutofillPredictions) { | 1803 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithoutAutofillPredictions) { |
1878 LoadHTML(kFormHTMLWithTwoTextFields); | 1804 LoadHTML(kFormHTMLWithTwoTextFields); |
1879 UpdateUsernameAndPasswordElements(); | 1805 UpdateUsernameAndPasswordElements(); |
1880 blink::WebInputElement email_element = GetInputElementByID(kEmailName); | 1806 blink::WebInputElement email_element = GetInputElementByID(kEmailName); |
1881 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, | 1807 SimulateUsernameChange("temp"); |
1882 true); | 1808 SimulateUserInputChangeForElement(&email_element, "temp@google.com"); |
1883 SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), | 1809 SimulatePasswordChange("random"); |
1884 email_element, true); | |
1885 SimulateInputChangeForElement("random", true, GetMainFrame(), | |
1886 password_element_, true); | |
1887 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1810 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1888 ->WillSendSubmitEvent(username_element_.form()); | 1811 ->WillSendSubmitEvent(username_element_.form()); |
1889 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1812 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1890 ->WillSubmitForm(username_element_.form()); | 1813 ->WillSubmitForm(username_element_.form()); |
1891 | 1814 |
1892 // Observe that the PasswordAutofillAgent identifies the second field (e-mail) | 1815 // Observe that the PasswordAutofillAgent identifies the second field (e-mail) |
1893 // as username. | 1816 // as username. |
1894 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", ""); | 1817 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", ""); |
1895 } | 1818 } |
1896 | 1819 |
1897 // Tests that username predictions are followed when identifying the username | 1820 // Tests that username predictions are followed when identifying the username |
1898 // in a password form with two plain text fields. | 1821 // in a password form with two plain text fields. |
1899 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { | 1822 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { |
1900 LoadHTML(kFormHTMLWithTwoTextFields); | 1823 LoadHTML(kFormHTMLWithTwoTextFields); |
1901 UpdateUsernameAndPasswordElements(); | 1824 UpdateUsernameAndPasswordElements(); |
1902 blink::WebInputElement email_element = GetInputElementByID(kEmailName); | 1825 blink::WebInputElement email_element = GetInputElementByID(kEmailName); |
1903 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, | 1826 SimulateUsernameChange("temp"); |
1904 true); | 1827 SimulateUserInputChangeForElement(&email_element, "temp@google.com"); |
1905 SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), | 1828 SimulatePasswordChange("random"); |
1906 email_element, true); | |
1907 SimulateInputChangeForElement("random", true, GetMainFrame(), | |
1908 password_element_, true); | |
1909 | |
1910 // Find FormData for visible password form. | 1829 // Find FormData for visible password form. |
1911 blink::WebFormElement form_element = username_element_.form(); | 1830 blink::WebFormElement form_element = username_element_.form(); |
1912 FormData form_data; | 1831 FormData form_data; |
1913 ASSERT_TRUE(WebFormElementToFormData(form_element, | 1832 ASSERT_TRUE(WebFormElementToFormData(form_element, |
1914 blink::WebFormControlElement(), | 1833 blink::WebFormControlElement(), |
1915 EXTRACT_NONE, &form_data, nullptr)); | 1834 EXTRACT_NONE, &form_data, nullptr)); |
1916 // Simulate Autofill predictions: the first field is username. | 1835 // Simulate Autofill predictions: the first field is username. |
1917 std::map<autofill::FormData, autofill::FormFieldData> predictions; | 1836 std::map<autofill::FormData, autofill::FormFieldData> predictions; |
1918 predictions[form_data] = form_data.fields[0]; | 1837 predictions[form_data] = form_data.fields[0]; |
1919 AutofillMsg_AutofillUsernameDataReceived msg(0, predictions); | 1838 AutofillMsg_AutofillUsernameDataReceived msg(0, predictions); |
(...skipping 14 matching lines...) Expand all Loading... |
1934 ->WillSendSubmitEvent(username_element_.form()); | 1853 ->WillSendSubmitEvent(username_element_.form()); |
1935 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1854 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1936 ->WillSubmitForm(username_element_.form()); | 1855 ->WillSubmitForm(username_element_.form()); |
1937 | 1856 |
1938 // Observe that the PasswordAutofillAgent identifies the first field as | 1857 // Observe that the PasswordAutofillAgent identifies the first field as |
1939 // username. | 1858 // username. |
1940 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); | 1859 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
1941 } | 1860 } |
1942 | 1861 |
1943 } // namespace autofill | 1862 } // namespace autofill |
OLD | NEW |