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 "chrome/browser/password_manager/password_store_win.h" | 5 #include "chrome/browser/password_manager/password_store_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/run_loop.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
22 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
25 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
26 #include "components/os_crypt/ie7_password_win.h" | 27 #include "components/os_crypt/ie7_password_win.h" |
27 #include "components/password_manager/core/browser/password_manager_test_utils.h
" | 28 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
28 #include "components/password_manager/core/browser/password_store_consumer.h" | 29 #include "components/password_manager/core/browser/password_store_consumer.h" |
29 #include "components/password_manager/core/browser/webdata/logins_table.h" | 30 #include "components/password_manager/core/browser/webdata/logins_table.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 wdbs_ = nullptr; | 153 wdbs_ = nullptr; |
153 } | 154 } |
154 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 155 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
155 base::WaitableEvent::InitialState::NOT_SIGNALED); | 156 base::WaitableEvent::InitialState::NOT_SIGNALED); |
156 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
157 BrowserThread::DB, FROM_HERE, | 158 BrowserThread::DB, FROM_HERE, |
158 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 159 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
159 done.Wait(); | 160 done.Wait(); |
160 base::ThreadTaskRunnerHandle::Get()->PostTask( | 161 base::ThreadTaskRunnerHandle::Get()->PostTask( |
161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 162 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
162 base::MessageLoop::current()->Run(); | 163 base::RunLoop().Run(); |
163 db_thread_.Stop(); | 164 db_thread_.Stop(); |
164 } | 165 } |
165 | 166 |
166 base::FilePath test_login_db_file_path() const { | 167 base::FilePath test_login_db_file_path() const { |
167 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); | 168 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); |
168 } | 169 } |
169 | 170 |
170 PasswordStoreWin* CreatePasswordStore() { | 171 PasswordStoreWin* CreatePasswordStore() { |
171 return new PasswordStoreWin( | 172 return new PasswordStoreWin( |
172 base::ThreadTaskRunnerHandle::Get(), | 173 base::ThreadTaskRunnerHandle::Get(), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ScopedVector<autofill::PasswordForm> expected_forms; | 268 ScopedVector<autofill::PasswordForm> expected_forms; |
268 expected_forms.push_back( | 269 expected_forms.push_back( |
269 CreatePasswordFormFromDataForTesting(expected_form_data)); | 270 CreatePasswordFormFromDataForTesting(expected_form_data)); |
270 | 271 |
271 // The IE7 password should be returned. | 272 // The IE7 password should be returned. |
272 EXPECT_CALL(consumer, | 273 EXPECT_CALL(consumer, |
273 OnGetPasswordStoreResultsConstRef( | 274 OnGetPasswordStoreResultsConstRef( |
274 UnorderedPasswordFormElementsAre(expected_forms.get()))); | 275 UnorderedPasswordFormElementsAre(expected_forms.get()))); |
275 | 276 |
276 store_->GetLogins(form, &consumer); | 277 store_->GetLogins(form, &consumer); |
277 base::MessageLoop::current()->Run(); | 278 base::RunLoop().Run(); |
278 } | 279 } |
279 | 280 |
280 TEST_F(PasswordStoreWinTest, OutstandingWDSQueries) { | 281 TEST_F(PasswordStoreWinTest, OutstandingWDSQueries) { |
281 store_ = CreatePasswordStore(); | 282 store_ = CreatePasswordStore(); |
282 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 283 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
283 | 284 |
284 PasswordFormData form_data = { | 285 PasswordFormData form_data = { |
285 PasswordForm::SCHEME_HTML, | 286 PasswordForm::SCHEME_HTML, |
286 "http://example.com/", | 287 "http://example.com/", |
287 "http://example.com/origin", | 288 "http://example.com/origin", |
(...skipping 13 matching lines...) Expand all Loading... |
301 store_->GetLogins(form, &consumer); | 302 store_->GetLogins(form, &consumer); |
302 | 303 |
303 // Release the PSW and the WDS before the query can return. | 304 // Release the PSW and the WDS before the query can return. |
304 store_->ShutdownOnUIThread(); | 305 store_->ShutdownOnUIThread(); |
305 store_ = nullptr; | 306 store_ = nullptr; |
306 wds_->ShutdownOnUIThread(); | 307 wds_->ShutdownOnUIThread(); |
307 wds_ = nullptr; | 308 wds_ = nullptr; |
308 wdbs_->ShutdownDatabase(); | 309 wdbs_->ShutdownDatabase(); |
309 wdbs_ = nullptr; | 310 wdbs_ = nullptr; |
310 | 311 |
311 base::MessageLoop::current()->RunUntilIdle(); | 312 base::RunLoop().RunUntilIdle(); |
312 } | 313 } |
313 | 314 |
314 // Hangs flakily, see http://crbug.com/43836. | 315 // Hangs flakily, see http://crbug.com/43836. |
315 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) { | 316 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) { |
316 IE7PasswordInfo password_info; | 317 IE7PasswordInfo password_info; |
317 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", | 318 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", |
318 base::Time::FromDoubleT(1), | 319 base::Time::FromDoubleT(1), |
319 &password_info)); | 320 &password_info)); |
320 wds_->AddIE7Login(password_info); | 321 wds_->AddIE7Login(password_info); |
321 | 322 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 MockWebDataServiceConsumer wds_consumer; | 380 MockWebDataServiceConsumer wds_consumer; |
380 | 381 |
381 EXPECT_CALL(wds_consumer, OnWebDataServiceRequestDone(_, _)) | 382 EXPECT_CALL(wds_consumer, OnWebDataServiceRequestDone(_, _)) |
382 .WillOnce(QuitUIMessageLoop()); | 383 .WillOnce(QuitUIMessageLoop()); |
383 | 384 |
384 wds_->GetIE7Login(password_info, &wds_consumer); | 385 wds_->GetIE7Login(password_info, &wds_consumer); |
385 | 386 |
386 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin | 387 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin |
387 // schedules on the DB thread and once for the one we just scheduled on the UI | 388 // schedules on the DB thread and once for the one we just scheduled on the UI |
388 // thread. | 389 // thread. |
389 base::MessageLoop::current()->Run(); | 390 base::RunLoop().Run(); |
390 base::MessageLoop::current()->Run(); | 391 base::RunLoop().Run(); |
391 } | 392 } |
392 | 393 |
393 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 394 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
394 store_ = CreatePasswordStore(); | 395 store_ = CreatePasswordStore(); |
395 store_->Init(syncer::SyncableService::StartSyncFlare()); | 396 store_->Init(syncer::SyncableService::StartSyncFlare()); |
396 | 397 |
397 PasswordFormData form_data = { | 398 PasswordFormData form_data = { |
398 PasswordForm::SCHEME_HTML, | 399 PasswordForm::SCHEME_HTML, |
399 "http://example.com/", | 400 "http://example.com/", |
400 "http://example.com/origin", | 401 "http://example.com/origin", |
(...skipping 11 matching lines...) Expand all Loading... |
412 | 413 |
413 MockPasswordStoreConsumer consumer; | 414 MockPasswordStoreConsumer consumer; |
414 | 415 |
415 // Make sure we quit the MessageLoop even if the test fails. | 416 // Make sure we quit the MessageLoop even if the test fails. |
416 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 417 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
417 .WillByDefault(QuitUIMessageLoop()); | 418 .WillByDefault(QuitUIMessageLoop()); |
418 | 419 |
419 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 420 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
420 | 421 |
421 store_->GetLogins(form, &consumer); | 422 store_->GetLogins(form, &consumer); |
422 base::MessageLoop::current()->Run(); | 423 base::RunLoop().Run(); |
423 } | 424 } |
424 | 425 |
425 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { | 426 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { |
426 store_ = CreatePasswordStore(); | 427 store_ = CreatePasswordStore(); |
427 store_->Init(syncer::SyncableService::StartSyncFlare()); | 428 store_->Init(syncer::SyncableService::StartSyncFlare()); |
428 | 429 |
429 MockPasswordStoreConsumer consumer; | 430 MockPasswordStoreConsumer consumer; |
430 | 431 |
431 // Make sure we quit the MessageLoop even if the test fails. | 432 // Make sure we quit the MessageLoop even if the test fails. |
432 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 433 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
433 .WillByDefault(QuitUIMessageLoop()); | 434 .WillByDefault(QuitUIMessageLoop()); |
434 | 435 |
435 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 436 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
436 | 437 |
437 store_->GetBlacklistLogins(&consumer); | 438 store_->GetBlacklistLogins(&consumer); |
438 base::MessageLoop::current()->Run(); | 439 base::RunLoop().Run(); |
439 } | 440 } |
440 | 441 |
441 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { | 442 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { |
442 store_ = CreatePasswordStore(); | 443 store_ = CreatePasswordStore(); |
443 store_->Init(syncer::SyncableService::StartSyncFlare()); | 444 store_->Init(syncer::SyncableService::StartSyncFlare()); |
444 | 445 |
445 MockPasswordStoreConsumer consumer; | 446 MockPasswordStoreConsumer consumer; |
446 | 447 |
447 // Make sure we quit the MessageLoop even if the test fails. | 448 // Make sure we quit the MessageLoop even if the test fails. |
448 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 449 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
449 .WillByDefault(QuitUIMessageLoop()); | 450 .WillByDefault(QuitUIMessageLoop()); |
450 | 451 |
451 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 452 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
452 | 453 |
453 store_->GetAutofillableLogins(&consumer); | 454 store_->GetAutofillableLogins(&consumer); |
454 base::MessageLoop::current()->Run(); | 455 base::RunLoop().Run(); |
455 } | 456 } |
OLD | NEW |