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

Side by Side Diff: chrome/browser/password_manager/password_store_win_unittest.cc

Issue 1858513002: chrome/browser/password_manager: scoped_ptr -> unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Windows -- revert unwanted change Created 4 years, 8 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 "chrome/browser/password_manager/password_store_win.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 8
9 #include <memory>
7 #include <string> 10 #include <string>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
12 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 16 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
16 #include "base/stl_util.h" 19 #include "base/stl_util.h"
17 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
18 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h" 22 #include "base/time/time.h"
20 #include "chrome/browser/password_manager/password_store_win.h"
21 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
22 #include "components/os_crypt/ie7_password_win.h" 24 #include "components/os_crypt/ie7_password_win.h"
23 #include "components/password_manager/core/browser/password_manager_test_utils.h " 25 #include "components/password_manager/core/browser/password_manager_test_utils.h "
24 #include "components/password_manager/core/browser/password_store_consumer.h" 26 #include "components/password_manager/core/browser/password_store_consumer.h"
25 #include "components/password_manager/core/browser/webdata/logins_table.h" 27 #include "components/password_manager/core/browser/webdata/logins_table.h"
26 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" 28 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h"
27 #include "components/password_manager/core/common/password_manager_pref_names.h" 29 #include "components/password_manager/core/common/password_manager_pref_names.h"
28 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
29 #include "components/webdata/common/web_database_service.h" 31 #include "components/webdata/common/web_database_service.h"
30 #include "content/public/test/test_browser_thread.h" 32 #include "content/public/test/test_browser_thread.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ASSERT_TRUE(db_thread_.Start()); 122 ASSERT_TRUE(db_thread_.Start());
121 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 123 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
122 124
123 profile_.reset(new TestingProfile()); 125 profile_.reset(new TestingProfile());
124 126
125 base::FilePath path = temp_dir_.path().AppendASCII("web_data_test"); 127 base::FilePath path = temp_dir_.path().AppendASCII("web_data_test");
126 wdbs_ = new WebDatabaseService(path, 128 wdbs_ = new WebDatabaseService(path,
127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 129 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
128 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)); 130 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB));
129 // Need to add at least one table so the database gets created. 131 // Need to add at least one table so the database gets created.
130 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable())); 132 wdbs_->AddTable(std::unique_ptr<WebDatabaseTable>(new LoginsTable()));
131 wdbs_->LoadDatabase(); 133 wdbs_->LoadDatabase();
132 wds_ = new PasswordWebDataService( 134 wds_ = new PasswordWebDataService(
133 wdbs_, 135 wdbs_,
134 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 136 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
135 WebDataServiceBase::ProfileErrorCallback()); 137 WebDataServiceBase::ProfileErrorCallback());
136 wds_->Init(); 138 wds_->Init();
137 } 139 }
138 140
139 void TearDown() override { 141 void TearDown() override {
140 if (store_.get()) 142 if (store_.get())
(...skipping 13 matching lines...) Expand all
154 } 156 }
155 157
156 base::FilePath test_login_db_file_path() const { 158 base::FilePath test_login_db_file_path() const {
157 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); 159 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test"));
158 } 160 }
159 161
160 PasswordStoreWin* CreatePasswordStore() { 162 PasswordStoreWin* CreatePasswordStore() {
161 return new PasswordStoreWin( 163 return new PasswordStoreWin(
162 base::ThreadTaskRunnerHandle::Get(), 164 base::ThreadTaskRunnerHandle::Get(),
163 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), 165 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
164 make_scoped_ptr(new LoginDatabase(test_login_db_file_path())), 166 base::WrapUnique(new LoginDatabase(test_login_db_file_path())),
165 wds_.get()); 167 wds_.get());
166 } 168 }
167 169
168 base::MessageLoopForUI message_loop_; 170 base::MessageLoopForUI message_loop_;
169 content::TestBrowserThread ui_thread_; 171 content::TestBrowserThread ui_thread_;
170 // PasswordStore, WDS schedule work on this thread. 172 // PasswordStore, WDS schedule work on this thread.
171 content::TestBrowserThread db_thread_; 173 content::TestBrowserThread db_thread_;
172 174
173 base::ScopedTempDir temp_dir_; 175 base::ScopedTempDir temp_dir_;
174 scoped_ptr<TestingProfile> profile_; 176 std::unique_ptr<TestingProfile> profile_;
175 scoped_refptr<PasswordWebDataService> wds_; 177 scoped_refptr<PasswordWebDataService> wds_;
176 scoped_refptr<WebDatabaseService> wdbs_; 178 scoped_refptr<WebDatabaseService> wdbs_;
177 scoped_refptr<PasswordStore> store_; 179 scoped_refptr<PasswordStore> store_;
178 }; 180 };
179 181
180 ACTION(STLDeleteElements0) { 182 ACTION(STLDeleteElements0) {
181 STLDeleteContainerPointers(arg0.begin(), arg0.end()); 183 STLDeleteContainerPointers(arg0.begin(), arg0.end());
182 } 184 }
183 185
184 ACTION(QuitUIMessageLoop) { 186 ACTION(QuitUIMessageLoop) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 "http://example.com/", 227 "http://example.com/",
226 "http://example.com/origin", 228 "http://example.com/origin",
227 "http://example.com/action", 229 "http://example.com/action",
228 L"submit_element", 230 L"submit_element",
229 L"username_element", 231 L"username_element",
230 L"password_element", 232 L"password_element",
231 L"", 233 L"",
232 L"", 234 L"",
233 true, false, 1, 235 true, false, 1,
234 }; 236 };
235 scoped_ptr<PasswordForm> form = 237 std::unique_ptr<PasswordForm> form =
236 CreatePasswordFormFromDataForTesting(form_data); 238 CreatePasswordFormFromDataForTesting(form_data);
237 239
238 // The returned form will not have 'action' or '*_element' fields set. This 240 // The returned form will not have 'action' or '*_element' fields set. This
239 // is because credentials imported from IE don't have this information. 241 // is because credentials imported from IE don't have this information.
240 PasswordFormData expected_form_data = { 242 PasswordFormData expected_form_data = {
241 PasswordForm::SCHEME_HTML, 243 PasswordForm::SCHEME_HTML,
242 "http://example.com/", 244 "http://example.com/",
243 "http://example.com/origin", 245 "http://example.com/origin",
244 "", 246 "",
245 L"", 247 L"",
(...skipping 26 matching lines...) Expand all
272 "http://example.com/", 274 "http://example.com/",
273 "http://example.com/origin", 275 "http://example.com/origin",
274 "http://example.com/action", 276 "http://example.com/action",
275 L"submit_element", 277 L"submit_element",
276 L"username_element", 278 L"username_element",
277 L"password_element", 279 L"password_element",
278 L"", 280 L"",
279 L"", 281 L"",
280 true, false, 1, 282 true, false, 1,
281 }; 283 };
282 scoped_ptr<PasswordForm> form = 284 std::unique_ptr<PasswordForm> form =
283 CreatePasswordFormFromDataForTesting(form_data); 285 CreatePasswordFormFromDataForTesting(form_data);
284 286
285 MockPasswordStoreConsumer consumer; 287 MockPasswordStoreConsumer consumer;
286 store_->GetLogins(*form, &consumer); 288 store_->GetLogins(*form, &consumer);
287 289
288 // Release the PSW and the WDS before the query can return. 290 // Release the PSW and the WDS before the query can return.
289 store_->ShutdownOnUIThread(); 291 store_->ShutdownOnUIThread();
290 store_ = nullptr; 292 store_ = nullptr;
291 wds_ = nullptr; 293 wds_ = nullptr;
292 294
(...skipping 28 matching lines...) Expand all
321 "http://example.com/", 323 "http://example.com/",
322 "http://example.com/origin", 324 "http://example.com/origin",
323 "http://example.com/action", 325 "http://example.com/action",
324 L"submit_element", 326 L"submit_element",
325 L"username_element", 327 L"username_element",
326 L"password_element", 328 L"password_element",
327 L"", 329 L"",
328 L"", 330 L"",
329 true, false, 1, 331 true, false, 1,
330 }; 332 };
331 scoped_ptr<PasswordForm> form = 333 std::unique_ptr<PasswordForm> form =
332 CreatePasswordFormFromDataForTesting(form_data); 334 CreatePasswordFormFromDataForTesting(form_data);
333 335
334 PasswordFormData expected_form_data = { 336 PasswordFormData expected_form_data = {
335 PasswordForm::SCHEME_HTML, 337 PasswordForm::SCHEME_HTML,
336 "http://example.com/", 338 "http://example.com/",
337 "http://example.com/origin", 339 "http://example.com/origin",
338 "http://example.com/action", 340 "http://example.com/action",
339 L"submit_element", 341 L"submit_element",
340 L"username_element", 342 L"username_element",
341 L"password_element", 343 L"password_element",
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 "http://example.com/", 379 "http://example.com/",
378 "http://example.com/origin", 380 "http://example.com/origin",
379 "http://example.com/action", 381 "http://example.com/action",
380 L"submit_element", 382 L"submit_element",
381 L"username_element", 383 L"username_element",
382 L"password_element", 384 L"password_element",
383 L"", 385 L"",
384 L"", 386 L"",
385 true, false, 1, 387 true, false, 1,
386 }; 388 };
387 scoped_ptr<PasswordForm> form = 389 std::unique_ptr<PasswordForm> form =
388 CreatePasswordFormFromDataForTesting(form_data); 390 CreatePasswordFormFromDataForTesting(form_data);
389 391
390 MockPasswordStoreConsumer consumer; 392 MockPasswordStoreConsumer consumer;
391 393
392 // Make sure we quit the MessageLoop even if the test fails. 394 // Make sure we quit the MessageLoop even if the test fails.
393 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) 395 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_))
394 .WillByDefault(QuitUIMessageLoop()); 396 .WillByDefault(QuitUIMessageLoop());
395 397
396 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 398 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
397 399
(...skipping 25 matching lines...) Expand all
423 425
424 // Make sure we quit the MessageLoop even if the test fails. 426 // Make sure we quit the MessageLoop even if the test fails.
425 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) 427 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_))
426 .WillByDefault(QuitUIMessageLoop()); 428 .WillByDefault(QuitUIMessageLoop());
427 429
428 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 430 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
429 431
430 store_->GetAutofillableLogins(&consumer); 432 store_->GetAutofillableLogins(&consumer);
431 base::MessageLoop::current()->Run(); 433 base::MessageLoop::current()->Run();
432 } 434 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_win.cc ('k') | chrome/browser/password_manager/password_store_x.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698