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

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

Issue 8696001: Removing SignalingTask and replace with base::Bind(&WaitableEvent::Signal, ...) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h"
7 #include "base/bind_helpers.h"
6 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
7 #include "base/stl_util.h" 9 #include "base/stl_util.h"
8 #include "base/string_util.h" 10 #include "base/string_util.h"
9 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
10 #include "base/test/signaling_task.h"
11 #include "base/time.h" 12 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/password_manager/password_form_data.h" 14 #include "chrome/browser/password_manager/password_form_data.h"
14 #include "chrome/browser/password_manager/password_store_change.h" 15 #include "chrome/browser/password_manager/password_store_change.h"
15 #include "chrome/browser/password_manager/password_store_consumer.h" 16 #include "chrome/browser/password_manager/password_store_consumer.h"
16 #include "chrome/browser/password_manager/password_store_default.h" 17 #include "chrome/browser/password_manager/password_store_default.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/webdata/web_data_service.h" 19 #include "chrome/browser/webdata/web_data_service.h"
19 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(form_data); ++i) { 185 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(form_data); ++i) {
185 PasswordForm* form = CreatePasswordFormFromData(form_data[i]); 186 PasswordForm* form = CreatePasswordFormFromData(form_data[i]);
186 expected_forms.push_back(form); 187 expected_forms.push_back(form);
187 store->AddLogin(*form); 188 store->AddLogin(*form);
188 } 189 }
189 190
190 // The PasswordStore schedules tasks to run on the DB thread so we schedule 191 // The PasswordStore schedules tasks to run on the DB thread so we schedule
191 // yet another task to notify us that it's safe to carry on with the test. 192 // yet another task to notify us that it's safe to carry on with the test.
192 WaitableEvent done(false, false); 193 WaitableEvent done(false, false);
193 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 194 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
194 new base::SignalingTask(&done)); 195 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
195 done.Wait(); 196 done.Wait();
196 197
197 MockPasswordStoreConsumer consumer; 198 MockPasswordStoreConsumer consumer;
198 199
199 // Make sure we quit the MessageLoop even if the test fails. 200 // Make sure we quit the MessageLoop even if the test fails.
200 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 201 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
201 .WillByDefault(QuitUIMessageLoop()); 202 .WillByDefault(QuitUIMessageLoop());
202 203
203 // We expect to get the same data back, even though it's not all ASCII. 204 // We expect to get the same data back, even though it's not all ASCII.
204 EXPECT_CALL(consumer, 205 EXPECT_CALL(consumer,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) { 280 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) {
280 PasswordForm* form = CreatePasswordFormFromData(blacklisted_data[i]); 281 PasswordForm* form = CreatePasswordFormFromData(blacklisted_data[i]);
281 expected_blacklisted.push_back(form); 282 expected_blacklisted.push_back(form);
282 wds_->AddLogin(*form); 283 wds_->AddLogin(*form);
283 } 284 }
284 285
285 // The WDS schedules tasks to run on the DB thread so we schedule yet another 286 // The WDS schedules tasks to run on the DB thread so we schedule yet another
286 // task to notify us that it's safe to carry on with the test. 287 // task to notify us that it's safe to carry on with the test.
287 WaitableEvent done(false, false); 288 WaitableEvent done(false, false);
288 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 289 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
289 new base::SignalingTask(&done)); 290 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
290 done.Wait(); 291 done.Wait();
291 292
292 // Initializing the PasswordStore should trigger a migration. 293 // Initializing the PasswordStore should trigger a migration.
293 scoped_refptr<PasswordStore> store( 294 scoped_refptr<PasswordStore> store(
294 new PasswordStoreDefault(login_db_.release(), 295 new PasswordStoreDefault(login_db_.release(),
295 profile_.get(), wds_.get())); 296 profile_.get(), wds_.get()));
296 store->Init(); 297 store->Init();
297 298
298 // Check that the migration preference has not been initialized; 299 // Check that the migration preference has not been initialized;
299 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( 300 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference(
300 prefs::kLoginDatabaseMigrated)); 301 prefs::kLoginDatabaseMigrated));
301 302
302 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task 303 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task
303 // to signal us when it is safe to continue. 304 // to signal us when it is safe to continue.
304 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 305 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
305 new base::SignalingTask(&done)); 306 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
306 done.Wait(); 307 done.Wait();
307 308
308 // Let the WDS callbacks proceed so the logins can be migrated. 309 // Let the WDS callbacks proceed so the logins can be migrated.
309 MessageLoop::current()->RunAllPending(); 310 MessageLoop::current()->RunAllPending();
310 311
311 MockPasswordStoreConsumer consumer; 312 MockPasswordStoreConsumer consumer;
312 313
313 // Make sure we quit the MessageLoop even if the test fails. 314 // Make sure we quit the MessageLoop even if the test fails.
314 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 315 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
315 .WillByDefault(QuitUIMessageLoop()); 316 .WillByDefault(QuitUIMessageLoop());
(...skipping 24 matching lines...) Expand all
340 MockWebDataServiceConsumer wds_consumer; 341 MockWebDataServiceConsumer wds_consumer;
341 342
342 // No autofillable logins should be left in the WDS. 343 // No autofillable logins should be left in the WDS.
343 EXPECT_CALL(wds_consumer, 344 EXPECT_CALL(wds_consumer,
344 OnWebDataServiceRequestDone(_, EmptyWDResult())); 345 OnWebDataServiceRequestDone(_, EmptyWDResult()));
345 346
346 wds_->GetAutofillableLogins(&wds_consumer); 347 wds_->GetAutofillableLogins(&wds_consumer);
347 348
348 // Wait for the WDS methods to execute on the DB thread. 349 // Wait for the WDS methods to execute on the DB thread.
349 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 350 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
350 new base::SignalingTask(&done)); 351 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
351 done.Wait(); 352 done.Wait();
352 353
353 // Handle the callback from the WDS. 354 // Handle the callback from the WDS.
354 MessageLoop::current()->RunAllPending(); 355 MessageLoop::current()->RunAllPending();
355 356
356 // Likewise, no blacklisted logins should be left in the WDS. 357 // Likewise, no blacklisted logins should be left in the WDS.
357 EXPECT_CALL(wds_consumer, 358 EXPECT_CALL(wds_consumer,
358 OnWebDataServiceRequestDone(_, EmptyWDResult())); 359 OnWebDataServiceRequestDone(_, EmptyWDResult()));
359 360
360 wds_->GetBlacklistLogins(&wds_consumer); 361 wds_->GetBlacklistLogins(&wds_consumer);
361 362
362 // Wait for the WDS methods to execute on the DB thread. 363 // Wait for the WDS methods to execute on the DB thread.
363 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 364 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
364 new base::SignalingTask(&done)); 365 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
365 done.Wait(); 366 done.Wait();
366 367
367 // Handle the callback from the WDS. 368 // Handle the callback from the WDS.
368 MessageLoop::current()->RunAllPending(); 369 MessageLoop::current()->RunAllPending();
369 370
370 STLDeleteElements(&expected_autofillable); 371 STLDeleteElements(&expected_autofillable);
371 STLDeleteElements(&expected_blacklisted); 372 STLDeleteElements(&expected_blacklisted);
372 373
373 store->Shutdown(); 374 store->Shutdown();
374 } 375 }
(...skipping 17 matching lines...) Expand all
392 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(wds_data); ++i) { 393 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(wds_data); ++i) {
393 PasswordForm* form = CreatePasswordFormFromData(wds_data[i]); 394 PasswordForm* form = CreatePasswordFormFromData(wds_data[i]);
394 unexpected_autofillable.push_back(form); 395 unexpected_autofillable.push_back(form);
395 wds_->AddLogin(*form); 396 wds_->AddLogin(*form);
396 } 397 }
397 398
398 // The WDS schedules tasks to run on the DB thread so we schedule yet another 399 // The WDS schedules tasks to run on the DB thread so we schedule yet another
399 // task to notify us that it's safe to carry on with the test. 400 // task to notify us that it's safe to carry on with the test.
400 WaitableEvent done(false, false); 401 WaitableEvent done(false, false);
401 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 402 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
402 new base::SignalingTask(&done)); 403 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
403 done.Wait(); 404 done.Wait();
404 405
405 // Pretend that the migration has already taken place. 406 // Pretend that the migration has already taken place.
406 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 407 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
407 true, 408 true,
408 PrefService::UNSYNCABLE_PREF); 409 PrefService::UNSYNCABLE_PREF);
409 410
410 // Initializing the PasswordStore shouldn't trigger a migration. 411 // Initializing the PasswordStore shouldn't trigger a migration.
411 scoped_refptr<PasswordStore> store( 412 scoped_refptr<PasswordStore> store(
412 new PasswordStoreDefault(login_db_.release(), profile_.get(), 413 new PasswordStoreDefault(login_db_.release(), profile_.get(),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 Pointee(ElementsAreArray( 473 Pointee(ElementsAreArray(
473 expected_add_changes))))); 474 expected_add_changes)))));
474 475
475 // Adding a login should trigger a notification. 476 // Adding a login should trigger a notification.
476 store->AddLogin(*form); 477 store->AddLogin(*form);
477 478
478 // The PasswordStore schedules tasks to run on the DB thread so we schedule 479 // The PasswordStore schedules tasks to run on the DB thread so we schedule
479 // yet another task to notify us that it's safe to carry on with the test. 480 // yet another task to notify us that it's safe to carry on with the test.
480 WaitableEvent done(false, false); 481 WaitableEvent done(false, false);
481 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 482 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
482 new base::SignalingTask(&done)); 483 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
483 done.Wait(); 484 done.Wait();
484 485
485 // Change the password. 486 // Change the password.
486 form->password_value = WideToUTF16(L"a different password"); 487 form->password_value = WideToUTF16(L"a different password");
487 488
488 const PasswordStoreChange expected_update_changes[] = { 489 const PasswordStoreChange expected_update_changes[] = {
489 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), 490 PasswordStoreChange(PasswordStoreChange::UPDATE, *form),
490 }; 491 };
491 492
492 EXPECT_CALL(helper->observer(), 493 EXPECT_CALL(helper->observer(),
493 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 494 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
494 content::Source<PasswordStore>(store), 495 content::Source<PasswordStore>(store),
495 Property(&content::Details<const PasswordStoreChangeList>::ptr, 496 Property(&content::Details<const PasswordStoreChangeList>::ptr,
496 Pointee(ElementsAreArray( 497 Pointee(ElementsAreArray(
497 expected_update_changes))))); 498 expected_update_changes)))));
498 499
499 // Updating the login with the new password should trigger a notification. 500 // Updating the login with the new password should trigger a notification.
500 store->UpdateLogin(*form); 501 store->UpdateLogin(*form);
501 502
502 // Wait for PasswordStore to send the notification. 503 // Wait for PasswordStore to send the notification.
503 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 504 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
504 new base::SignalingTask(&done)); 505 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
505 done.Wait(); 506 done.Wait();
506 507
507 const PasswordStoreChange expected_delete_changes[] = { 508 const PasswordStoreChange expected_delete_changes[] = {
508 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), 509 PasswordStoreChange(PasswordStoreChange::REMOVE, *form),
509 }; 510 };
510 511
511 EXPECT_CALL(helper->observer(), 512 EXPECT_CALL(helper->observer(),
512 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 513 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
513 content::Source<PasswordStore>(store), 514 content::Source<PasswordStore>(store),
514 Property(&content::Details<const PasswordStoreChangeList>::ptr, 515 Property(&content::Details<const PasswordStoreChangeList>::ptr,
515 Pointee(ElementsAreArray( 516 Pointee(ElementsAreArray(
516 expected_delete_changes))))); 517 expected_delete_changes)))));
517 518
518 // Deleting the login should trigger a notification. 519 // Deleting the login should trigger a notification.
519 store->RemoveLogin(*form); 520 store->RemoveLogin(*form);
520 521
521 // Wait for PasswordStore to send the notification. 522 // Wait for PasswordStore to send the notification.
522 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 523 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
523 new base::SignalingTask(&done)); 524 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
524 done.Wait(); 525 done.Wait();
525 526
526 store->Shutdown(); 527 store->Shutdown();
527 } 528 }
OLDNEW
« no previous file with comments | « chrome/browser/net/gaia/token_service_unittest.cc ('k') | chrome/browser/password_manager/password_store_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698