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