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

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: Do not show autofill popup if desktop IME is composing. 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 300 void SimulateInputChangeForElement(const std::string& new_value,
301 bool move_caret_to_end, 301 bool move_caret_to_end,
302 WebFrame* input_frame, 302 WebFrame* input_frame,
303 WebInputElement& input, 303 WebInputElement& input,
304 bool is_user_input) { 304 bool is_user_input) {
305 input.setValue(WebString::fromUTF8(new_value), is_user_input); 305 if (is_user_input)
306 // The field must have focus or AutofillAgent will think the 306 SimulateUserInputChangeForElement(&input, input_frame, new_value);
307 // change should be ignored. 307 else
308 while (!input.focused()) 308 input.setValue(WebString::fromUTF8(new_value), false);
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 309
316 // Also pass the message to the testing object. 310 ProcessEvents();
317 if (input_frame == GetMainFrame()) 311 }
318 password_autofill_agent_->FirstUserGestureObserved(); 312
319 } 313 void ProcessEvents() {
320 input_frame->toWebLocalFrame()->autofillClient()->textFieldDidChange(input);
321 // Processing is delayed because of a Blink bug: 314 // Processing is delayed because of a Blink bug:
322 // https://bugs.webkit.org/show_bug.cgi?id=16976 315 // https://bugs.webkit.org/show_bug.cgi?id=16976
323 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. 316 // See PasswordAutofillAgent::TextDidChangeInTextField() for details.
324 317
325 // Autocomplete will trigger a style recalculation when we put up the next 318 // 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 319 // frame, but we don't want to wait that long. Instead, trigger a style
327 // recalcuation manually after TextFieldDidChangeImpl runs. 320 // recalcuation manually after TextFieldDidChangeImpl runs.
328 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 321 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
329 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); 322 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this)));
330 323
(...skipping 29 matching lines...) Expand all
360 void SimulateUsernameChange(const std::string& username, 353 void SimulateUsernameChange(const std::string& username,
361 bool move_caret_to_end, 354 bool move_caret_to_end,
362 bool is_user_input = false) { 355 bool is_user_input = false) {
363 SimulateInputChangeForElement(username, 356 SimulateInputChangeForElement(username,
364 move_caret_to_end, 357 move_caret_to_end,
365 GetMainFrame(), 358 GetMainFrame(),
366 username_element_, 359 username_element_,
367 is_user_input); 360 is_user_input);
368 } 361 }
369 362
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 }
377
378 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 363 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
379 const std::string& username, 364 const std::string& username,
380 bool username_autofilled, 365 bool username_autofilled,
381 const WebInputElement& password_element, 366 const WebInputElement& password_element,
382 const std::string& password, 367 const std::string& password,
383 bool password_autofilled, 368 bool password_autofilled,
384 bool checkSuggestedValue) { 369 bool checkSuggestedValue) {
385 EXPECT_EQ(username, 370 EXPECT_EQ(username,
386 static_cast<std::string>(username_element.value().utf8())); 371 static_cast<std::string>(username_element.value().utf8()));
387 EXPECT_EQ(username_autofilled, username_element.isAutofilled()); 372 EXPECT_EQ(username_autofilled, username_element.isAutofilled());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 666 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
682 } 667 }
683 668
684 // Tests that editing the password clears the autocompleted password field. 669 // Tests that editing the password clears the autocompleted password field.
685 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) { 670 TEST_F(PasswordAutofillAgentTest, PasswordClearOnEdit) {
686 // Simulate the browser sending back the login info, it triggers the 671 // Simulate the browser sending back the login info, it triggers the
687 // autocomplete. 672 // autocomplete.
688 SimulateOnFillPasswordForm(fill_data_); 673 SimulateOnFillPasswordForm(fill_data_);
689 674
690 // Simulate the user changing the username to some unknown username. 675 // Simulate the user changing the username to some unknown username.
691 SimulateUsernameChange("alicia", true); 676 SimulateUsernameChange("alicia", true, true);
692 677
693 // The password should have been cleared. 678 // The password should have been cleared.
694 CheckTextFieldsState("alicia", false, std::string(), false); 679 CheckTextFieldsState("alicia", false, std::string(), false);
695 } 680 }
696 681
697 // Tests that we only autocomplete on focus lost and with a full username match 682 // Tests that we only autocomplete on focus lost and with a full username match
698 // when |wait_for_username| is true. 683 // when |wait_for_username| is true.
699 TEST_F(PasswordAutofillAgentTest, WaitUsername) { 684 TEST_F(PasswordAutofillAgentTest, WaitUsername) {
700 // Simulate the browser sending back the login info. 685 // Simulate the browser sending back the login info.
701 fill_data_.wait_for_username = true; 686 fill_data_.wait_for_username = true;
702 SimulateOnFillPasswordForm(fill_data_); 687 SimulateOnFillPasswordForm(fill_data_);
703 688
704 // No auto-fill should have taken place. 689 // No auto-fill should have taken place.
705 CheckTextFieldsState(std::string(), false, std::string(), false); 690 CheckTextFieldsState(std::string(), false, std::string(), false);
706 691
707 // No autocomplete should happen when text is entered in the username. 692 // No autocomplete should happen when text is entered in the username.
708 SimulateUsernameChange("a", true); 693 SimulateUsernameChange("a", true, true);
709 CheckTextFieldsState("a", false, std::string(), false); 694 CheckTextFieldsState("a", false, std::string(), false);
710 SimulateUsernameChange("al", true); 695 SimulateUsernameChange("al", true, true);
711 CheckTextFieldsState("al", false, std::string(), false); 696 CheckTextFieldsState("al", false, std::string(), false);
712 SimulateUsernameChange(kAliceUsername, true); 697 SimulateUsernameChange(kAliceUsername, true, true);
713 CheckTextFieldsState(kAliceUsername, false, std::string(), false); 698 CheckTextFieldsState(kAliceUsername, false, std::string(), false);
714 699
715 // Autocomplete should happen only when the username textfield is blurred with 700 // Autocomplete should happen only when the username textfield is blurred with
716 // a full match. 701 // a full match.
717 username_element_.setValue("a"); 702 SimulateUsernameChange("a", true, true);
718 static_cast<blink::WebAutofillClient*>(autofill_agent_) 703 static_cast<blink::WebAutofillClient*>(autofill_agent_)
719 ->textFieldDidEndEditing(username_element_); 704 ->textFieldDidEndEditing(username_element_);
720 CheckTextFieldsState("a", false, std::string(), false); 705 CheckTextFieldsState("a", false, std::string(), false);
721 username_element_.setValue("al"); 706 SimulateUsernameChange("al", true, true);
722 static_cast<blink::WebAutofillClient*>(autofill_agent_) 707 static_cast<blink::WebAutofillClient*>(autofill_agent_)
723 ->textFieldDidEndEditing(username_element_); 708 ->textFieldDidEndEditing(username_element_);
724 CheckTextFieldsState("al", false, std::string(), false); 709 CheckTextFieldsState("al", false, std::string(), false);
725 username_element_.setValue("alices"); 710 SimulateUsernameChange("alices", true, true);
726 static_cast<blink::WebAutofillClient*>(autofill_agent_) 711 static_cast<blink::WebAutofillClient*>(autofill_agent_)
727 ->textFieldDidEndEditing(username_element_); 712 ->textFieldDidEndEditing(username_element_);
728 CheckTextFieldsState("alices", false, std::string(), false); 713 CheckTextFieldsState("alices", false, std::string(), false);
729 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); 714 SimulateUsernameChange(kAliceUsername, true, true);
730 static_cast<blink::WebAutofillClient*>(autofill_agent_) 715 static_cast<blink::WebAutofillClient*>(autofill_agent_)
731 ->textFieldDidEndEditing(username_element_); 716 ->textFieldDidEndEditing(username_element_);
732 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 717 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
733 } 718 }
734 719
735 // Tests that inline autocompletion works properly. 720 // Tests that inline autocompletion works properly.
736 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { 721 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) {
737 // Simulate the browser sending back the login info. 722 // Simulate the browser sending back the login info.
738 SimulateOnFillPasswordForm(fill_data_); 723 SimulateOnFillPasswordForm(fill_data_);
739 724
740 ClearUsernameAndPasswordFields(); 725 ClearUsernameAndPasswordFields();
741 726
742 // Simulate the user typing in the first letter of 'alice', a stored 727 // Simulate the user typing in the first letter of 'alice', a stored
743 // username. 728 // username.
744 SimulateUsernameChange("a", true); 729 SimulateUsernameChange("a", true, true);
745 // Both the username and password text fields should reflect selection of the 730 // Both the username and password text fields should reflect selection of the
746 // stored login. 731 // stored login.
747 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 732 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
748 // And the selection should have been set to 'lice', the last 4 letters. 733 // And the selection should have been set to 'lice', the last 4 letters.
749 CheckUsernameSelection(1, 5); 734 CheckUsernameSelection(1, 5);
750 735
751 // Now the user types the next letter of the same username, 'l'. 736 // Now the user types the next letter of the same username, 'l'.
752 SimulateUsernameChange("al", true); 737 SimulateUserTypingASCIICharacter('l');
738 ProcessEvents();
753 // Now the fields should have the same value, but the selection should have a 739 // Now the fields should have the same value, but the selection should have a
754 // different start value. 740 // different start value.
755 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 741 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
756 CheckUsernameSelection(2, 5); 742 CheckUsernameSelection(2, 5);
757 743
758 // Test that deleting does not trigger autocomplete. 744 // Test that backspace will erase the selection and will stop autocompletion.
759 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); 745 SimulateUserTypingKeyCodeWithShift(ui::VKEY_BACK, false);
760 SimulateUsernameChange("alic", true); 746 ProcessEvents();
761 CheckTextFieldsState("alic", false, std::string(), false); 747 CheckTextFieldsState("al", false, std::string(), false);
762 CheckUsernameSelection(4, 4); // No selection. 748 CheckUsernameSelection(2, 2); // No selection.
763 // Reset the last pressed key to something other than backspace.
764 SimulateKeyDownEvent(username_element_, ui::VKEY_A);
765 749
766 // Now lets say the user goes astray from the stored username and types the 750 // 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 751 // 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 752 // practice the username should no longer be 'alice' and the selected range
769 // should be empty. 753 // should be empty.
770 SimulateUsernameChange("alf", true); 754 SimulateUserTypingASCIICharacter('f');
755 ProcessEvents();
771 CheckTextFieldsState("alf", false, std::string(), false); 756 CheckTextFieldsState("alf", false, std::string(), false);
772 CheckUsernameSelection(3, 3); // No selection. 757 CheckUsernameSelection(3, 3); // No selection.
773 758
774 // Ok, so now the user removes all the text and enters the letter 'b'. 759 // Ok, so now the user removes all the text and enters the letter 'b'.
775 SimulateUsernameChange("b", true); 760 SimulateUsernameChange("b", true, true);
776 // The username and password fields should match the 'bob' entry. 761 // The username and password fields should match the 'bob' entry.
777 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); 762 CheckTextFieldsDOMState(kBobUsername, true, kBobPassword, true);
778 CheckUsernameSelection(1, 3); 763 CheckUsernameSelection(1, 3);
779 764
780 // Then, the user again removes all the text and types an uppercase 'C'. 765 // Then, the user again removes all the text and types an uppercase 'C'.
781 SimulateUsernameChange("C", true); 766 SimulateUsernameChange("C", true, true);
782 // The username and password fields should match the 'Carol' entry. 767 // The username and password fields should match the 'Carol' entry.
783 CheckTextFieldsState(kCarolUsername, true, kCarolPassword, true); 768 CheckTextFieldsDOMState(kCarolUsername, true, kCarolPassword, true);
784 CheckUsernameSelection(1, 5); 769 CheckUsernameSelection(1, 5);
770
785 // The user removes all the text and types a lowercase 'c'. We only 771 // 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 772 // want case-sensitive autocompletion, so the username and the selected range
787 // should be empty. 773 // should be empty.
788 SimulateUsernameChange("c", true); 774 SimulateUsernameChange("c", true, true);
789 CheckTextFieldsState("c", false, std::string(), false); 775 CheckTextFieldsState("c", false, std::string(), false);
790 CheckUsernameSelection(1, 1); 776 CheckUsernameSelection(1, 1);
791 777
792 // Check that we complete other_possible_usernames as well. 778 // Check that we complete other_possible_usernames as well.
793 SimulateUsernameChange("R", true); 779 SimulateUsernameChange("R", true, true);
794 CheckTextFieldsState(kCarolAlternateUsername, true, kCarolPassword, true); 780 CheckTextFieldsDOMState(kCarolAlternateUsername, true, kCarolPassword, true);
795 CheckUsernameSelection(1, 17); 781 CheckUsernameSelection(1, 17);
796 } 782 }
797 783
798 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { 784 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) {
799 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3; 785 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3;
800 blink::WebFrame* frame; 786 blink::WebFrame* frame;
801 787
802 LoadHTML(kVisibleFormWithNoUsernameHTML); 788 LoadHTML(kVisibleFormWithNoUsernameHTML);
803 frame = GetMainFrame(); 789 frame = GetMainFrame();
804 frame->document().forms(forms1); 790 frame->document().forms(forms1);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 899
914 WebInputElement username_input = username_element.to<WebInputElement>(); 900 WebInputElement username_input = username_element.to<WebInputElement>();
915 WebInputElement password_input = password_element.to<WebInputElement>(); 901 WebInputElement password_input = password_element.to<WebInputElement>();
916 ASSERT_FALSE(username_element.isNull()); 902 ASSERT_FALSE(username_element.isNull());
917 903
918 CheckTextFieldsStateForElements( 904 CheckTextFieldsStateForElements(
919 username_input, "", false, password_input, "", false, false); 905 username_input, "", false, password_input, "", false, false);
920 906
921 // Simulate the user typing in the username in the iframe which should cause 907 // Simulate the user typing in the username in the iframe which should cause
922 // an autofill. 908 // an autofill.
909 content::RenderFrame::FromWebFrame(iframe)
910 ->OnMessageReceived(AutofillMsg_FirstUserGestureObservedInTab(0));
923 SimulateInputChangeForElement( 911 SimulateInputChangeForElement(
924 kAliceUsername, true, iframe, username_input, true); 912 kAliceUsername, true, iframe, username_input, true);
925 913
926 CheckTextFieldsStateForElements(username_input, 914 CheckTextFieldsStateForElements(username_input,
927 kAliceUsername, 915 kAliceUsername,
928 true, 916 true,
929 password_input, 917 password_input,
930 kAlicePassword, 918 kAlicePassword,
931 true, 919 true,
932 false); 920 false);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 fill_data_.wait_for_username = true; 1010 fill_data_.wait_for_username = true;
1023 SimulateOnFillPasswordForm(fill_data_); 1011 SimulateOnFillPasswordForm(fill_data_);
1024 1012
1025 // The username and password should not yet have been autocompleted. 1013 // The username and password should not yet have been autocompleted.
1026 CheckTextFieldsState(std::string(), false, std::string(), false); 1014 CheckTextFieldsState(std::string(), false, std::string(), false);
1027 1015
1028 // Simulate a click just to force a user gesture, since the username value is 1016 // Simulate a click just to force a user gesture, since the username value is
1029 // set directly. 1017 // set directly.
1030 SimulateElementClick(kUsernameName); 1018 SimulateElementClick(kUsernameName);
1031 1019
1032 // Simulate the user entering her username and selecting the matching autofill 1020 // Simulate the user entering the first letter of her username and selecting
1033 // from the dropdown. 1021 // the matching autofill from the dropdown.
1034 SimulateUsernameChange(kAliceUsername, true, true); 1022 SimulateUsernameChange("a", true, true);
1035 SimulateSuggestionChoice(username_element_); 1023 SimulateSuggestionChoice(username_element_);
1036 1024
1037 // The username and password should now have been autocompleted. 1025 // The username and password should now have been autocompleted.
1038 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1026 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1039 1027
1040 // JavaScript onChange events should have been triggered both for the username 1028 // JavaScript onChange events should have been triggered both for the username
1041 // and for the password. 1029 // and for the password.
1042 int username_onchange_called = -1; 1030 int username_onchange_called = -1;
1043 int password_onchange_called = -1; 1031 int password_onchange_called = -1;
1044 ASSERT_TRUE( 1032 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 1270 // Tests that |ClearPreview| properly restores the original selection range of
1283 // username field that has initially been filled by inline autocomplete. 1271 // username field that has initially been filled by inline autocomplete.
1284 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { 1272 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
1285 // Simulate the browser sending back the login info. 1273 // Simulate the browser sending back the login info.
1286 SimulateOnFillPasswordForm(fill_data_); 1274 SimulateOnFillPasswordForm(fill_data_);
1287 1275
1288 // Clear the text fields to start fresh. 1276 // Clear the text fields to start fresh.
1289 ClearUsernameAndPasswordFields(); 1277 ClearUsernameAndPasswordFields();
1290 1278
1291 // Simulate the user typing in the first letter of 'alice', a stored username. 1279 // Simulate the user typing in the first letter of 'alice', a stored username.
1292 SimulateUsernameChange("a", true); 1280 SimulateUsernameChange("a", true, true);
1293 // Both the username and password text fields should reflect selection of the 1281 // Both the username and password text fields should reflect selection of the
1294 // stored login. 1282 // stored login.
1295 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 1283 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1296 // The selection should have been set to 'lice', the last 4 letters. 1284 // The selection should have been set to 'lice', the last 4 letters.
1297 CheckUsernameSelection(1, 5); 1285 CheckUsernameSelection(1, 5);
1298 1286
1299 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1287 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1300 username_element_, "alicia", "secret")); 1288 username_element_, "alicia", "secret"));
1301 EXPECT_EQ( 1289 EXPECT_EQ(
1302 "alicia", 1290 "alicia",
1303 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1291 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1304 EXPECT_TRUE(username_element_.isAutofilled()); 1292 EXPECT_TRUE(username_element_.isAutofilled());
1305 EXPECT_EQ( 1293 EXPECT_EQ(
1306 "secret", 1294 "secret",
1307 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1295 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1308 EXPECT_TRUE(password_element_.isAutofilled()); 1296 EXPECT_TRUE(password_element_.isAutofilled());
1309 CheckUsernameSelection(1, 6); 1297 CheckUsernameSelection(1, 6);
1310 1298
1311 EXPECT_TRUE( 1299 EXPECT_TRUE(
1312 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1300 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1313 1301
1314 EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); 1302 EXPECT_EQ(kAliceUsername, username_element_.value().utf8());
1315 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1303 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1316 EXPECT_TRUE(username_element_.isAutofilled()); 1304 EXPECT_TRUE(username_element_.isAutofilled());
1317 EXPECT_TRUE(password_element_.value().isEmpty()); 1305 EXPECT_EQ(kAlicePassword, password_element_.value().utf8());
1318 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1306 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1319 EXPECT_TRUE(password_element_.isAutofilled()); 1307 EXPECT_TRUE(password_element_.isAutofilled());
1320 CheckUsernameSelection(1, 5); 1308 CheckUsernameSelection(1, 5);
1321 } 1309 }
1322 1310
1323 // Tests that logging is off by default. 1311 // Tests that logging is off by default.
1324 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { 1312 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
1325 render_thread_->sink().ClearMessages(); 1313 render_thread_->sink().ClearMessages();
1326 SendVisiblePasswordForms(); 1314 SendVisiblePasswordForms();
1327 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1315 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 CheckSuggestions(std::string(), false); 1400 CheckSuggestions(std::string(), false);
1413 1401
1414 // Now simulate a user typing in an unrecognized username and then 1402 // Now simulate a user typing in an unrecognized username and then
1415 // clicking on the username element. This should also produce a message with 1403 // clicking on the username element. This should also produce a message with
1416 // all the usernames. 1404 // all the usernames.
1417 SimulateUsernameChange("baz", true); 1405 SimulateUsernameChange("baz", true);
1418 render_thread_->sink().ClearMessages(); 1406 render_thread_->sink().ClearMessages();
1419 static_cast<PageClickListener*>(autofill_agent_) 1407 static_cast<PageClickListener*>(autofill_agent_)
1420 ->FormControlElementClicked(username_element_, true); 1408 ->FormControlElementClicked(username_element_, true);
1421 CheckSuggestions("baz", true); 1409 CheckSuggestions("baz", true);
1410 ClearUsernameAndPasswordFields();
1422 1411
1423 // Now simulate a user typing in the first letter of the username and then 1412 // 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 1413 // 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 1414 // inline autocomplete, clicking on the element should still produce a full
1426 // suggestion list. 1415 // suggestion list.
1427 SimulateUsernameChange("a", true); 1416 SimulateUsernameChange("a", true, true);
1428 render_thread_->sink().ClearMessages(); 1417 render_thread_->sink().ClearMessages();
1429 static_cast<PageClickListener*>(autofill_agent_) 1418 static_cast<PageClickListener*>(autofill_agent_)
1430 ->FormControlElementClicked(username_element_, true); 1419 ->FormControlElementClicked(username_element_, true);
1431 CheckSuggestions(kAliceUsername, true); 1420 CheckSuggestions(kAliceUsername, true);
1432 } 1421 }
1433 1422
1434 // Tests that there are no autosuggestions from the password manager when the 1423 // 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 1424 // user clicks on the password field and the username field is editable when
1436 // FillOnAccountSelect is enabled. 1425 // FillOnAccountSelect is enabled.
1437 TEST_F(PasswordAutofillAgentTest, 1426 TEST_F(PasswordAutofillAgentTest,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 ClearUsernameAndPasswordFields(); 1626 ClearUsernameAndPasswordFields();
1638 1627
1639 // The user enters a password 1628 // The user enters a password
1640 SimulateInputChangeForElement("someOtherPassword", 1629 SimulateInputChangeForElement("someOtherPassword",
1641 /*move_caret_to_end=*/true, 1630 /*move_caret_to_end=*/true,
1642 GetMainFrame(), 1631 GetMainFrame(),
1643 password_element_, 1632 password_element_,
1644 /*is_user_input=*/true); 1633 /*is_user_input=*/true);
1645 1634
1646 // Simulate the user typing a stored username. 1635 // Simulate the user typing a stored username.
1647 SimulateUsernameChange(kAliceUsername, true); 1636 SimulateUsernameChange(kAliceUsername, true, true);
1648 // The autofileld password should replace the typed one. 1637 // The autofileld password should replace the typed one.
1649 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1638 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1650 } 1639 }
1651 1640
1652 // The user types in a username and a password, but then just before sending 1641 // 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 1642 // the form off, a script changes them. This test checks that
1654 // PasswordAutofillAgent can still remember the username and the password 1643 // PasswordAutofillAgent can still remember the username and the password
1655 // typed by the user. 1644 // typed by the user.
1656 TEST_F(PasswordAutofillAgentTest, 1645 TEST_F(PasswordAutofillAgentTest,
1657 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) { 1646 RememberLastTypedUsernameAndPasswordOnSubmit_ScriptChanged) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 ->WillSendSubmitEvent(username_element_.form()); 1912 ->WillSendSubmitEvent(username_element_.form());
1924 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1913 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1925 ->WillSubmitForm(username_element_.form()); 1914 ->WillSubmitForm(username_element_.form());
1926 1915
1927 // Observe that the PasswordAutofillAgent identifies the first field as 1916 // Observe that the PasswordAutofillAgent identifies the first field as
1928 // username. 1917 // username.
1929 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); 1918 ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", "");
1930 } 1919 }
1931 1920
1932 } // namespace autofill 1921 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698