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

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

Issue 492043003: Fill on account select in the password manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests 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 | Annotate | Revision Log
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"
14 #include "components/autofill/core/common/autofill_switches.h"
13 #include "components/autofill/core/common/form_data.h" 15 #include "components/autofill/core/common/form_data.h"
14 #include "components/autofill/core/common/form_field_data.h" 16 #include "components/autofill/core/common/form_field_data.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 19 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 20 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebElement.h" 21 #include "third_party/WebKit/public/web/WebElement.h"
20 #include "third_party/WebKit/public/web/WebFormElement.h" 22 #include "third_party/WebKit/public/web/WebFormElement.h"
21 #include "third_party/WebKit/public/web/WebInputElement.h" 23 #include "third_party/WebKit/public/web/WebInputElement.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" 24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 391
390 // Checks the message sent to PasswordAutofillManager to build the suggestion 392 // Checks the message sent to PasswordAutofillManager to build the suggestion
391 // list. |username| is the expected username field value, and |show_all| is 393 // list. |username| is the expected username field value, and |show_all| is
392 // the expected flag for the PasswordAutofillManager, whether to show all 394 // the expected flag for the PasswordAutofillManager, whether to show all
393 // suggestions, or only those starting with |username|. 395 // suggestions, or only those starting with |username|.
394 void CheckSuggestions(const std::string& username, bool show_all) { 396 void CheckSuggestions(const std::string& username, bool show_all) {
395 const IPC::Message* message = 397 const IPC::Message* message =
396 render_thread_->sink().GetFirstMessageMatching( 398 render_thread_->sink().GetFirstMessageMatching(
397 AutofillHostMsg_ShowPasswordSuggestions::ID); 399 AutofillHostMsg_ShowPasswordSuggestions::ID);
398 EXPECT_TRUE(message); 400 EXPECT_TRUE(message);
399 Tuple5<int, base::i18n::TextDirection, base::string16, bool, gfx::RectF> 401 Tuple5<int, base::i18n::TextDirection, base::string16, int, gfx::RectF>
400 args; 402 args;
401 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); 403 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args);
402 EXPECT_EQ(kPasswordFillFormDataId, args.a); 404 EXPECT_EQ(kPasswordFillFormDataId, args.a);
403 EXPECT_EQ(ASCIIToUTF16(username), args.c); 405 EXPECT_EQ(ASCIIToUTF16(username), args.c);
404 EXPECT_EQ(show_all, args.d); 406 EXPECT_EQ(show_all,
407 args.d & autofill::ShowPasswordSuggestionsOptions::SHOW_ALL);
405 408
406 render_thread_->sink().ClearMessages(); 409 render_thread_->sink().ClearMessages();
407 } 410 }
408 411
409 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 412 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
410 const std::string& new_password_value) { 413 const std::string& new_password_value) {
411 const IPC::Message* message = 414 const IPC::Message* message =
412 render_thread_->sink().GetFirstMessageMatching( 415 render_thread_->sink().GetFirstMessageMatching(
413 AutofillHostMsg_PasswordFormSubmitted::ID); 416 AutofillHostMsg_PasswordFormSubmitted::ID);
414 ASSERT_TRUE(message); 417 ASSERT_TRUE(message);
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 GetMainFrame(), 1515 GetMainFrame(),
1513 password_element_, 1516 password_element_,
1514 /*is_user_input=*/true); 1517 /*is_user_input=*/true);
1515 1518
1516 // Simulate the user typing a stored username. 1519 // Simulate the user typing a stored username.
1517 SimulateUsernameChange(kAliceUsername, true); 1520 SimulateUsernameChange(kAliceUsername, true);
1518 // The autofileld password should replace the typed one. 1521 // The autofileld password should replace the typed one.
1519 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1522 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1520 } 1523 }
1521 1524
1525 TEST_F(PasswordAutofillAgentTest, FormFillDataMustHaveUsername) {
1526 ClearUsernameAndPasswordFields();
1527
1528 PasswordFormFillData no_username_fill_data = fill_data_;
1529 no_username_fill_data.username_field.name = base::string16();
1530 SimulateOnFillPasswordForm(no_username_fill_data);
1531
1532 // The username and password should not have been autocompleted.
1533 CheckTextFieldsState("", false, "", false);
1534 }
1535
1536 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) {
1537 CommandLine::ForCurrentProcess()->AppendSwitch(
1538 autofill::switches::kEnableFillOnAccountSelect);
1539
1540 ClearUsernameAndPasswordFields();
1541
1542 // Simulate the browser sending back the login info for an initial page load.
1543 SimulateOnFillPasswordForm(fill_data_);
1544
1545 CheckTextFieldsState(std::string(), true, std::string(), false);
1546 }
1547
1548 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) {
1549 CommandLine::ForCurrentProcess()->AppendSwitch(
1550 autofill::switches::kEnableFillOnAccountSelect);
1551
1552 ClearUsernameAndPasswordFields();
1553
1554 username_element_.setValue("alicia");
1555 SetElementReadOnly(username_element_, true);
1556
1557 // Simulate the browser sending back the login info for an initial page load.
1558 SimulateOnFillPasswordForm(fill_data_);
1559
1560 CheckTextFieldsState(std::string("alicia"), false, std::string(), true);
1561 }
1562
1522 } // namespace autofill 1563 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_popup_controller_impl.cc ('k') | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698