OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
12 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
14 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
15 #include "base/test/signaling_task.h" | |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "chrome/browser/password_manager/ie7_password.h" | 18 #include "chrome/browser/password_manager/ie7_password.h" |
18 #include "chrome/browser/password_manager/password_form_data.h" | 19 #include "chrome/browser/password_manager/password_form_data.h" |
19 #include "chrome/browser/password_manager/password_store_consumer.h" | 20 #include "chrome/browser/password_manager/password_store_consumer.h" |
20 #include "chrome/browser/password_manager/password_store_win.h" | 21 #include "chrome/browser/password_manager/password_store_win.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/webdata/web_data_service.h" | 23 #include "chrome/browser/webdata/web_data_service.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
25 #include "content/test/test_browser_thread.h" | 26 #include "content/test/test_browser_thread.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ASSERT_EQ(L"39471418FF5453FEEB3731E382DEB5D53E14FAF9B5", | 160 ASSERT_EQ(L"39471418FF5453FEEB3731E382DEB5D53E14FAF9B5", |
160 password_info.url_hash); | 161 password_info.url_hash); |
161 | 162 |
162 // This IE7 password will be retrieved by the GetLogins call. | 163 // This IE7 password will be retrieved by the GetLogins call. |
163 wds_->AddIE7Login(password_info); | 164 wds_->AddIE7Login(password_info); |
164 | 165 |
165 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 166 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
166 // task to notify us that it's safe to carry on with the test. | 167 // task to notify us that it's safe to carry on with the test. |
167 WaitableEvent done(false, false); | 168 WaitableEvent done(false, false); |
168 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 169 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
169 new base::SignalingTask(&done)); | 170 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
170 done.Wait(); | 171 done.Wait(); |
171 | 172 |
172 // Prentend that the migration has already taken place. | 173 // Prentend that the migration has already taken place. |
173 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | 174 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, |
174 true, | 175 true, |
175 PrefService::UNSYNCABLE_PREF); | 176 PrefService::UNSYNCABLE_PREF); |
176 | 177 |
177 // Initializing the PasswordStore shouldn't trigger a migration. | 178 // Initializing the PasswordStore shouldn't trigger a migration. |
178 scoped_refptr<PasswordStore> store( | 179 scoped_refptr<PasswordStore> store( |
179 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); | 180 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 IE7PasswordInfo password_info; | 272 IE7PasswordInfo password_info; |
272 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", | 273 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", |
273 base::Time::FromDoubleT(1), | 274 base::Time::FromDoubleT(1), |
274 &password_info)); | 275 &password_info)); |
275 wds_->AddIE7Login(password_info); | 276 wds_->AddIE7Login(password_info); |
276 | 277 |
277 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 278 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
278 // task to notify us that it's safe to carry on with the test. | 279 // task to notify us that it's safe to carry on with the test. |
279 WaitableEvent done(false, false); | 280 WaitableEvent done(false, false); |
280 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 281 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
281 new base::SignalingTask(&done)); | 282 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
282 done.Wait(); | 283 done.Wait(); |
283 | 284 |
284 // Prentend that the migration has already taken place. | 285 // Prentend that the migration has already taken place. |
285 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | 286 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, |
286 true, | 287 true, |
287 PrefService::UNSYNCABLE_PREF); | 288 PrefService::UNSYNCABLE_PREF); |
288 | 289 |
289 // Initializing the PasswordStore shouldn't trigger a migration. | 290 // Initializing the PasswordStore shouldn't trigger a migration. |
290 scoped_refptr<PasswordStore> store( | 291 scoped_refptr<PasswordStore> store( |
291 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); | 292 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 428 } |
428 for (VectorOfForms::iterator it = expected_blacklisted.begin(); | 429 for (VectorOfForms::iterator it = expected_blacklisted.begin(); |
429 it != expected_blacklisted.end(); ++it) { | 430 it != expected_blacklisted.end(); ++it) { |
430 wds_->AddLogin(**it); | 431 wds_->AddLogin(**it); |
431 } | 432 } |
432 | 433 |
433 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 434 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
434 // task to notify us that it's safe to carry on with the test. | 435 // task to notify us that it's safe to carry on with the test. |
435 WaitableEvent done(false, false); | 436 WaitableEvent done(false, false); |
436 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 437 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
437 new base::SignalingTask(&done)); | 438 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
438 done.Wait(); | 439 done.Wait(); |
439 | 440 |
440 // Initializing the PasswordStore should trigger a migration. | 441 // Initializing the PasswordStore should trigger a migration. |
441 scoped_refptr<PasswordStore> store( | 442 scoped_refptr<PasswordStore> store( |
442 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); | 443 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); |
443 store->Init(); | 444 store->Init(); |
444 | 445 |
445 // Check that the migration preference has not been initialized; | 446 // Check that the migration preference has not been initialized; |
446 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( | 447 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( |
447 prefs::kLoginDatabaseMigrated)); | 448 prefs::kLoginDatabaseMigrated)); |
448 | 449 |
449 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task | 450 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task |
450 // to signal us when it is safe to continue. | 451 // to signal us when it is safe to continue. |
451 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 452 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
452 new base::SignalingTask(&done)); | 453 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
453 done.Wait(); | 454 done.Wait(); |
454 | 455 |
455 // Let the WDS callbacks proceed so the logins can be migrated. | 456 // Let the WDS callbacks proceed so the logins can be migrated. |
456 MessageLoop::current()->RunAllPending(); | 457 MessageLoop::current()->RunAllPending(); |
457 | 458 |
458 MockPasswordStoreConsumer consumer; | 459 MockPasswordStoreConsumer consumer; |
459 | 460 |
460 // Make sure we quit the MessageLoop even if the test fails. | 461 // Make sure we quit the MessageLoop even if the test fails. |
461 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | 462 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) |
462 .WillByDefault(QuitUIMessageLoop()); | 463 .WillByDefault(QuitUIMessageLoop()); |
(...skipping 24 matching lines...) Expand all Loading... |
487 MockWebDataServiceConsumer wds_consumer; | 488 MockWebDataServiceConsumer wds_consumer; |
488 | 489 |
489 // No autofillable logins should be left in the WDS. | 490 // No autofillable logins should be left in the WDS. |
490 EXPECT_CALL(wds_consumer, | 491 EXPECT_CALL(wds_consumer, |
491 OnWebDataServiceRequestDone(_, EmptyWDResult())); | 492 OnWebDataServiceRequestDone(_, EmptyWDResult())); |
492 | 493 |
493 wds_->GetAutofillableLogins(&wds_consumer); | 494 wds_->GetAutofillableLogins(&wds_consumer); |
494 | 495 |
495 // Wait for the WDS methods to execute on the DB thread. | 496 // Wait for the WDS methods to execute on the DB thread. |
496 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 497 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
497 new base::SignalingTask(&done)); | 498 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
498 done.Wait(); | 499 done.Wait(); |
499 | 500 |
500 // Handle the callback from the WDS. | 501 // Handle the callback from the WDS. |
501 MessageLoop::current()->RunAllPending(); | 502 MessageLoop::current()->RunAllPending(); |
502 | 503 |
503 // Likewise, no blacklisted logins should be left in the WDS. | 504 // Likewise, no blacklisted logins should be left in the WDS. |
504 EXPECT_CALL(wds_consumer, | 505 EXPECT_CALL(wds_consumer, |
505 OnWebDataServiceRequestDone(_, EmptyWDResult())); | 506 OnWebDataServiceRequestDone(_, EmptyWDResult())); |
506 | 507 |
507 wds_->GetBlacklistLogins(&wds_consumer); | 508 wds_->GetBlacklistLogins(&wds_consumer); |
508 | 509 |
509 // Wait for the WDS methods to execute on the DB thread. | 510 // Wait for the WDS methods to execute on the DB thread. |
510 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 511 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
511 new base::SignalingTask(&done)); | 512 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
512 done.Wait(); | 513 done.Wait(); |
513 | 514 |
514 // Handle the callback from the WDS. | 515 // Handle the callback from the WDS. |
515 MessageLoop::current()->RunAllPending(); | 516 MessageLoop::current()->RunAllPending(); |
516 | 517 |
517 STLDeleteElements(&expected_autofillable); | 518 STLDeleteElements(&expected_autofillable); |
518 STLDeleteElements(&expected_blacklisted); | 519 STLDeleteElements(&expected_blacklisted); |
519 } | 520 } |
520 | 521 |
521 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 522 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // expect that we get no results; | 594 // expect that we get no results; |
594 EXPECT_CALL(consumer, OnPasswordStoreRequestDone( | 595 EXPECT_CALL(consumer, OnPasswordStoreRequestDone( |
595 _, ContainsAllPasswordForms(expect_none))) | 596 _, ContainsAllPasswordForms(expect_none))) |
596 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | 597 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); |
597 | 598 |
598 store->GetAutofillableLogins(&consumer); | 599 store->GetAutofillableLogins(&consumer); |
599 MessageLoop::current()->Run(); | 600 MessageLoop::current()->Run(); |
600 | 601 |
601 store->Shutdown(); | 602 store->Shutdown(); |
602 } | 603 } |
OLD | NEW |