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

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

Issue 1026493002: Allow only a user gesture to trigger autofill popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hide popup. Created 5 years, 8 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
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 "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
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
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');
705 ProcessInputForAutofill();
753 // Now the fields should have the same value, but the selection should have a 706 // Now the fields should have the same value, but the selection should have a
754 // different start value. 707 // different start value.
755 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 708 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
756 CheckUsernameSelection(2, 5); 709 CheckUsernameSelection(2, 5);
757 710
758 // Test that deleting does not trigger autocomplete. 711 // Test that backspace will erase the selection and will stop autocompletion.
759 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); 712 SimulateUserTypingASCIICharacter(ui::VKEY_BACK);
760 SimulateUsernameChange("alic", true); 713 ProcessInputForAutofill();
761 CheckTextFieldsState("alic", false, std::string(), false); 714 CheckTextFieldsState("al", false, std::string(), false);
762 CheckUsernameSelection(4, 4); // No selection. 715 CheckUsernameSelection(2, 2); // No selection.
763 // Reset the last pressed key to something other than backspace.
764 SimulateKeyDownEvent(username_element_, ui::VKEY_A);
765 716
766 // Now lets say the user goes astray from the stored username and types the 717 // 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 718 // 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 719 // practice the username should no longer be 'alice' and the selected range
769 // should be empty. 720 // should be empty.
770 SimulateUsernameChange("alf", true); 721 SimulateUserTypingASCIICharacter('f');
722 ProcessInputForAutofill();
771 CheckTextFieldsState("alf", false, std::string(), false); 723 CheckTextFieldsState("alf", false, std::string(), false);
772 CheckUsernameSelection(3, 3); // No selection. 724 CheckUsernameSelection(3, 3); // No selection.
773 725
774 // Ok, so now the user removes all the text and enters the letter 'b'. 726 // Ok, so now the user removes all the text and enters the letter 'b'.
775 SimulateUsernameChange("b", true); 727 SimulateUsernameChange("b");
776 // The username and password fields should match the 'bob' entry. 728 // The username and password fields should match the 'bob' entry.
777 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); 729 CheckTextFieldsDOMState(kBobUsername, true, kBobPassword, true);
778 CheckUsernameSelection(1, 3); 730 CheckUsernameSelection(1, 3);
779 731
780 // Then, the user again removes all the text and types an uppercase 'C'. 732 // Then, the user again removes all the text and types an uppercase 'C'.
781 SimulateUsernameChange("C", true); 733 SimulateUsernameChange("C");
782 // The username and password fields should match the 'Carol' entry. 734 // The username and password fields should match the 'Carol' entry.
783 CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); 735 CheckTextFieldsDOMState(kCarolUsername, true, kCarolPassword, true);
784 CheckUsernameSelection(1, 5); 736 CheckUsernameSelection(1, 5);
737
785 // The user removes all the text and types a lowercase 'c'. We only 738 // 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 739 // want case-sensitive autocompletion, so the username and the selected range
787 // should be empty. 740 // should be empty.
788 SimulateUsernameChange("c", true); 741 SimulateUsernameChange("c");
789 CheckTextFieldsState("c", false, std::string(), false); 742 CheckTextFieldsState("c", false, std::string(), false);
790 CheckUsernameSelection(1, 1); 743 CheckUsernameSelection(1, 1);
791 744
792 // Check that we complete other_possible_usernames as well. 745 // Check that we complete other_possible_usernames as well.
793 SimulateUsernameChange("R", true); 746 SimulateUsernameChange("R");
794 CheckTextFieldsState(kCarolAlternateUsername, true, kCarolPassword, true); 747 CheckTextFieldsDOMState(kCarolAlternateUsername, true, kCarolPassword, true);
795 CheckUsernameSelection(1, 17); 748 CheckUsernameSelection(1, 17);
796 } 749 }
797 750
798 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { 751 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) {
799 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; 752 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3;
800 blink::WebFrame* frame; 753 blink::WebFrame* frame;
801 754
802 LoadHTML(kVisibleFormWithNoUsernameHTML); 755 LoadHTML(kVisibleFormWithNoUsernameHTML);
803 frame = GetMainFrame(); 756 frame = GetMainFrame();
804 frame->document().forms(forms1); 757 frame->document().forms(forms1);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 866
914 WebInputElement username_input = username_element.to<WebInputElement>(); 867 WebInputElement username_input = username_element.to<WebInputElement>();
915 WebInputElement password_input = password_element.to<WebInputElement>(); 868 WebInputElement password_input = password_element.to<WebInputElement>();
916 ASSERT_FALSE(username_element.isNull()); 869 ASSERT_FALSE(username_element.isNull());
917 870
918 CheckTextFieldsStateForElements( 871 CheckTextFieldsStateForElements(
919 username_input, "", false, password_input, "", false, false); 872 username_input, "", false, password_input, "", false, false);
920 873
921 // Simulate the user typing in the username in the iframe which should cause 874 // Simulate the user typing in the username in the iframe which should cause
922 // an autofill. 875 // an autofill.
923 SimulateInputChangeForElement( 876 content::RenderFrame::FromWebFrame(iframe)
924 kAliceUsername, true, iframe, username_input, true); 877 ->OnMessageReceived(AutofillMsg_FirstUserGestureObservedInTab(0));
878 SimulateUserInputChangeForElement(&username_input, kAliceUsername);
925 879
926 CheckTextFieldsStateForElements(username_input, 880 CheckTextFieldsStateForElements(username_input,
927 kAliceUsername, 881 kAliceUsername,
928 true, 882 true,
929 password_input, 883 password_input,
930 kAlicePassword, 884 kAlicePassword,
931 true, 885 true,
932 false); 886 false);
933 } 887 }
934 888
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 fill_data_.wait_for_username = true; 976 fill_data_.wait_for_username = true;
1023 SimulateOnFillPasswordForm(fill_data_); 977 SimulateOnFillPasswordForm(fill_data_);
1024 978
1025 // The username and password should not yet have been autocompleted. 979 // The username and password should not yet have been autocompleted.
1026 CheckTextFieldsState(std::string(), false, std::string(), false); 980 CheckTextFieldsState(std::string(), false, std::string(), false);
1027 981
1028 // Simulate a click just to force a user gesture, since the username value is 982 // Simulate a click just to force a user gesture, since the username value is
1029 // set directly. 983 // set directly.
1030 SimulateElementClick(kUsernameName); 984 SimulateElementClick(kUsernameName);
1031 985
1032 // Simulate the user entering her username and selecting the matching autofill 986 // Simulate the user entering the first letter of her username and selecting
1033 // from the dropdown. 987 // the matching autofill from the dropdown.
1034 SimulateUsernameChange(kAliceUsername, true, true); 988 SimulateUsernameChange("a");
1035 SimulateSuggestionChoice(username_element_); 989 SimulateSuggestionChoice(username_element_);
1036 990
1037 // The username and password should now have been autocompleted. 991 // The username and password should now have been autocompleted.
1038 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 992 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1039 993
1040 // JavaScript onChange events should have been triggered both for the username 994 // JavaScript onChange events should have been triggered both for the username
1041 // and for the password. 995 // and for the password.
1042 int username_onchange_called = -1; 996 int username_onchange_called = -1;
1043 int password_onchange_called = -1; 997 int password_onchange_called = -1;
1044 ASSERT_TRUE( 998 ASSERT_TRUE(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 // Tests that |ClearPreview| properly restores the original selection range of 1236 // Tests that |ClearPreview| properly restores the original selection range of
1283 // username field that has initially been filled by inline autocomplete. 1237 // username field that has initially been filled by inline autocomplete.
1284 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { 1238 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
1285 // Simulate the browser sending back the login info. 1239 // Simulate the browser sending back the login info.
1286 SimulateOnFillPasswordForm(fill_data_); 1240 SimulateOnFillPasswordForm(fill_data_);
1287 1241
1288 // Clear the text fields to start fresh. 1242 // Clear the text fields to start fresh.
1289 ClearUsernameAndPasswordFields(); 1243 ClearUsernameAndPasswordFields();
1290 1244
1291 // Simulate the user typing in the first letter of 'alice', a stored username. 1245 // Simulate the user typing in the first letter of 'alice', a stored username.
1292 SimulateUsernameChange("a", true); 1246 SimulateUsernameChange("a");
1293 // Both the username and password text fields should reflect selection of the 1247 // Both the username and password text fields should reflect selection of the
1294 // stored login. 1248 // stored login.
1295 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 1249 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1296 // The selection should have been set to 'lice', the last 4 letters. 1250 // The selection should have been set to 'lice', the last 4 letters.
1297 CheckUsernameSelection(1, 5); 1251 CheckUsernameSelection(1, 5);
1298 1252
1299 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1253 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1300 username_element_, "alicia", "secret")); 1254 username_element_, "alicia", "secret"));
1301 EXPECT_EQ( 1255 EXPECT_EQ(
1302 "alicia", 1256 "alicia",
1303 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1257 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1304 EXPECT_TRUE(username_element_.isAutofilled()); 1258 EXPECT_TRUE(username_element_.isAutofilled());
1305 EXPECT_EQ( 1259 EXPECT_EQ(
1306 "secret", 1260 "secret",
1307 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1261 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1308 EXPECT_TRUE(password_element_.isAutofilled()); 1262 EXPECT_TRUE(password_element_.isAutofilled());
1309 CheckUsernameSelection(1, 6); 1263 CheckUsernameSelection(1, 6);
1310 1264
1311 EXPECT_TRUE( 1265 EXPECT_TRUE(
1312 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1266 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1313 1267
1314 EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); 1268 EXPECT_EQ(kAliceUsername, username_element_.value().utf8());
1315 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1269 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1316 EXPECT_TRUE(username_element_.isAutofilled()); 1270 EXPECT_TRUE(username_element_.isAutofilled());
1317 EXPECT_TRUE(password_element_.value().isEmpty()); 1271 EXPECT_EQ(kAlicePassword, password_element_.value().utf8());
1318 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1272 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1319 EXPECT_TRUE(password_element_.isAutofilled()); 1273 EXPECT_TRUE(password_element_.isAutofilled());
1320 CheckUsernameSelection(1, 5); 1274 CheckUsernameSelection(1, 5);
1321 } 1275 }
1322 1276
1323 // Tests that logging is off by default. 1277 // Tests that logging is off by default.
1324 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { 1278 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
1325 render_thread_->sink().ClearMessages(); 1279 render_thread_->sink().ClearMessages();
1326 SendVisiblePasswordForms(); 1280 SendVisiblePasswordForms();
1327 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1281 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 // Simulate a user clicking on the username element. This should produce a 1361 // Simulate a user clicking on the username element. This should produce a
1408 // message with all the usernames. 1362 // message with all the usernames.
1409 render_thread_->sink().ClearMessages(); 1363 render_thread_->sink().ClearMessages();
1410 static_cast<PageClickListener*>(autofill_agent_) 1364 static_cast<PageClickListener*>(autofill_agent_)
1411 ->FormControlElementClicked(username_element_, false); 1365 ->FormControlElementClicked(username_element_, false);
1412 CheckSuggestions(std::string(), false); 1366 CheckSuggestions(std::string(), false);
1413 1367
1414 // Now simulate a user typing in an unrecognized username and then 1368 // Now simulate a user typing in an unrecognized username and then
1415 // clicking on the username element. This should also produce a message with 1369 // clicking on the username element. This should also produce a message with
1416 // all the usernames. 1370 // all the usernames.
1417 SimulateUsernameChange("baz", true); 1371 SimulateUsernameChange("baz");
1418 render_thread_->sink().ClearMessages(); 1372 render_thread_->sink().ClearMessages();
1419 static_cast<PageClickListener*>(autofill_agent_) 1373 static_cast<PageClickListener*>(autofill_agent_)
1420 ->FormControlElementClicked(username_element_, true); 1374 ->FormControlElementClicked(username_element_, true);
1421 CheckSuggestions("baz", true); 1375 CheckSuggestions("baz", true);
1376 ClearUsernameAndPasswordFields();
1422 1377
1423 // Now simulate a user typing in the first letter of the username and then 1378 // 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 1379 // 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 1380 // inline autocomplete, clicking on the element should still produce a full
1426 // suggestion list. 1381 // suggestion list.
1427 SimulateUsernameChange("a", true); 1382 SimulateUsernameChange("a");
1428 render_thread_->sink().ClearMessages(); 1383 render_thread_->sink().ClearMessages();
1429 static_cast<PageClickListener*>(autofill_agent_) 1384 static_cast<PageClickListener*>(autofill_agent_)
1430 ->FormControlElementClicked(username_element_, true); 1385 ->FormControlElementClicked(username_element_, true);
1431 CheckSuggestions(kAliceUsername, true); 1386 CheckSuggestions(kAliceUsername, true);
1432 } 1387 }
1433 1388
1434 // Tests that there are no autosuggestions from the password manager when the 1389 // 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 1390 // user clicks on the password field and the username field is editable when
1436 // FillOnAccountSelect is enabled. 1391 // FillOnAccountSelect is enabled.
1437 TEST_F(PasswordAutofillAgentTest, 1392 TEST_F(PasswordAutofillAgentTest,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 1468 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
1514 AutofillHostMsg_ShowPasswordSuggestions::ID)); 1469 AutofillHostMsg_ShowPasswordSuggestions::ID));
1515 } 1470 }
1516 1471
1517 // The user types in a username and a password, but then just before sending 1472 // 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 1473 // the form off, a script clears them. This test checks that
1519 // PasswordAutofillAgent can still remember the username and the password 1474 // PasswordAutofillAgent can still remember the username and the password
1520 // typed by the user. 1475 // typed by the user.
1521 TEST_F(PasswordAutofillAgentTest, 1476 TEST_F(PasswordAutofillAgentTest,
1522 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { 1477 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) {
1523 SimulateInputChangeForElement( 1478 SimulateUsernameChange("temp");
1524 "temp", true, GetMainFrame(), username_element_, true); 1479 SimulatePasswordChange("random");
1525 SimulateInputChangeForElement(
1526 "random", true, GetMainFrame(), password_element_, true);
1527 1480
1528 // Simulate that the username and the password value was cleared by the 1481 // Simulate that the username and the password value was cleared by the
1529 // site's JavaScript before submit. 1482 // site's JavaScript before submit.
1530 username_element_.setValue(WebString()); 1483 username_element_.setValue(WebString());
1531 password_element_.setValue(WebString()); 1484 password_element_.setValue(WebString());
1532 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1485 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1533 ->WillSubmitForm(username_element_.form()); 1486 ->WillSubmitForm(username_element_.form());
1534 1487
1535 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1488 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1536 // username and password and sent that to the browser. 1489 // username and password and sent that to the browser.
1537 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1490 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1538 } 1491 }
1539 1492
1540 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time 1493 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time
1541 // it's the user who clears the username and the password. This test checks 1494 // 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 1495 // that in that case, the last non-empty username and password are not
1543 // remembered. 1496 // remembered.
1544 TEST_F(PasswordAutofillAgentTest, 1497 TEST_F(PasswordAutofillAgentTest,
1545 RememberLastNonEmptyUsernameAndPasswordOnSubmit_UserCleared) { 1498 RememberLastNonEmptyUsernameAndPasswordOnSubmit_UserCleared) {
1546 SimulateInputChangeForElement( 1499 SimulateUsernameChange("temp");
1547 "temp", true, GetMainFrame(), username_element_, true); 1500 SimulatePasswordChange("random");
1548 SimulateInputChangeForElement(
1549 "random", true, GetMainFrame(), password_element_, true);
1550 1501
1551 // Simulate that the user actually cleared the username and password again. 1502 // Simulate that the user actually cleared the username and password again.
1552 SimulateInputChangeForElement("", true, GetMainFrame(), username_element_, 1503 SimulateUsernameChange("");
1553 true); 1504 SimulatePasswordChange("");
1554 SimulateInputChangeForElement(
1555 "", true, GetMainFrame(), password_element_, true);
1556 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1505 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1557 ->WillSubmitForm(username_element_.form()); 1506 ->WillSubmitForm(username_element_.form());
1558 1507
1559 // Observe that the PasswordAutofillAgent respects the user having cleared the 1508 // Observe that the PasswordAutofillAgent respects the user having cleared the
1560 // password. 1509 // password.
1561 ExpectFormSubmittedWithUsernameAndPasswords("", "", ""); 1510 ExpectFormSubmittedWithUsernameAndPasswords("", "", "");
1562 } 1511 }
1563 1512
1564 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the 1513 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the
1565 // new password instead of the current password. 1514 // new password instead of the current password.
1566 TEST_F(PasswordAutofillAgentTest, 1515 TEST_F(PasswordAutofillAgentTest,
1567 RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) { 1516 RememberLastNonEmptyUsernameAndPasswordOnSubmit_New) {
1568 const char kNewPasswordFormHTML[] = 1517 const char kNewPasswordFormHTML[] =
1569 "<FORM name='LoginTestForm'>" 1518 "<FORM name='LoginTestForm'>"
1570 " <INPUT type='text' id='username' autocomplete='username'/>" 1519 " <INPUT type='text' id='username' autocomplete='username'/>"
1571 " <INPUT type='password' id='password' autocomplete='new-password'/>" 1520 " <INPUT type='password' id='password' autocomplete='new-password'/>"
1572 " <INPUT type='submit' value='Login'/>" 1521 " <INPUT type='submit' value='Login'/>"
1573 "</FORM>"; 1522 "</FORM>";
1574 LoadHTML(kNewPasswordFormHTML); 1523 LoadHTML(kNewPasswordFormHTML);
1575 UpdateUsernameAndPasswordElements(); 1524 UpdateUsernameAndPasswordElements();
1576 1525
1577 SimulateInputChangeForElement( 1526 SimulateUsernameChange("temp");
1578 "temp", true, GetMainFrame(), username_element_, true); 1527 SimulatePasswordChange("random");
1579 SimulateInputChangeForElement(
1580 "random", true, GetMainFrame(), password_element_, true);
1581 1528
1582 // Simulate that the username and the password value was cleared by 1529 // Simulate that the username and the password value was cleared by
1583 // the site's JavaScript before submit. 1530 // the site's JavaScript before submit.
1584 username_element_.setValue(WebString()); 1531 username_element_.setValue(WebString());
1585 password_element_.setValue(WebString()); 1532 password_element_.setValue(WebString());
1586 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1533 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1587 ->WillSubmitForm(username_element_.form()); 1534 ->WillSubmitForm(username_element_.form());
1588 1535
1589 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1536 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1590 // password and sent that to the browser. 1537 // password and sent that to the browser.
1591 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random"); 1538 ExpectFormSubmittedWithUsernameAndPasswords("temp", "", "random");
1592 } 1539 }
1593 1540
1594 // The user first accepts a suggestion, but then overwrites the password. This 1541 // 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 1542 // test checks that the overwritten password is not reverted back if the user
1596 // triggers autofill through focusing (but not changing) the username again. 1543 // triggers autofill through focusing (but not changing) the username again.
1597 TEST_F(PasswordAutofillAgentTest, 1544 TEST_F(PasswordAutofillAgentTest,
1598 NoopEditingDoesNotOverwriteManuallyEditedPassword) { 1545 NoopEditingDoesNotOverwriteManuallyEditedPassword) {
1599 // Simulate having credentials which needed to wait until the user starts 1546 // 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 1547 // 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. 1548 // the ones which can be filled as a result of TextFieldDidEndEditing.
1602 fill_data_.wait_for_username = true; 1549 fill_data_.wait_for_username = true;
1603 SimulateOnFillPasswordForm(fill_data_); 1550 SimulateOnFillPasswordForm(fill_data_);
1604 // Simulate that the user typed her name to make the autofill work. 1551 // Simulate that the user typed her name to make the autofill work.
1605 SimulateInputChangeForElement(kAliceUsername, 1552 SimulateUsernameChange(kAliceUsername);
1606 /*move_caret_to_end=*/true,
1607 GetMainFrame(),
1608 username_element_,
1609 /*is_user_input=*/true);
1610 SimulateDidEndEditing(GetMainFrame(), username_element_); 1553 SimulateDidEndEditing(GetMainFrame(), username_element_);
1611 const std::string old_username(username_element_.value().utf8()); 1554 const std::string old_username(username_element_.value().utf8());
1612 const std::string old_password(password_element_.value().utf8()); 1555 const std::string old_password(password_element_.value().utf8());
1613 const std::string new_password(old_password + "modify"); 1556 const std::string new_password(old_password + "modify");
1614 1557
1615 // The user changes the password. 1558 // The user changes the password.
1616 SimulateInputChangeForElement(new_password, 1559 SimulatePasswordChange(new_password);
1617 /*move_caret_to_end=*/true,
1618 GetMainFrame(),
1619 password_element_,
1620 /*is_user_input=*/true);
1621 1560
1622 // The user switches back into the username field, but leaves that without 1561 // The user switches back into the username field, but leaves that without
1623 // changes. 1562 // changes.
1624 SimulateDidEndEditing(GetMainFrame(), username_element_); 1563 SimulateDidEndEditing(GetMainFrame(), username_element_);
1625 1564
1626 // The password should have stayed as the user changed it. 1565 // The password should have stayed as the user changed it.
1627 CheckTextFieldsDOMState(old_username, true, new_password, false); 1566 CheckTextFieldsDOMState(old_username, true, new_password, false);
1628 // The password should not have a suggested value. 1567 // The password should not have a suggested value.
1629 CheckTextFieldsState(old_username, true, std::string(), false); 1568 CheckTextFieldsState(old_username, true, std::string(), false);
1630 } 1569 }
1631 1570
1632 TEST_F(PasswordAutofillAgentTest, 1571 TEST_F(PasswordAutofillAgentTest,
1633 InlineAutocompleteOverwritesManuallyEditedPassword) { 1572 InlineAutocompleteOverwritesManuallyEditedPassword) {
1634 // Simulate the browser sending back the login info. 1573 // Simulate the browser sending back the login info.
1635 SimulateOnFillPasswordForm(fill_data_); 1574 SimulateOnFillPasswordForm(fill_data_);
1636 1575
1637 ClearUsernameAndPasswordFields(); 1576 ClearUsernameAndPasswordFields();
1638 1577
1639 // The user enters a password 1578 // The user enters a password
1640 SimulateInputChangeForElement("someOtherPassword", 1579 SimulatePasswordChange("someOtherPassword");
1641 /*move_caret_to_end=*/true,
1642 GetMainFrame(),
1643 password_element_,
1644 /*is_user_input=*/true);
1645 1580
1646 // Simulate the user typing a stored username. 1581 // Simulate the user typing a stored username.
1647 SimulateUsernameChange(kAliceUsername, true); 1582 SimulateUsernameChange(kAliceUsername);
1648 // The autofileld password should replace the typed one. 1583 // The autofileld password should replace the typed one.
1649 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1584 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1650 } 1585 }
1651 1586
1652 // The user types in a username and a password, but then just before sending 1587 // 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 1588 // the form off, a script changes them. This test checks that
1654 // PasswordAutofillAgent can still remember the username and the password 1589 // PasswordAutofillAgent can still remember the username and the password
1655 // typed by the user. 1590 // typed by the user.
1656 TEST_F(PasswordAutofillAgentTest, 1591 TEST_F(PasswordAutofillAgentTest,
1657 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) { 1592 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) {
1658 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, 1593 SimulateUsernameChange("temp");
1659 true); 1594 SimulatePasswordChange("random");
1660 SimulateInputChangeForElement("random", true, GetMainFrame(),
1661 password_element_, true);
1662 1595
1663 // Simulate that the username and the password value was changed by the 1596 // Simulate that the username and the password value was changed by the
1664 // site's JavaScript before submit. 1597 // site's JavaScript before submit.
1665 username_element_.setValue(WebString("new username")); 1598 username_element_.setValue(WebString("new username"));
1666 password_element_.setValue(WebString("new password")); 1599 password_element_.setValue(WebString("new password"));
1667 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1600 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1668 ->WillSendSubmitEvent(username_element_.form()); 1601 ->WillSendSubmitEvent(username_element_.form());
1669 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1602 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1670 ->WillSubmitForm(username_element_.form()); 1603 ->WillSubmitForm(username_element_.form());
1671 1604
(...skipping 26 matching lines...) Expand all
1698 1631
1699 // The username/password is autofilled by password manager then user types in a 1632 // 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 1633 // username and a password. Then just before sending the form off, a script
1701 // changes them. This test checks that PasswordAutofillAgent can still remember 1634 // changes them. This test checks that PasswordAutofillAgent can still remember
1702 // the username and the password typed by the user. 1635 // the username and the password typed by the user.
1703 TEST_F( 1636 TEST_F(
1704 PasswordAutofillAgentTest, 1637 PasswordAutofillAgentTest,
1705 RememberLastTypedAfterAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { 1638 RememberLastTypedAfterAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) {
1706 SimulateOnFillPasswordForm(fill_data_); 1639 SimulateOnFillPasswordForm(fill_data_);
1707 1640
1708 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, 1641 SimulateUsernameChange("temp");
1709 true); 1642 SimulatePasswordChange("random");
1710 SimulateInputChangeForElement("random", true, GetMainFrame(),
1711 password_element_, true);
1712 1643
1713 // Simulate that the username and the password value was changed by the 1644 // Simulate that the username and the password value was changed by the
1714 // site's JavaScript before submit. 1645 // site's JavaScript before submit.
1715 username_element_.setValue(WebString("new username")); 1646 username_element_.setValue(WebString("new username"));
1716 password_element_.setValue(WebString("new password")); 1647 password_element_.setValue(WebString("new password"));
1717 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1648 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1718 ->WillSendSubmitEvent(username_element_.form()); 1649 ->WillSendSubmitEvent(username_element_.form());
1719 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1650 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1720 ->WillSubmitForm(username_element_.form()); 1651 ->WillSubmitForm(username_element_.form());
1721 1652
1722 // Observe that the PasswordAutofillAgent still remembered the last typed 1653 // Observe that the PasswordAutofillAgent still remembered the last typed
1723 // username and password and sent that to the browser. 1654 // username and password and sent that to the browser.
1724 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1655 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1725 } 1656 }
1726 1657
1727 // The user starts typing username then it is autofilled. 1658 // The user starts typing username then it is autofilled.
1728 // PasswordAutofillAgent should remember the username that was autofilled, 1659 // PasswordAutofillAgent should remember the username that was autofilled,
1729 // not last typed. 1660 // not last typed.
1730 TEST_F(PasswordAutofillAgentTest, RememberAutofilledUsername) { 1661 TEST_F(PasswordAutofillAgentTest, RememberAutofilledUsername) {
1731 SimulateInputChangeForElement("Te", true, GetMainFrame(), username_element_, 1662 SimulateUsernameChange("Te");
1732 true);
1733 // Simulate that the username was changed by autofilling. 1663 // Simulate that the username was changed by autofilling.
1734 username_element_.setValue(WebString("temp")); 1664 username_element_.setValue(WebString("temp"));
1735 SimulateInputChangeForElement("random", true, GetMainFrame(), 1665 SimulatePasswordChange("random");
1736 password_element_, true);
1737 1666
1738 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1667 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1739 ->WillSendSubmitEvent(username_element_.form()); 1668 ->WillSendSubmitEvent(username_element_.form());
1740 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1669 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1741 ->WillSubmitForm(username_element_.form()); 1670 ->WillSubmitForm(username_element_.form());
1742 1671
1743 // Observe that the PasswordAutofillAgent still remembered the last typed 1672 // Observe that the PasswordAutofillAgent still remembered the last typed
1744 // username and password and sent that to the browser. 1673 // username and password and sent that to the browser.
1745 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1674 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1746 } 1675 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 1800
1872 CheckTextFieldsState(std::string("foobar"), false, std::string(), false); 1801 CheckTextFieldsState(std::string("foobar"), false, std::string(), false);
1873 } 1802 }
1874 1803
1875 // Test that the last plain text field before a password field is chosen as a 1804 // 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. 1805 // username, in a form with 2 plain text fields without username predictions.
1877 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithoutAutofillPredictions) { 1806 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithoutAutofillPredictions) {
1878 LoadHTML(kFormHTMLWithTwoTextFields); 1807 LoadHTML(kFormHTMLWithTwoTextFields);
1879 UpdateUsernameAndPasswordElements(); 1808 UpdateUsernameAndPasswordElements();
1880 blink::WebInputElement email_element = GetInputElementByID(kEmailName); 1809 blink::WebInputElement email_element = GetInputElementByID(kEmailName);
1881 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, 1810 SimulateUsernameChange("temp");
1882 true); 1811 SimulateUserInputChangeForElement(&email_element, "temp@google.com");
1883 SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), 1812 SimulatePasswordChange("random");
1884 email_element, true);
1885 SimulateInputChangeForElement("random", true, GetMainFrame(),
1886 password_element_, true);
1887 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1813 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1888 ->WillSendSubmitEvent(username_element_.form()); 1814 ->WillSendSubmitEvent(username_element_.form());
1889 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1815 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1890 ->WillSubmitForm(username_element_.form()); 1816 ->WillSubmitForm(username_element_.form());
1891 1817
1892 // Observe that the PasswordAutofillAgent identifies the second field (e-mail) 1818 // Observe that the PasswordAutofillAgent identifies the second field (e-mail)
1893 // as username. 1819 // as username.
1894 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", ""); 1820 ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", "");
1895 } 1821 }
1896 1822
1897 // Tests that username predictions are followed when identifying the username 1823 // Tests that username predictions are followed when identifying the username
1898 // in a password form with two plain text fields. 1824 // in a password form with two plain text fields.
1899 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { 1825 TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) {
1900 LoadHTML(kFormHTMLWithTwoTextFields); 1826 LoadHTML(kFormHTMLWithTwoTextFields);
1901 UpdateUsernameAndPasswordElements(); 1827 UpdateUsernameAndPasswordElements();
1902 blink::WebInputElement email_element = GetInputElementByID(kEmailName); 1828 blink::WebInputElement email_element = GetInputElementByID(kEmailName);
1903 SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, 1829 SimulateUsernameChange("temp");
1904 true); 1830 SimulateUserInputChangeForElement(&email_element, "temp@google.com");
1905 SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), 1831 SimulatePasswordChange("random");
1906 email_element, true);
1907 SimulateInputChangeForElement("random", true, GetMainFrame(),
1908 password_element_, true);
1909
1910 // Find FormData for visible password form. 1832 // Find FormData for visible password form.
1911 blink::WebFormElement form_element = username_element_.form(); 1833 blink::WebFormElement form_element = username_element_.form();
1912 FormData form_data; 1834 FormData form_data;
1913 ASSERT_TRUE(WebFormElementToFormData(form_element, 1835 ASSERT_TRUE(WebFormElementToFormData(form_element,
1914 blink::WebFormControlElement(), 1836 blink::WebFormControlElement(),
1915 EXTRACT_NONE, &form_data, nullptr)); 1837 EXTRACT_NONE, &form_data, nullptr));
1916 // Simulate Autofill predictions: the first field is username. 1838 // Simulate Autofill predictions: the first field is username.
1917 std::map<autofill::FormData, autofill::FormFieldData> predictions; 1839 std::map<autofill::FormData, autofill::FormFieldData> predictions;
1918 predictions[form_data] = form_data.fields[0]; 1840 predictions[form_data] = form_data.fields[0];
1919 AutofillMsg_AutofillUsernameDataReceived msg(0, predictions); 1841 AutofillMsg_AutofillUsernameDataReceived msg(0, predictions);
(...skipping 14 matching lines...) Expand all
1934 ->WillSendSubmitEvent(username_element_.form()); 1856 ->WillSendSubmitEvent(username_element_.form());
1935 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1857 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1936 ->WillSubmitForm(username_element_.form()); 1858 ->WillSubmitForm(username_element_.form());
1937 1859
1938 // Observe that the PasswordAutofillAgent identifies the first field as 1860 // Observe that the PasswordAutofillAgent identifies the first field as
1939 // username. 1861 // username.
1940 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1862 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1941 } 1863 }
1942 1864
1943 } // namespace autofill 1865 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698