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" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 NotificationObserverMock& observer() { | 71 NotificationObserverMock& observer() { |
72 return observer_; | 72 return observer_; |
73 } | 73 } |
74 | 74 |
75 protected: | 75 protected: |
76 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; | 76 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; |
77 | 77 |
78 void AddObserverTask() { | 78 void AddObserverTask() { |
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
80 registrar_.Add(&observer_, | 80 registrar_.Add(&observer_, |
81 NotificationType::LOGINS_CHANGED, | 81 chrome::LOGINS_CHANGED, |
82 NotificationService::AllSources()); | 82 NotificationService::AllSources()); |
83 done_event_.Signal(); | 83 done_event_.Signal(); |
84 } | 84 } |
85 | 85 |
86 WaitableEvent done_event_; | 86 WaitableEvent done_event_; |
87 NotificationRegistrar registrar_; | 87 NotificationRegistrar registrar_; |
88 NotificationObserverMock observer_; | 88 NotificationObserverMock observer_; |
89 }; | 89 }; |
90 | 90 |
91 class FailingBackend : public PasswordStoreX::NativeBackend { | 91 class FailingBackend : public PasswordStoreX::NativeBackend { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 534 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
535 | 535 |
536 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; | 536 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; |
537 helper->Init(); | 537 helper->Init(); |
538 | 538 |
539 const PasswordStoreChange expected_add_changes[] = { | 539 const PasswordStoreChange expected_add_changes[] = { |
540 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 540 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
541 }; | 541 }; |
542 | 542 |
543 EXPECT_CALL(helper->observer(), | 543 EXPECT_CALL(helper->observer(), |
544 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 544 Observe(int(chrome::LOGINS_CHANGED), |
545 NotificationService::AllSources(), | 545 NotificationService::AllSources(), |
546 Property(&Details<const PasswordStoreChangeList>::ptr, | 546 Property(&Details<const PasswordStoreChangeList>::ptr, |
547 Pointee(ElementsAreArray( | 547 Pointee(ElementsAreArray( |
548 expected_add_changes))))); | 548 expected_add_changes))))); |
549 | 549 |
550 // Adding a login should trigger a notification. | 550 // Adding a login should trigger a notification. |
551 store->AddLogin(*form); | 551 store->AddLogin(*form); |
552 | 552 |
553 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 553 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
554 // yet another task to notify us that it's safe to carry on with the test. | 554 // yet another task to notify us that it's safe to carry on with the test. |
555 WaitableEvent done(false, false); | 555 WaitableEvent done(false, false); |
556 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 556 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
557 new SignalingTask(&done)); | 557 new SignalingTask(&done)); |
558 done.Wait(); | 558 done.Wait(); |
559 | 559 |
560 // Change the password. | 560 // Change the password. |
561 form->password_value = WideToUTF16(L"a different password"); | 561 form->password_value = WideToUTF16(L"a different password"); |
562 | 562 |
563 const PasswordStoreChange expected_update_changes[] = { | 563 const PasswordStoreChange expected_update_changes[] = { |
564 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), | 564 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), |
565 }; | 565 }; |
566 | 566 |
567 EXPECT_CALL(helper->observer(), | 567 EXPECT_CALL(helper->observer(), |
568 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 568 Observe(int(chrome::LOGINS_CHANGED), |
569 NotificationService::AllSources(), | 569 NotificationService::AllSources(), |
570 Property(&Details<const PasswordStoreChangeList>::ptr, | 570 Property(&Details<const PasswordStoreChangeList>::ptr, |
571 Pointee(ElementsAreArray( | 571 Pointee(ElementsAreArray( |
572 expected_update_changes))))); | 572 expected_update_changes))))); |
573 | 573 |
574 // Updating the login with the new password should trigger a notification. | 574 // Updating the login with the new password should trigger a notification. |
575 store->UpdateLogin(*form); | 575 store->UpdateLogin(*form); |
576 | 576 |
577 // Wait for PasswordStore to send the notification. | 577 // Wait for PasswordStore to send the notification. |
578 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 578 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
579 new SignalingTask(&done)); | 579 new SignalingTask(&done)); |
580 done.Wait(); | 580 done.Wait(); |
581 | 581 |
582 const PasswordStoreChange expected_delete_changes[] = { | 582 const PasswordStoreChange expected_delete_changes[] = { |
583 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), | 583 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), |
584 }; | 584 }; |
585 | 585 |
586 EXPECT_CALL(helper->observer(), | 586 EXPECT_CALL(helper->observer(), |
587 Observe(NotificationType(NotificationType::LOGINS_CHANGED), | 587 Observe(int(chrome::LOGINS_CHANGED), |
588 NotificationService::AllSources(), | 588 NotificationService::AllSources(), |
589 Property(&Details<const PasswordStoreChangeList>::ptr, | 589 Property(&Details<const PasswordStoreChangeList>::ptr, |
590 Pointee(ElementsAreArray( | 590 Pointee(ElementsAreArray( |
591 expected_delete_changes))))); | 591 expected_delete_changes))))); |
592 | 592 |
593 // Deleting the login should trigger a notification. | 593 // Deleting the login should trigger a notification. |
594 store->RemoveLogin(*form); | 594 store->RemoveLogin(*form); |
595 | 595 |
596 // Wait for PasswordStore to send the notification. | 596 // Wait for PasswordStore to send the notification. |
597 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 597 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 745 |
746 INSTANTIATE_TEST_CASE_P(NoBackend, | 746 INSTANTIATE_TEST_CASE_P(NoBackend, |
747 PasswordStoreXTest, | 747 PasswordStoreXTest, |
748 testing::Values(NO_BACKEND)); | 748 testing::Values(NO_BACKEND)); |
749 INSTANTIATE_TEST_CASE_P(FailingBackend, | 749 INSTANTIATE_TEST_CASE_P(FailingBackend, |
750 PasswordStoreXTest, | 750 PasswordStoreXTest, |
751 testing::Values(FAILING_BACKEND)); | 751 testing::Values(FAILING_BACKEND)); |
752 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 752 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
753 PasswordStoreXTest, | 753 PasswordStoreXTest, |
754 testing::Values(WORKING_BACKEND)); | 754 testing::Values(WORKING_BACKEND)); |
OLD | NEW |