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

Side by Side Diff: components/password_manager/core/browser/password_manager_unittest.cc

Issue 380713003: PasswordManager - update "password_manager_enabled_" pref name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trybots failure (rebase was needed) Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 private: 70 private:
71 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); 71 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager);
72 }; 72 };
73 73
74 } // namespace 74 } // namespace
75 75
76 class PasswordManagerTest : public testing::Test { 76 class PasswordManagerTest : public testing::Test {
77 protected: 77 protected:
78 virtual void SetUp() { 78 virtual void SetUp() {
79 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerEnabled, 79 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled,
80 true); 80 true);
81 81
82 store_ = new MockPasswordStore; 82 store_ = new MockPasswordStore;
83 EXPECT_CALL(*store_, ReportMetrics(_)).Times(AnyNumber()); 83 EXPECT_CALL(*store_, ReportMetrics(_)).Times(AnyNumber());
84 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), "")); 84 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), ""));
85 85
86 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) 86 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage())
87 .WillRepeatedly(Return(true)); 87 .WillRepeatedly(Return(true));
88 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); 88 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_));
89 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); 89 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_));
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. 477 manager()->OnPasswordFormsRendered(observed, true); // The initial layout.
478 478
479 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 479 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
480 manager()->OnPasswordFormsRendered(observed, 480 manager()->OnPasswordFormsRendered(observed,
481 true); // The post-navigation layout. 481 true); // The post-navigation layout.
482 } 482 }
483 483
484 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { 484 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) {
485 // Test that saving passwords depends on the password manager enabled 485 // Test that saving passwords depends on the password manager enabled
486 // preference. 486 // preference.
487 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, 487 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
488 base::Value::CreateBooleanValue(true)); 488 base::Value::CreateBooleanValue(true));
489 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); 489 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage());
490 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, 490 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
491 base::Value::CreateBooleanValue(false)); 491 base::Value::CreateBooleanValue(false));
492 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); 492 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage());
493 } 493 }
494 494
495 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { 495 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) {
496 // Test fix for issue 158296: Passwords must be filled even if the password 496 // Test fix for issue 158296: Passwords must be filled even if the password
497 // manager is disabled. 497 // manager is disabled.
498 std::vector<PasswordForm*> result; 498 std::vector<PasswordForm*> result;
499 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); 499 PasswordForm* existing = new PasswordForm(MakeSimpleForm());
500 result.push_back(existing); 500 result.push_back(existing);
501 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, 501 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled,
502 base::Value::CreateBooleanValue(false)); 502 base::Value::CreateBooleanValue(false));
503 EXPECT_CALL(driver_, FillPasswordForm(_)); 503 EXPECT_CALL(driver_, FillPasswordForm(_));
504 EXPECT_CALL(*store_.get(), 504 EXPECT_CALL(*store_.get(),
505 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) 505 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _))
506 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); 506 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
507 std::vector<PasswordForm> observed; 507 std::vector<PasswordForm> observed;
508 PasswordForm form(MakeSimpleForm()); 508 PasswordForm form(MakeSimpleForm());
509 observed.push_back(form); 509 observed.push_back(form);
510 manager()->OnPasswordFormsParsed(observed); 510 manager()->OnPasswordFormsParsed(observed);
511 } 511 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 std::vector<PasswordForm> forms; 642 std::vector<PasswordForm> forms;
643 forms.push_back(MakeSimpleForm()); 643 forms.push_back(MakeSimpleForm());
644 644
645 // Feed those forms to |manager()| and check that it does not try to find 645 // Feed those forms to |manager()| and check that it does not try to find
646 // matching saved credentials for the forms. 646 // matching saved credentials for the forms.
647 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); 647 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0));
648 manager()->OnPasswordFormsParsed(forms); 648 manager()->OnPasswordFormsParsed(forms);
649 } 649 }
650 650
651 } // namespace password_manager 651 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698