Chromium Code Reviews| 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/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/password_manager/password_store_x.h" | 17 #include "chrome/browser/password_manager/password_store_x.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "components/password_manager/core/browser/password_form_data.h" | 19 #include "components/password_manager/core/browser/password_form_data.h" |
| 20 #include "components/password_manager/core/browser/password_store_change.h" | 20 #include "components/password_manager/core/browser/password_store_change.h" |
| 21 #include "components/password_manager/core/browser/password_store_consumer.h" | 21 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 22 #include "components/password_manager/core/common/password_manager_pref_names.h" | 22 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using autofill::PasswordForm; | 28 using autofill::PasswordForm; |
| 29 using password_manager::ContainsAllPasswordForms; | |
| 30 using password_manager::PasswordStoreChange; | 29 using password_manager::PasswordStoreChange; |
| 31 using password_manager::PasswordStoreChangeList; | 30 using password_manager::PasswordStoreChangeList; |
| 32 using testing::_; | 31 using testing::_; |
| 33 using testing::ElementsAreArray; | 32 using testing::ElementsAreArray; |
| 34 using testing::WithArg; | 33 using testing::WithArg; |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 class MockPasswordStoreConsumer | 37 class MockPasswordStoreConsumer |
| 39 : public password_manager::PasswordStoreConsumer { | 38 : public password_manager::PasswordStoreConsumer { |
| 40 public: | 39 public: |
| 41 MOCK_METHOD1(OnGetPasswordStoreResults, | 40 MOCK_METHOD0(OnGetPasswordStoreResults, void()); |
| 42 void(const std::vector<PasswordForm*>&)); | |
| 43 }; | 41 }; |
| 44 | 42 |
| 45 class MockPasswordStoreObserver | 43 class MockPasswordStoreObserver |
| 46 : public password_manager::PasswordStore::Observer { | 44 : public password_manager::PasswordStore::Observer { |
| 47 public: | 45 public: |
| 48 MOCK_METHOD1(OnLoginsChanged, | 46 MOCK_METHOD1(OnLoginsChanged, |
| 49 void(const password_manager::PasswordStoreChangeList& changes)); | 47 void(const password_manager::PasswordStoreChangeList& changes)); |
| 50 }; | 48 }; |
| 51 | 49 |
| 52 class FailingBackend : public PasswordStoreX::NativeBackend { | 50 class FailingBackend : public PasswordStoreX::NativeBackend { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 189 |
| 192 std::vector<PasswordForm> all_forms_; | 190 std::vector<PasswordForm> all_forms_; |
| 193 }; | 191 }; |
| 194 | 192 |
| 195 class MockLoginDatabaseReturn { | 193 class MockLoginDatabaseReturn { |
| 196 public: | 194 public: |
| 197 MOCK_METHOD1(OnLoginDatabaseQueryDone, | 195 MOCK_METHOD1(OnLoginDatabaseQueryDone, |
| 198 void(const std::vector<PasswordForm*>&)); | 196 void(const std::vector<PasswordForm*>&)); |
| 199 }; | 197 }; |
| 200 | 198 |
| 199 // This gmock matcher is used to check that the |arg| contains exactly the same | |
| 200 // PasswordForms as |forms|, regardless of order. | |
| 201 MATCHER_P(ContainsAllPasswordForms, forms, "") { | |
| 202 return password_manager::ContainsSamePasswordFormsPtr(forms, arg); | |
| 203 } | |
| 204 | |
| 201 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db, | 205 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db, |
| 202 bool autofillable, | 206 bool autofillable, |
| 203 MockLoginDatabaseReturn* mock_return) { | 207 MockLoginDatabaseReturn* mock_return) { |
| 204 ScopedVector<autofill::PasswordForm> forms; | 208 ScopedVector<autofill::PasswordForm> forms; |
| 205 if (autofillable) | 209 if (autofillable) |
| 206 login_db->GetAutofillableLogins(&forms); | 210 login_db->GetAutofillableLogins(&forms); |
| 207 else | 211 else |
| 208 login_db->GetBlacklistLogins(&forms); | 212 login_db->GetBlacklistLogins(&forms); |
| 209 mock_return->OnLoginDatabaseQueryDone(forms.get()); | 213 mock_return->OnLoginDatabaseQueryDone(forms.get()); |
| 210 } | 214 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 // Initializing the PasswordStore shouldn't trigger a native migration (yet). | 385 // Initializing the PasswordStore shouldn't trigger a native migration (yet). |
| 382 login_db.reset(new password_manager::LoginDatabase(login_db_file)); | 386 login_db.reset(new password_manager::LoginDatabase(login_db_file)); |
| 383 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( | 387 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( |
| 384 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), | 388 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), |
| 385 login_db.Pass(), GetBackend())); | 389 login_db.Pass(), GetBackend())); |
| 386 store->Init(syncer::SyncableService::StartSyncFlare()); | 390 store->Init(syncer::SyncableService::StartSyncFlare()); |
| 387 | 391 |
| 388 MockPasswordStoreConsumer consumer; | 392 MockPasswordStoreConsumer consumer; |
| 389 | 393 |
| 390 // The autofillable forms should have been migrated to the native backend. | 394 // The autofillable forms should have been migrated to the native backend. |
| 391 EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms( | 395 EXPECT_CALL(consumer, OnGetPasswordStoreResults()); |
| 392 expected_autofillable.get()))) | |
| 393 .WillOnce(WithArg<0>(STLDeleteElements0())); | |
| 394 | 396 |
| 395 store->GetAutofillableLogins(&consumer); | 397 store->GetAutofillableLogins(&consumer); |
| 396 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
| 399 EXPECT_TRUE(password_manager::ContainsSamePasswordFormsPtr( | |
|
vasilii
2015/02/03 19:22:16
This place definitely suffered from the changed On
vabr (Chromium)
2015/02/04 16:13:44
Acknowledged.
| |
| 400 expected_autofillable.get(), consumer.results()->get())); | |
| 397 | 401 |
| 398 // The blacklisted forms should have been migrated to the native backend. | 402 // The blacklisted forms should have been migrated to the native backend. |
| 399 EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms( | 403 EXPECT_CALL(consumer, OnGetPasswordStoreResults()); |
| 400 expected_blacklisted.get()))) | |
| 401 .WillOnce(WithArg<0>(STLDeleteElements0())); | |
| 402 | 404 |
| 403 store->GetBlacklistLogins(&consumer); | 405 store->GetBlacklistLogins(&consumer); |
| 404 base::RunLoop().RunUntilIdle(); | 406 base::RunLoop().RunUntilIdle(); |
| 407 EXPECT_TRUE(password_manager::ContainsSamePasswordFormsPtr( | |
| 408 expected_blacklisted.get(), consumer.results()->get())); | |
| 405 | 409 |
| 406 ScopedVector<autofill::PasswordForm> empty; | 410 ScopedVector<autofill::PasswordForm> empty; |
| 407 MockLoginDatabaseReturn ld_return; | 411 MockLoginDatabaseReturn ld_return; |
| 408 | 412 |
| 409 if (GetParam() == WORKING_BACKEND) { | 413 if (GetParam() == WORKING_BACKEND) { |
| 410 // No autofillable logins should be left in the login DB. | 414 // No autofillable logins should be left in the login DB. |
| 411 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone( | 415 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone( |
| 412 ContainsAllPasswordForms(empty.get()))); | 416 ContainsAllPasswordForms(empty.get()))); |
| 413 } else { | 417 } else { |
| 414 // The autofillable logins should still be in the login DB. | 418 // The autofillable logins should still be in the login DB. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 | 456 |
| 453 INSTANTIATE_TEST_CASE_P(NoBackend, | 457 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 454 PasswordStoreXTest, | 458 PasswordStoreXTest, |
| 455 testing::Values(NO_BACKEND)); | 459 testing::Values(NO_BACKEND)); |
| 456 INSTANTIATE_TEST_CASE_P(FailingBackend, | 460 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 457 PasswordStoreXTest, | 461 PasswordStoreXTest, |
| 458 testing::Values(FAILING_BACKEND)); | 462 testing::Values(FAILING_BACKEND)); |
| 459 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 463 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 460 PasswordStoreXTest, | 464 PasswordStoreXTest, |
| 461 testing::Values(WORKING_BACKEND)); | 465 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |