| 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 "chrome/browser/password_manager/password_store_x.h" | 5 #include "chrome/browser/password_manager/password_store_x.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <string> | 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 17 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "components/password_manager/core/browser/password_manager_test_utils.h
" | 25 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 24 #include "components/password_manager/core/browser/password_store_change.h" | 26 #include "components/password_manager/core/browser/password_store_change.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 scoped_refptr<PasswordStoreX> store_; | 324 scoped_refptr<PasswordStoreX> store_; |
| 323 | 325 |
| 324 DISALLOW_COPY_AND_ASSIGN(PasswordStoreXTestDelegate); | 326 DISALLOW_COPY_AND_ASSIGN(PasswordStoreXTestDelegate); |
| 325 }; | 327 }; |
| 326 | 328 |
| 327 PasswordStoreXTestDelegate::PasswordStoreXTestDelegate(BackendType backend_type) | 329 PasswordStoreXTestDelegate::PasswordStoreXTestDelegate(BackendType backend_type) |
| 328 : backend_type_(backend_type) { | 330 : backend_type_(backend_type) { |
| 329 SetupTempDir(); | 331 SetupTempDir(); |
| 330 store_ = new PasswordStoreX( | 332 store_ = new PasswordStoreX( |
| 331 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 333 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
| 332 make_scoped_ptr( | 334 base::WrapUnique( |
| 333 new password_manager::LoginDatabase(test_login_db_file_path())), | 335 new password_manager::LoginDatabase(test_login_db_file_path())), |
| 334 GetBackend(backend_type_)); | 336 GetBackend(backend_type_)); |
| 335 store_->Init(syncer::SyncableService::StartSyncFlare()); | 337 store_->Init(syncer::SyncableService::StartSyncFlare()); |
| 336 } | 338 } |
| 337 | 339 |
| 338 PasswordStoreXTestDelegate::~PasswordStoreXTestDelegate() { | 340 PasswordStoreXTestDelegate::~PasswordStoreXTestDelegate() { |
| 339 store_->ShutdownOnUIThread(); | 341 store_->ShutdownOnUIThread(); |
| 340 FinishAsyncProcessing(); | 342 FinishAsyncProcessing(); |
| 341 } | 343 } |
| 342 | 344 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 content::TestBrowserThreadBundle thread_bundle_; | 395 content::TestBrowserThreadBundle thread_bundle_; |
| 394 | 396 |
| 395 base::ScopedTempDir temp_dir_; | 397 base::ScopedTempDir temp_dir_; |
| 396 }; | 398 }; |
| 397 | 399 |
| 398 ACTION(STLDeleteElements0) { | 400 ACTION(STLDeleteElements0) { |
| 399 STLDeleteContainerPointers(arg0.begin(), arg0.end()); | 401 STLDeleteContainerPointers(arg0.begin(), arg0.end()); |
| 400 } | 402 } |
| 401 | 403 |
| 402 TEST_P(PasswordStoreXTest, Notifications) { | 404 TEST_P(PasswordStoreXTest, Notifications) { |
| 403 scoped_ptr<password_manager::LoginDatabase> login_db( | 405 std::unique_ptr<password_manager::LoginDatabase> login_db( |
| 404 new password_manager::LoginDatabase(test_login_db_file_path())); | 406 new password_manager::LoginDatabase(test_login_db_file_path())); |
| 405 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( | 407 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( |
| 406 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), | 408 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), |
| 407 std::move(login_db), GetBackend(GetParam()))); | 409 std::move(login_db), GetBackend(GetParam()))); |
| 408 store->Init(syncer::SyncableService::StartSyncFlare()); | 410 store->Init(syncer::SyncableService::StartSyncFlare()); |
| 409 | 411 |
| 410 password_manager::PasswordFormData form_data = { | 412 password_manager::PasswordFormData form_data = { |
| 411 PasswordForm::SCHEME_HTML, "http://bar.example.com", | 413 PasswordForm::SCHEME_HTML, "http://bar.example.com", |
| 412 "http://bar.example.com/origin", "http://bar.example.com/action", | 414 "http://bar.example.com/origin", "http://bar.example.com/action", |
| 413 L"submit_element", L"username_element", | 415 L"submit_element", L"username_element", |
| 414 L"password_element", L"username_value", | 416 L"password_element", L"username_value", |
| 415 L"password_value", true, | 417 L"password_value", true, |
| 416 false, 1}; | 418 false, 1}; |
| 417 scoped_ptr<PasswordForm> form = | 419 std::unique_ptr<PasswordForm> form = |
| 418 CreatePasswordFormFromDataForTesting(form_data); | 420 CreatePasswordFormFromDataForTesting(form_data); |
| 419 | 421 |
| 420 password_manager::MockPasswordStoreObserver observer; | 422 password_manager::MockPasswordStoreObserver observer; |
| 421 store->AddObserver(&observer); | 423 store->AddObserver(&observer); |
| 422 | 424 |
| 423 const PasswordStoreChange expected_add_changes[] = { | 425 const PasswordStoreChange expected_add_changes[] = { |
| 424 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 426 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
| 425 }; | 427 }; |
| 426 | 428 |
| 427 EXPECT_CALL( | 429 EXPECT_CALL( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 474 } |
| 473 | 475 |
| 474 TEST_P(PasswordStoreXTest, NativeMigration) { | 476 TEST_P(PasswordStoreXTest, NativeMigration) { |
| 475 ScopedVector<autofill::PasswordForm> expected_autofillable; | 477 ScopedVector<autofill::PasswordForm> expected_autofillable; |
| 476 InitExpectedForms(true, 50, &expected_autofillable); | 478 InitExpectedForms(true, 50, &expected_autofillable); |
| 477 | 479 |
| 478 ScopedVector<autofill::PasswordForm> expected_blacklisted; | 480 ScopedVector<autofill::PasswordForm> expected_blacklisted; |
| 479 InitExpectedForms(false, 50, &expected_blacklisted); | 481 InitExpectedForms(false, 50, &expected_blacklisted); |
| 480 | 482 |
| 481 const base::FilePath login_db_file = test_login_db_file_path(); | 483 const base::FilePath login_db_file = test_login_db_file_path(); |
| 482 scoped_ptr<password_manager::LoginDatabase> login_db( | 484 std::unique_ptr<password_manager::LoginDatabase> login_db( |
| 483 new password_manager::LoginDatabase(login_db_file)); | 485 new password_manager::LoginDatabase(login_db_file)); |
| 484 ASSERT_TRUE(login_db->Init()); | 486 ASSERT_TRUE(login_db->Init()); |
| 485 | 487 |
| 486 // Get the initial size of the login DB file, before we populate it. | 488 // Get the initial size of the login DB file, before we populate it. |
| 487 // This will be used later to make sure it gets back to this size. | 489 // This will be used later to make sure it gets back to this size. |
| 488 base::File::Info db_file_start_info; | 490 base::File::Info db_file_start_info; |
| 489 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_start_info)); | 491 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_start_info)); |
| 490 | 492 |
| 491 // Populate the login DB with logins that should be migrated. | 493 // Populate the login DB with logins that should be migrated. |
| 492 for (const autofill::PasswordForm* form : expected_autofillable) { | 494 for (const autofill::PasswordForm* form : expected_autofillable) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 578 |
| 577 INSTANTIATE_TEST_CASE_P(NoBackend, | 579 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 578 PasswordStoreXTest, | 580 PasswordStoreXTest, |
| 579 testing::Values(NO_BACKEND)); | 581 testing::Values(NO_BACKEND)); |
| 580 INSTANTIATE_TEST_CASE_P(FailingBackend, | 582 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 581 PasswordStoreXTest, | 583 PasswordStoreXTest, |
| 582 testing::Values(FAILING_BACKEND)); | 584 testing::Values(FAILING_BACKEND)); |
| 583 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 585 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 584 PasswordStoreXTest, | 586 PasswordStoreXTest, |
| 585 testing::Values(WORKING_BACKEND)); | 587 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |