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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/password_manager/password_form_data.h" | 12 #include "chrome/browser/password_manager/password_form_data.h" |
13 #include "chrome/browser/password_manager/password_store_change.h" | 13 #include "chrome/browser/password_manager/password_store_change.h" |
14 #include "chrome/browser/password_manager/password_store_consumer.h" | 14 #include "chrome/browser/password_manager/password_store_consumer.h" |
15 #include "chrome/browser/password_manager/password_store_default.h" | 15 #include "chrome/browser/password_manager/password_store_default.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/webdata/web_data_service.h" | 17 #include "chrome/browser/webdata/web_data_service.h" |
| 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/signaling_task.h" | 20 #include "chrome/test/signaling_task.h" |
20 #include "chrome/test/testing_profile.h" | 21 #include "chrome/test/testing_profile.h" |
21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
22 #include "content/common/notification_observer_mock.h" | 23 #include "content/common/notification_observer_mock.h" |
23 #include "content/common/notification_registrar.h" | 24 #include "content/common/notification_registrar.h" |
24 #include "content/common/notification_source.h" | 25 #include "content/common/notification_source.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NotificationObserverMock& observer() { | 77 NotificationObserverMock& observer() { |
77 return observer_; | 78 return observer_; |
78 } | 79 } |
79 | 80 |
80 protected: | 81 protected: |
81 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; | 82 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; |
82 | 83 |
83 void AddObserverTask(PasswordStore* password_store) { | 84 void AddObserverTask(PasswordStore* password_store) { |
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
85 registrar_.Add(&observer_, | 86 registrar_.Add(&observer_, |
86 NotificationType::LOGINS_CHANGED, | 87 chrome::NOTIFICATION_LOGINS_CHANGED, |
87 Source<PasswordStore>(password_store)); | 88 Source<PasswordStore>(password_store)); |
88 done_event_.Signal(); | 89 done_event_.Signal(); |
89 } | 90 } |
90 | 91 |
91 WaitableEvent done_event_; | 92 WaitableEvent done_event_; |
92 NotificationRegistrar registrar_; | 93 NotificationRegistrar registrar_; |
93 NotificationObserverMock observer_; | 94 NotificationObserverMock observer_; |
94 }; | 95 }; |
95 | 96 |
96 } // anonymous namespace | 97 } // anonymous namespace |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 456 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
456 | 457 |
457 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; | 458 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; |
458 helper->Init(store); | 459 helper->Init(store); |
459 | 460 |
460 const PasswordStoreChange expected_add_changes[] = { | 461 const PasswordStoreChange expected_add_changes[] = { |
461 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 462 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
462 }; | 463 }; |
463 | 464 |
464 EXPECT_CALL(helper->observer(), | 465 EXPECT_CALL(helper->observer(), |
465 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 466 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
466 Source<PasswordStore>(store), | 467 Source<PasswordStore>(store), |
467 Property(&Details<const PasswordStoreChangeList>::ptr, | 468 Property(&Details<const PasswordStoreChangeList>::ptr, |
468 Pointee(ElementsAreArray( | 469 Pointee(ElementsAreArray( |
469 expected_add_changes))))); | 470 expected_add_changes))))); |
470 | 471 |
471 // Adding a login should trigger a notification. | 472 // Adding a login should trigger a notification. |
472 store->AddLogin(*form); | 473 store->AddLogin(*form); |
473 | 474 |
474 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 475 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
475 // yet another task to notify us that it's safe to carry on with the test. | 476 // yet another task to notify us that it's safe to carry on with the test. |
476 WaitableEvent done(false, false); | 477 WaitableEvent done(false, false); |
477 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 478 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
478 new SignalingTask(&done)); | 479 new SignalingTask(&done)); |
479 done.Wait(); | 480 done.Wait(); |
480 | 481 |
481 // Change the password. | 482 // Change the password. |
482 form->password_value = WideToUTF16(L"a different password"); | 483 form->password_value = WideToUTF16(L"a different password"); |
483 | 484 |
484 const PasswordStoreChange expected_update_changes[] = { | 485 const PasswordStoreChange expected_update_changes[] = { |
485 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), | 486 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), |
486 }; | 487 }; |
487 | 488 |
488 EXPECT_CALL(helper->observer(), | 489 EXPECT_CALL(helper->observer(), |
489 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 490 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
490 Source<PasswordStore>(store), | 491 Source<PasswordStore>(store), |
491 Property(&Details<const PasswordStoreChangeList>::ptr, | 492 Property(&Details<const PasswordStoreChangeList>::ptr, |
492 Pointee(ElementsAreArray( | 493 Pointee(ElementsAreArray( |
493 expected_update_changes))))); | 494 expected_update_changes))))); |
494 | 495 |
495 // Updating the login with the new password should trigger a notification. | 496 // Updating the login with the new password should trigger a notification. |
496 store->UpdateLogin(*form); | 497 store->UpdateLogin(*form); |
497 | 498 |
498 // Wait for PasswordStore to send the notification. | 499 // Wait for PasswordStore to send the notification. |
499 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 500 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
500 new SignalingTask(&done)); | 501 new SignalingTask(&done)); |
501 done.Wait(); | 502 done.Wait(); |
502 | 503 |
503 const PasswordStoreChange expected_delete_changes[] = { | 504 const PasswordStoreChange expected_delete_changes[] = { |
504 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), | 505 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), |
505 }; | 506 }; |
506 | 507 |
507 EXPECT_CALL(helper->observer(), | 508 EXPECT_CALL(helper->observer(), |
508 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 509 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
509 Source<PasswordStore>(store), | 510 Source<PasswordStore>(store), |
510 Property(&Details<const PasswordStoreChangeList>::ptr, | 511 Property(&Details<const PasswordStoreChangeList>::ptr, |
511 Pointee(ElementsAreArray( | 512 Pointee(ElementsAreArray( |
512 expected_delete_changes))))); | 513 expected_delete_changes))))); |
513 | 514 |
514 // Deleting the login should trigger a notification. | 515 // Deleting the login should trigger a notification. |
515 store->RemoveLogin(*form); | 516 store->RemoveLogin(*form); |
516 | 517 |
517 // Wait for PasswordStore to send the notification. | 518 // Wait for PasswordStore to send the notification. |
518 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 519 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
519 new SignalingTask(&done)); | 520 new SignalingTask(&done)); |
520 done.Wait(); | 521 done.Wait(); |
521 | 522 |
522 store->Shutdown(); | 523 store->Shutdown(); |
523 } | 524 } |
OLD | NEW |