| Index: components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| diff --git a/components/password_manager/core/browser/password_autofill_manager_unittest.cc b/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| index 3e0d9c431d1df27aa4443c39776661465fa1f6f8..6e53922abb19dbd17a7263748fb12dba1ff3b1eb 100644
|
| --- a/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| +++ b/components/password_manager/core/browser/password_autofill_manager_unittest.cc
|
| @@ -18,6 +18,7 @@
|
| #include "components/autofill/core/common/password_form_fill_data.h"
|
| #include "components/password_manager/core/browser/stub_password_manager_client.h"
|
| #include "components/password_manager/core/browser/stub_password_manager_driver.h"
|
| +#include "components/security_state/switches.h"
|
| #include "components/strings/grit/components_strings.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -577,4 +578,102 @@ TEST_F(PasswordAutofillManagerTest, PreviewAndFillEmptyUsernameSuggestion) {
|
| testing::Mock::VerifyAndClearExpectations(client->mock_driver());
|
| }
|
|
|
| +TEST_F(PasswordAutofillManagerTest, NonSecurePasswordFieldHttpWarningMessage) {
|
| + auto client = base::MakeUnique<TestPasswordManagerClient>();
|
| + auto autofill_client = base::MakeUnique<MockAutofillClient>();
|
| + InitializePasswordAutofillManager(client.get(), autofill_client.get());
|
| +
|
| + gfx::RectF element_bounds;
|
| + autofill::PasswordFormFillData data;
|
| + data.username_field.value = test_username_;
|
| + data.password_field.value = test_password_;
|
| + data.origin = GURL("http://foo.test");
|
| +
|
| + int dummy_key = 0;
|
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
|
| +
|
| + // String "Login not secure" shown as a warning messages if password form is
|
| + // on http sites.
|
| + base::string16 warning_message =
|
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_PASSWORD_HTTP_WARNING_MESSAGE);
|
| +
|
| + // String "Use password for:" shown when displaying suggestions matching a
|
| + // username and specifying that the field is a password field.
|
| + base::string16 title =
|
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
|
| +
|
| + // Http warning message won't show with switch flag off.
|
| + EXPECT_CALL(*autofill_client,
|
| + ShowAutofillPopup(element_bounds, _,
|
| + SuggestionVectorValuesAre(testing::ElementsAre(
|
| + title, test_username_)),
|
| + _));
|
| + password_autofill_manager_->OnShowPasswordSuggestions(
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
|
| + autofill::IS_PASSWORD_FIELD, element_bounds);
|
| +
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::
|
| + kMarkHttpWithPasswordsOrCcWithChipAndFormWarning);
|
| +
|
| + // Http warning message shows for non-secure context and switch flag on, so
|
| + // there are 3 suggestions in total, and the message comes first among
|
| + // suggestions.
|
| + EXPECT_CALL(*autofill_client,
|
| + ShowAutofillPopup(element_bounds, _,
|
| + SuggestionVectorValuesAre(testing::ElementsAre(
|
| + warning_message, title, test_username_)),
|
| + _));
|
| + password_autofill_manager_->OnShowPasswordSuggestions(
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
|
| + autofill::IS_PASSWORD_FIELD, element_bounds);
|
| +}
|
| +
|
| +TEST_F(PasswordAutofillManagerTest, SecurePasswordFieldHttpWarningMessage) {
|
| + auto client = base::MakeUnique<TestPasswordManagerClient>();
|
| + auto autofill_client = base::MakeUnique<MockAutofillClient>();
|
| + InitializePasswordAutofillManager(client.get(), autofill_client.get());
|
| +
|
| + gfx::RectF element_bounds;
|
| + autofill::PasswordFormFillData data;
|
| + data.username_field.value = test_username_;
|
| + data.password_field.value = test_password_;
|
| + data.origin = GURL("https://foo.test");
|
| +
|
| + int dummy_key = 0;
|
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
|
| +
|
| + // String "Use password for:" shown when displaying suggestions matching a
|
| + // username and specifying that the field is a password field.
|
| + base::string16 title =
|
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
|
| +
|
| + // Http warning message won't show with switch flag off.
|
| + EXPECT_CALL(*autofill_client,
|
| + ShowAutofillPopup(element_bounds, _,
|
| + SuggestionVectorValuesAre(testing::ElementsAre(
|
| + title, test_username_)),
|
| + _));
|
| + password_autofill_manager_->OnShowPasswordSuggestions(
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
|
| + autofill::IS_PASSWORD_FIELD, element_bounds);
|
| +
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::
|
| + kMarkHttpWithPasswordsOrCcWithChipAndFormWarning);
|
| +
|
| + // Http warning message won't show for secure context, even with switch flag
|
| + // on.
|
| + EXPECT_CALL(*autofill_client,
|
| + ShowAutofillPopup(element_bounds, _,
|
| + SuggestionVectorValuesAre(testing::ElementsAre(
|
| + title, test_username_)),
|
| + _));
|
| + password_autofill_manager_->OnShowPasswordSuggestions(
|
| + dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
|
| + autofill::IS_PASSWORD_FIELD, element_bounds);
|
| +}
|
| +
|
| } // namespace password_manager
|
|
|