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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/content/browser/credential_manager_impl.h" 5 #include "components/password_manager/content/browser/credential_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1153
1154 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { 1154 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
1155 autofill::PasswordForm synthesized = 1155 autofill::PasswordForm synthesized =
1156 cm_service_impl_->GetSynthesizedFormForOrigin(); 1156 cm_service_impl_->GetSynthesizedFormForOrigin();
1157 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1157 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1158 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1158 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1159 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1159 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1160 EXPECT_TRUE(synthesized.ssl_valid); 1160 EXPECT_TRUE(synthesized.ssl_valid);
1161 } 1161 }
1162 1162
1163 TEST_F(CredentialManagerImplTest, BlacklistPasswordCredential) {
1164 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1165 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1166
1167 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
1168 bool called = false;
1169 CallStore(info, base::Bind(&RespondCallback, &called));
1170 // Allow the PasswordFormManager to talk to the password store
1171 RunAllPendingTasks();
1172
1173 ASSERT_TRUE(client_->pending_manager());
1174 client_->pending_manager()->PermanentlyBlacklist();
1175 // Allow the PasswordFormManager to talk to the password store.
1176 RunAllPendingTasks();
1177
1178 // Verify that the site is blacklisted.
1179 autofill::PasswordForm blacklisted;
1180 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
1181 blacklisted.blacklisted_by_user = true;
1182 blacklisted.origin = form_.origin;
1183 blacklisted.signon_realm = form_.signon_realm;
1184 blacklisted.type = autofill::PasswordForm::TYPE_API;
1185 blacklisted.ssl_valid = true;
1186 blacklisted.date_created = passwords[form_.signon_realm][0].date_created;
1187 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted));
1188 }
1189
1190 TEST_F(CredentialManagerImplTest, BlacklistFederatedCredential) {
1191 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1192 form_.signon_realm = "federation://example.com/example.com";
1193
1194 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1195 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1196 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1197 bool called = false;
1198 CallStore(info, base::Bind(&RespondCallback, &called));
1199 // Allow the PasswordFormManager to talk to the password store
1200 RunAllPendingTasks();
1201
1202 ASSERT_TRUE(client_->pending_manager());
1203 client_->pending_manager()->PermanentlyBlacklist();
1204 // Allow the PasswordFormManager to talk to the password store.
1205 RunAllPendingTasks();
1206
1207 // Verify that the site is blacklisted.
1208 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
1209 ASSERT_TRUE(passwords.count(form_.origin.spec()));
1210 autofill::PasswordForm blacklisted;
1211 blacklisted.blacklisted_by_user = true;
1212 blacklisted.origin = form_.origin;
1213 blacklisted.signon_realm = blacklisted.origin.spec();
1214 blacklisted.type = autofill::PasswordForm::TYPE_API;
1215 blacklisted.ssl_valid = true;
1216 blacklisted.date_created =
1217 passwords[blacklisted.signon_realm][0].date_created;
1218 EXPECT_THAT(passwords[blacklisted.signon_realm],
1219 testing::ElementsAre(blacklisted));
1220 }
1221
1222 TEST_F(CredentialManagerImplTest, RespectBlacklistingPasswordCredential) {
1223 autofill::PasswordForm blacklisted;
1224 blacklisted.blacklisted_by_user = true;
1225 blacklisted.origin = form_.origin;
1226 blacklisted.signon_realm = blacklisted.origin.spec();
1227 blacklisted.ssl_valid = true;
1228 store_->AddLogin(blacklisted);
1229
1230 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
1231 bool called = false;
1232 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1233 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1234 CallStore(info, base::Bind(&RespondCallback, &called));
1235 // Allow the PasswordFormManager to talk to the password store
1236 RunAllPendingTasks();
1237
1238 ASSERT_TRUE(client_->pending_manager());
1239 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1240 }
1241
1242 TEST_F(CredentialManagerImplTest, RespectBlacklistingFederatedCredential) {
1243 autofill::PasswordForm blacklisted;
1244 blacklisted.blacklisted_by_user = true;
1245 blacklisted.origin = form_.origin;
1246 blacklisted.signon_realm = blacklisted.origin.spec();
1247 blacklisted.ssl_valid = true;
1248 store_->AddLogin(blacklisted);
1249
1250 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1251 form_.signon_realm = "federation://example.com/example.com";
1252 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1253 bool called = false;
1254 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1255 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1256 CallStore(info, base::Bind(&RespondCallback, &called));
1257 // Allow the PasswordFormManager to talk to the password store
1258 RunAllPendingTasks();
1259
1260 ASSERT_TRUE(client_->pending_manager());
1261 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1262 }
1263
1163 } // namespace password_manager 1264 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698