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