| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); | 70 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 class PasswordManagerTest : public testing::Test { | 75 class PasswordManagerTest : public testing::Test { |
| 76 protected: | 76 protected: |
| 77 virtual void SetUp() { | 77 virtual void SetUp() { |
| 78 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerEnabled, | 78 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
| 79 true); | 79 true); |
| 80 | 80 |
| 81 store_ = new MockPasswordStore; | 81 store_ = new MockPasswordStore; |
| 82 EXPECT_CALL(*store_, ReportMetrics()).Times(AnyNumber()); | 82 EXPECT_CALL(*store_, ReportMetrics()).Times(AnyNumber()); |
| 83 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); | 83 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 84 | 84 |
| 85 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); | 85 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); |
| 86 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); | 86 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); |
| 87 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); | 87 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); |
| 88 | 88 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. | 474 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 475 | 475 |
| 476 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 476 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 477 manager()->OnPasswordFormsRendered(observed, | 477 manager()->OnPasswordFormsRendered(observed, |
| 478 true); // The post-navigation layout. | 478 true); // The post-navigation layout. |
| 479 } | 479 } |
| 480 | 480 |
| 481 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { | 481 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
| 482 // Test that saving passwords depends on the password manager enabled | 482 // Test that saving passwords depends on the password manager enabled |
| 483 // preference. | 483 // preference. |
| 484 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 484 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
| 485 base::Value::CreateBooleanValue(true)); | 485 base::Value::CreateBooleanValue(true)); |
| 486 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); | 486 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); |
| 487 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 487 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
| 488 base::Value::CreateBooleanValue(false)); | 488 base::Value::CreateBooleanValue(false)); |
| 489 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); | 489 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 492 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
| 493 // Test fix for issue 158296: Passwords must be filled even if the password | 493 // Test fix for issue 158296: Passwords must be filled even if the password |
| 494 // manager is disabled. | 494 // manager is disabled. |
| 495 std::vector<PasswordForm*> result; | 495 std::vector<PasswordForm*> result; |
| 496 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 496 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
| 497 result.push_back(existing); | 497 result.push_back(existing); |
| 498 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 498 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
| 499 base::Value::CreateBooleanValue(false)); | 499 base::Value::CreateBooleanValue(false)); |
| 500 EXPECT_CALL(driver_, FillPasswordForm(_)); | 500 EXPECT_CALL(driver_, FillPasswordForm(_)); |
| 501 EXPECT_CALL(*store_.get(), | 501 EXPECT_CALL(*store_.get(), |
| 502 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 502 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| 503 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 503 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 504 std::vector<PasswordForm> observed; | 504 std::vector<PasswordForm> observed; |
| 505 PasswordForm form(MakeSimpleForm()); | 505 PasswordForm form(MakeSimpleForm()); |
| 506 observed.push_back(form); | 506 observed.push_back(form); |
| 507 manager()->OnPasswordFormsParsed(observed); | 507 manager()->OnPasswordFormsParsed(observed); |
| 508 } | 508 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 std::vector<PasswordForm> forms; | 619 std::vector<PasswordForm> forms; |
| 620 forms.push_back(MakeSimpleForm()); | 620 forms.push_back(MakeSimpleForm()); |
| 621 | 621 |
| 622 // Feed those forms to |manager()| and check that it does not try to find | 622 // Feed those forms to |manager()| and check that it does not try to find |
| 623 // matching saved credentials for the forms. | 623 // matching saved credentials for the forms. |
| 624 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); | 624 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); |
| 625 manager()->OnPasswordFormsParsed(forms); | 625 manager()->OnPasswordFormsParsed(forms); |
| 626 } | 626 } |
| 627 | 627 |
| 628 } // namespace password_manager | 628 } // namespace password_manager |
| OLD | NEW |