OLD | NEW |
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/feature_list.h" | 5 #include "base/feature_list.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" | 10 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" |
| 11 #include "chrome/renderer/autofill/fake_password_manager_client.h" |
11 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 12 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
12 #include "chrome/test/base/chrome_render_view_test.h" | 13 #include "chrome/test/base/chrome_render_view_test.h" |
13 #include "components/autofill/content/common/autofill_messages.h" | |
14 #include "components/autofill/content/renderer/autofill_agent.h" | 14 #include "components/autofill/content/renderer/autofill_agent.h" |
15 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
16 #include "components/autofill/content/renderer/password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/password_autofill_agent.h" |
17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
18 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 18 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
19 #include "components/autofill/core/common/autofill_constants.h" | 19 #include "components/autofill/core/common/autofill_constants.h" |
20 #include "components/autofill/core/common/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
21 #include "components/autofill/core/common/form_field_data.h" | 21 #include "components/autofill/core/common/form_field_data.h" |
22 #include <components/autofill/core/common/password_form.h> | 22 #include <components/autofill/core/common/password_form.h> |
23 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 23 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
24 #include "components/password_manager/core/common/password_manager_features.h" | 24 #include "components/password_manager/core/common/password_manager_features.h" |
| 25 #include "content/public/common/associated_interface_provider.h" |
25 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
27 #include "services/shell/public/cpp/interface_provider.h" | 28 #include "services/shell/public/cpp/interface_provider.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "third_party/WebKit/public/platform/WebString.h" | 30 #include "third_party/WebKit/public/platform/WebString.h" |
30 #include "third_party/WebKit/public/platform/WebVector.h" | 31 #include "third_party/WebKit/public/platform/WebVector.h" |
31 #include "third_party/WebKit/public/web/WebDocument.h" | 32 #include "third_party/WebKit/public/web/WebDocument.h" |
32 #include "third_party/WebKit/public/web/WebElement.h" | 33 #include "third_party/WebKit/public/web/WebElement.h" |
33 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 34 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
34 #include "third_party/WebKit/public/web/WebFormElement.h" | 35 #include "third_party/WebKit/public/web/WebFormElement.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 void RegisterMainFrameRemoteInterfaces() override { | 327 void RegisterMainFrameRemoteInterfaces() override { |
327 // We only use the fake driver for main frame | 328 // We only use the fake driver for main frame |
328 // because our test cases only involve the main frame. | 329 // because our test cases only involve the main frame. |
329 shell::InterfaceProvider* remote_interfaces = | 330 shell::InterfaceProvider* remote_interfaces = |
330 view_->GetMainRenderFrame()->GetRemoteInterfaces(); | 331 view_->GetMainRenderFrame()->GetRemoteInterfaces(); |
331 shell::InterfaceProvider::TestApi test_api(remote_interfaces); | 332 shell::InterfaceProvider::TestApi test_api(remote_interfaces); |
332 test_api.SetBinderForName( | 333 test_api.SetBinderForName( |
333 mojom::PasswordManagerDriver::Name_, | 334 mojom::PasswordManagerDriver::Name_, |
334 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerDriver, | 335 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerDriver, |
335 base::Unretained(this))); | 336 base::Unretained(this))); |
| 337 |
| 338 // Because the test cases only involve the main frame in this test, |
| 339 // the fake password client is only used for the main frame. |
| 340 content::AssociatedInterfaceProvider* remote_associated_interfaces = |
| 341 view_->GetMainRenderFrame()->GetRemoteAssociatedInterfaces(); |
| 342 remote_associated_interfaces->OverrideBinderForTesting( |
| 343 mojom::PasswordManagerClient::Name_, |
| 344 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerClient, |
| 345 base::Unretained(this))); |
336 } | 346 } |
337 | 347 |
338 void SetFillOnAccountSelect() { | 348 void SetFillOnAccountSelect() { |
339 base::FeatureList::ClearInstanceForTesting(); | 349 base::FeatureList::ClearInstanceForTesting(); |
340 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 350 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
341 feature_list->InitializeFromCommandLine( | 351 feature_list->InitializeFromCommandLine( |
342 password_manager::features::kFillOnAccountSelect.name, ""); | 352 password_manager::features::kFillOnAccountSelect.name, ""); |
343 base::FeatureList::SetInstance(std::move(feature_list)); | 353 base::FeatureList::SetInstance(std::move(feature_list)); |
344 } | 354 } |
345 | 355 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); | 538 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
529 ASSERT_TRUE( | 539 ASSERT_TRUE( |
530 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); | 540 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); |
531 const autofill::PasswordForm& form = | 541 const autofill::PasswordForm& form = |
532 *(fake_driver_.password_form_inpage_navigation()); | 542 *(fake_driver_.password_form_inpage_navigation()); |
533 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); | 543 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
534 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); | 544 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
535 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); | 545 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); |
536 } | 546 } |
537 | 547 |
| 548 bool GetCalledShowPasswordGenerationPopup() { |
| 549 fake_pw_client_.Flush(); |
| 550 return fake_pw_client_.called_show_pw_generation_popup(); |
| 551 } |
| 552 |
538 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { | 553 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { |
539 fake_driver_.BindRequest( | 554 fake_driver_.BindRequest( |
540 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); | 555 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); |
541 } | 556 } |
542 | 557 |
| 558 void BindPasswordManagerClient(mojo::ScopedInterfaceEndpointHandle handle) { |
| 559 fake_pw_client_.BindRequest( |
| 560 mojo::MakeAssociatedRequest<mojom::PasswordManagerClient>( |
| 561 std::move(handle))); |
| 562 } |
| 563 |
543 FakeContentPasswordManagerDriver fake_driver_; | 564 FakeContentPasswordManagerDriver fake_driver_; |
| 565 FakePasswordManagerClient fake_pw_client_; |
544 | 566 |
545 base::string16 username1_; | 567 base::string16 username1_; |
546 base::string16 username2_; | 568 base::string16 username2_; |
547 base::string16 username3_; | 569 base::string16 username3_; |
548 base::string16 password1_; | 570 base::string16 password1_; |
549 base::string16 password2_; | 571 base::string16 password2_; |
550 base::string16 password3_; | 572 base::string16 password3_; |
551 base::string16 alternate_username3_; | 573 base::string16 alternate_username3_; |
552 PasswordFormFillData fill_data_; | 574 PasswordFormFillData fill_data_; |
553 | 575 |
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1976 SetNotBlacklistedMessage(password_generation_, | 1998 SetNotBlacklistedMessage(password_generation_, |
1977 kSignupFormHTML); | 1999 kSignupFormHTML); |
1978 SetAccountCreationFormsDetectedMessage(password_generation_, | 2000 SetAccountCreationFormsDetectedMessage(password_generation_, |
1979 GetMainFrame()->document(), 0, 1); | 2001 GetMainFrame()->document(), 0, 1); |
1980 | 2002 |
1981 // Simulate the field being clicked to start typing. This should trigger | 2003 // Simulate the field being clicked to start typing. This should trigger |
1982 // generation but not password autofill. | 2004 // generation but not password autofill. |
1983 SetFocused(password_element_); | 2005 SetFocused(password_element_); |
1984 SimulateElementClick("new_password"); | 2006 SimulateElementClick("new_password"); |
1985 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); | 2007 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
1986 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 2008 EXPECT_TRUE(GetCalledShowPasswordGenerationPopup()); |
1987 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); | |
1988 } | 2009 } |
1989 | 2010 |
1990 // Tests that a password change form is properly filled with the username and | 2011 // Tests that a password change form is properly filled with the username and |
1991 // password. | 2012 // password. |
1992 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { | 2013 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { |
1993 LoadHTML(kPasswordChangeFormHTML); | 2014 LoadHTML(kPasswordChangeFormHTML); |
1994 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2015 UpdateOriginForHTML(kPasswordChangeFormHTML); |
1995 UpdateUsernameAndPasswordElements(); | 2016 UpdateUsernameAndPasswordElements(); |
1996 // Simulate the browser sending the login info, but set |wait_for_username| | 2017 // Simulate the browser sending the login info, but set |wait_for_username| |
1997 // to prevent the form from being immediately filled. | 2018 // to prevent the form from being immediately filled. |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 SimulateElementClick("confirmpassword"); | 2462 SimulateElementClick("confirmpassword"); |
2442 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); | 2463 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
2443 | 2464 |
2444 // But when the user clicks on the autofilled password field again it should | 2465 // But when the user clicks on the autofilled password field again it should |
2445 // still produce a suggestion dropdown. | 2466 // still produce a suggestion dropdown. |
2446 SimulateElementClick("password"); | 2467 SimulateElementClick("password"); |
2447 CheckSuggestions("", false); | 2468 CheckSuggestions("", false); |
2448 } | 2469 } |
2449 | 2470 |
2450 } // namespace autofill | 2471 } // namespace autofill |
OLD | NEW |