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

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

Issue 701073002: Reland "Do not haul suggestions back to browser in AutofillHostMsg_ShowPasswordSuggestions" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Boolean typo Created 6 years, 1 month 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
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 password, 378 password,
379 password_autofilled, 379 password_autofilled,
380 false); 380 false);
381 } 381 }
382 382
383 void CheckUsernameSelection(int start, int end) { 383 void CheckUsernameSelection(int start, int end) {
384 EXPECT_EQ(start, username_element_.selectionStart()); 384 EXPECT_EQ(start, username_element_.selectionStart());
385 EXPECT_EQ(end, username_element_.selectionEnd()); 385 EXPECT_EQ(end, username_element_.selectionEnd());
386 } 386 }
387 387
388 void ExpectOneCredential(const base::string16& username) { 388 // Checks the message sent to PasswordAutofillManager to build the suggestion
389 // list. |username| is the expected username field value, and |show_all| is
390 // the expected flag for the PasswordAutofillManager, whether to show all
391 // suggestions, or only those starting with |username|.
392 void CheckSuggestions(const std::string& username, bool show_all) {
389 const IPC::Message* message = 393 const IPC::Message* message =
390 render_thread_->sink().GetFirstMessageMatching( 394 render_thread_->sink().GetFirstMessageMatching(
391 AutofillHostMsg_ShowPasswordSuggestions::ID); 395 AutofillHostMsg_ShowPasswordSuggestions::ID);
392 ASSERT_TRUE(message); 396 EXPECT_TRUE(message);
393 Tuple4<autofill::FormFieldData, 397 Tuple4<autofill::FormFieldData, base::string16, bool, gfx::RectF> args;
394 gfx::RectF,
395 std::vector<base::string16>,
396 std::vector<base::string16> > args;
397 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); 398 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
398 ASSERT_EQ(1u, args.c.size()); 399 EXPECT_EQ(2u, fill_data_.basic_data.fields.size());
399 EXPECT_TRUE(args.c[0] == username); 400 EXPECT_EQ(fill_data_.basic_data.fields[0].name, args.a.name);
400 } 401 EXPECT_EQ(ASCIIToUTF16(username), args.a.value);
401 402 EXPECT_EQ(ASCIIToUTF16(username), args.b);
402 void ExpectAllCredentials() { 403 EXPECT_EQ(show_all, args.c);
403 std::set<base::string16> usernames;
404 usernames.insert(username1_);
405 usernames.insert(username2_);
406 usernames.insert(username3_);
407 usernames.insert(alternate_username3_);
408
409 const IPC::Message* message =
410 render_thread_->sink().GetFirstMessageMatching(
411 AutofillHostMsg_ShowPasswordSuggestions::ID);
412 ASSERT_TRUE(message);
413 Tuple4<autofill::FormFieldData,
414 gfx::RectF,
415 std::vector<base::string16>,
416 std::vector<base::string16> > args;
417 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
418 ASSERT_EQ(4u, args.c.size());
419 std::set<base::string16>::iterator it;
420
421 for (int i = 0; i < 4; i++) {
422 it = usernames.find(args.c[i]);
423 EXPECT_TRUE(it != usernames.end());
424 if (it != usernames.end())
425 usernames.erase(it);
426 }
427
428 EXPECT_TRUE(usernames.empty());
429 404
430 render_thread_->sink().ClearMessages(); 405 render_thread_->sink().ClearMessages();
431 } 406 }
432 407
433 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 408 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
434 const std::string& new_password_value) { 409 const std::string& new_password_value) {
435 const IPC::Message* message = 410 const IPC::Message* message =
436 render_thread_->sink().GetFirstMessageMatching( 411 render_thread_->sink().GetFirstMessageMatching(
437 AutofillHostMsg_PasswordFormSubmitted::ID); 412 AutofillHostMsg_PasswordFormSubmitted::ID);
438 ASSERT_TRUE(message); 413 ASSERT_TRUE(message);
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { 1332 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) {
1358 // SimulateElementClick() is called so that a user gesture is actually made 1333 // SimulateElementClick() is called so that a user gesture is actually made
1359 // and the password can be filled. However, SimulateElementClick() does not 1334 // and the password can be filled. However, SimulateElementClick() does not
1360 // actually lead to the AutofillAgent's InputElementClicked() method being 1335 // actually lead to the AutofillAgent's InputElementClicked() method being
1361 // called, so SimulateSuggestionChoice has to manually call 1336 // called, so SimulateSuggestionChoice has to manually call
1362 // InputElementClicked(). 1337 // InputElementClicked().
1363 ClearUsernameAndPasswordFields(); 1338 ClearUsernameAndPasswordFields();
1364 SimulateOnFillPasswordForm(fill_data_); 1339 SimulateOnFillPasswordForm(fill_data_);
1365 SimulateElementClick(kUsernameName); 1340 SimulateElementClick(kUsernameName);
1366 SimulateSuggestionChoice(username_element_); 1341 SimulateSuggestionChoice(username_element_);
1367 ExpectAllCredentials(); 1342 CheckSuggestions(kAliceUsername, true);
1368 1343
1369 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1344 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1370 } 1345 }
1371 1346
1372 // Tests the autosuggestions that are given when the element is clicked. 1347 // Tests the autosuggestions that are given when the element is clicked.
1373 // Specifically, tests when the user clicks on the username element after page 1348 // Specifically, tests when the user clicks on the username element after page
1374 // load and the element is autofilled, when the user clicks on an element that 1349 // load and the element is autofilled, when the user clicks on an element that
1375 // has a non-matching username, and when the user clicks on an element that's 1350 // has a non-matching username, and when the user clicks on an element that's
1376 // already been autofilled and they've already modified. 1351 // already been autofilled and they've already modified.
1377 TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { 1352 TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
1378 // Simulate the browser sending back the login info. 1353 // Simulate the browser sending back the login info.
1379 SimulateOnFillPasswordForm(fill_data_); 1354 SimulateOnFillPasswordForm(fill_data_);
1380 1355
1381 // Clear the text fields to start fresh. 1356 // Clear the text fields to start fresh.
1382 ClearUsernameAndPasswordFields(); 1357 ClearUsernameAndPasswordFields();
1383 1358
1384 // Call SimulateElementClick() to produce a user gesture on the page so 1359 // Call SimulateElementClick() to produce a user gesture on the page so
1385 // autofill will actually fill. 1360 // autofill will actually fill.
1386 SimulateElementClick(kUsernameName); 1361 SimulateElementClick(kUsernameName);
1387 1362
1388 // Simulate a user clicking on the username element. This should produce a 1363 // Simulate a user clicking on the username element. This should produce a
1389 // message with all the usernames. 1364 // message with all the usernames.
1390 render_thread_->sink().ClearMessages(); 1365 render_thread_->sink().ClearMessages();
1391 static_cast<PageClickListener*>(autofill_agent_) 1366 static_cast<PageClickListener*>(autofill_agent_)
1392 ->FormControlElementClicked(username_element_, false); 1367 ->FormControlElementClicked(username_element_, false);
1393 ExpectAllCredentials(); 1368 CheckSuggestions(std::string(), false);
1394 1369
1395 // Now simulate a user typing in an unrecognized username and then 1370 // Now simulate a user typing in an unrecognized username and then
1396 // clicking on the username element. This should also produce a message with 1371 // clicking on the username element. This should also produce a message with
1397 // all the usernames. 1372 // all the usernames.
1398 SimulateUsernameChange("baz", true); 1373 SimulateUsernameChange("baz", true);
1399 render_thread_->sink().ClearMessages(); 1374 render_thread_->sink().ClearMessages();
1400 static_cast<PageClickListener*>(autofill_agent_) 1375 static_cast<PageClickListener*>(autofill_agent_)
1401 ->FormControlElementClicked(username_element_, true); 1376 ->FormControlElementClicked(username_element_, true);
1402 ExpectAllCredentials(); 1377 CheckSuggestions("baz", true);
1403 1378
1404 // Now simulate a user typing in the first letter of the username and then 1379 // Now simulate a user typing in the first letter of the username and then
1405 // clicking on the username element. While the typing of the first letter will 1380 // clicking on the username element. While the typing of the first letter will
1406 // inline autocomplete, clicking on the element should still produce a full 1381 // inline autocomplete, clicking on the element should still produce a full
1407 // suggestion list. 1382 // suggestion list.
1408 SimulateUsernameChange("a", true); 1383 SimulateUsernameChange("a", true);
1409 render_thread_->sink().ClearMessages(); 1384 render_thread_->sink().ClearMessages();
1410 static_cast<PageClickListener*>(autofill_agent_) 1385 static_cast<PageClickListener*>(autofill_agent_)
1411 ->FormControlElementClicked(username_element_, true); 1386 ->FormControlElementClicked(username_element_, true);
1412 ExpectAllCredentials(); 1387 CheckSuggestions(kAliceUsername, true);
1413 } 1388 }
1414 1389
1415 #endif // !defined(OS_ANDROID) 1390 #endif // !defined(OS_ANDROID)
1416 1391
1417 // The user types in a password, but then just before sending the form off, a 1392 // The user types in a password, but then just before sending the form off, a
1418 // script clears that password. This test checks that PasswordAutofillAgent can 1393 // script clears that password. This test checks that PasswordAutofillAgent can
1419 // still remember the password typed by the user. 1394 // still remember the password typed by the user.
1420 TEST_F(PasswordAutofillAgentTest, 1395 TEST_F(PasswordAutofillAgentTest,
1421 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { 1396 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) {
1422 SimulateInputChangeForElement( 1397 SimulateInputChangeForElement(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 password_element_, 1512 password_element_,
1538 /*is_user_input=*/true); 1513 /*is_user_input=*/true);
1539 1514
1540 // Simulate the user typing a stored username. 1515 // Simulate the user typing a stored username.
1541 SimulateUsernameChange(kAliceUsername, true); 1516 SimulateUsernameChange(kAliceUsername, true);
1542 // The autofileld password should replace the typed one. 1517 // The autofileld password should replace the typed one.
1543 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1518 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1544 } 1519 }
1545 1520
1546 } // namespace autofill 1521 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698