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

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

Issue 2298733002: Filter out credentials with non-matching schemes (Closed)
Patch Set: Created 4 years, 4 months 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_form_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_form_manager_unittest.cc
diff --git a/components/password_manager/core/browser/password_form_manager_unittest.cc b/components/password_manager/core/browser/password_form_manager_unittest.cc
index 658e12fd4168d1d489d3898da4bc576d202b9d04..eb82655a32b6e0080c68196eb7daa46128b6a1a8 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -3016,4 +3016,54 @@ TEST_F(PasswordFormManagerTest, ReportProcessingUpdate) {
EXPECT_EQ(1, tester.GetActionCount("PasswordManager_LoginFollowingAutofill"));
}
+// For all combinations of PasswordForm schemes, test that ProcessMatches
+// filters out forms with schemes not matching the observed form.
+TEST_F(PasswordFormManagerTest, RemoveResultsWithWrongScheme_ObservingHTML) {
+ for (int correct = 0; correct <= PasswordForm::SCHEME_LAST; ++correct) {
+ for (int wrong = 0; wrong <= PasswordForm::SCHEME_LAST; ++wrong) {
+ if (correct == wrong)
+ continue;
+
+ const PasswordForm::Scheme kCorrectScheme =
+ static_cast<PasswordForm::Scheme>(correct);
+ const PasswordForm::Scheme kWrongScheme =
+ static_cast<PasswordForm::Scheme>(wrong);
+ SCOPED_TRACE(testing::Message() << "Correct scheme = " << kCorrectScheme
+ << ", wrong scheme = " << kWrongScheme);
+
+ PasswordForm observed = *observed_form();
+ observed.scheme = kCorrectScheme;
+ PasswordFormManager form_manager(
+ password_manager(), client(),
+ (kCorrectScheme == PasswordForm::SCHEME_HTML ? client()->driver()
+ : nullptr),
+ observed, base::MakeUnique<NiceMock<MockFormSaver>>());
+
+ PasswordForm match = *saved_match();
+ match.scheme = kCorrectScheme;
+
+ PasswordForm non_match = match;
+ non_match.scheme = kWrongScheme;
+
+ // First try putting the correct scheme first in returned matches.
+ std::vector<const PasswordForm*> all_matches = {&match, &non_match};
+ static_cast<FormFetcher::Consumer*>(&form_manager)
+ ->ProcessMatches(all_matches, 0u);
+
+ EXPECT_EQ(1u, form_manager.best_matches().size());
+ EXPECT_EQ(kCorrectScheme,
+ form_manager.best_matches().begin()->second->scheme);
+
+ // Now try putting the correct scheme last in returned matches.
+ all_matches = {&non_match, &match};
+ static_cast<FormFetcher::Consumer*>(&form_manager)
+ ->ProcessMatches(all_matches, 0u);
+
+ EXPECT_EQ(1u, form_manager.best_matches().size());
+ EXPECT_EQ(kCorrectScheme,
+ form_manager.best_matches().begin()->second->scheme);
+ }
+ }
+}
+
} // namespace password_manager
« no previous file with comments | « components/password_manager/core/browser/password_form_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698