| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/password_manager/password_form_data.h" | 13 #include "chrome/browser/password_manager/password_form_data.h" |
| 14 #include "chrome/browser/password_manager/password_store_change.h" | 14 #include "chrome/browser/password_manager/password_store_change.h" |
| 15 #include "chrome/browser/password_manager/password_store_consumer.h" | 15 #include "chrome/browser/password_manager/password_store_consumer.h" |
| 16 #include "chrome/browser/password_manager/password_store_default.h" | 16 #include "chrome/browser/password_manager/password_store_default.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 24 #include "content/test/notification_observer_mock.h" | 24 #include "content/public/test/mock_notification_observer.h" |
| 25 #include "content/test/test_browser_thread.h" | 25 #include "content/test/test_browser_thread.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using base::WaitableEvent; | 29 using base::WaitableEvent; |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using testing::_; | 31 using testing::_; |
| 32 using testing::DoAll; | 32 using testing::DoAll; |
| 33 using testing::ElementsAreArray; | 33 using testing::ElementsAreArray; |
| 34 using testing::Pointee; | 34 using testing::Pointee; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 BrowserThread::PostTask( | 58 BrowserThread::PostTask( |
| 59 BrowserThread::DB, | 59 BrowserThread::DB, |
| 60 FROM_HERE, | 60 FROM_HERE, |
| 61 base::Bind(&DBThreadObserverHelper::AddObserverTask, | 61 base::Bind(&DBThreadObserverHelper::AddObserverTask, |
| 62 this, | 62 this, |
| 63 make_scoped_refptr(password_store))); | 63 make_scoped_refptr(password_store))); |
| 64 done_event_.Wait(); | 64 done_event_.Wait(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 content::NotificationObserverMock& observer() { | 67 content::MockNotificationObserver& observer() { |
| 68 return observer_; | 68 return observer_; |
| 69 } | 69 } |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | 72 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; |
| 73 friend class base::DeleteHelper<DBThreadObserverHelper>; | 73 friend class base::DeleteHelper<DBThreadObserverHelper>; |
| 74 | 74 |
| 75 virtual ~DBThreadObserverHelper() { | 75 virtual ~DBThreadObserverHelper() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 77 registrar_.RemoveAll(); | 77 registrar_.RemoveAll(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void AddObserverTask(PasswordStore* password_store) { | 80 void AddObserverTask(PasswordStore* password_store) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 82 registrar_.Add(&observer_, | 82 registrar_.Add(&observer_, |
| 83 chrome::NOTIFICATION_LOGINS_CHANGED, | 83 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 84 content::Source<PasswordStore>(password_store)); | 84 content::Source<PasswordStore>(password_store)); |
| 85 done_event_.Signal(); | 85 done_event_.Signal(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 WaitableEvent done_event_; | 88 WaitableEvent done_event_; |
| 89 content::NotificationRegistrar registrar_; | 89 content::NotificationRegistrar registrar_; |
| 90 content::NotificationObserverMock observer_; | 90 content::MockNotificationObserver observer_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 } // anonymous namespace | 93 } // anonymous namespace |
| 94 | 94 |
| 95 class PasswordStoreDefaultTest : public testing::Test { | 95 class PasswordStoreDefaultTest : public testing::Test { |
| 96 protected: | 96 protected: |
| 97 PasswordStoreDefaultTest() | 97 PasswordStoreDefaultTest() |
| 98 : ui_thread_(BrowserThread::UI, &message_loop_), | 98 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 99 db_thread_(BrowserThread::DB) { | 99 db_thread_(BrowserThread::DB) { |
| 100 } | 100 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Deleting the login should trigger a notification. | 265 // Deleting the login should trigger a notification. |
| 266 store->RemoveLogin(*form); | 266 store->RemoveLogin(*form); |
| 267 | 267 |
| 268 // Wait for PasswordStore to send the notification. | 268 // Wait for PasswordStore to send the notification. |
| 269 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 269 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 270 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 270 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 271 done.Wait(); | 271 done.Wait(); |
| 272 | 272 |
| 273 store->ShutdownOnUIThread(); | 273 store->ShutdownOnUIThread(); |
| 274 } | 274 } |
| OLD | NEW |