| 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 "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/scoped_feature_list.h" | 11 #include "base/test/scoped_feature_list.h" |
| 12 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" | 12 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" |
| 13 #include "chrome/renderer/autofill/fake_password_manager_client.h" | 13 #include "chrome/renderer/autofill/fake_password_manager_client.h" |
| 14 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 14 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
| 15 #include "chrome/test/base/chrome_render_view_test.h" | 15 #include "chrome/test/base/chrome_render_view_test.h" |
| 16 #include "components/autofill/content/renderer/autofill_agent.h" | 16 #include "components/autofill/content/renderer/autofill_agent.h" |
| 17 #include "components/autofill/content/renderer/form_autofill_util.h" | 17 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 18 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 18 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
| 19 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 19 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
| 20 #include "components/autofill/core/common/autofill_constants.h" | 20 #include "components/autofill/core/common/autofill_constants.h" |
| 21 #include "components/autofill/core/common/form_data.h" | 21 #include "components/autofill/core/common/form_data.h" |
| 22 #include "components/autofill/core/common/form_field_data.h" | 22 #include "components/autofill/core/common/form_field_data.h" |
| 23 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 24 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 24 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
| 25 #include "components/password_manager/core/common/password_manager_features.h" | 25 #include "components/password_manager/core/common/password_manager_features.h" |
| 26 #include "components/security_state/core/security_state.h" | |
| 27 #include "content/public/common/associated_interface_provider.h" | 26 #include "content/public/common/associated_interface_provider.h" |
| 28 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
| 29 #include "content/public/renderer/render_view.h" | 28 #include "content/public/renderer/render_view.h" |
| 30 #include "services/service_manager/public/cpp/interface_provider.h" | 29 #include "services/service_manager/public/cpp/interface_provider.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "third_party/WebKit/public/platform/WebString.h" | 31 #include "third_party/WebKit/public/platform/WebString.h" |
| 33 #include "third_party/WebKit/public/platform/WebVector.h" | 32 #include "third_party/WebKit/public/platform/WebVector.h" |
| 34 #include "third_party/WebKit/public/web/WebDocument.h" | 33 #include "third_party/WebKit/public/web/WebDocument.h" |
| 35 #include "third_party/WebKit/public/web/WebElement.h" | 34 #include "third_party/WebKit/public/web/WebElement.h" |
| 36 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 35 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 mojom::PasswordManagerClient::Name_, | 344 mojom::PasswordManagerClient::Name_, |
| 346 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerClient, | 345 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerClient, |
| 347 base::Unretained(this))); | 346 base::Unretained(this))); |
| 348 } | 347 } |
| 349 | 348 |
| 350 void SetFillOnAccountSelect() { | 349 void SetFillOnAccountSelect() { |
| 351 scoped_feature_list_.InitAndEnableFeature( | 350 scoped_feature_list_.InitAndEnableFeature( |
| 352 password_manager::features::kFillOnAccountSelect); | 351 password_manager::features::kFillOnAccountSelect); |
| 353 } | 352 } |
| 354 | 353 |
| 355 void SetHttpFormWarning() { | |
| 356 scoped_feature_list_.InitAndEnableFeature( | |
| 357 security_state::kHttpFormWarningFeature); | |
| 358 } | |
| 359 | |
| 360 void UpdateOriginForHTML(const std::string& html) { | 354 void UpdateOriginForHTML(const std::string& html) { |
| 361 std::string origin = "data:text/html;charset=utf-8," + html; | 355 std::string origin = "data:text/html;charset=utf-8," + html; |
| 362 fill_data_.origin = GURL(origin); | 356 fill_data_.origin = GURL(origin); |
| 363 } | 357 } |
| 364 | 358 |
| 365 void UpdateUsernameAndPasswordElements() { | 359 void UpdateUsernameAndPasswordElements() { |
| 366 WebDocument document = GetMainFrame()->document(); | 360 WebDocument document = GetMainFrame()->document(); |
| 367 WebElement element = | 361 WebElement element = |
| 368 document.getElementById(WebString::fromUTF8(kUsernameName)); | 362 document.getElementById(WebString::fromUTF8(kUsernameName)); |
| 369 ASSERT_FALSE(element.isNull()); | 363 ASSERT_FALSE(element.isNull()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 autofill::SHOW_ALL)); | 476 autofill::SHOW_ALL)); |
| 483 | 477 |
| 484 fake_driver_.reset_show_pw_suggestions(); | 478 fake_driver_.reset_show_pw_suggestions(); |
| 485 } | 479 } |
| 486 | 480 |
| 487 bool GetCalledShowPasswordSuggestions() { | 481 bool GetCalledShowPasswordSuggestions() { |
| 488 base::RunLoop().RunUntilIdle(); | 482 base::RunLoop().RunUntilIdle(); |
| 489 return fake_driver_.called_show_pw_suggestions(); | 483 return fake_driver_.called_show_pw_suggestions(); |
| 490 } | 484 } |
| 491 | 485 |
| 492 bool GetCalledShowNotSecureWarning() { | |
| 493 base::RunLoop().RunUntilIdle(); | |
| 494 return fake_driver_.called_show_not_secure_warning(); | |
| 495 } | |
| 496 | |
| 497 void ExpectFormSubmittedWithUsernameAndPasswords( | 486 void ExpectFormSubmittedWithUsernameAndPasswords( |
| 498 const std::string& username_value, | 487 const std::string& username_value, |
| 499 const std::string& password_value, | 488 const std::string& password_value, |
| 500 const std::string& new_password_value) { | 489 const std::string& new_password_value) { |
| 501 base::RunLoop().RunUntilIdle(); | 490 base::RunLoop().RunUntilIdle(); |
| 502 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); | 491 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
| 503 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); | 492 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 504 const autofill::PasswordForm& form = | 493 const autofill::PasswordForm& form = |
| 505 *(fake_driver_.password_form_submitted()); | 494 *(fake_driver_.password_form_submitted()); |
| 506 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); | 495 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 // Now simulate a user typing in an unrecognized username and then | 1349 // Now simulate a user typing in an unrecognized username and then |
| 1361 // clicking on the username element. This should also produce a message with | 1350 // clicking on the username element. This should also produce a message with |
| 1362 // all the usernames. | 1351 // all the usernames. |
| 1363 SimulateUsernameChange("baz"); | 1352 SimulateUsernameChange("baz"); |
| 1364 static_cast<PageClickListener*>(autofill_agent_) | 1353 static_cast<PageClickListener*>(autofill_agent_) |
| 1365 ->FormControlElementClicked(username_element_, true); | 1354 ->FormControlElementClicked(username_element_, true); |
| 1366 CheckSuggestions("baz", true); | 1355 CheckSuggestions("baz", true); |
| 1367 ClearUsernameAndPasswordFields(); | 1356 ClearUsernameAndPasswordFields(); |
| 1368 } | 1357 } |
| 1369 | 1358 |
| 1370 // Tests that the Form Not Secure warning appears when a password form | |
| 1371 // is autofilled when the Form Not Secure feature is enabled. | |
| 1372 TEST_F(PasswordAutofillAgentTest, FormNotSecureWarningOnAutofill) { | |
| 1373 SetHttpFormWarning(); | |
| 1374 | |
| 1375 fill_data_.show_form_not_secure_warning_on_autofill = true; | |
| 1376 | |
| 1377 // Simulate the browser autofilling a password form. | |
| 1378 SimulateOnFillPasswordForm(fill_data_); | |
| 1379 EXPECT_TRUE(GetCalledShowNotSecureWarning()); | |
| 1380 } | |
| 1381 | |
| 1382 // Tests that the Form Not Secure warning does not appear when the | |
| 1383 // PasswordFormFillData does not indicate that it should show. | |
| 1384 TEST_F(PasswordAutofillAgentTest, FormNotSecureWarningNotShownOnAutofill) { | |
| 1385 SetHttpFormWarning(); | |
| 1386 | |
| 1387 fill_data_.show_form_not_secure_warning_on_autofill = false; | |
| 1388 | |
| 1389 // Simulate the browser autofilling a password form. | |
| 1390 SimulateOnFillPasswordForm(fill_data_); | |
| 1391 EXPECT_FALSE(GetCalledShowNotSecureWarning()); | |
| 1392 } | |
| 1393 | |
| 1394 // Tests that there is an autosuggestion from the password manager when the | 1359 // Tests that there is an autosuggestion from the password manager when the |
| 1395 // user clicks on the password field when FillOnAccountSelect is enabled. | 1360 // user clicks on the password field when FillOnAccountSelect is enabled. |
| 1396 TEST_F(PasswordAutofillAgentTest, | 1361 TEST_F(PasswordAutofillAgentTest, |
| 1397 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1362 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
| 1398 SetFillOnAccountSelect(); | 1363 SetFillOnAccountSelect(); |
| 1399 | 1364 |
| 1400 // Simulate the browser sending back the login info. | 1365 // Simulate the browser sending back the login info. |
| 1401 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); | 1366 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
| 1402 | 1367 |
| 1403 // Clear the text fields to start fresh. | 1368 // Clear the text fields to start fresh. |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2496 SimulateElementClick("confirmpassword"); | 2461 SimulateElementClick("confirmpassword"); |
| 2497 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); | 2462 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
| 2498 | 2463 |
| 2499 // But when the user clicks on the autofilled password field again it should | 2464 // But when the user clicks on the autofilled password field again it should |
| 2500 // still produce a suggestion dropdown. | 2465 // still produce a suggestion dropdown. |
| 2501 SimulateElementClick("password"); | 2466 SimulateElementClick("password"); |
| 2502 CheckSuggestions("", false); | 2467 CheckSuggestions("", false); |
| 2503 } | 2468 } |
| 2504 | 2469 |
| 2505 } // namespace autofill | 2470 } // namespace autofill |
| OLD | NEW |