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; | 29 using password_manager::ContainsSamePasswordForms; |
| 30 using password_manager::PasswordStoreChange; | 30 using password_manager::PasswordStoreChange; |
| 31 using password_manager::PasswordStoreChangeList; | 31 using password_manager::PasswordStoreChangeList; |
| 32 using testing::_; | 32 using testing::_; |
| 33 using testing::ElementsAre; | |
| 33 using testing::ElementsAreArray; | 34 using testing::ElementsAreArray; |
| 34 using testing::WithArg; | 35 using testing::WithArg; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 class MockPasswordStoreConsumer | 39 class MockPasswordStoreConsumer |
| 39 : public password_manager::PasswordStoreConsumer { | 40 : public password_manager::PasswordStoreConsumer { |
| 40 public: | 41 public: |
| 41 MOCK_METHOD1(OnGetPasswordStoreResults, | 42 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef, |
| 42 void(const std::vector<PasswordForm*>&)); | 43 void(const std::vector<PasswordForm*>&)); |
| 44 | |
| 45 // GMock cannot mock methods with move-only args. | |
| 46 void OnGetPasswordStoreResults(ScopedVector<PasswordForm> results) override { | |
| 47 OnGetPasswordStoreResultsConstRef(results.get()); | |
| 48 } | |
| 43 }; | 49 }; |
| 44 | 50 |
| 45 class MockPasswordStoreObserver | 51 class MockPasswordStoreObserver |
| 46 : public password_manager::PasswordStore::Observer { | 52 : public password_manager::PasswordStore::Observer { |
| 47 public: | 53 public: |
| 48 MOCK_METHOD1(OnLoginsChanged, | 54 MOCK_METHOD1(OnLoginsChanged, |
| 49 void(const password_manager::PasswordStoreChangeList& changes)); | 55 void(const password_manager::PasswordStoreChangeList& changes)); |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 class FailingBackend : public PasswordStoreX::NativeBackend { | 58 class FailingBackend : public PasswordStoreX::NativeBackend { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 origin.c_str(), | 232 origin.c_str(), |
| 227 action.c_str(), | 233 action.c_str(), |
| 228 L"submit_element", | 234 L"submit_element", |
| 229 L"username_element", | 235 L"username_element", |
| 230 L"password_element", | 236 L"password_element", |
| 231 autofillable ? L"username_value" : NULL, | 237 autofillable ? L"username_value" : NULL, |
| 232 autofillable ? L"password_value" : NULL, | 238 autofillable ? L"password_value" : NULL, |
| 233 autofillable, | 239 autofillable, |
| 234 false, | 240 false, |
| 235 static_cast<double>(i + 1)}; | 241 static_cast<double>(i + 1)}; |
| 236 forms->push_back(CreatePasswordFormFromData(data)); | 242 forms->push_back(CreatePasswordFormFromData(data).release()); |
| 237 } | 243 } |
| 238 } | 244 } |
| 239 | 245 |
| 240 } // anonymous namespace | 246 } // anonymous namespace |
| 241 | 247 |
| 242 enum BackendType { | 248 enum BackendType { |
| 243 NO_BACKEND, | 249 NO_BACKEND, |
| 244 FAILING_BACKEND, | 250 FAILING_BACKEND, |
| 245 WORKING_BACKEND | 251 WORKING_BACKEND |
| 246 }; | 252 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 login_db.Pass(), GetBackend())); | 291 login_db.Pass(), GetBackend())); |
| 286 store->Init(syncer::SyncableService::StartSyncFlare()); | 292 store->Init(syncer::SyncableService::StartSyncFlare()); |
| 287 | 293 |
| 288 password_manager::PasswordFormData form_data = { | 294 password_manager::PasswordFormData form_data = { |
| 289 PasswordForm::SCHEME_HTML, "http://bar.example.com", | 295 PasswordForm::SCHEME_HTML, "http://bar.example.com", |
| 290 "http://bar.example.com/origin", "http://bar.example.com/action", | 296 "http://bar.example.com/origin", "http://bar.example.com/action", |
| 291 L"submit_element", L"username_element", | 297 L"submit_element", L"username_element", |
| 292 L"password_element", L"username_value", | 298 L"password_element", L"username_value", |
| 293 L"password_value", true, | 299 L"password_value", true, |
| 294 false, 1}; | 300 false, 1}; |
| 295 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 301 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); |
| 296 | 302 |
| 297 MockPasswordStoreObserver observer; | 303 MockPasswordStoreObserver observer; |
| 298 store->AddObserver(&observer); | 304 store->AddObserver(&observer); |
| 299 | 305 |
| 300 const PasswordStoreChange expected_add_changes[] = { | 306 const PasswordStoreChange expected_add_changes[] = { |
| 301 PasswordStoreChange(PasswordStoreChange::ADD, *form), | 307 PasswordStoreChange(PasswordStoreChange::ADD, *form), |
| 302 }; | 308 }; |
| 303 | 309 |
| 304 EXPECT_CALL( | 310 EXPECT_CALL( |
| 305 observer, | 311 observer, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 // Initializing the PasswordStore shouldn't trigger a native migration (yet). | 387 // Initializing the PasswordStore shouldn't trigger a native migration (yet). |
| 382 login_db.reset(new password_manager::LoginDatabase(login_db_file)); | 388 login_db.reset(new password_manager::LoginDatabase(login_db_file)); |
| 383 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( | 389 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( |
| 384 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), | 390 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), |
| 385 login_db.Pass(), GetBackend())); | 391 login_db.Pass(), GetBackend())); |
| 386 store->Init(syncer::SyncableService::StartSyncFlare()); | 392 store->Init(syncer::SyncableService::StartSyncFlare()); |
| 387 | 393 |
| 388 MockPasswordStoreConsumer consumer; | 394 MockPasswordStoreConsumer consumer; |
| 389 | 395 |
| 390 // The autofillable forms should have been migrated to the native backend. | 396 // The autofillable forms should have been migrated to the native backend. |
| 391 EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms( | 397 EXPECT_CALL(consumer, |
| 392 expected_autofillable.get()))) | 398 OnGetPasswordStoreResultsConstRef( |
| 393 .WillOnce(WithArg<0>(STLDeleteElements0())); | 399 ContainsSamePasswordForms(expected_autofillable.get()))); |
| 394 | 400 |
| 395 store->GetAutofillableLogins(&consumer); | 401 store->GetAutofillableLogins(&consumer); |
| 396 base::RunLoop().RunUntilIdle(); | 402 base::RunLoop().RunUntilIdle(); |
| 397 | 403 |
| 398 // The blacklisted forms should have been migrated to the native backend. | 404 // The blacklisted forms should have been migrated to the native backend. |
| 399 EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms( | 405 EXPECT_CALL(consumer, |
| 400 expected_blacklisted.get()))) | 406 OnGetPasswordStoreResultsConstRef( |
| 401 .WillOnce(WithArg<0>(STLDeleteElements0())); | 407 ContainsSamePasswordForms(expected_blacklisted.get()))); |
| 402 | 408 |
| 403 store->GetBlacklistLogins(&consumer); | 409 store->GetBlacklistLogins(&consumer); |
| 404 base::RunLoop().RunUntilIdle(); | 410 base::RunLoop().RunUntilIdle(); |
| 405 | 411 |
| 406 ScopedVector<autofill::PasswordForm> empty; | |
| 407 MockLoginDatabaseReturn ld_return; | 412 MockLoginDatabaseReturn ld_return; |
| 408 | 413 |
| 409 if (GetParam() == WORKING_BACKEND) { | 414 if (GetParam() == WORKING_BACKEND) { |
| 410 // No autofillable logins should be left in the login DB. | 415 // No autofillable logins should be left in the login DB. |
| 411 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone( | 416 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ElementsAre())); |
|
vasilii
2015/02/05 19:23:27
IsEmpty() here and below.
vabr (Chromium)
2015/02/06 14:16:05
Done.
| |
| 412 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. |
| 415 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsAllPasswordForms( | 419 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsSamePasswordForms( |
| 416 expected_autofillable.get()))); | 420 expected_autofillable.get()))); |
| 417 } | 421 } |
| 418 | 422 |
| 419 LoginDatabaseQueryCallback(store->login_db(), true, &ld_return); | 423 LoginDatabaseQueryCallback(store->login_db(), true, &ld_return); |
| 420 | 424 |
| 421 // Wait for the login DB methods to execute. | 425 // Wait for the login DB methods to execute. |
| 422 base::RunLoop().RunUntilIdle(); | 426 base::RunLoop().RunUntilIdle(); |
| 423 | 427 |
| 424 if (GetParam() == WORKING_BACKEND) { | 428 if (GetParam() == WORKING_BACKEND) { |
| 425 // Likewise, no blacklisted logins should be left in the login DB. | 429 // Likewise, no blacklisted logins should be left in the login DB. |
| 426 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone( | 430 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ElementsAre())); |
| 427 ContainsAllPasswordForms(empty.get()))); | |
| 428 } else { | 431 } else { |
| 429 // The blacklisted logins should still be in the login DB. | 432 // The blacklisted logins should still be in the login DB. |
| 430 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsAllPasswordForms( | 433 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsSamePasswordForms( |
| 431 expected_blacklisted.get()))); | 434 expected_blacklisted.get()))); |
| 432 } | 435 } |
| 433 | 436 |
| 434 LoginDatabaseQueryCallback(store->login_db(), false, &ld_return); | 437 LoginDatabaseQueryCallback(store->login_db(), false, &ld_return); |
| 435 | 438 |
| 436 // Wait for the login DB methods to execute. | 439 // Wait for the login DB methods to execute. |
| 437 base::RunLoop().RunUntilIdle(); | 440 base::RunLoop().RunUntilIdle(); |
| 438 | 441 |
| 439 if (GetParam() == WORKING_BACKEND) { | 442 if (GetParam() == WORKING_BACKEND) { |
| 440 // If the migration succeeded, then not only should there be no logins left | 443 // If the migration succeeded, then not only should there be no logins left |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 452 | 455 |
| 453 INSTANTIATE_TEST_CASE_P(NoBackend, | 456 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 454 PasswordStoreXTest, | 457 PasswordStoreXTest, |
| 455 testing::Values(NO_BACKEND)); | 458 testing::Values(NO_BACKEND)); |
| 456 INSTANTIATE_TEST_CASE_P(FailingBackend, | 459 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 457 PasswordStoreXTest, | 460 PasswordStoreXTest, |
| 458 testing::Values(FAILING_BACKEND)); | 461 testing::Values(FAILING_BACKEND)); |
| 459 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 462 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 460 PasswordStoreXTest, | 463 PasswordStoreXTest, |
| 461 testing::Values(WORKING_BACKEND)); | 464 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |