| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/stl_util-inl.h" | 6 #include "base/stl_util-inl.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/waitable_event.h" | 11 #include "base/waitable_event.h" |
| 12 #include "chrome/browser/password_manager/password_store_change.h" | 12 #include "chrome/browser/password_manager/password_store_change.h" |
| 13 #include "chrome/browser/password_manager/password_store_default.h" | 13 #include "chrome/browser/password_manager/password_store_default.h" |
| 14 #include "chrome/browser/password_manager/password_form_data.h" | 14 #include "chrome/browser/password_manager/password_form_data.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/webdata/web_data_service.h" | 16 #include "chrome/browser/webdata/web_data_service.h" |
| 17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_details.h" |
| 18 #include "chrome/common/notification_observer_mock.h" |
| 19 #include "chrome/common/notification_source.h" |
| 18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/mock_notification_observer.h" | |
| 20 #include "chrome/test/signaling_task.h" | 21 #include "chrome/test/signaling_task.h" |
| 21 #include "chrome/test/testing_profile.h" | 22 #include "chrome/test/testing_profile.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 using base::WaitableEvent; | 26 using base::WaitableEvent; |
| 26 using testing::_; | 27 using testing::_; |
| 27 using testing::DoAll; | 28 using testing::DoAll; |
| 28 using testing::ElementsAreArray; | 29 using testing::ElementsAreArray; |
| 29 using testing::Pointee; | 30 using testing::Pointee; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 &DBThreadObserverHelper::AddObserverTask, | 63 &DBThreadObserverHelper::AddObserverTask, |
| 63 password_store)); | 64 password_store)); |
| 64 done_event_.Wait(); | 65 done_event_.Wait(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 virtual ~DBThreadObserverHelper() { | 68 virtual ~DBThreadObserverHelper() { |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 69 registrar_.RemoveAll(); | 70 registrar_.RemoveAll(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 MockNotificationObserver& observer() { | 73 NotificationObserverMock& observer() { |
| 73 return observer_; | 74 return observer_; |
| 74 } | 75 } |
| 75 | 76 |
| 76 protected: | 77 protected: |
| 77 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; | 78 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; |
| 78 | 79 |
| 79 void AddObserverTask(PasswordStore* password_store) { | 80 void AddObserverTask(PasswordStore* password_store) { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 81 registrar_.Add(&observer_, | 82 registrar_.Add(&observer_, |
| 82 NotificationType::LOGINS_CHANGED, | 83 NotificationType::LOGINS_CHANGED, |
| 83 Source<PasswordStore>(password_store)); | 84 Source<PasswordStore>(password_store)); |
| 84 done_event_.Signal(); | 85 done_event_.Signal(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 WaitableEvent done_event_; | 88 WaitableEvent done_event_; |
| 88 NotificationRegistrar registrar_; | 89 NotificationRegistrar registrar_; |
| 89 MockNotificationObserver observer_; | 90 NotificationObserverMock observer_; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 } // anonymous namespace | 93 } // anonymous namespace |
| 93 | 94 |
| 94 typedef std::vector<PasswordForm*> VectorOfForms; | 95 typedef std::vector<PasswordForm*> VectorOfForms; |
| 95 | 96 |
| 96 class PasswordStoreDefaultTest : public testing::Test { | 97 class PasswordStoreDefaultTest : public testing::Test { |
| 97 protected: | 98 protected: |
| 98 PasswordStoreDefaultTest() | 99 PasswordStoreDefaultTest() |
| 99 : ui_thread_(BrowserThread::UI, &message_loop_), | 100 : ui_thread_(BrowserThread::UI, &message_loop_), |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 expected_delete_changes))))); | 502 expected_delete_changes))))); |
| 502 | 503 |
| 503 // Deleting the login should trigger a notification. | 504 // Deleting the login should trigger a notification. |
| 504 store->RemoveLogin(*form); | 505 store->RemoveLogin(*form); |
| 505 | 506 |
| 506 // Wait for PasswordStore to send the notification. | 507 // Wait for PasswordStore to send the notification. |
| 507 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 508 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 508 new SignalingTask(&done)); | 509 new SignalingTask(&done)); |
| 509 done.Wait(); | 510 done.Wait(); |
| 510 } | 511 } |
| OLD | NEW |