OLD | NEW |
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/core/browser/password_generation_manager.h
" |
| 6 |
| 7 #include <utility> |
5 #include <vector> | 8 #include <vector> |
6 | 9 |
7 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_field.h" | 15 #include "components/autofill/core/browser/autofill_field.h" |
13 #include "components/autofill/core/browser/autofill_metrics.h" | 16 #include "components/autofill/core/browser/autofill_metrics.h" |
14 #include "components/autofill/core/browser/form_structure.h" | 17 #include "components/autofill/core/browser/form_structure.h" |
15 #include "components/autofill/core/common/form_data.h" | 18 #include "components/autofill/core/common/form_data.h" |
16 #include "components/autofill/core/common/form_field_data.h" | 19 #include "components/autofill/core/common/form_field_data.h" |
17 #include "components/autofill/core/common/password_form_generation_data.h" | 20 #include "components/autofill/core/common/password_form_generation_data.h" |
18 #include "components/password_manager/core/browser/password_autofill_manager.h" | 21 #include "components/password_manager/core/browser/password_autofill_manager.h" |
19 #include "components/password_manager/core/browser/password_generation_manager.h
" | |
20 #include "components/password_manager/core/browser/password_manager.h" | 22 #include "components/password_manager/core/browser/password_manager.h" |
21 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 23 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
22 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 24 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
23 #include "components/password_manager/core/browser/test_password_store.h" | 25 #include "components/password_manager/core/browser/test_password_store.h" |
24 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "url/gurl.h" | 29 #include "url/gurl.h" |
28 | 30 |
29 using base::ASCIIToUTF16; | 31 using base::ASCIIToUTF16; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 found_forms_eligible_for_generation_; | 71 found_forms_eligible_for_generation_; |
70 }; | 72 }; |
71 | 73 |
72 class MockPasswordManagerClient : public StubPasswordManagerClient { | 74 class MockPasswordManagerClient : public StubPasswordManagerClient { |
73 public: | 75 public: |
74 MOCK_CONST_METHOD0(GetPasswordSyncState, PasswordSyncState()); | 76 MOCK_CONST_METHOD0(GetPasswordSyncState, PasswordSyncState()); |
75 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); | 77 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); |
76 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 78 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
77 | 79 |
78 explicit MockPasswordManagerClient(scoped_ptr<PrefService> prefs) | 80 explicit MockPasswordManagerClient(scoped_ptr<PrefService> prefs) |
79 : prefs_(prefs.Pass()), store_(new TestPasswordStore), driver_(this) {} | 81 : prefs_(std::move(prefs)), |
| 82 store_(new TestPasswordStore), |
| 83 driver_(this) {} |
80 | 84 |
81 ~MockPasswordManagerClient() override { store_->ShutdownOnUIThread(); } | 85 ~MockPasswordManagerClient() override { store_->ShutdownOnUIThread(); } |
82 | 86 |
83 PasswordStore* GetPasswordStore() const override { return store_.get(); } | 87 PasswordStore* GetPasswordStore() const override { return store_.get(); } |
84 PrefService* GetPrefs() override { return prefs_.get(); } | 88 PrefService* GetPrefs() override { return prefs_.get(); } |
85 | 89 |
86 TestPasswordManagerDriver* test_driver() { return &driver_; } | 90 TestPasswordManagerDriver* test_driver() { return &driver_; } |
87 | 91 |
88 private: | 92 private: |
89 scoped_ptr<PrefService> prefs_; | 93 scoped_ptr<PrefService> prefs_; |
90 scoped_refptr<TestPasswordStore> store_; | 94 scoped_refptr<TestPasswordStore> store_; |
91 TestPasswordManagerDriver driver_; | 95 TestPasswordManagerDriver driver_; |
92 }; | 96 }; |
93 | 97 |
94 } // anonymous namespace | 98 } // anonymous namespace |
95 | 99 |
96 class PasswordGenerationManagerTest : public testing::Test { | 100 class PasswordGenerationManagerTest : public testing::Test { |
97 protected: | 101 protected: |
98 void SetUp() override { | 102 void SetUp() override { |
99 // Construct a PrefService and register all necessary prefs before handing | 103 // Construct a PrefService and register all necessary prefs before handing |
100 // it off to |client_|, as the initialization flow of |client_| will | 104 // it off to |client_|, as the initialization flow of |client_| will |
101 // indirectly cause those prefs to be immediately accessed. | 105 // indirectly cause those prefs to be immediately accessed. |
102 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); | 106 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); |
103 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, | 107 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
104 true); | 108 true); |
105 client_.reset(new MockPasswordManagerClient(prefs.Pass())); | 109 client_.reset(new MockPasswordManagerClient(std::move(prefs))); |
106 } | 110 } |
107 | 111 |
108 void TearDown() override { client_.reset(); } | 112 void TearDown() override { client_.reset(); } |
109 | 113 |
110 PasswordGenerationManager* GetGenerationManager() { | 114 PasswordGenerationManager* GetGenerationManager() { |
111 return client_->test_driver()->GetPasswordGenerationManager(); | 115 return client_->test_driver()->GetPasswordGenerationManager(); |
112 } | 116 } |
113 | 117 |
114 TestPasswordManagerDriver* GetTestDriver() { return client_->test_driver(); } | 118 TestPasswordManagerDriver* GetTestDriver() { return client_->test_driver(); } |
115 | 119 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 250 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
247 PrefService* prefs = client_->GetPrefs(); | 251 PrefService* prefs = client_->GetPrefs(); |
248 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); | 252 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
249 EXPECT_CALL(*client_, GetPasswordSyncState()) | 253 EXPECT_CALL(*client_, GetPasswordSyncState()) |
250 .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION)); | 254 .WillRepeatedly(testing::Return(SYNCING_NORMAL_ENCRYPTION)); |
251 | 255 |
252 EXPECT_FALSE(IsGenerationEnabled()); | 256 EXPECT_FALSE(IsGenerationEnabled()); |
253 } | 257 } |
254 | 258 |
255 } // namespace password_manager | 259 } // namespace password_manager |
OLD | NEW |