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

Unified Diff: components/password_manager/core/browser/password_autofill_manager_unittest.cc

Issue 2478043002: HTTP Bad: Add warning message to autofill dropdown for http sites (Closed)
Patch Set: nit change Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/password_manager/core/browser/password_autofill_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/password_manager/core/browser/password_autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698