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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 "http://bar.example.com/action", | 202 "http://bar.example.com/action", |
203 L"submit_element", | 203 L"submit_element", |
204 L"username_element", | 204 L"username_element", |
205 L"password_element", | 205 L"password_element", |
206 L"username_value", | 206 L"username_value", |
207 L"password_value", | 207 L"password_value", |
208 true, false, 1 }; | 208 true, false, 1 }; |
209 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 209 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
210 | 210 |
211 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; | 211 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; |
212 helper->Init(store); | 212 helper->Init(store.get()); |
213 | 213 |
214 const PasswordStoreChange expected_add_changes[] = { | 214 const PasswordStoreChange expected_add_changes[] = { |
215 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 215 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
216 }; | 216 }; |
217 | 217 |
218 EXPECT_CALL(helper->observer(), | 218 EXPECT_CALL( |
| 219 helper->observer(), |
219 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 220 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
220 content::Source<PasswordStore>(store), | 221 content::Source<PasswordStore>(store.get()), |
221 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 222 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
222 Pointee(ElementsAreArray( | 223 Pointee(ElementsAreArray(expected_add_changes))))); |
223 expected_add_changes))))); | |
224 | 224 |
225 // Adding a login should trigger a notification. | 225 // Adding a login should trigger a notification. |
226 store->AddLogin(*form); | 226 store->AddLogin(*form); |
227 | 227 |
228 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 228 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
229 // yet another task to notify us that it's safe to carry on with the test. | 229 // yet another task to notify us that it's safe to carry on with the test. |
230 WaitableEvent done(false, false); | 230 WaitableEvent done(false, false); |
231 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 231 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
232 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 232 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
233 done.Wait(); | 233 done.Wait(); |
234 | 234 |
235 // Change the password. | 235 // Change the password. |
236 form->password_value = WideToUTF16(L"a different password"); | 236 form->password_value = WideToUTF16(L"a different password"); |
237 | 237 |
238 const PasswordStoreChange expected_update_changes[] = { | 238 const PasswordStoreChange expected_update_changes[] = { |
239 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), | 239 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), |
240 }; | 240 }; |
241 | 241 |
242 EXPECT_CALL(helper->observer(), | 242 EXPECT_CALL( |
| 243 helper->observer(), |
243 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 244 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
244 content::Source<PasswordStore>(store), | 245 content::Source<PasswordStore>(store.get()), |
245 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 246 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
246 Pointee(ElementsAreArray( | 247 Pointee(ElementsAreArray(expected_update_changes))))); |
247 expected_update_changes))))); | |
248 | 248 |
249 // Updating the login with the new password should trigger a notification. | 249 // Updating the login with the new password should trigger a notification. |
250 store->UpdateLogin(*form); | 250 store->UpdateLogin(*form); |
251 | 251 |
252 // Wait for PasswordStore to send the notification. | 252 // Wait for PasswordStore to send the notification. |
253 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 253 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
254 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 254 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
255 done.Wait(); | 255 done.Wait(); |
256 | 256 |
257 const PasswordStoreChange expected_delete_changes[] = { | 257 const PasswordStoreChange expected_delete_changes[] = { |
258 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), | 258 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), |
259 }; | 259 }; |
260 | 260 |
261 EXPECT_CALL(helper->observer(), | 261 EXPECT_CALL( |
| 262 helper->observer(), |
262 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 263 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
263 content::Source<PasswordStore>(store), | 264 content::Source<PasswordStore>(store.get()), |
264 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 265 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
265 Pointee(ElementsAreArray( | 266 Pointee(ElementsAreArray(expected_delete_changes))))); |
266 expected_delete_changes))))); | |
267 | 267 |
268 // Deleting the login should trigger a notification. | 268 // Deleting the login should trigger a notification. |
269 store->RemoveLogin(*form); | 269 store->RemoveLogin(*form); |
270 | 270 |
271 // Wait for PasswordStore to send the notification. | 271 // Wait for PasswordStore to send the notification. |
272 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 272 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
273 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 273 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
274 done.Wait(); | 274 done.Wait(); |
275 | 275 |
276 store->ShutdownOnUIThread(); | 276 store->ShutdownOnUIThread(); |
277 } | 277 } |
OLD | NEW |