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

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

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added BrowserThread::WaitForPendingTasksOn, removed SignalingTask Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
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"
15 #include "base/time.h" 14 #include "base/time.h"
16 #include "chrome/browser/password_manager/ie7_password.h" 15 #include "chrome/browser/password_manager/ie7_password.h"
17 #include "chrome/browser/password_manager/password_form_data.h" 16 #include "chrome/browser/password_manager/password_form_data.h"
18 #include "chrome/browser/password_manager/password_store_consumer.h" 17 #include "chrome/browser/password_manager/password_store_consumer.h"
19 #include "chrome/browser/password_manager/password_store_win.h" 18 #include "chrome/browser/password_manager/password_store_win.h"
20 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/webdata/web_data_service.h" 20 #include "chrome/browser/webdata/web_data_service.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/signaling_task.h"
24 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
25 #include "content/browser/browser_thread.h" 23 #include "content/browser/browser_thread.h"
26 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
28 26
29 using base::WaitableEvent;
30 using testing::_; 27 using testing::_;
31 using testing::DoAll; 28 using testing::DoAll;
32 using testing::WithArg; 29 using testing::WithArg;
33 using webkit_glue::PasswordForm; 30 using webkit_glue::PasswordForm;
34 31
35 namespace { 32 namespace {
36 33
37 class MockPasswordStoreConsumer : public PasswordStoreConsumer { 34 class MockPasswordStoreConsumer : public PasswordStoreConsumer {
38 public: 35 public:
39 MOCK_METHOD2(OnPasswordStoreRequestDone, 36 MOCK_METHOD2(OnPasswordStoreRequestDone,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 &password_info)); 152 &password_info));
156 // Verify the URL hash 153 // Verify the URL hash
157 ASSERT_EQ(L"39471418FF5453FEEB3731E382DEB5D53E14FAF9B5", 154 ASSERT_EQ(L"39471418FF5453FEEB3731E382DEB5D53E14FAF9B5",
158 password_info.url_hash); 155 password_info.url_hash);
159 156
160 // This IE7 password will be retrieved by the GetLogins call. 157 // This IE7 password will be retrieved by the GetLogins call.
161 wds_->AddIE7Login(password_info); 158 wds_->AddIE7Login(password_info);
162 159
163 // The WDS schedules tasks to run on the DB thread so we schedule yet another 160 // The WDS schedules tasks to run on the DB thread so we schedule yet another
164 // task to notify us that it's safe to carry on with the test. 161 // task to notify us that it's safe to carry on with the test.
165 WaitableEvent done(false, false); 162 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
166 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
167 new SignalingTask(&done));
168 done.Wait();
169 163
170 // Prentend that the migration has already taken place. 164 // Prentend that the migration has already taken place.
171 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 165 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
172 true, 166 true,
173 PrefService::UNSYNCABLE_PREF); 167 PrefService::UNSYNCABLE_PREF);
174 168
175 // Initializing the PasswordStore shouldn't trigger a migration. 169 // Initializing the PasswordStore shouldn't trigger a migration.
176 scoped_refptr<PasswordStore> store( 170 scoped_refptr<PasswordStore> store(
177 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); 171 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get()));
178 EXPECT_TRUE(store->Init()); 172 EXPECT_TRUE(store->Init());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // Hangs flakily, see http://crbug.com/43836. 261 // Hangs flakily, see http://crbug.com/43836.
268 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) { 262 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) {
269 IE7PasswordInfo password_info; 263 IE7PasswordInfo password_info;
270 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", 264 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin",
271 base::Time::FromDoubleT(1), 265 base::Time::FromDoubleT(1),
272 &password_info)); 266 &password_info));
273 wds_->AddIE7Login(password_info); 267 wds_->AddIE7Login(password_info);
274 268
275 // The WDS schedules tasks to run on the DB thread so we schedule yet another 269 // The WDS schedules tasks to run on the DB thread so we schedule yet another
276 // task to notify us that it's safe to carry on with the test. 270 // task to notify us that it's safe to carry on with the test.
277 WaitableEvent done(false, false); 271 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
278 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
279 new SignalingTask(&done));
280 done.Wait();
281 272
282 // Prentend that the migration has already taken place. 273 // Prentend that the migration has already taken place.
283 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 274 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
284 true, 275 true,
285 PrefService::UNSYNCABLE_PREF); 276 PrefService::UNSYNCABLE_PREF);
286 277
287 // Initializing the PasswordStore shouldn't trigger a migration. 278 // Initializing the PasswordStore shouldn't trigger a migration.
288 scoped_refptr<PasswordStore> store( 279 scoped_refptr<PasswordStore> store(
289 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); 280 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get()));
290 EXPECT_TRUE(store->Init()); 281 EXPECT_TRUE(store->Init());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 it != expected_autofillable.end(); ++it) { 414 it != expected_autofillable.end(); ++it) {
424 wds_->AddLogin(**it); 415 wds_->AddLogin(**it);
425 } 416 }
426 for (VectorOfForms::iterator it = expected_blacklisted.begin(); 417 for (VectorOfForms::iterator it = expected_blacklisted.begin();
427 it != expected_blacklisted.end(); ++it) { 418 it != expected_blacklisted.end(); ++it) {
428 wds_->AddLogin(**it); 419 wds_->AddLogin(**it);
429 } 420 }
430 421
431 // The WDS schedules tasks to run on the DB thread so we schedule yet another 422 // The WDS schedules tasks to run on the DB thread so we schedule yet another
432 // task to notify us that it's safe to carry on with the test. 423 // task to notify us that it's safe to carry on with the test.
433 WaitableEvent done(false, false); 424 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
434 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
435 new SignalingTask(&done));
436 done.Wait();
437 425
438 // Initializing the PasswordStore should trigger a migration. 426 // Initializing the PasswordStore should trigger a migration.
439 scoped_refptr<PasswordStore> store( 427 scoped_refptr<PasswordStore> store(
440 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get())); 428 new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get()));
441 store->Init(); 429 store->Init();
442 430
443 // Check that the migration preference has not been initialized; 431 // Check that the migration preference has not been initialized;
444 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( 432 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference(
445 prefs::kLoginDatabaseMigrated)); 433 prefs::kLoginDatabaseMigrated));
446 434
447 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task 435 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task
448 // to signal us when it is safe to continue. 436 // to signal us when it is safe to continue.
449 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 437 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
450 new SignalingTask(&done));
451 done.Wait();
452 438
453 // Let the WDS callbacks proceed so the logins can be migrated. 439 // Let the WDS callbacks proceed so the logins can be migrated.
454 MessageLoop::current()->RunAllPending(); 440 MessageLoop::current()->RunAllPending();
455 441
456 MockPasswordStoreConsumer consumer; 442 MockPasswordStoreConsumer consumer;
457 443
458 // Make sure we quit the MessageLoop even if the test fails. 444 // Make sure we quit the MessageLoop even if the test fails.
459 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 445 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
460 .WillByDefault(QuitUIMessageLoop()); 446 .WillByDefault(QuitUIMessageLoop());
461 447
(...skipping 22 matching lines...) Expand all
484 470
485 MockWebDataServiceConsumer wds_consumer; 471 MockWebDataServiceConsumer wds_consumer;
486 472
487 // No autofillable logins should be left in the WDS. 473 // No autofillable logins should be left in the WDS.
488 EXPECT_CALL(wds_consumer, 474 EXPECT_CALL(wds_consumer,
489 OnWebDataServiceRequestDone(_, EmptyWDResult())); 475 OnWebDataServiceRequestDone(_, EmptyWDResult()));
490 476
491 wds_->GetAutofillableLogins(&wds_consumer); 477 wds_->GetAutofillableLogins(&wds_consumer);
492 478
493 // Wait for the WDS methods to execute on the DB thread. 479 // Wait for the WDS methods to execute on the DB thread.
494 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 480 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
495 new SignalingTask(&done));
496 done.Wait();
497 481
498 // Handle the callback from the WDS. 482 // Handle the callback from the WDS.
499 MessageLoop::current()->RunAllPending(); 483 MessageLoop::current()->RunAllPending();
500 484
501 // Likewise, no blacklisted logins should be left in the WDS. 485 // Likewise, no blacklisted logins should be left in the WDS.
502 EXPECT_CALL(wds_consumer, 486 EXPECT_CALL(wds_consumer,
503 OnWebDataServiceRequestDone(_, EmptyWDResult())); 487 OnWebDataServiceRequestDone(_, EmptyWDResult()));
504 488
505 wds_->GetBlacklistLogins(&wds_consumer); 489 wds_->GetBlacklistLogins(&wds_consumer);
506 490
507 // Wait for the WDS methods to execute on the DB thread. 491 // Wait for the WDS methods to execute on the DB thread.
508 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 492 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
509 new SignalingTask(&done));
510 done.Wait();
511 493
512 // Handle the callback from the WDS. 494 // Handle the callback from the WDS.
513 MessageLoop::current()->RunAllPending(); 495 MessageLoop::current()->RunAllPending();
514 496
515 STLDeleteElements(&expected_autofillable); 497 STLDeleteElements(&expected_autofillable);
516 STLDeleteElements(&expected_blacklisted); 498 STLDeleteElements(&expected_blacklisted);
517 } 499 }
518 500
519 TEST_F(PasswordStoreWinTest, EmptyLogins) { 501 TEST_F(PasswordStoreWinTest, EmptyLogins) {
520 scoped_refptr<PasswordStore> store( 502 scoped_refptr<PasswordStore> store(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 // expect that we get no results; 573 // expect that we get no results;
592 EXPECT_CALL(consumer, OnPasswordStoreRequestDone( 574 EXPECT_CALL(consumer, OnPasswordStoreRequestDone(
593 _, ContainsAllPasswordForms(expect_none))) 575 _, ContainsAllPasswordForms(expect_none)))
594 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); 576 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
595 577
596 store->GetAutofillableLogins(&consumer); 578 store->GetAutofillableLogins(&consumer);
597 MessageLoop::current()->Run(); 579 MessageLoop::current()->Run();
598 580
599 store->Shutdown(); 581 store->Shutdown();
600 } 582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698