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

Unified Diff: components/password_manager/content/browser/credential_manager_impl_unittest.cc

Issue 1946563003: Fix blacklisting password forms with Credential Manager API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios Created 4 years, 8 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
Index: components/password_manager/content/browser/credential_manager_impl_unittest.cc
diff --git a/components/password_manager/content/browser/credential_manager_impl_unittest.cc b/components/password_manager/content/browser/credential_manager_impl_unittest.cc
index 66c30d36bee799f85bd3f81baa80471b5854a190..cfd372840685025edfbe94abfa522cbc215e4918 100644
--- a/components/password_manager/content/browser/credential_manager_impl_unittest.cc
+++ b/components/password_manager/content/browser/credential_manager_impl_unittest.cc
@@ -1160,4 +1160,105 @@ TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
EXPECT_TRUE(synthesized.ssl_valid);
}
+TEST_F(CredentialManagerImplTest, BlacklistPasswordCredential) {
+ EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
+ _, CredentialSourceType::CREDENTIAL_SOURCE_API));
+
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
+ bool called = false;
+ CallStore(info, base::Bind(&RespondCallback, &called));
+ // Allow the PasswordFormManager to talk to the password store
+ RunAllPendingTasks();
+
+ ASSERT_TRUE(client_->pending_manager());
+ client_->pending_manager()->PermanentlyBlacklist();
+ // Allow the PasswordFormManager to talk to the password store.
+ RunAllPendingTasks();
+
+ // Verify that the site is blacklisted.
+ autofill::PasswordForm blacklisted;
+ TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
+ blacklisted.blacklisted_by_user = true;
+ blacklisted.origin = form_.origin;
+ blacklisted.signon_realm = form_.signon_realm;
+ blacklisted.type = autofill::PasswordForm::TYPE_API;
+ blacklisted.ssl_valid = true;
+ blacklisted.date_created = passwords[form_.signon_realm][0].date_created;
+ EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted));
+}
+
+TEST_F(CredentialManagerImplTest, BlacklistFederatedCredential) {
+ form_.federation_origin = url::Origin(GURL("https://example.com/"));
+ form_.signon_realm = "federation://example.com/example.com";
+
+ EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
+ _, CredentialSourceType::CREDENTIAL_SOURCE_API));
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
+ bool called = false;
+ CallStore(info, base::Bind(&RespondCallback, &called));
+ // Allow the PasswordFormManager to talk to the password store
+ RunAllPendingTasks();
+
+ ASSERT_TRUE(client_->pending_manager());
+ client_->pending_manager()->PermanentlyBlacklist();
+ // Allow the PasswordFormManager to talk to the password store.
+ RunAllPendingTasks();
+
+ // Verify that the site is blacklisted.
+ TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
+ ASSERT_TRUE(passwords.count(form_.origin.spec()));
+ autofill::PasswordForm blacklisted;
+ blacklisted.blacklisted_by_user = true;
+ blacklisted.origin = form_.origin;
+ blacklisted.signon_realm = blacklisted.origin.spec();
+ blacklisted.type = autofill::PasswordForm::TYPE_API;
+ blacklisted.ssl_valid = true;
+ blacklisted.date_created =
+ passwords[blacklisted.signon_realm][0].date_created;
+ EXPECT_THAT(passwords[blacklisted.signon_realm],
+ testing::ElementsAre(blacklisted));
+}
+
+TEST_F(CredentialManagerImplTest, RespectBlacklistingPasswordCredential) {
+ autofill::PasswordForm blacklisted;
+ blacklisted.blacklisted_by_user = true;
+ blacklisted.origin = form_.origin;
+ blacklisted.signon_realm = blacklisted.origin.spec();
+ blacklisted.ssl_valid = true;
+ store_->AddLogin(blacklisted);
+
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
+ bool called = false;
+ EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
+ _, CredentialSourceType::CREDENTIAL_SOURCE_API));
+ CallStore(info, base::Bind(&RespondCallback, &called));
+ // Allow the PasswordFormManager to talk to the password store
+ RunAllPendingTasks();
+
+ ASSERT_TRUE(client_->pending_manager());
+ EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
+}
+
+TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) {
+ autofill::PasswordForm blacklisted;
+ blacklisted.blacklisted_by_user = true;
+ blacklisted.origin = form_.origin;
+ blacklisted.signon_realm = blacklisted.origin.spec();
+ blacklisted.ssl_valid = true;
+ store_->AddLogin(blacklisted);
+
+ form_.federation_origin = url::Origin(GURL("https://example.com/"));
+ form_.signon_realm = "federation://example.com/example.com";
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
+ bool called = false;
+ EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
+ _, CredentialSourceType::CREDENTIAL_SOURCE_API));
+ CallStore(info, base::Bind(&RespondCallback, &called));
+ // Allow the PasswordFormManager to talk to the password store
+ RunAllPendingTasks();
+
+ ASSERT_TRUE(client_->pending_manager());
+ EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
+}
+
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698