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

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

Issue 1962713002: Kill the autofill password manager in case 'store()' was called. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 class MockPasswordManagerClient : public StubPasswordManagerClient { 52 class MockPasswordManagerClient : public StubPasswordManagerClient {
53 public: 53 public:
54 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); 54 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool());
55 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); 55 MOCK_CONST_METHOD0(IsOffTheRecord, bool());
56 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 56 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
57 MOCK_METHOD1(NotifyUserAutoSigninPtr, 57 MOCK_METHOD1(NotifyUserAutoSigninPtr,
58 bool(const std::vector<autofill::PasswordForm*>& local_forms)); 58 bool(const std::vector<autofill::PasswordForm*>& local_forms));
59 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, 59 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr,
60 bool(autofill::PasswordForm* form)); 60 bool(autofill::PasswordForm* form));
61 MOCK_METHOD0(NotifyStorePasswordCalled, void());
61 MOCK_METHOD2(PromptUserToSavePasswordPtr, 62 MOCK_METHOD2(PromptUserToSavePasswordPtr,
62 void(PasswordFormManager*, CredentialSourceType type)); 63 void(PasswordFormManager*, CredentialSourceType type));
63 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, 64 MOCK_METHOD4(PromptUserToChooseCredentialsPtr,
64 bool(const std::vector<autofill::PasswordForm*>& local_forms, 65 bool(const std::vector<autofill::PasswordForm*>& local_forms,
65 const std::vector<autofill::PasswordForm*>& federated_forms, 66 const std::vector<autofill::PasswordForm*>& federated_forms,
66 const GURL& origin, 67 const GURL& origin,
67 const CredentialsCallback& callback)); 68 const CredentialsCallback& callback));
68 69
69 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { 70 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) {
70 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, 71 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin,
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 client_->set_zero_click_enabled(false); 388 client_->set_zero_click_enabled(false);
388 client_->set_first_run_seen(false); 389 client_->set_first_run_seen(false);
389 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed()); 390 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed());
390 } 391 }
391 392
392 TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) { 393 TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) {
393 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 394 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
394 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 395 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
395 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 396 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
396 .Times(testing::Exactly(1)); 397 .Times(testing::Exactly(1));
398 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
397 399
398 bool called = false; 400 bool called = false;
399 CallStore(info, base::Bind(&RespondCallback, &called)); 401 CallStore(info, base::Bind(&RespondCallback, &called));
400 402
401 // Allow the PasswordFormManager to talk to the password store, determine 403 // Allow the PasswordFormManager to talk to the password store, determine
402 // that the form is new, and set it as pending. 404 // that the form is new, and set it as pending.
403 RunAllPendingTasks(); 405 RunAllPendingTasks();
404 406
405 EXPECT_TRUE(called); 407 EXPECT_TRUE(called);
406 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); 408 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching());
(...skipping 10 matching lines...) Expand all
417 419
418 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { 420 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
419 // Populate the PasswordStore with a form. 421 // Populate the PasswordStore with a form.
420 store_->AddLogin(form_); 422 store_->AddLogin(form_);
421 RunAllPendingTasks(); 423 RunAllPendingTasks();
422 424
423 // Calling 'Store' with a credential that matches |form_| should update 425 // Calling 'Store' with a credential that matches |form_| should update
424 // the password without prompting the user. 426 // the password without prompting the user.
425 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 427 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
426 info.password = base::ASCIIToUTF16("Totally new password."); 428 info.password = base::ASCIIToUTF16("Totally new password.");
429 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0);
430 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
427 bool called = false; 431 bool called = false;
428 CallStore(info, base::Bind(&RespondCallback, &called)); 432 CallStore(info, base::Bind(&RespondCallback, &called));
429 433
430 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
431 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
432 .Times(testing::Exactly(0));
433
434 // Allow the PasswordFormManager to talk to the password store, determine 434 // Allow the PasswordFormManager to talk to the password store, determine
435 // the form is a match for an existing form, and update the PasswordStore. 435 // the form is a match for an existing form, and update the PasswordStore.
436 RunAllPendingTasks(); 436 RunAllPendingTasks();
437 437
438 EXPECT_TRUE(called); 438 EXPECT_TRUE(called);
439 439
440 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 440 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
441 EXPECT_EQ(1U, passwords.size()); 441 EXPECT_EQ(1U, passwords.size());
442 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 442 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
443 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), 443 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."),
444 passwords[form_.signon_realm][0].password_value); 444 passwords[form_.signon_realm][0].password_value);
445 } 445 }
446 446
447 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { 447 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
448 // Set the global zero click flag on, and populate the PasswordStore with a 448 // Set the global zero click flag on, and populate the PasswordStore with a
449 // form that's set to skip zero click. 449 // form that's set to skip zero click.
450 client_->set_zero_click_enabled(true); 450 client_->set_zero_click_enabled(true);
451 client_->set_first_run_seen(true); 451 client_->set_first_run_seen(true);
452 form_.skip_zero_click = true; 452 form_.skip_zero_click = true;
453 store_->AddLogin(form_); 453 store_->AddLogin(form_);
454 RunAllPendingTasks(); 454 RunAllPendingTasks();
455 455
456 // Calling 'Store' with a credential that matches |form_| should update 456 // Calling 'Store' with a credential that matches |form_| should update
457 // the credential without prompting the user. 457 // the credential without prompting the user.
458 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 458 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
459 bool called = false; 459 bool called = false;
460 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
460 CallStore(info, base::Bind(&RespondCallback, &called)); 461 CallStore(info, base::Bind(&RespondCallback, &called));
461 462
462 // Allow the PasswordFormManager to talk to the password store, determine 463 // Allow the PasswordFormManager to talk to the password store, determine
463 // the form is a match for an existing form, and update the PasswordStore. 464 // the form is a match for an existing form, and update the PasswordStore.
464 RunAllPendingTasks(); 465 RunAllPendingTasks();
465 466
466 // Verify that the update toggled the skip_zero_click flag off. 467 // Verify that the update toggled the skip_zero_click flag off.
467 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 468 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
468 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 469 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
469 } 470 }
470 471
471 TEST_F(CredentialManagerImplTest, 472 TEST_F(CredentialManagerImplTest,
472 CredentialManagerFederatedStoreOverwriteZeroClick) { 473 CredentialManagerFederatedStoreOverwriteZeroClick) {
473 // Set the global zero click flag on, and populate the PasswordStore with a 474 // Set the global zero click flag on, and populate the PasswordStore with a
474 // form that's set to skip zero click. 475 // form that's set to skip zero click.
475 client_->set_zero_click_enabled(true); 476 client_->set_zero_click_enabled(true);
476 client_->set_first_run_seen(true); 477 client_->set_first_run_seen(true);
477 form_.federation_origin = url::Origin(GURL("https://example.com/")); 478 form_.federation_origin = url::Origin(GURL("https://example.com/"));
478 form_.skip_zero_click = true; 479 form_.skip_zero_click = true;
479 form_.signon_realm = "federation://example.com/example.com"; 480 form_.signon_realm = "federation://example.com/example.com";
480 store_->AddLogin(form_); 481 store_->AddLogin(form_);
481 RunAllPendingTasks(); 482 RunAllPendingTasks();
482 483
483 // Calling 'Store' with a credential that matches |form_| should update 484 // Calling 'Store' with a credential that matches |form_| should update
484 // the credential without prompting the user. 485 // the credential without prompting the user.
485 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); 486 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
486 bool called = false; 487 bool called = false;
488 EXPECT_CALL(*client_, NotifyStorePasswordCalled());
487 CallStore(info, base::Bind(&RespondCallback, &called)); 489 CallStore(info, base::Bind(&RespondCallback, &called));
488 490
489 // Allow the PasswordFormManager to talk to the password store, determine 491 // Allow the PasswordFormManager to talk to the password store, determine
490 // the form is a match for an existing form, and update the PasswordStore. 492 // the form is a match for an existing form, and update the PasswordStore.
491 RunAllPendingTasks(); 493 RunAllPendingTasks();
492 494
493 // Verify that the update toggled the skip_zero_click flag off. 495 // Verify that the update toggled the skip_zero_click flag off.
494 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 496 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
495 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 497 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
496 } 498 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 532 }
531 533
532 TEST_F(CredentialManagerImplTest, 534 TEST_F(CredentialManagerImplTest,
533 CredentialManagerSignInWithSavingDisabledForCurrentPage) { 535 CredentialManagerSignInWithSavingDisabledForCurrentPage) {
534 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 536 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
535 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 537 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
536 .WillRepeatedly(testing::Return(false)); 538 .WillRepeatedly(testing::Return(false));
537 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 539 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
538 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 540 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
539 .Times(testing::Exactly(0)); 541 .Times(testing::Exactly(0));
542 EXPECT_CALL(*client_, NotifyStorePasswordCalled()).Times(0);
540 543
541 bool called = false; 544 bool called = false;
542 CallStore(info, base::Bind(&RespondCallback, &called)); 545 CallStore(info, base::Bind(&RespondCallback, &called));
543 546
544 RunAllPendingTasks(); 547 RunAllPendingTasks();
545 548
546 EXPECT_TRUE(called); 549 EXPECT_TRUE(called);
547 EXPECT_FALSE(client_->pending_manager()); 550 EXPECT_FALSE(client_->pending_manager());
548 } 551 }
549 552
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1258 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1256 CallStore(info, base::Bind(&RespondCallback, &called)); 1259 CallStore(info, base::Bind(&RespondCallback, &called));
1257 // Allow the PasswordFormManager to talk to the password store 1260 // Allow the PasswordFormManager to talk to the password store
1258 RunAllPendingTasks(); 1261 RunAllPendingTasks();
1259 1262
1260 ASSERT_TRUE(client_->pending_manager()); 1263 ASSERT_TRUE(client_->pending_manager());
1261 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1264 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1262 } 1265 }
1263 1266
1264 } // namespace password_manager 1267 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698