| 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..6a359230af0f03414d3d40a2fcea5ba4e4424080 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"
|
| @@ -64,12 +65,22 @@ class TestPasswordManagerClient : public StubPasswordManagerClient {
|
|
|
| class MockAutofillClient : public autofill::TestAutofillClient {
|
| public:
|
| + MockAutofillClient() : top_level_url_secure_(true) {}
|
| MOCK_METHOD4(ShowAutofillPopup,
|
| void(const gfx::RectF& element_bounds,
|
| base::i18n::TextDirection text_direction,
|
| const std::vector<Suggestion>& suggestions,
|
| base::WeakPtr<autofill::AutofillPopupDelegate> delegate));
|
| MOCK_METHOD0(HideAutofillPopup, void());
|
| +
|
| + bool IsTopLevelURLSecure() override { return top_level_url_secure_; }
|
| +
|
| + void NavigateToHttp() { top_level_url_secure_ = false; }
|
| +
|
| + void NavigateToHttps() { top_level_url_secure_ = true; }
|
| +
|
| + private:
|
| + bool top_level_url_secure_;
|
| };
|
|
|
| } // namespace
|
| @@ -577,4 +588,78 @@ TEST_F(PasswordAutofillManagerTest, PreviewAndFillEmptyUsernameSuggestion) {
|
| testing::Mock::VerifyAndClearExpectations(client->mock_driver());
|
| }
|
|
|
| +TEST_F(PasswordAutofillManagerTest, PasswordFieldHttpWarningMessage) {
|
| + std::unique_ptr<TestPasswordManagerClient> client(
|
| + new TestPasswordManagerClient);
|
| + std::unique_ptr<MockAutofillClient> autofill_client(new 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_;
|
| +
|
| + 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 is behind a switch flag, so with the flag disabled, it
|
| + // won't get displayed whenever on http or https sites.
|
| + autofill_client->NavigateToHttp();
|
| + 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);
|
| +
|
| + autofill_client->NavigateToHttps();
|
| + 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::kMarkHttpWithPasswordsOrCcWithChip);
|
| +
|
| + // Http warning message shown for http sites, so there are 3 suggestions in
|
| + // total, and the message comes first among suggestions.
|
| + autofill_client->NavigateToHttp();
|
| + 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);
|
| +
|
| + // Http warning message not shown for https sites.
|
| + autofill_client->NavigateToHttps();
|
| + 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
|
|
|