| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/password_manager/core/browser/mock_password_store.h" | 13 #include "components/password_manager/core/browser/mock_password_store.h" |
| 14 #include "components/password_manager/core/browser/password_autofill_manager.h" |
| 14 #include "components/password_manager/core/browser/password_manager.h" | 15 #include "components/password_manager/core/browser/password_manager.h" |
| 15 #include "components/password_manager/core/browser/password_manager_driver.h" | 16 #include "components/password_manager/core/browser/password_manager_driver.h" |
| 16 #include "components/password_manager/core/browser/password_store.h" | 17 #include "components/password_manager/core/browser/password_store.h" |
| 17 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 18 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 18 #include "components/password_manager/core/common/password_manager_pref_names.h" | 19 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 class PasswordGenerationManager; | 23 class PasswordGenerationManager; |
| 23 | 24 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 public: | 51 public: |
| 51 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); | 52 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
| 52 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 53 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 53 MOCK_METHOD0(IsOffTheRecord, bool()); | 54 MOCK_METHOD0(IsOffTheRecord, bool()); |
| 54 MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*()); | 55 MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*()); |
| 55 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); | 56 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); |
| 56 MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*()); | 57 MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*()); |
| 57 MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*)); | 58 MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*)); |
| 58 MOCK_METHOD1(AccountCreationFormsFound, | 59 MOCK_METHOD1(AccountCreationFormsFound, |
| 59 void(const std::vector<autofill::FormData>&)); | 60 void(const std::vector<autofill::FormData>&)); |
| 61 MOCK_METHOD2(AcceptPasswordAutofillSuggestion, |
| 62 void(const base::string16&, const base::string16&)); |
| 63 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); } | 66 ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); } |
| 63 | 67 |
| 64 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } | 68 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
| 65 | 69 |
| 66 class TestPasswordManager : public PasswordManager { | 70 class TestPasswordManager : public PasswordManager { |
| 67 public: | 71 public: |
| 68 explicit TestPasswordManager(PasswordManagerClient* client) | 72 explicit TestPasswordManager(PasswordManagerClient* client) |
| 69 : PasswordManager(client) {} | 73 : PasswordManager(client) {} |
| 70 virtual ~TestPasswordManager() {} | 74 virtual ~TestPasswordManager() {} |
| 71 | 75 |
| 72 virtual void OnPasswordFormSubmitted(const PasswordForm& form) OVERRIDE { | |
| 73 PasswordManager::OnPasswordFormSubmitted(form); | |
| 74 } | |
| 75 | |
| 76 private: | 76 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); | 77 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 class PasswordManagerTest : public testing::Test { | 82 class PasswordManagerTest : public testing::Test { |
| 83 protected: | 83 protected: |
| 84 virtual void SetUp() { | 84 virtual void SetUp() { |
| 85 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerEnabled, | 85 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerEnabled, |
| 86 true); | 86 true); |
| 87 | 87 |
| 88 store_ = new MockPasswordStore; | 88 store_ = new MockPasswordStore; |
| 89 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); | 89 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 90 | 90 |
| 91 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); | 91 EXPECT_CALL(client_, GetPasswordStore()).WillRepeatedly(Return(store_)); |
| 92 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); | 92 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); |
| 93 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); | 93 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); |
| 94 | 94 |
| 95 manager_.reset(new TestPasswordManager(&client_)); | 95 manager_.reset(new TestPasswordManager(&client_)); |
| 96 password_autofill_manager_.reset( |
| 97 new PasswordAutofillManager(&client_, NULL)); |
| 96 | 98 |
| 97 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) | 99 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 98 .WillRepeatedly(Return(false)); | 100 .WillRepeatedly(Return(false)); |
| 99 EXPECT_CALL(driver_, IsOffTheRecord()).WillRepeatedly(Return(false)); | 101 EXPECT_CALL(driver_, IsOffTheRecord()).WillRepeatedly(Return(false)); |
| 100 EXPECT_CALL(driver_, GetPasswordGenerationManager()) | 102 EXPECT_CALL(driver_, GetPasswordGenerationManager()) |
| 101 .WillRepeatedly(Return(static_cast<PasswordGenerationManager*>(NULL))); | 103 .WillRepeatedly(Return(static_cast<PasswordGenerationManager*>(NULL))); |
| 102 EXPECT_CALL(driver_, GetPasswordManager()) | 104 EXPECT_CALL(driver_, GetPasswordManager()) |
| 103 .WillRepeatedly(Return(manager_.get())); | 105 .WillRepeatedly(Return(manager_.get())); |
| 104 EXPECT_CALL(driver_, AllowPasswordGenerationForForm(_)).Times(AnyNumber()); | 106 EXPECT_CALL(driver_, AllowPasswordGenerationForForm(_)).Times(AnyNumber()); |
| 107 EXPECT_CALL(driver_, GetPasswordAutofillManager()) |
| 108 .WillRepeatedly(Return(password_autofill_manager_.get())); |
| 105 | 109 |
| 106 EXPECT_CALL(*store_, ReportMetricsImpl()).Times(AnyNumber()); | 110 EXPECT_CALL(*store_, ReportMetricsImpl()).Times(AnyNumber()); |
| 107 } | 111 } |
| 108 | 112 |
| 109 virtual void TearDown() { | 113 virtual void TearDown() { |
| 110 store_->Shutdown(); | 114 store_->Shutdown(); |
| 111 store_ = NULL; | 115 store_ = NULL; |
| 112 } | 116 } |
| 113 | 117 |
| 114 PasswordForm MakeSimpleForm() { | 118 PasswordForm MakeSimpleForm() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 195 } |
| 192 | 196 |
| 193 void FormSubmitted(const autofill::PasswordForm& form) { | 197 void FormSubmitted(const autofill::PasswordForm& form) { |
| 194 submitted_form_ = form; | 198 submitted_form_ = form; |
| 195 } | 199 } |
| 196 | 200 |
| 197 TestingPrefServiceSimple prefs_; | 201 TestingPrefServiceSimple prefs_; |
| 198 scoped_refptr<MockPasswordStore> store_; | 202 scoped_refptr<MockPasswordStore> store_; |
| 199 MockPasswordManagerClient client_; | 203 MockPasswordManagerClient client_; |
| 200 MockPasswordManagerDriver driver_; | 204 MockPasswordManagerDriver driver_; |
| 205 scoped_ptr<PasswordAutofillManager> password_autofill_manager_; |
| 201 scoped_ptr<TestPasswordManager> manager_; | 206 scoped_ptr<TestPasswordManager> manager_; |
| 202 PasswordForm submitted_form_; | 207 PasswordForm submitted_form_; |
| 203 }; | 208 }; |
| 204 | 209 |
| 205 MATCHER_P(FormMatches, form, "") { | 210 MATCHER_P(FormMatches, form, "") { |
| 206 return form.signon_realm == arg.signon_realm && form.origin == arg.origin && | 211 return form.signon_realm == arg.signon_realm && form.origin == arg.origin && |
| 207 form.action == arg.action && | 212 form.action == arg.action && |
| 208 form.username_element == arg.username_element && | 213 form.username_element == arg.username_element && |
| 209 form.password_element == arg.password_element && | 214 form.password_element == arg.password_element && |
| 210 form.password_autocomplete_set == arg.password_autocomplete_set && | 215 form.password_autocomplete_set == arg.password_autocomplete_set && |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 603 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
| 599 observed.clear(); | 604 observed.clear(); |
| 600 observed.push_back(failed_login_form); | 605 observed.push_back(failed_login_form); |
| 601 // A PasswordForm appears, and is visible in the layout: | 606 // A PasswordForm appears, and is visible in the layout: |
| 602 // No expected calls to the PasswordStore... | 607 // No expected calls to the PasswordStore... |
| 603 manager()->OnPasswordFormsParsed(observed); | 608 manager()->OnPasswordFormsParsed(observed); |
| 604 manager()->OnPasswordFormsRendered(observed); | 609 manager()->OnPasswordFormsRendered(observed); |
| 605 } | 610 } |
| 606 | 611 |
| 607 } // namespace password_manager | 612 } // namespace password_manager |
| OLD | NEW |