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/stl_util.h" | 7 #include "base/stl_util.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
50 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
51 BrowserThread::DB, | 51 BrowserThread::DB, |
52 FROM_HERE, | 52 FROM_HERE, |
53 base::Bind(&DBThreadObserverHelper::AddObserverTask, | 53 base::Bind(&DBThreadObserverHelper::AddObserverTask, |
54 this, | 54 this, |
55 make_scoped_refptr(password_store))); | 55 make_scoped_refptr(password_store))); |
56 done_event_.Wait(); | 56 done_event_.Wait(); |
57 } | 57 } |
58 | 58 |
59 virtual ~DBThreadObserverHelper() { | |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
61 registrar_.RemoveAll(); | |
62 } | |
63 | |
64 content::NotificationObserverMock& observer() { | 59 content::NotificationObserverMock& observer() { |
65 return observer_; | 60 return observer_; |
66 } | 61 } |
67 | 62 |
68 protected: | 63 protected: |
69 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; | 64 virtual ~DBThreadObserverHelper() { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 66 registrar_.RemoveAll(); |
| 67 } |
70 | 68 |
71 void AddObserverTask(PasswordStore* password_store) { | 69 void AddObserverTask(PasswordStore* password_store) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
73 registrar_.Add(&observer_, | 71 registrar_.Add(&observer_, |
74 chrome::NOTIFICATION_LOGINS_CHANGED, | 72 chrome::NOTIFICATION_LOGINS_CHANGED, |
75 content::Source<PasswordStore>(password_store)); | 73 content::Source<PasswordStore>(password_store)); |
76 done_event_.Signal(); | 74 done_event_.Signal(); |
77 } | 75 } |
78 | 76 |
79 WaitableEvent done_event_; | 77 WaitableEvent done_event_; |
80 content::NotificationRegistrar registrar_; | 78 content::NotificationRegistrar registrar_; |
81 content::NotificationObserverMock observer_; | 79 content::NotificationObserverMock observer_; |
| 80 |
| 81 private: |
| 82 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; |
| 83 friend class base::DeleteHelper<DBThreadObserverHelper>; |
82 }; | 84 }; |
83 | 85 |
84 } // anonymous namespace | 86 } // anonymous namespace |
85 | 87 |
86 class PasswordStoreTest : public testing::Test { | 88 class PasswordStoreTest : public testing::Test { |
87 protected: | 89 protected: |
88 PasswordStoreTest() | 90 PasswordStoreTest() |
89 : ui_thread_(BrowserThread::UI, &message_loop_), | 91 : ui_thread_(BrowserThread::UI, &message_loop_), |
90 db_thread_(BrowserThread::DB) { | 92 db_thread_(BrowserThread::DB) { |
91 } | 93 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 .WillOnce(WithArg<1>(STLDeleteElements0())).RetiresOnSaturation(); | 258 .WillOnce(WithArg<1>(STLDeleteElements0())).RetiresOnSaturation(); |
257 | 259 |
258 store->GetLogins(www_google, &consumer); | 260 store->GetLogins(www_google, &consumer); |
259 store->GetLogins(accounts_google, &consumer); | 261 store->GetLogins(accounts_google, &consumer); |
260 store->GetLogins(bar_example, &consumer); | 262 store->GetLogins(bar_example, &consumer); |
261 | 263 |
262 MessageLoop::current()->Run(); | 264 MessageLoop::current()->Run(); |
263 | 265 |
264 STLDeleteElements(&all_forms); | 266 STLDeleteElements(&all_forms); |
265 } | 267 } |
OLD | NEW |