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

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

Issue 773573004: Fill on account select in the password manager behind a flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix browser_test crashes Created 6 years 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"
11 #include "components/autofill/content/renderer/password_autofill_agent.h" 11 #include "components/autofill/content/renderer/password_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
13 #include "components/autofill/core/common/autofill_constants.h" 13 #include "components/autofill/core/common/autofill_constants.h"
14 #include "components/autofill/core/common/autofill_switches.h"
14 #include "components/autofill/core/common/form_data.h" 15 #include "components/autofill/core/common/form_data.h"
15 #include "components/autofill/core/common/form_field_data.h" 16 #include "components/autofill/core/common/form_field_data.h"
16 #include "content/public/renderer/render_frame.h" 17 #include "content/public/renderer/render_frame.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebVector.h" 20 #include "third_party/WebKit/public/platform/WebVector.h"
20 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
21 #include "third_party/WebKit/public/web/WebElement.h" 22 #include "third_party/WebKit/public/web/WebElement.h"
22 #include "third_party/WebKit/public/web/WebFormElement.h" 23 #include "third_party/WebKit/public/web/WebFormElement.h"
23 #include "third_party/WebKit/public/web/WebInputElement.h" 24 #include "third_party/WebKit/public/web/WebInputElement.h"
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 void CheckSuggestions(const std::string& username, bool show_all) { 410 void CheckSuggestions(const std::string& username, bool show_all) {
410 const IPC::Message* message = 411 const IPC::Message* message =
411 render_thread_->sink().GetFirstMessageMatching( 412 render_thread_->sink().GetFirstMessageMatching(
412 AutofillHostMsg_ShowPasswordSuggestions::ID); 413 AutofillHostMsg_ShowPasswordSuggestions::ID);
413 EXPECT_TRUE(message); 414 EXPECT_TRUE(message);
414 Tuple5<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> 415 Tuple5<int, base::i18n::TextDirection, base::string16, int, gfx::RectF>
415 args; 416 args;
416 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); 417 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
417 EXPECT_EQ(kPasswordFillFormDataId, args.a); 418 EXPECT_EQ(kPasswordFillFormDataId, args.a);
418 EXPECT_EQ(ASCIIToUTF16(username), args.c); 419 EXPECT_EQ(ASCIIToUTF16(username), args.c);
419 int options = args.d; 420 EXPECT_EQ(show_all, static_cast<bool>(args.d & autofill::SHOW_ALL));
420 EXPECT_EQ(show_all, static_cast<bool>(options & autofill::SHOW_ALL));
421 421
422 render_thread_->sink().ClearMessages(); 422 render_thread_->sink().ClearMessages();
423 } 423 }
424 424
425 void ExpectFormSubmittedWithUsernameAndPasswords( 425 void ExpectFormSubmittedWithUsernameAndPasswords(
426 const std::string& username_value, 426 const std::string& username_value,
427 const std::string& password_value, 427 const std::string& password_value,
428 const std::string& new_password_value) { 428 const std::string& new_password_value) {
429 const IPC::Message* message = 429 const IPC::Message* message =
430 render_thread_->sink().GetFirstMessageMatching( 430 render_thread_->sink().GetFirstMessageMatching(
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 // clicking on the username element. While the typing of the first letter will 1401 // clicking on the username element. While the typing of the first letter will
1402 // inline autocomplete, clicking on the element should still produce a full 1402 // inline autocomplete, clicking on the element should still produce a full
1403 // suggestion list. 1403 // suggestion list.
1404 SimulateUsernameChange("a", true); 1404 SimulateUsernameChange("a", true);
1405 render_thread_->sink().ClearMessages(); 1405 render_thread_->sink().ClearMessages();
1406 static_cast<PageClickListener*>(autofill_agent_) 1406 static_cast<PageClickListener*>(autofill_agent_)
1407 ->FormControlElementClicked(username_element_, true); 1407 ->FormControlElementClicked(username_element_, true);
1408 CheckSuggestions(kAliceUsername, true); 1408 CheckSuggestions(kAliceUsername, true);
1409 } 1409 }
1410 1410
1411 // Tests that there are no autosuggestions from the password manager when the
1412 // user clicks on the password field and the username field is editable when
1413 // FillOnAccountSelect is enabled.
1414 TEST_F(PasswordAutofillAgentTest,
1415 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) {
1416 CommandLine::ForCurrentProcess()->AppendSwitch(
1417 autofill::switches::kEnableFillOnAccountSelect);
1418
1419 // Simulate the browser sending back the login info.
1420 SimulateOnFillPasswordForm(fill_data_);
1421
1422 // Clear the text fields to start fresh.
1423 ClearUsernameAndPasswordFields();
1424
1425 // Call SimulateElementClick() to produce a user gesture on the page so
1426 // autofill will actually fill.
1427 SimulateElementClick(kUsernameName);
1428
1429 // Simulate a user clicking on the password element. This should produce no
1430 // message.
1431 render_thread_->sink().ClearMessages();
1432 static_cast<PageClickListener*>(autofill_agent_)
1433 ->FormControlElementClicked(password_element_, false);
1434 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
1435 AutofillHostMsg_ShowPasswordSuggestions::ID));
1436 }
1437
1438 // Tests the autosuggestions that are given when a password element is clicked,
1439 // the username element is not editable, and FillOnAccountSelect is enabled.
1440 // Specifically, tests when the user clicks on the password element after page
1441 // load, and the corresponding username element is readonly (and thus
1442 // uneditable), that the credentials for the already-filled username are
1443 // suggested.
1444 TEST_F(PasswordAutofillAgentTest,
1445 FillOnAccountSelectOnlyCredentialsOnPasswordClick) {
1446 CommandLine::ForCurrentProcess()->AppendSwitch(
1447 autofill::switches::kEnableFillOnAccountSelect);
1448
1449 // Simulate the browser sending back the login info.
1450 SimulateOnFillPasswordForm(fill_data_);
1451
1452 // Clear the text fields to start fresh.
1453 ClearUsernameAndPasswordFields();
1454
1455 // Simulate the page loading with a prefilled username element that is
1456 // uneditable.
1457 username_element_.setValue("alicia");
1458 SetElementReadOnly(username_element_, true);
1459
1460 // Call SimulateElementClick() to produce a user gesture on the page so
1461 // autofill will actually fill.
1462 SimulateElementClick(kUsernameName);
1463
1464 // Simulate a user clicking on the password element. This should produce a
1465 // message with "alicia" suggested as the credential.
1466 render_thread_->sink().ClearMessages();
1467 static_cast<PageClickListener*>(autofill_agent_)
1468 ->FormControlElementClicked(password_element_, false);
1469 CheckSuggestions("alicia", false);
1470 }
1471
1472 // Tests that there are no autosuggestions from the password manager when the
1473 // user clicks on the password field (not the username field).
1474 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) {
1475 // Simulate the browser sending back the login info.
1476 SimulateOnFillPasswordForm(fill_data_);
1477
1478 // Clear the text fields to start fresh.
1479 ClearUsernameAndPasswordFields();
1480
1481 // Call SimulateElementClick() to produce a user gesture on the page so
1482 // autofill will actually fill.
1483 SimulateElementClick(kUsernameName);
1484
1485 // Simulate a user clicking on the password element. This should produce no
1486 // message.
1487 render_thread_->sink().ClearMessages();
1488 static_cast<PageClickListener*>(autofill_agent_)
1489 ->FormControlElementClicked(password_element_, false);
1490 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
1491 AutofillHostMsg_ShowPasswordSuggestions::ID));
1492 }
1493
1411 #endif // !defined(OS_ANDROID) 1494 #endif // !defined(OS_ANDROID)
1412 1495
1413 // The user types in a username and a password, but then just before sending 1496 // The user types in a username and a password, but then just before sending
1414 // the form off, a script clears them. This test checks that 1497 // the form off, a script clears them. This test checks that
1415 // PasswordAutofillAgent can still remember the username and the password 1498 // PasswordAutofillAgent can still remember the username and the password
1416 // typed by the user. 1499 // typed by the user.
1417 TEST_F(PasswordAutofillAgentTest, 1500 TEST_F(PasswordAutofillAgentTest,
1418 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { 1501 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) {
1419 SimulateInputChangeForElement( 1502 SimulateInputChangeForElement(
1420 "temp", true, GetMainFrame(), username_element_, true); 1503 "temp", true, GetMainFrame(), username_element_, true);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 GetMainFrame(), 1621 GetMainFrame(),
1539 password_element_, 1622 password_element_,
1540 /*is_user_input=*/true); 1623 /*is_user_input=*/true);
1541 1624
1542 // Simulate the user typing a stored username. 1625 // Simulate the user typing a stored username.
1543 SimulateUsernameChange(kAliceUsername, true); 1626 SimulateUsernameChange(kAliceUsername, true);
1544 // The autofileld password should replace the typed one. 1627 // The autofileld password should replace the typed one.
1545 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1628 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1546 } 1629 }
1547 1630
1631 TEST_F(PasswordAutofillAgentTest, FormFillDataMustHaveUsername) {
1632 ClearUsernameAndPasswordFields();
1633
1634 PasswordFormFillData no_username_fill_data = fill_data_;
1635 no_username_fill_data.username_field.name = base::string16();
1636 SimulateOnFillPasswordForm(no_username_fill_data);
1637
1638 // The username and password should not have been autocompleted.
1639 CheckTextFieldsState("", false, "", false);
1640 }
1641
1642 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) {
1643 CommandLine::ForCurrentProcess()->AppendSwitch(
1644 autofill::switches::kEnableFillOnAccountSelect);
1645
1646 ClearUsernameAndPasswordFields();
1647
1648 // Simulate the browser sending back the login info for an initial page load.
1649 SimulateOnFillPasswordForm(fill_data_);
1650
1651 CheckTextFieldsState(std::string(), true, std::string(), false);
1652 }
1653
1654 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) {
1655 CommandLine::ForCurrentProcess()->AppendSwitch(
1656 autofill::switches::kEnableFillOnAccountSelect);
1657
1658 ClearUsernameAndPasswordFields();
1659
1660 username_element_.setValue("alicia");
1661 SetElementReadOnly(username_element_, true);
1662
1663 // Simulate the browser sending back the login info for an initial page load.
1664 SimulateOnFillPasswordForm(fill_data_);
1665
1666 CheckTextFieldsState(std::string("alicia"), false, std::string(), true);
1667 }
1668
1548 } // namespace autofill 1669 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698