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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 "http://bar.example.com/action", | 324 "http://bar.example.com/action", |
325 L"submit_element", | 325 L"submit_element", |
326 L"username_element", | 326 L"username_element", |
327 L"password_element", | 327 L"password_element", |
328 L"username_value", | 328 L"username_value", |
329 L"password_value", | 329 L"password_value", |
330 true, false, 1 }; | 330 true, false, 1 }; |
331 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 331 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
332 | 332 |
333 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; | 333 scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper; |
334 helper->Init(store); | 334 helper->Init(store.get()); |
335 | 335 |
336 const PasswordStoreChange expected_add_changes[] = { | 336 const PasswordStoreChange expected_add_changes[] = { |
337 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 337 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
338 }; | 338 }; |
339 | 339 |
340 EXPECT_CALL(helper->observer(), | 340 EXPECT_CALL(helper->observer(), |
341 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 341 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
342 content::Source<PasswordStore>(store), | 342 content::Source<PasswordStore>(store.get()), |
343 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 343 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
344 Pointee(ElementsAreArray( | 344 Pointee(ElementsAreArray( |
345 expected_add_changes))))); | 345 expected_add_changes))))); |
346 | 346 |
347 // Adding a login should trigger a notification. | 347 // Adding a login should trigger a notification. |
348 store->AddLogin(*form); | 348 store->AddLogin(*form); |
349 | 349 |
350 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 350 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
351 // yet another task to notify us that it's safe to carry on with the test. | 351 // yet another task to notify us that it's safe to carry on with the test. |
352 WaitableEvent done(false, false); | 352 WaitableEvent done(false, false); |
353 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 353 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
354 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 354 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
355 done.Wait(); | 355 done.Wait(); |
356 | 356 |
357 // Change the password. | 357 // Change the password. |
358 form->password_value = WideToUTF16(L"a different password"); | 358 form->password_value = WideToUTF16(L"a different password"); |
359 | 359 |
360 const PasswordStoreChange expected_update_changes[] = { | 360 const PasswordStoreChange expected_update_changes[] = { |
361 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), | 361 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), |
362 }; | 362 }; |
363 | 363 |
364 EXPECT_CALL(helper->observer(), | 364 EXPECT_CALL(helper->observer(), |
365 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 365 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
366 content::Source<PasswordStore>(store), | 366 content::Source<PasswordStore>(store.get()), |
367 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 367 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
368 Pointee(ElementsAreArray( | 368 Pointee(ElementsAreArray( |
369 expected_update_changes))))); | 369 expected_update_changes))))); |
370 | 370 |
371 // Updating the login with the new password should trigger a notification. | 371 // Updating the login with the new password should trigger a notification. |
372 store->UpdateLogin(*form); | 372 store->UpdateLogin(*form); |
373 | 373 |
374 // Wait for PasswordStore to send the notification. | 374 // Wait for PasswordStore to send the notification. |
375 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 375 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
376 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 376 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
377 done.Wait(); | 377 done.Wait(); |
378 | 378 |
379 const PasswordStoreChange expected_delete_changes[] = { | 379 const PasswordStoreChange expected_delete_changes[] = { |
380 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), | 380 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), |
381 }; | 381 }; |
382 | 382 |
383 EXPECT_CALL(helper->observer(), | 383 EXPECT_CALL(helper->observer(), |
384 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 384 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
385 content::Source<PasswordStore>(store), | 385 content::Source<PasswordStore>(store.get()), |
386 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 386 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
387 Pointee(ElementsAreArray( | 387 Pointee(ElementsAreArray( |
388 expected_delete_changes))))); | 388 expected_delete_changes))))); |
389 | 389 |
390 // Deleting the login should trigger a notification. | 390 // Deleting the login should trigger a notification. |
391 store->RemoveLogin(*form); | 391 store->RemoveLogin(*form); |
392 | 392 |
393 // Wait for PasswordStore to send the notification. | 393 // Wait for PasswordStore to send the notification. |
394 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 394 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
395 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 395 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
396 done.Wait(); | 396 done.Wait(); |
397 | 397 |
398 // Public in PasswordStore, protected in PasswordStoreX. | 398 // Public in PasswordStore, protected in PasswordStoreX. |
399 static_cast<PasswordStore*>(store)->ShutdownOnUIThread(); | 399 static_cast<PasswordStore*>(store.get())->ShutdownOnUIThread(); |
400 } | 400 } |
401 | 401 |
402 TEST_P(PasswordStoreXTest, NativeMigration) { | 402 TEST_P(PasswordStoreXTest, NativeMigration) { |
403 VectorOfForms expected_autofillable; | 403 VectorOfForms expected_autofillable; |
404 InitExpectedForms(true, 50, &expected_autofillable); | 404 InitExpectedForms(true, 50, &expected_autofillable); |
405 | 405 |
406 VectorOfForms expected_blacklisted; | 406 VectorOfForms expected_blacklisted; |
407 InitExpectedForms(false, 50, &expected_blacklisted); | 407 InitExpectedForms(false, 50, &expected_blacklisted); |
408 | 408 |
409 // Get the initial size of the login DB file, before we populate it. | 409 // Get the initial size of the login DB file, before we populate it. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // larger after populating it. | 526 // larger after populating it. |
527 base::PlatformFileInfo db_file_end_info; | 527 base::PlatformFileInfo db_file_end_info; |
528 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); | 528 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); |
529 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); | 529 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); |
530 } | 530 } |
531 | 531 |
532 STLDeleteElements(&expected_autofillable); | 532 STLDeleteElements(&expected_autofillable); |
533 STLDeleteElements(&expected_blacklisted); | 533 STLDeleteElements(&expected_blacklisted); |
534 | 534 |
535 // Public in PasswordStore, protected in PasswordStoreX. | 535 // Public in PasswordStore, protected in PasswordStoreX. |
536 static_cast<PasswordStore*>(store)->ShutdownOnUIThread(); | 536 static_cast<PasswordStore*>(store.get())->ShutdownOnUIThread(); |
537 } | 537 } |
538 | 538 |
539 INSTANTIATE_TEST_CASE_P(NoBackend, | 539 INSTANTIATE_TEST_CASE_P(NoBackend, |
540 PasswordStoreXTest, | 540 PasswordStoreXTest, |
541 testing::Values(NO_BACKEND)); | 541 testing::Values(NO_BACKEND)); |
542 INSTANTIATE_TEST_CASE_P(FailingBackend, | 542 INSTANTIATE_TEST_CASE_P(FailingBackend, |
543 PasswordStoreXTest, | 543 PasswordStoreXTest, |
544 testing::Values(FAILING_BACKEND)); | 544 testing::Values(FAILING_BACKEND)); |
545 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 545 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
546 PasswordStoreXTest, | 546 PasswordStoreXTest, |
547 testing::Values(WORKING_BACKEND)); | 547 testing::Values(WORKING_BACKEND)); |
OLD | NEW |