| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 wdbs_ = nullptr; | 154 wdbs_ = nullptr; |
| 154 } | 155 } |
| 155 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 156 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 156 base::WaitableEvent::InitialState::NOT_SIGNALED); | 157 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 157 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
| 158 BrowserThread::DB, FROM_HERE, | 159 BrowserThread::DB, FROM_HERE, |
| 159 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 160 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 160 done.Wait(); | 161 done.Wait(); |
| 161 base::ThreadTaskRunnerHandle::Get()->PostTask( | 162 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 162 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 163 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 163 base::MessageLoop::current()->Run(); | 164 base::RunLoop().Run(); |
| 164 db_thread_.Stop(); | 165 db_thread_.Stop(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 base::FilePath test_login_db_file_path() const { | 168 base::FilePath test_login_db_file_path() const { |
| 168 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); | 169 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); |
| 169 } | 170 } |
| 170 | 171 |
| 171 PasswordStoreWin* CreatePasswordStore() { | 172 PasswordStoreWin* CreatePasswordStore() { |
| 172 return new PasswordStoreWin( | 173 return new PasswordStoreWin( |
| 173 base::ThreadTaskRunnerHandle::Get(), | 174 base::ThreadTaskRunnerHandle::Get(), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 }; | 268 }; |
| 268 std::vector<std::unique_ptr<PasswordForm>> expected_forms; | 269 std::vector<std::unique_ptr<PasswordForm>> expected_forms; |
| 269 expected_forms.push_back( | 270 expected_forms.push_back( |
| 270 CreatePasswordFormFromDataForTesting(expected_form_data)); | 271 CreatePasswordFormFromDataForTesting(expected_form_data)); |
| 271 | 272 |
| 272 // The IE7 password should be returned. | 273 // The IE7 password should be returned. |
| 273 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( | 274 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( |
| 274 UnorderedPasswordFormElementsAre(&expected_forms))); | 275 UnorderedPasswordFormElementsAre(&expected_forms))); |
| 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 |