Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <tuple> | 5 #include <tuple> |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 // Try Filling with a suggestion with password different from the one that was | 990 // Try Filling with a suggestion with password different from the one that was |
| 991 // initially sent to the renderer. | 991 // initially sent to the renderer. |
| 992 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | 992 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
| 993 username_element_, ASCIIToUTF16(kBobUsername), | 993 username_element_, ASCIIToUTF16(kBobUsername), |
| 994 ASCIIToUTF16(kCarolPassword))); | 994 ASCIIToUTF16(kCarolPassword))); |
| 995 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); | 995 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); |
| 996 username_length = strlen(kBobUsername); | 996 username_length = strlen(kBobUsername); |
| 997 CheckUsernameSelection(username_length, username_length); | 997 CheckUsernameSelection(username_length, username_length); |
| 998 } | 998 } |
| 999 | 999 |
| 1000 // Tests that |FillSuggestion| properly fills the password if username is | |
| 1001 // read-only. | |
| 1002 TEST_F(PasswordAutofillAgentTest, FillSuggestionIfUsernameReadOnly) { | |
| 1003 // Simulate the browser sending the login info. | |
| 1004 SetElementReadOnly(username_element_, true); | |
| 1005 SimulateOnFillPasswordForm(fill_data_); | |
| 1006 | |
| 1007 // Neither field should have been autocompleted. | |
| 1008 CheckTextFieldsDOMState(std::string(), false, std::string(), false); | |
| 1009 | |
| 1010 // Username field is not autocompletable, it should not be affected. | |
| 1011 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | |
| 1012 password_element_, ASCIIToUTF16(kAliceUsername), | |
| 1013 ASCIIToUTF16(kAlicePassword))); | |
| 1014 CheckTextFieldsDOMState(std::string(), false, kAlicePassword, true); | |
| 1015 | |
| 1016 // Try Filling with a suggestion with password different from the one that was | |
| 1017 // initially sent to the renderer. | |
| 1018 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | |
| 1019 password_element_, ASCIIToUTF16(kBobUsername), | |
| 1020 ASCIIToUTF16(kCarolPassword))); | |
| 1021 CheckTextFieldsDOMState(std::string(), false, kCarolPassword, true); | |
| 1022 } | |
| 1023 | |
| 1000 // Tests that |PreviewSuggestion| properly previews the username and password. | 1024 // Tests that |PreviewSuggestion| properly previews the username and password. |
| 1001 TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { | 1025 TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { |
| 1002 // Simulate the browser sending the login info, but set |wait_for_username| | 1026 // Simulate the browser sending the login info, but set |wait_for_username| |
| 1003 // to prevent the form from being immediately filled. | 1027 // to prevent the form from being immediately filled. |
| 1004 fill_data_.wait_for_username = true; | 1028 fill_data_.wait_for_username = true; |
| 1005 SimulateOnFillPasswordForm(fill_data_); | 1029 SimulateOnFillPasswordForm(fill_data_); |
| 1006 | 1030 |
| 1007 // Neither field should have been autocompleted. | 1031 // Neither field should have been autocompleted. |
| 1008 CheckTextFieldsDOMState(std::string(), false, std::string(), false); | 1032 CheckTextFieldsDOMState(std::string(), false, std::string(), false); |
| 1009 | 1033 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 static_cast<std::string>(username_element_.suggestedValue().utf8())); | 1065 static_cast<std::string>(username_element_.suggestedValue().utf8())); |
| 1042 EXPECT_TRUE(username_element_.isAutofilled()); | 1066 EXPECT_TRUE(username_element_.isAutofilled()); |
| 1043 EXPECT_EQ( | 1067 EXPECT_EQ( |
| 1044 kCarolPassword, | 1068 kCarolPassword, |
| 1045 static_cast<std::string>(password_element_.suggestedValue().utf8())); | 1069 static_cast<std::string>(password_element_.suggestedValue().utf8())); |
| 1046 EXPECT_TRUE(password_element_.isAutofilled()); | 1070 EXPECT_TRUE(password_element_.isAutofilled()); |
| 1047 username_length = strlen(kBobUsername); | 1071 username_length = strlen(kBobUsername); |
| 1048 CheckUsernameSelection(0, username_length); | 1072 CheckUsernameSelection(0, username_length); |
| 1049 } | 1073 } |
| 1050 | 1074 |
| 1075 // Tests that |PreviewSuggestion| properly previews the password if username is | |
| 1076 // read-only. | |
| 1077 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionIfUsernameReadOnly) { | |
| 1078 // Simulate the browser sending the login info. | |
| 1079 SetElementReadOnly(username_element_, true); | |
| 1080 SimulateOnFillPasswordForm(fill_data_); | |
| 1081 | |
| 1082 // Neither field should have been autocompleted. | |
| 1083 CheckTextFieldsDOMState(std::string(), false, std::string(), false); | |
| 1084 | |
| 1085 // Username field is not autocompletable, it should not be affected. | |
| 1086 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( | |
| 1087 password_element_, kAliceUsername, kAlicePassword)); | |
| 1088 EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); | |
| 1089 EXPECT_FALSE(username_element_.isAutofilled()); | |
| 1090 | |
| 1091 // Password field must be autofilled. | |
| 1092 EXPECT_EQ( | |
| 1093 kAlicePassword, | |
| 1094 static_cast<std::string>(password_element_.suggestedValue().utf8())); | |
|
vabr (Chromium)
2016/09/07 08:32:53
Does this really need the cast? utf8() should alre
sense (YandexTeam)
2016/09/07 11:40:14
Yes, I also thought about this cast, but to be con
| |
| 1095 EXPECT_TRUE(password_element_.isAutofilled()); | |
| 1096 | |
| 1097 // Try previewing with a password different from the one that was initially | |
| 1098 // sent to the renderer. | |
| 1099 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( | |
| 1100 password_element_, kBobUsername, kCarolPassword)); | |
| 1101 EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); | |
| 1102 EXPECT_FALSE(username_element_.isAutofilled()); | |
| 1103 EXPECT_EQ( | |
| 1104 kCarolPassword, | |
| 1105 static_cast<std::string>(password_element_.suggestedValue().utf8())); | |
| 1106 EXPECT_TRUE(password_element_.isAutofilled()); | |
| 1107 } | |
| 1108 | |
| 1051 // Tests that |PreviewSuggestion| properly sets the username selection range. | 1109 // Tests that |PreviewSuggestion| properly sets the username selection range. |
| 1052 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { | 1110 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { |
| 1053 username_element_.setValue(WebString::fromUTF8("ali")); | 1111 username_element_.setValue(WebString::fromUTF8("ali")); |
| 1054 username_element_.setSelectionRange(3, 3); | 1112 username_element_.setSelectionRange(3, 3); |
| 1055 username_element_.setAutofilled(true); | 1113 username_element_.setAutofilled(true); |
| 1056 | 1114 |
| 1057 CheckTextFieldsDOMState("ali", true, std::string(), false); | 1115 CheckTextFieldsDOMState("ali", true, std::string(), false); |
| 1058 | 1116 |
| 1059 // Simulate the browser sending the login info, but set |wait_for_username| | 1117 // Simulate the browser sending the login info, but set |wait_for_username| |
| 1060 // to prevent the form from being immediately filled. | 1118 // to prevent the form from being immediately filled. |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2417 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2475 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 2418 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 2476 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 2419 | 2477 |
| 2420 // But when the user clicks on the autofilled password field again it should | 2478 // But when the user clicks on the autofilled password field again it should |
| 2421 // still produce a suggestion dropdown. | 2479 // still produce a suggestion dropdown. |
| 2422 SimulateElementClick("password"); | 2480 SimulateElementClick("password"); |
| 2423 CheckSuggestions("", false); | 2481 CheckSuggestions("", false); |
| 2424 } | 2482 } |
| 2425 | 2483 |
| 2426 } // namespace autofill | 2484 } // namespace autofill |
| OLD | NEW |