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

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

Issue 2902113004: Autofill username when the user interacts with the password field. (Closed)
Patch Set: Created 3 years, 7 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 "components/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 void SimulatePasswordChange(const std::string& password) { 419 void SimulatePasswordChange(const std::string& password) {
420 SimulateUserInputChangeForElement(&password_element_, password); 420 SimulateUserInputChangeForElement(&password_element_, password);
421 } 421 }
422 422
423 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 423 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
424 const std::string& username, 424 const std::string& username,
425 bool username_autofilled, 425 bool username_autofilled,
426 const WebInputElement& password_element, 426 const WebInputElement& password_element,
427 const std::string& password, 427 const std::string& password,
428 bool password_autofilled, 428 bool password_autofilled,
429 bool checkSuggestedValue) { 429 bool check_suggested_username,
430 EXPECT_EQ(username, username_element.Value().Utf8()); 430 bool check_suggested_password) {
431 EXPECT_EQ(username, check_suggested_username
432 ? username_element.SuggestedValue().Utf8()
433 : username_element.Value().Utf8())
434 << "check_suggested_username == " << check_suggested_username;
431 EXPECT_EQ(username_autofilled, username_element.IsAutofilled()); 435 EXPECT_EQ(username_autofilled, username_element.IsAutofilled());
432 EXPECT_EQ(password, checkSuggestedValue 436
437 EXPECT_EQ(password, check_suggested_password
433 ? password_element.SuggestedValue().Utf8() 438 ? password_element.SuggestedValue().Utf8()
434 : password_element.Value().Utf8()) 439 : password_element.Value().Utf8())
435 << "checkSuggestedValue == " << checkSuggestedValue; 440 << "check_suggested_password == " << check_suggested_password;
436 EXPECT_EQ(password_autofilled, password_element.IsAutofilled()); 441 EXPECT_EQ(password_autofilled, password_element.IsAutofilled());
437 } 442 }
438 443
439 // Checks the DOM-accessible value of the username element and the 444 // Checks the DOM-accessible value of the username element and the
440 // *suggested* value of the password element. 445 // *suggested* value of the password element.
441 void CheckTextFieldsState(const std::string& username, 446 void CheckTextFieldsState(const std::string& username,
442 bool username_autofilled, 447 bool username_autofilled,
443 const std::string& password, 448 const std::string& password,
444 bool password_autofilled) { 449 bool password_autofilled) {
445 CheckTextFieldsStateForElements(username_element_, 450 CheckTextFieldsStateForElements(username_element_, username,
446 username, 451 username_autofilled, password_element_,
447 username_autofilled, 452 password, password_autofilled, false, true);
448 password_element_,
449 password,
450 password_autofilled,
451 true);
452 } 453 }
453 454
454 // Checks the DOM-accessible value of the username element and the 455 // Checks the DOM-accessible value of the username element and the
455 // DOM-accessible value of the password element. 456 // DOM-accessible value of the password element.
456 void CheckTextFieldsDOMState(const std::string& username, 457 void CheckTextFieldsDOMState(const std::string& username,
457 bool username_autofilled, 458 bool username_autofilled,
458 const std::string& password, 459 const std::string& password,
459 bool password_autofilled) { 460 bool password_autofilled) {
460 CheckTextFieldsStateForElements(username_element_, 461 CheckTextFieldsStateForElements(
461 username, 462 username_element_, username, username_autofilled, password_element_,
462 username_autofilled, 463 password, password_autofilled, false, false);
463 password_element_, 464 }
464 password, 465
465 password_autofilled, 466 // Checks the suggested values of the |username| and |password| elements.
466 false); 467 void CheckTextFieldsSuggestedState(const std::string& username,
468 bool username_autofilled,
469 const std::string& password,
470 bool password_autofilled) {
471 CheckTextFieldsStateForElements(username_element_, username,
472 username_autofilled, password_element_,
473 password, password_autofilled, true, true);
467 } 474 }
468 475
469 void CheckUsernameSelection(int start, int end) { 476 void CheckUsernameSelection(int start, int end) {
470 EXPECT_EQ(start, username_element_.SelectionStart()); 477 EXPECT_EQ(start, username_element_.SelectionStart());
471 EXPECT_EQ(end, username_element_.SelectionEnd()); 478 EXPECT_EQ(end, username_element_.SelectionEnd());
472 } 479 }
473 480
474 // Checks the message sent to PasswordAutofillManager to build the suggestion 481 // Checks the message sent to PasswordAutofillManager to build the suggestion
475 // list. |username| is the expected username field value, and |show_all| is 482 // list. |username| is the expected username field value, and |show_all| is
476 // the expected flag for the PasswordAutofillManager, whether to show all 483 // the expected flag for the PasswordAutofillManager, whether to show all
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 // Try Filling with a suggestion with password different from the one that was 1139 // Try Filling with a suggestion with password different from the one that was
1133 // initially sent to the renderer. 1140 // initially sent to the renderer.
1134 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( 1141 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1135 username_element_, ASCIIToUTF16(kBobUsername), 1142 username_element_, ASCIIToUTF16(kBobUsername),
1136 ASCIIToUTF16(kCarolPassword))); 1143 ASCIIToUTF16(kCarolPassword)));
1137 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); 1144 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
1138 username_length = strlen(kBobUsername); 1145 username_length = strlen(kBobUsername);
1139 CheckUsernameSelection(username_length, username_length); 1146 CheckUsernameSelection(username_length, username_length);
1140 } 1147 }
1141 1148
1142 // Tests that |FillSuggestion| properly fills the password if username is 1149 // Tests that |FillSuggestion| properly fills username/password when interacting
1143 // read-only. 1150 // with the password field.
1151 TEST_F(PasswordAutofillAgentTest, FillSuggestionFromPasswordField) {
1152 // Simulate the browser sending the login info, but set |wait_for_username| to
1153 // prevent the form from being immediately filled.
1154 fill_data_.wait_for_username = true;
1155 SimulateOnFillPasswordForm(fill_data_);
1156 // Neither field should have been autocompleted.
1157 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1158
1159 // Both fields are autocompletable and should be filled.
1160 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1161 password_element_, ASCIIToUTF16(kAliceUsername),
1162 ASCIIToUTF16(kAlicePassword)));
1163 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1164
1165 // Try Filling with a different password. Only password should be changed.
pkalinnikov 2017/05/24 10:43:31 selfnit: ... Both fields should be changed.
pkalinnikov 2017/05/24 13:54:36 Done.
1166 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1167 password_element_, ASCIIToUTF16(kBobUsername),
1168 ASCIIToUTF16(kCarolPassword)));
1169 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
1170 }
1171
1172 // Tests that |FillSuggestion| doesn't change non-empty non-autofilled username
1173 // when interacting with the password field.
1174 TEST_F(PasswordAutofillAgentTest,
1175 FillSuggestionFromPasswordFieldWithUsernameManuallyFilled) {
1176 username_element_.SetValue(WebString::FromUTF8("user1"));
1177
1178 // Simulate the browser sending the login info, but set |wait_for_username| to
1179 // prevent the form from being immediately filled.
1180 fill_data_.wait_for_username = true;
1181 SimulateOnFillPasswordForm(fill_data_);
1182 // Neither field should have been autocompleted.
1183 CheckTextFieldsDOMState("user1", false, std::string(), false);
1184
1185 // Only password field should be autocompleted.
1186 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1187 password_element_, ASCIIToUTF16(kAliceUsername),
1188 ASCIIToUTF16(kAlicePassword)));
1189 CheckTextFieldsDOMState("user1", false, kAlicePassword, true);
1190
1191 // Try Filling with a different password. Only password should be changed.
1192 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1193 password_element_, ASCIIToUTF16(kBobUsername),
1194 ASCIIToUTF16(kCarolPassword)));
1195 CheckTextFieldsDOMState("user1", false, kCarolPassword, true);
1196 }
1197
1198 // Tests that |FillSuggestion| properly fills the password if the username field
1199 // is read-only.
1144 TEST_F(PasswordAutofillAgentTest, FillSuggestionIfUsernameReadOnly) { 1200 TEST_F(PasswordAutofillAgentTest, FillSuggestionIfUsernameReadOnly) {
1145 // Simulate the browser sending the login info. 1201 // Simulate the browser sending the login info.
1146 SetElementReadOnly(username_element_, true); 1202 SetElementReadOnly(username_element_, true);
1147 SimulateOnFillPasswordForm(fill_data_); 1203 SimulateOnFillPasswordForm(fill_data_);
1148 1204
1149 // Neither field should have been autocompleted. 1205 // Neither field should have been autocompleted.
1150 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1206 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1151 1207
1152 // Username field is not autocompletable, it should not be affected. 1208 // Username field is not autocompletable, it should not be affected.
1153 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( 1209 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
(...skipping 16 matching lines...) Expand all
1170 fill_data_.wait_for_username = true; 1226 fill_data_.wait_for_username = true;
1171 SimulateOnFillPasswordForm(fill_data_); 1227 SimulateOnFillPasswordForm(fill_data_);
1172 1228
1173 // Neither field should have been autocompleted. 1229 // Neither field should have been autocompleted.
1174 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1230 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1175 1231
1176 // If the password field is not autocompletable, it should not be affected. 1232 // If the password field is not autocompletable, it should not be affected.
1177 SetElementReadOnly(password_element_, true); 1233 SetElementReadOnly(password_element_, true);
1178 EXPECT_FALSE(password_autofill_agent_->PreviewSuggestion( 1234 EXPECT_FALSE(password_autofill_agent_->PreviewSuggestion(
1179 username_element_, kAliceUsername, kAlicePassword)); 1235 username_element_, kAliceUsername, kAlicePassword));
1180 EXPECT_EQ(std::string(), username_element_.SuggestedValue().Utf8()); 1236 CheckTextFieldsSuggestedState(std::string(), false, std::string(), false);
1181 EXPECT_FALSE(username_element_.IsAutofilled());
1182 EXPECT_EQ(std::string(), password_element_.SuggestedValue().Utf8());
1183 EXPECT_FALSE(password_element_.IsAutofilled());
1184 SetElementReadOnly(password_element_, false); 1237 SetElementReadOnly(password_element_, false);
1185 1238
1186 // After selecting the suggestion, both fields should be previewed 1239 // After selecting the suggestion, both fields should be previewed
1187 // with suggested values. 1240 // with suggested values.
1188 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1241 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1189 username_element_, kAliceUsername, kAlicePassword)); 1242 username_element_, kAliceUsername, kAlicePassword));
1190 EXPECT_EQ(kAliceUsername, username_element_.SuggestedValue().Utf8()); 1243 CheckTextFieldsSuggestedState(kAliceUsername, true, kAlicePassword, true);
1191 EXPECT_TRUE(username_element_.IsAutofilled());
1192 EXPECT_EQ(kAlicePassword, password_element_.SuggestedValue().Utf8());
1193 EXPECT_TRUE(password_element_.IsAutofilled());
1194 int username_length = strlen(kAliceUsername); 1244 int username_length = strlen(kAliceUsername);
1195 CheckUsernameSelection(0, username_length); 1245 CheckUsernameSelection(0, username_length);
1196 1246
1197 // Try previewing with a password different from the one that was initially 1247 // Try previewing with a password different from the one that was initially
1198 // sent to the renderer. 1248 // sent to the renderer.
1199 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1249 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1200 username_element_, kBobUsername, kCarolPassword)); 1250 username_element_, kBobUsername, kCarolPassword));
1201 EXPECT_EQ(kBobUsername, username_element_.SuggestedValue().Utf8()); 1251 CheckTextFieldsSuggestedState(kBobUsername, true, kCarolPassword, true);
1202 EXPECT_TRUE(username_element_.IsAutofilled());
1203 EXPECT_EQ(kCarolPassword, password_element_.SuggestedValue().Utf8());
1204 EXPECT_TRUE(password_element_.IsAutofilled());
1205 username_length = strlen(kBobUsername); 1252 username_length = strlen(kBobUsername);
1206 CheckUsernameSelection(0, username_length); 1253 CheckUsernameSelection(0, username_length);
1207 } 1254 }
1208 1255
1256 // Tests that |PreviewSuggestion| doesn't change non-empty non-autofilled
1257 // username when previewing autofills on interacting with the password field.
1258 TEST_F(PasswordAutofillAgentTest,
1259 PreviewSuggestionFromPasswordFieldWithUsernameManuallyFilled) {
pkalinnikov 2017/05/24 10:43:31 selfnit: Move this test below PreviewSuggestionFro
pkalinnikov 2017/05/24 13:54:36 Done.
1260 username_element_.SetValue(WebString::FromUTF8("user1"));
1261
1262 // Simulate the browser sending the login info, but set |wait_for_username| to
1263 // prevent the form from being immediately filled.
1264 fill_data_.wait_for_username = true;
1265 SimulateOnFillPasswordForm(fill_data_);
1266 // Neither field should have been autocompleted.
1267 CheckTextFieldsDOMState("user1", false, std::string(), false);
1268
1269 // Only password field should be autocompleted.
1270 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1271 password_element_, kAliceUsername, kAlicePassword));
1272 CheckTextFieldsSuggestedState(std::string(), false, kAlicePassword, true);
1273 CheckTextFieldsDOMState("user1", false, std::string(), true);
1274
1275 // Try previewing with a different password. Only password should be changed.
1276 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1277 password_element_, kBobUsername, kCarolPassword));
1278 CheckTextFieldsSuggestedState(std::string(), false, kCarolPassword, true);
1279 CheckTextFieldsDOMState("user1", false, std::string(), true);
1280 }
1281
1282 // Tests that |PreviewSuggestion| properly previews username/password when
1283 // interacting with the password field.
1284 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionFromPasswordField) {
1285 // Simulate the browser sending the login info, but set |wait_for_username| to
1286 // prevent the form from being immediately filled.
1287 fill_data_.wait_for_username = true;
1288 SimulateOnFillPasswordForm(fill_data_);
1289 // Neither field should have been autocompleted.
1290 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1291
1292 // Only password field should be autocompleted.
pkalinnikov 2017/05/24 10:43:31 selfnit: // Both fields should be filled with sugg
pkalinnikov 2017/05/24 13:54:36 Done.
1293 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1294 password_element_, kAliceUsername, kAlicePassword));
1295 CheckTextFieldsSuggestedState(kAliceUsername, true, kAlicePassword, true);
1296
1297 // Try previewing with a different password. Only password should be changed.
pkalinnikov 2017/05/24 10:43:31 selfnit: ... Both fields should be changed.
pkalinnikov 2017/05/24 13:54:36 Done.
1298 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1299 password_element_, kBobUsername, kCarolPassword));
1300 CheckTextFieldsSuggestedState(kBobUsername, true, kCarolPassword, true);
1301 }
1302
1209 // Tests that |PreviewSuggestion| properly previews the password if username is 1303 // Tests that |PreviewSuggestion| properly previews the password if username is
1210 // read-only. 1304 // read-only.
1211 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionIfUsernameReadOnly) { 1305 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionIfUsernameReadOnly) {
1212 // Simulate the browser sending the login info. 1306 // Simulate the browser sending the login info.
1213 SetElementReadOnly(username_element_, true); 1307 SetElementReadOnly(username_element_, true);
1214 SimulateOnFillPasswordForm(fill_data_); 1308 SimulateOnFillPasswordForm(fill_data_);
1215 1309
1216 // Neither field should have been autocompleted. 1310 // Neither field should have been autocompleted.
1217 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1311 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1218 1312
1219 // Username field is not autocompletable, it should not be affected. 1313 // Username field is not autocompletable, it should not be affected.
1220 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1314 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1221 password_element_, kAliceUsername, kAlicePassword)); 1315 password_element_, kAliceUsername, kAlicePassword));
1222 EXPECT_EQ(std::string(), username_element_.SuggestedValue().Utf8());
1223 EXPECT_FALSE(username_element_.IsAutofilled());
1224
1225 // Password field must be autofilled. 1316 // Password field must be autofilled.
1226 EXPECT_EQ(kAlicePassword, password_element_.SuggestedValue().Utf8()); 1317 CheckTextFieldsSuggestedState(std::string(), false, kAlicePassword, true);
1227 EXPECT_TRUE(password_element_.IsAutofilled());
1228 1318
1229 // Try previewing with a password different from the one that was initially 1319 // Try previewing with a password different from the one that was initially
1230 // sent to the renderer. 1320 // sent to the renderer.
1231 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1321 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1232 password_element_, kBobUsername, kCarolPassword)); 1322 password_element_, kBobUsername, kCarolPassword));
1233 EXPECT_EQ(std::string(), username_element_.SuggestedValue().Utf8()); 1323 CheckTextFieldsSuggestedState(std::string(), false, kCarolPassword, true);
1234 EXPECT_FALSE(username_element_.IsAutofilled());
1235 EXPECT_EQ(kCarolPassword, password_element_.SuggestedValue().Utf8());
1236 EXPECT_TRUE(password_element_.IsAutofilled());
1237 } 1324 }
1238 1325
1239 // Tests that |PreviewSuggestion| properly sets the username selection range. 1326 // Tests that |PreviewSuggestion| properly sets the username selection range.
1240 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { 1327 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) {
1241 username_element_.SetValue(WebString::FromUTF8("ali")); 1328 username_element_.SetValue(WebString::FromUTF8("ali"));
1242 username_element_.SetSelectionRange(3, 3); 1329 username_element_.SetSelectionRange(3, 3);
1243 username_element_.SetAutofilled(true); 1330 username_element_.SetAutofilled(true);
1244 1331
1245 CheckTextFieldsDOMState("ali", true, std::string(), false); 1332 CheckTextFieldsDOMState("ali", true, std::string(), false);
1246 1333
1247 // Simulate the browser sending the login info, but set |wait_for_username| 1334 // Simulate the browser sending the login info, but set |wait_for_username|
1248 // to prevent the form from being immediately filled. 1335 // to prevent the form from being immediately filled.
1249 fill_data_.wait_for_username = true; 1336 fill_data_.wait_for_username = true;
1250 SimulateOnFillPasswordForm(fill_data_); 1337 SimulateOnFillPasswordForm(fill_data_);
1251 1338
1252 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1339 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1253 username_element_, kAliceUsername, kAlicePassword)); 1340 username_element_, kAliceUsername, kAlicePassword));
1254 EXPECT_EQ(kAliceUsername, username_element_.SuggestedValue().Utf8()); 1341 CheckTextFieldsSuggestedState(kAliceUsername, true, kAlicePassword, true);
1255 EXPECT_TRUE(username_element_.IsAutofilled());
1256 EXPECT_EQ(kAlicePassword, password_element_.SuggestedValue().Utf8());
1257 EXPECT_TRUE(password_element_.IsAutofilled());
1258 int username_length = strlen(kAliceUsername); 1342 int username_length = strlen(kAliceUsername);
1259 CheckUsernameSelection(3, username_length); 1343 CheckUsernameSelection(3, username_length);
1260 } 1344 }
1261 1345
1262 // Tests that |ClearPreview| properly clears previewed username and password 1346 // Tests that |ClearPreview| properly clears previewed username and password
1263 // with password being previously autofilled. 1347 // with password being previously autofilled.
1264 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) { 1348 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) {
1265 password_element_.SetValue(WebString::FromUTF8("sec")); 1349 password_element_.SetValue(WebString::FromUTF8("sec"));
1266 password_element_.SetAutofilled(true); 1350 password_element_.SetAutofilled(true);
1267 1351
1268 // Simulate the browser sending the login info, but set |wait_for_username| 1352 // Simulate the browser sending the login info, but set |wait_for_username|
1269 // to prevent the form from being immediately filled. 1353 // to prevent the form from being immediately filled.
1270 fill_data_.wait_for_username = true; 1354 fill_data_.wait_for_username = true;
1271 SimulateOnFillPasswordForm(fill_data_); 1355 SimulateOnFillPasswordForm(fill_data_);
1272 1356
1273 CheckTextFieldsDOMState(std::string(), false, "sec", true); 1357 CheckTextFieldsDOMState(std::string(), false, "sec", true);
1274 1358
1275 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1359 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1276 username_element_, kAliceUsername, kAlicePassword)); 1360 username_element_, kAliceUsername, kAlicePassword));
1277 1361
1278 EXPECT_TRUE( 1362 EXPECT_TRUE(
1279 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1363 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1280 1364
1281 EXPECT_TRUE(username_element_.Value().IsEmpty());
1282 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty()); 1365 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty());
1283 EXPECT_FALSE(username_element_.IsAutofilled());
1284 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.Value().Utf16());
1285 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty()); 1366 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty());
1286 EXPECT_TRUE(password_element_.IsAutofilled()); 1367 CheckTextFieldsDOMState(std::string(), false, "sec", true);
1287 CheckUsernameSelection(0, 0); 1368 CheckUsernameSelection(0, 0);
1288 } 1369 }
1289 1370
1290 // Tests that |ClearPreview| properly clears previewed username and password 1371 // Tests that |ClearPreview| properly clears previewed username and password
1291 // with username being previously autofilled. 1372 // with username being previously autofilled.
1292 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) { 1373 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
1293 username_element_.SetValue(WebString::FromUTF8("ali")); 1374 username_element_.SetValue(WebString::FromUTF8("ali"));
1294 username_element_.SetSelectionRange(3, 3); 1375 username_element_.SetSelectionRange(3, 3);
1295 username_element_.SetAutofilled(true); 1376 username_element_.SetAutofilled(true);
1296 1377
1297 // Simulate the browser sending the login info, but set |wait_for_username| 1378 // Simulate the browser sending the login info, but set |wait_for_username|
1298 // to prevent the form from being immediately filled. 1379 // to prevent the form from being immediately filled.
1299 fill_data_.wait_for_username = true; 1380 fill_data_.wait_for_username = true;
1300 SimulateOnFillPasswordForm(fill_data_); 1381 SimulateOnFillPasswordForm(fill_data_);
1301 1382
1302 CheckTextFieldsDOMState("ali", true, std::string(), false); 1383 CheckTextFieldsDOMState("ali", true, std::string(), false);
1303 1384
1304 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1385 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1305 username_element_, kAliceUsername, kAlicePassword)); 1386 username_element_, kAliceUsername, kAlicePassword));
1306 1387
1307 EXPECT_TRUE( 1388 EXPECT_TRUE(
1308 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1389 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1309 1390
1310 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.Value().Utf16());
1311 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty()); 1391 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty());
1312 EXPECT_TRUE(username_element_.IsAutofilled());
1313 EXPECT_TRUE(password_element_.Value().IsEmpty());
1314 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty()); 1392 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty());
1315 EXPECT_FALSE(password_element_.IsAutofilled()); 1393 CheckTextFieldsDOMState("ali", true, std::string(), false);
1316 CheckUsernameSelection(3, 3); 1394 CheckUsernameSelection(3, 3);
1317 } 1395 }
1318 1396
1319 // Tests that |ClearPreview| properly clears previewed username and password 1397 // Tests that |ClearPreview| properly clears previewed username and password
1320 // with username and password being previously autofilled. 1398 // with username and password being previously autofilled.
1321 TEST_F(PasswordAutofillAgentTest, 1399 TEST_F(PasswordAutofillAgentTest,
1322 ClearPreviewWithAutofilledUsernameAndPassword) { 1400 ClearPreviewWithAutofilledUsernameAndPassword) {
1323 username_element_.SetValue(WebString::FromUTF8("ali")); 1401 username_element_.SetValue(WebString::FromUTF8("ali"));
1324 username_element_.SetSelectionRange(3, 3); 1402 username_element_.SetSelectionRange(3, 3);
1325 username_element_.SetAutofilled(true); 1403 username_element_.SetAutofilled(true);
1326 password_element_.SetValue(WebString::FromUTF8("sec")); 1404 password_element_.SetValue(WebString::FromUTF8("sec"));
1327 password_element_.SetAutofilled(true); 1405 password_element_.SetAutofilled(true);
1328 1406
1329 // Simulate the browser sending the login info, but set |wait_for_username| 1407 // Simulate the browser sending the login info, but set |wait_for_username|
1330 // to prevent the form from being immediately filled. 1408 // to prevent the form from being immediately filled.
1331 fill_data_.wait_for_username = true; 1409 fill_data_.wait_for_username = true;
1332 SimulateOnFillPasswordForm(fill_data_); 1410 SimulateOnFillPasswordForm(fill_data_);
1333 1411
1334 CheckTextFieldsDOMState("ali", true, "sec", true); 1412 CheckTextFieldsDOMState("ali", true, "sec", true);
1335 1413
1336 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1414 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1337 username_element_, kAliceUsername, kAlicePassword)); 1415 username_element_, kAliceUsername, kAlicePassword));
1338 1416
1339 EXPECT_TRUE( 1417 EXPECT_TRUE(
1340 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1418 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1341 1419
1342 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.Value().Utf16());
1343 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty()); 1420 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty());
1344 EXPECT_TRUE(username_element_.IsAutofilled());
1345 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.Value().Utf16());
1346 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty()); 1421 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty());
1347 EXPECT_TRUE(password_element_.IsAutofilled()); 1422 CheckTextFieldsDOMState("ali", true, "sec", true);
1348 CheckUsernameSelection(3, 3); 1423 CheckUsernameSelection(3, 3);
1349 } 1424 }
1350 1425
1426 // Tests that, when interacting with the password field, |ClearPreview| properly
1427 // clears previewed username and password with both being previously autofilled.
1428 TEST_F(PasswordAutofillAgentTest,
1429 ClearPreviewFromPasswordWithAutofilledUsernameAndPassword) {
1430 username_element_.SetValue(WebString::FromUTF8("ali"));
1431 username_element_.SetSelectionRange(3, 3);
1432 username_element_.SetAutofilled(true);
1433 password_element_.SetValue(WebString::FromUTF8("sec"));
1434 password_element_.SetAutofilled(true);
1435
1436 // Simulate the browser sending the login info, but set |wait_for_username| to
1437 // prevent the form from being immediately filled.
1438 fill_data_.wait_for_username = true;
1439 SimulateOnFillPasswordForm(fill_data_);
1440
1441 CheckTextFieldsDOMState("ali", true, "sec", true);
1442
1443 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1444 username_element_, kAliceUsername, kAlicePassword));
1445 EXPECT_TRUE(
1446 password_autofill_agent_->DidClearAutofillSelection(password_element_));
1447
1448 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty());
1449 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty());
1450 CheckTextFieldsDOMState("ali", true, "sec", true);
1451 CheckUsernameSelection(3, 3);
1452 }
1453
1351 // Tests that |ClearPreview| properly clears previewed username and password 1454 // Tests that |ClearPreview| properly clears previewed username and password
1352 // with neither username nor password being previously autofilled. 1455 // with neither username nor password being previously autofilled.
1353 TEST_F(PasswordAutofillAgentTest, 1456 TEST_F(PasswordAutofillAgentTest,
1354 ClearPreviewWithNotAutofilledUsernameAndPassword) { 1457 ClearPreviewWithNotAutofilledUsernameAndPassword) {
1355 // Simulate the browser sending the login info, but set |wait_for_username| 1458 // Simulate the browser sending the login info, but set |wait_for_username|
1356 // to prevent the form from being immediately filled. 1459 // to prevent the form from being immediately filled.
1357 fill_data_.wait_for_username = true; 1460 fill_data_.wait_for_username = true;
1358 SimulateOnFillPasswordForm(fill_data_); 1461 SimulateOnFillPasswordForm(fill_data_);
1359 1462
1360 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1463 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1361 1464
1362 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1465 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1363 username_element_, kAliceUsername, kAlicePassword)); 1466 username_element_, kAliceUsername, kAlicePassword));
1364 1467
1365 EXPECT_TRUE( 1468 EXPECT_TRUE(
1366 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1469 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1367 1470
1368 EXPECT_TRUE(username_element_.Value().IsEmpty());
1369 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty()); 1471 EXPECT_TRUE(username_element_.SuggestedValue().IsEmpty());
1370 EXPECT_FALSE(username_element_.IsAutofilled());
1371 EXPECT_TRUE(password_element_.Value().IsEmpty());
1372 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty()); 1472 EXPECT_TRUE(password_element_.SuggestedValue().IsEmpty());
1373 EXPECT_FALSE(password_element_.IsAutofilled()); 1473 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1374 CheckUsernameSelection(0, 0); 1474 CheckUsernameSelection(0, 0);
1375 } 1475 }
1376 1476
1377 // Tests that logging is off by default. 1477 // Tests that logging is off by default.
1378 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { 1478 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
1379 SendVisiblePasswordForms(); 1479 SendVisiblePasswordForms();
1380 base::RunLoop().RunUntilIdle(); 1480 base::RunLoop().RunUntilIdle();
1381 EXPECT_FALSE(fake_driver_.called_record_save_progress()); 1481 EXPECT_FALSE(fake_driver_.called_record_save_progress());
1382 } 1482 }
1383 1483
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 2249
2150 // Neither field should have been autocompleted. 2250 // Neither field should have been autocompleted.
2151 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 2251 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
2152 2252
2153 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( 2253 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
2154 username_element_, ASCIIToUTF16(kAliceUsername), 2254 username_element_, ASCIIToUTF16(kAliceUsername),
2155 ASCIIToUTF16(kAlicePassword))); 2255 ASCIIToUTF16(kAlicePassword)));
2156 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 2256 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
2157 } 2257 }
2158 2258
2159 // Tests that a password change form is properly filled with the password when 2259 // Tests that a password change form is properly filled with the
2160 // the user click on the password field. 2260 // username/password when the user clicks on the password field.
2161 TEST_F(PasswordAutofillAgentTest, 2261 TEST_F(PasswordAutofillAgentTest,
2162 FillSuggestionPasswordChangeFormsOnlyPassword) { 2262 FillSuggestionPasswordChangeFormsOnlyPassword) {
2163 LoadHTML(kPasswordChangeFormHTML); 2263 LoadHTML(kPasswordChangeFormHTML);
2164 UpdateOriginForHTML(kPasswordChangeFormHTML); 2264 UpdateOriginForHTML(kPasswordChangeFormHTML);
2165 UpdateUsernameAndPasswordElements(); 2265 UpdateUsernameAndPasswordElements();
2166 // Simulate the browser sending the login info, but set |wait_for_username| 2266 // Simulate the browser sending the login info, but set |wait_for_username|
2167 // to prevent the form from being immediately filled. 2267 // to prevent the form from being immediately filled.
2168 fill_data_.wait_for_username = true; 2268 fill_data_.wait_for_username = true;
2169 fill_data_.is_possible_change_password_form = true; 2269 fill_data_.is_possible_change_password_form = true;
2170 SimulateOnFillPasswordForm(fill_data_); 2270 SimulateOnFillPasswordForm(fill_data_);
2171 2271
2172 // Neither field should have been autocompleted. 2272 // Neither field should have been autocompleted.
2173 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 2273 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
2174 2274
2175 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( 2275 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
2176 password_element_, ASCIIToUTF16(kAliceUsername), 2276 password_element_, ASCIIToUTF16(kAliceUsername),
2177 ASCIIToUTF16(kAlicePassword))); 2277 ASCIIToUTF16(kAlicePassword)));
2178 CheckTextFieldsDOMState("", false, kAlicePassword, true); 2278 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
2179 } 2279 }
2180 2280
2181 // Tests that one user click on a username field is sufficient to bring up a 2281 // Tests that one user click on a username field is sufficient to bring up a
2182 // credential suggestion popup on a change password form. 2282 // credential suggestion popup on a change password form.
2183 TEST_F(PasswordAutofillAgentTest, 2283 TEST_F(PasswordAutofillAgentTest,
2184 SuggestionsOnUsernameFieldOfChangePasswordForm) { 2284 SuggestionsOnUsernameFieldOfChangePasswordForm) {
2185 LoadHTML(kPasswordChangeFormHTML); 2285 LoadHTML(kPasswordChangeFormHTML);
2186 UpdateOriginForHTML(kPasswordChangeFormHTML); 2286 UpdateOriginForHTML(kPasswordChangeFormHTML);
2187 UpdateUsernameAndPasswordElements(); 2287 UpdateUsernameAndPasswordElements();
2188 2288
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 2989
2890 // Navigate to another page and click on username field, 2990 // Navigate to another page and click on username field,
2891 // CheckSafeBrowsingReputation() should be triggered again. 2991 // CheckSafeBrowsingReputation() should be triggered again.
2892 LoadHTML(kFormHTML); 2992 LoadHTML(kFormHTML);
2893 SimulateElementClick(kUsernameName); 2993 SimulateElementClick(kUsernameName);
2894 base::RunLoop().RunUntilIdle(); 2994 base::RunLoop().RunUntilIdle();
2895 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt()); 2995 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt());
2896 } 2996 }
2897 #endif 2997 #endif
2898 } // namespace autofill 2998 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698