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

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

Issue 695233002: Revert of Do not haul suggestions back to browser in AutofillHostMsg_ShowPasswordSuggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 password, 410 password,
411 password_autofilled, 411 password_autofilled,
412 false); 412 false);
413 } 413 }
414 414
415 void CheckUsernameSelection(int start, int end) { 415 void CheckUsernameSelection(int start, int end) {
416 EXPECT_EQ(start, username_element_.selectionStart()); 416 EXPECT_EQ(start, username_element_.selectionStart());
417 EXPECT_EQ(end, username_element_.selectionEnd()); 417 EXPECT_EQ(end, username_element_.selectionEnd());
418 } 418 }
419 419
420 // Checks the message sent to PasswordAutofillManager to build the suggestion 420 void ExpectOneCredential(const base::string16& username) {
421 // list. |username| is the expected username field value, and |show_all| is
422 // the expected flag for the PasswordAutofillManager, whether to show all
423 // suggestions, or only those starting with |username|.
424 void CheckSuggestions(const std::string& username, bool show_all) {
425 const IPC::Message* message = 421 const IPC::Message* message =
426 render_thread_->sink().GetFirstMessageMatching( 422 render_thread_->sink().GetFirstMessageMatching(
427 AutofillHostMsg_ShowPasswordSuggestions::ID); 423 AutofillHostMsg_ShowPasswordSuggestions::ID);
428 EXPECT_TRUE(message); 424 ASSERT_TRUE(message);
429 Tuple4<autofill::FormFieldData, base::string16, bool, gfx::RectF> args; 425 Tuple4<autofill::FormFieldData,
426 gfx::RectF,
427 std::vector<base::string16>,
428 std::vector<base::string16> > args;
430 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); 429 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
431 EXPECT_EQ(2u, fill_data_.basic_data.fields.size()); 430 ASSERT_EQ(1u, args.c.size());
432 EXPECT_EQ(fill_data_.basic_data.fields[0].name, args.a.name); 431 EXPECT_TRUE(args.c[0] == username);
433 EXPECT_EQ(ASCIIToUTF16(username), args.a.value); 432 }
434 EXPECT_EQ(ASCIIToUTF16(username), args.b); 433
435 EXPECT_EQ(show_all, args.c); 434 void ExpectAllCredentials() {
435 std::set<base::string16> usernames;
436 usernames.insert(username1_);
437 usernames.insert(username2_);
438 usernames.insert(username3_);
439 usernames.insert(alternate_username3_);
440
441 const IPC::Message* message =
442 render_thread_->sink().GetFirstMessageMatching(
443 AutofillHostMsg_ShowPasswordSuggestions::ID);
444 ASSERT_TRUE(message);
445 Tuple4<autofill::FormFieldData,
446 gfx::RectF,
447 std::vector<base::string16>,
448 std::vector<base::string16> > args;
449 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
450 ASSERT_EQ(4u, args.c.size());
451 std::set<base::string16>::iterator it;
452
453 for (int i = 0; i < 4; i++) {
454 it = usernames.find(args.c[i]);
455 EXPECT_TRUE(it != usernames.end());
456 if (it != usernames.end())
457 usernames.erase(it);
458 }
459
460 EXPECT_TRUE(usernames.empty());
436 461
437 render_thread_->sink().ClearMessages(); 462 render_thread_->sink().ClearMessages();
438 } 463 }
439 464
440 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 465 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
441 const std::string& new_password_value) { 466 const std::string& new_password_value) {
442 const IPC::Message* message = 467 const IPC::Message* message =
443 render_thread_->sink().GetFirstMessageMatching( 468 render_thread_->sink().GetFirstMessageMatching(
444 AutofillHostMsg_PasswordFormSubmitted::ID); 469 AutofillHostMsg_PasswordFormSubmitted::ID);
445 ASSERT_TRUE(message); 470 ASSERT_TRUE(message);
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { 1448 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) {
1424 // SimulateElementClick() is called so that a user gesture is actually made 1449 // SimulateElementClick() is called so that a user gesture is actually made
1425 // and the password can be filled. However, SimulateElementClick() does not 1450 // and the password can be filled. However, SimulateElementClick() does not
1426 // actually lead to the AutofillAgent's InputElementClicked() method being 1451 // actually lead to the AutofillAgent's InputElementClicked() method being
1427 // called, so SimulateSuggestionChoice has to manually call 1452 // called, so SimulateSuggestionChoice has to manually call
1428 // InputElementClicked(). 1453 // InputElementClicked().
1429 ClearUsernameAndPasswordFields(); 1454 ClearUsernameAndPasswordFields();
1430 SimulateOnFillPasswordForm(fill_data_); 1455 SimulateOnFillPasswordForm(fill_data_);
1431 SimulateElementClick(kUsernameName); 1456 SimulateElementClick(kUsernameName);
1432 SimulateSuggestionChoice(username_element_); 1457 SimulateSuggestionChoice(username_element_);
1433 CheckSuggestions(kAliceUsername, true); 1458 ExpectAllCredentials();
1434 1459
1435 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1460 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1436 } 1461 }
1437 1462
1438 // Tests the autosuggestions that are given when the element is clicked. 1463 // Tests the autosuggestions that are given when the element is clicked.
1439 // Specifically, tests when the user clicks on the username element after page 1464 // Specifically, tests when the user clicks on the username element after page
1440 // load and the element is autofilled, when the user clicks on an element that 1465 // load and the element is autofilled, when the user clicks on an element that
1441 // has a non-matching username, and when the user clicks on an element that's 1466 // has a non-matching username, and when the user clicks on an element that's
1442 // already been autofilled and they've already modified. 1467 // already been autofilled and they've already modified.
1443 TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) { 1468 TEST_F(PasswordAutofillAgentTest, CredentialsOnClick) {
1444 // Simulate the browser sending back the login info. 1469 // Simulate the browser sending back the login info.
1445 SimulateOnFillPasswordForm(fill_data_); 1470 SimulateOnFillPasswordForm(fill_data_);
1446 1471
1447 // Clear the text fields to start fresh. 1472 // Clear the text fields to start fresh.
1448 ClearUsernameAndPasswordFields(); 1473 ClearUsernameAndPasswordFields();
1449 1474
1450 // Call SimulateElementClick() to produce a user gesture on the page so 1475 // Call SimulateElementClick() to produce a user gesture on the page so
1451 // autofill will actually fill. 1476 // autofill will actually fill.
1452 SimulateElementClick(kUsernameName); 1477 SimulateElementClick(kUsernameName);
1453 1478
1454 // Simulate a user clicking on the username element. This should produce a 1479 // Simulate a user clicking on the username element. This should produce a
1455 // message with all the usernames. 1480 // message with all the usernames.
1456 render_thread_->sink().ClearMessages(); 1481 render_thread_->sink().ClearMessages();
1457 static_cast<PageClickListener*>(autofill_agent_) 1482 static_cast<PageClickListener*>(autofill_agent_)
1458 ->FormControlElementClicked(username_element_, false); 1483 ->FormControlElementClicked(username_element_, false);
1459 CheckSuggestions(std::string(), false); 1484 ExpectAllCredentials();
1460 1485
1461 // Now simulate a user typing in an unrecognized username and then 1486 // Now simulate a user typing in an unrecognized username and then
1462 // clicking on the username element. This should also produce a message with 1487 // clicking on the username element. This should also produce a message with
1463 // all the usernames. 1488 // all the usernames.
1464 SimulateUsernameChange("baz", true); 1489 SimulateUsernameChange("baz", true);
1465 render_thread_->sink().ClearMessages(); 1490 render_thread_->sink().ClearMessages();
1466 static_cast<PageClickListener*>(autofill_agent_) 1491 static_cast<PageClickListener*>(autofill_agent_)
1467 ->FormControlElementClicked(username_element_, true); 1492 ->FormControlElementClicked(username_element_, true);
1468 CheckSuggestions("baz", true); 1493 ExpectAllCredentials();
1469 1494
1470 // Now simulate a user typing in the first letter of the username and then 1495 // Now simulate a user typing in the first letter of the username and then
1471 // clicking on the username element. While the typing of the first letter will 1496 // clicking on the username element. While the typing of the first letter will
1472 // inline autocomplete, clicking on the element should still produce a full 1497 // inline autocomplete, clicking on the element should still produce a full
1473 // suggestion list. 1498 // suggestion list.
1474 SimulateUsernameChange("a", true); 1499 SimulateUsernameChange("a", true);
1475 render_thread_->sink().ClearMessages(); 1500 render_thread_->sink().ClearMessages();
1476 static_cast<PageClickListener*>(autofill_agent_) 1501 static_cast<PageClickListener*>(autofill_agent_)
1477 ->FormControlElementClicked(username_element_, true); 1502 ->FormControlElementClicked(username_element_, true);
1478 CheckSuggestions(kAliceUsername, true); 1503 ExpectAllCredentials();
1479 } 1504 }
1480 1505
1481 // The user types in a password, but then just before sending the form off, a 1506 // The user types in a password, but then just before sending the form off, a
1482 // script clears that password. This test checks that PasswordAutofillAgent can 1507 // script clears that password. This test checks that PasswordAutofillAgent can
1483 // still remember the password typed by the user. 1508 // still remember the password typed by the user.
1484 TEST_F(PasswordAutofillAgentTest, 1509 TEST_F(PasswordAutofillAgentTest,
1485 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { 1510 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) {
1486 SimulateInputChangeForElement( 1511 SimulateInputChangeForElement(
1487 "temp", true, GetMainFrame(), username_element_, true); 1512 "temp", true, GetMainFrame(), username_element_, true);
1488 SimulateInputChangeForElement( 1513 SimulateInputChangeForElement(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 password_element_, 1626 password_element_,
1602 /*is_user_input=*/true); 1627 /*is_user_input=*/true);
1603 1628
1604 // Simulate the user typing a stored username. 1629 // Simulate the user typing a stored username.
1605 SimulateUsernameChange(kAliceUsername, true); 1630 SimulateUsernameChange(kAliceUsername, true);
1606 // The autofileld password should replace the typed one. 1631 // The autofileld password should replace the typed one.
1607 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1632 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1608 } 1633 }
1609 1634
1610 } // namespace autofill 1635 } // 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