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 "components/password_manager/core/browser/password_store_default.h" |
| 6 |
| 7 #include <utility> |
| 8 |
5 #include "base/bind.h" | 9 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
7 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
9 #include "base/macros.h" | 13 #include "base/macros.h" |
10 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
11 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
12 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
13 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 19 #include "base/time/time.h" |
16 #include "components/password_manager/core/browser/login_database.h" | 20 #include "components/password_manager/core/browser/login_database.h" |
17 #include "components/password_manager/core/browser/password_manager_test_utils.h
" | 21 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
18 #include "components/password_manager/core/browser/password_store_change.h" | 22 #include "components/password_manager/core/browser/password_store_change.h" |
19 #include "components/password_manager/core/browser/password_store_consumer.h" | 23 #include "components/password_manager/core/browser/password_store_consumer.h" |
20 #include "components/password_manager/core/browser/password_store_default.h" | |
21 #include "components/password_manager/core/browser/password_store_origin_unittes
t.h" | 24 #include "components/password_manager/core/browser/password_store_origin_unittes
t.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/origin.h" | 27 #include "url/origin.h" |
25 | 28 |
26 using autofill::PasswordForm; | 29 using autofill::PasswordForm; |
27 using testing::ElementsAre; | 30 using testing::ElementsAre; |
28 using testing::ElementsAreArray; | 31 using testing::ElementsAreArray; |
29 using testing::IsEmpty; | 32 using testing::IsEmpty; |
30 using testing::_; | 33 using testing::_; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 107 |
105 PasswordStoreDefaultTestDelegate::PasswordStoreDefaultTestDelegate() { | 108 PasswordStoreDefaultTestDelegate::PasswordStoreDefaultTestDelegate() { |
106 SetupTempDir(); | 109 SetupTempDir(); |
107 store_ = CreateInitializedStore( | 110 store_ = CreateInitializedStore( |
108 make_scoped_ptr(new LoginDatabase(test_login_db_file_path()))); | 111 make_scoped_ptr(new LoginDatabase(test_login_db_file_path()))); |
109 } | 112 } |
110 | 113 |
111 PasswordStoreDefaultTestDelegate::PasswordStoreDefaultTestDelegate( | 114 PasswordStoreDefaultTestDelegate::PasswordStoreDefaultTestDelegate( |
112 scoped_ptr<LoginDatabase> database) { | 115 scoped_ptr<LoginDatabase> database) { |
113 SetupTempDir(); | 116 SetupTempDir(); |
114 store_ = CreateInitializedStore(database.Pass()); | 117 store_ = CreateInitializedStore(std::move(database)); |
115 } | 118 } |
116 | 119 |
117 PasswordStoreDefaultTestDelegate::~PasswordStoreDefaultTestDelegate() { | 120 PasswordStoreDefaultTestDelegate::~PasswordStoreDefaultTestDelegate() { |
118 ClosePasswordStore(); | 121 ClosePasswordStore(); |
119 } | 122 } |
120 | 123 |
121 void PasswordStoreDefaultTestDelegate::FinishAsyncProcessing() { | 124 void PasswordStoreDefaultTestDelegate::FinishAsyncProcessing() { |
122 base::MessageLoop::current()->RunUntilIdle(); | 125 base::MessageLoop::current()->RunUntilIdle(); |
123 } | 126 } |
124 | 127 |
125 void PasswordStoreDefaultTestDelegate::SetupTempDir() { | 128 void PasswordStoreDefaultTestDelegate::SetupTempDir() { |
126 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 129 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
127 } | 130 } |
128 | 131 |
129 void PasswordStoreDefaultTestDelegate::ClosePasswordStore() { | 132 void PasswordStoreDefaultTestDelegate::ClosePasswordStore() { |
130 store_->ShutdownOnUIThread(); | 133 store_->ShutdownOnUIThread(); |
131 base::MessageLoop::current()->RunUntilIdle(); | 134 base::MessageLoop::current()->RunUntilIdle(); |
132 ASSERT_TRUE(temp_dir_.Delete()); | 135 ASSERT_TRUE(temp_dir_.Delete()); |
133 } | 136 } |
134 | 137 |
135 scoped_refptr<PasswordStoreDefault> | 138 scoped_refptr<PasswordStoreDefault> |
136 PasswordStoreDefaultTestDelegate::CreateInitializedStore( | 139 PasswordStoreDefaultTestDelegate::CreateInitializedStore( |
137 scoped_ptr<LoginDatabase> database) { | 140 scoped_ptr<LoginDatabase> database) { |
138 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( | 141 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( |
139 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 142 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
140 database.Pass())); | 143 std::move(database))); |
141 store->Init(syncer::SyncableService::StartSyncFlare()); | 144 store->Init(syncer::SyncableService::StartSyncFlare()); |
142 | 145 |
143 return store; | 146 return store; |
144 } | 147 } |
145 | 148 |
146 base::FilePath PasswordStoreDefaultTestDelegate::test_login_db_file_path() | 149 base::FilePath PasswordStoreDefaultTestDelegate::test_login_db_file_path() |
147 const { | 150 const { |
148 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); | 151 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); |
149 } | 152 } |
150 | 153 |
(...skipping 22 matching lines...) Expand all Loading... |
173 L"盆栽", | 176 L"盆栽", |
174 L"أحب كرة", | 177 L"أحب كرة", |
175 L"£éä국수çà", | 178 L"£éä국수çà", |
176 true, false, 1 }, | 179 true, false, 1 }, |
177 }; | 180 }; |
178 | 181 |
179 // Build the expected forms vector and add the forms to the store. | 182 // Build the expected forms vector and add the forms to the store. |
180 ScopedVector<PasswordForm> expected_forms; | 183 ScopedVector<PasswordForm> expected_forms; |
181 for (unsigned int i = 0; i < arraysize(form_data); ++i) { | 184 for (unsigned int i = 0; i < arraysize(form_data); ++i) { |
182 expected_forms.push_back( | 185 expected_forms.push_back( |
183 CreatePasswordFormFromDataForTesting(form_data[i]).Pass()); | 186 CreatePasswordFormFromDataForTesting(form_data[i])); |
184 store->AddLogin(*expected_forms.back()); | 187 store->AddLogin(*expected_forms.back()); |
185 } | 188 } |
186 | 189 |
187 base::MessageLoop::current()->RunUntilIdle(); | 190 base::MessageLoop::current()->RunUntilIdle(); |
188 | 191 |
189 MockPasswordStoreConsumer consumer; | 192 MockPasswordStoreConsumer consumer; |
190 | 193 |
191 // We expect to get the same data back, even though it's not all ASCII. | 194 // We expect to get the same data back, even though it's not all ASCII. |
192 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( | 195 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( |
193 password_manager::UnorderedPasswordFormElementsAre( | 196 password_manager::UnorderedPasswordFormElementsAre( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 run_loop.Run(); | 306 run_loop.Run(); |
304 | 307 |
305 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); | 308 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); |
306 base::MessageLoop::current()->RunUntilIdle(); | 309 base::MessageLoop::current()->RunUntilIdle(); |
307 | 310 |
308 // Ensure no notifications and no explosions during shutdown either. | 311 // Ensure no notifications and no explosions during shutdown either. |
309 bad_store->RemoveObserver(&mock_observer); | 312 bad_store->RemoveObserver(&mock_observer); |
310 } | 313 } |
311 | 314 |
312 } // namespace password_manager | 315 } // namespace password_manager |
OLD | NEW |