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

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc

Issue 1960653002: Fix blacklisting password forms with Credential Manager API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: 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_dispatc her.h" 5 #include "components/password_manager/content/browser/credential_manager_dispatc her.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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 1195
1196 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { 1196 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) {
1197 autofill::PasswordForm synthesized = 1197 autofill::PasswordForm synthesized =
1198 dispatcher_->GetSynthesizedFormForOrigin(); 1198 dispatcher_->GetSynthesizedFormForOrigin();
1199 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1199 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1200 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1200 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1201 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1201 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1202 EXPECT_TRUE(synthesized.ssl_valid); 1202 EXPECT_TRUE(synthesized.ssl_valid);
1203 } 1203 }
1204 1204
1205 TEST_F(CredentialManagerDispatcherTest, BlacklistPasswordCredential) {
1206 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1207 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1208
1209 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
1210 dispatcher()->OnStore(kRequestId, info);
1211 process()->sink().ClearMessages();
1212 // Allow the PasswordFormManager to talk to the password store
1213 RunAllPendingTasks();
1214
1215 ASSERT_TRUE(client_->pending_manager());
1216 client_->pending_manager()->PermanentlyBlacklist();
1217 // Allow the PasswordFormManager to talk to the password store.
1218 RunAllPendingTasks();
1219
1220 // Verify that the site is blacklisted.
1221 autofill::PasswordForm blacklisted;
1222 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
1223 blacklisted.blacklisted_by_user = true;
1224 blacklisted.origin = form_.origin;
1225 blacklisted.signon_realm = form_.signon_realm;
1226 blacklisted.type = autofill::PasswordForm::TYPE_API;
1227 blacklisted.ssl_valid = true;
1228 blacklisted.date_created = passwords[form_.signon_realm][0].date_created;
1229 EXPECT_THAT(passwords[form_.signon_realm], testing::ElementsAre(blacklisted));
1230 }
1231
1232 TEST_F(CredentialManagerDispatcherTest, BlacklistFederatedCredential) {
1233 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1234 form_.signon_realm = "federation://example.com/example.com";
1235
1236 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1237 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1238 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1239 dispatcher()->OnStore(kRequestId, info);
1240 process()->sink().ClearMessages();
1241 // Allow the PasswordFormManager to talk to the password store
1242 RunAllPendingTasks();
1243
1244 ASSERT_TRUE(client_->pending_manager());
1245 client_->pending_manager()->PermanentlyBlacklist();
1246 // Allow the PasswordFormManager to talk to the password store.
1247 RunAllPendingTasks();
1248
1249 // Verify that the site is blacklisted.
1250 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
1251 ASSERT_TRUE(passwords.count(form_.origin.spec()));
1252 autofill::PasswordForm blacklisted;
1253 blacklisted.blacklisted_by_user = true;
1254 blacklisted.origin = form_.origin;
1255 blacklisted.signon_realm = blacklisted.origin.spec();
1256 blacklisted.type = autofill::PasswordForm::TYPE_API;
1257 blacklisted.ssl_valid = true;
1258 blacklisted.date_created =
1259 passwords[blacklisted.signon_realm][0].date_created;
1260 EXPECT_THAT(passwords[blacklisted.signon_realm],
1261 testing::ElementsAre(blacklisted));
1262 }
1263
1264 TEST_F(CredentialManagerDispatcherTest, RespectBlacklistingPasswordCredential) {
1265 autofill::PasswordForm blacklisted;
1266 blacklisted.blacklisted_by_user = true;
1267 blacklisted.origin = form_.origin;
1268 blacklisted.signon_realm = blacklisted.origin.spec();
1269 blacklisted.ssl_valid = true;
1270 store_->AddLogin(blacklisted);
1271
1272 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
1273 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1274 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1275 dispatcher()->OnStore(kRequestId, info);
1276 process()->sink().ClearMessages();
1277 // Allow the PasswordFormManager to talk to the password store
1278 RunAllPendingTasks();
1279
1280 ASSERT_TRUE(client_->pending_manager());
1281 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1282 }
1283
1284 TEST_F(CredentialManagerDispatcherTest,
1285 RespectBlacklistingFederatedCredential) {
1286 autofill::PasswordForm blacklisted;
1287 blacklisted.blacklisted_by_user = true;
1288 blacklisted.origin = form_.origin;
1289 blacklisted.signon_realm = blacklisted.origin.spec();
1290 blacklisted.ssl_valid = true;
1291 store_->AddLogin(blacklisted);
1292
1293 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1294 form_.signon_realm = "federation://example.com/example.com";
1295 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
1296 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
1297 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1298 dispatcher()->OnStore(kRequestId, info);
1299 process()->sink().ClearMessages();
1300 // Allow the PasswordFormManager to talk to the password store
1301 RunAllPendingTasks();
1302
1303 ASSERT_TRUE(client_->pending_manager());
1304 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1305 }
1306
1205 } // namespace password_manager 1307 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698