Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/password_manager/password_store_x_unittest.cc

Issue 1022823002: Make test outputs involving PasswordForms more readable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + added new field that was added inbetween. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_manager_test_utils.h " 19 #include "components/password_manager/core/browser/password_manager_test_utils.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::ContainsSamePasswordForms;
30 using password_manager::PasswordStoreChange; 29 using password_manager::PasswordStoreChange;
31 using password_manager::PasswordStoreChangeList; 30 using password_manager::PasswordStoreChangeList;
31 using password_manager::UnorderedPasswordFormElementsAre;
32 using testing::ElementsAreArray; 32 using testing::ElementsAreArray;
33 using testing::IsEmpty; 33 using testing::IsEmpty;
34 34
35 namespace { 35 namespace {
36 36
37 class MockPasswordStoreConsumer 37 class MockPasswordStoreConsumer
38 : public password_manager::PasswordStoreConsumer { 38 : public password_manager::PasswordStoreConsumer {
39 public: 39 public:
40 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef, 40 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef,
41 void(const std::vector<PasswordForm*>&)); 41 void(const std::vector<PasswordForm*>&));
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // Initializing the PasswordStore shouldn't trigger a native migration (yet). 410 // Initializing the PasswordStore shouldn't trigger a native migration (yet).
411 login_db.reset(new password_manager::LoginDatabase(login_db_file)); 411 login_db.reset(new password_manager::LoginDatabase(login_db_file));
412 scoped_refptr<PasswordStoreX> store(new PasswordStoreX( 412 scoped_refptr<PasswordStoreX> store(new PasswordStoreX(
413 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), 413 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
414 login_db.Pass(), GetBackend())); 414 login_db.Pass(), GetBackend()));
415 store->Init(syncer::SyncableService::StartSyncFlare()); 415 store->Init(syncer::SyncableService::StartSyncFlare());
416 416
417 MockPasswordStoreConsumer consumer; 417 MockPasswordStoreConsumer consumer;
418 418
419 // The autofillable forms should have been migrated to the native backend. 419 // The autofillable forms should have been migrated to the native backend.
420 EXPECT_CALL(consumer, 420 EXPECT_CALL(
421 OnGetPasswordStoreResultsConstRef( 421 consumer,
422 ContainsSamePasswordForms(expected_autofillable.get()))); 422 OnGetPasswordStoreResultsConstRef(
423 UnorderedPasswordFormElementsAre(expected_autofillable.get())));
423 424
424 store->GetAutofillableLogins(&consumer); 425 store->GetAutofillableLogins(&consumer);
425 base::RunLoop().RunUntilIdle(); 426 base::RunLoop().RunUntilIdle();
426 427
427 // The blacklisted forms should have been migrated to the native backend. 428 // The blacklisted forms should have been migrated to the native backend.
428 EXPECT_CALL(consumer, 429 EXPECT_CALL(
429 OnGetPasswordStoreResultsConstRef( 430 consumer,
430 ContainsSamePasswordForms(expected_blacklisted.get()))); 431 OnGetPasswordStoreResultsConstRef(
432 UnorderedPasswordFormElementsAre(expected_blacklisted.get())));
431 433
432 store->GetBlacklistLogins(&consumer); 434 store->GetBlacklistLogins(&consumer);
433 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
434 436
435 MockLoginDatabaseReturn ld_return; 437 MockLoginDatabaseReturn ld_return;
436 438
437 if (GetParam() == WORKING_BACKEND) { 439 if (GetParam() == WORKING_BACKEND) {
438 // No autofillable logins should be left in the login DB. 440 // No autofillable logins should be left in the login DB.
439 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(IsEmpty())); 441 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(IsEmpty()));
440 } else { 442 } else {
441 // The autofillable logins should still be in the login DB. 443 // The autofillable logins should still be in the login DB.
442 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsSamePasswordForms( 444 EXPECT_CALL(ld_return,
443 expected_autofillable.get()))); 445 OnLoginDatabaseQueryDone(UnorderedPasswordFormElementsAre(
446 expected_autofillable.get())));
444 } 447 }
445 448
446 LoginDatabaseQueryCallback(store->login_db(), true, &ld_return); 449 LoginDatabaseQueryCallback(store->login_db(), true, &ld_return);
447 450
448 // Wait for the login DB methods to execute. 451 // Wait for the login DB methods to execute.
449 base::RunLoop().RunUntilIdle(); 452 base::RunLoop().RunUntilIdle();
450 453
451 if (GetParam() == WORKING_BACKEND) { 454 if (GetParam() == WORKING_BACKEND) {
452 // Likewise, no blacklisted logins should be left in the login DB. 455 // Likewise, no blacklisted logins should be left in the login DB.
453 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(IsEmpty())); 456 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(IsEmpty()));
454 } else { 457 } else {
455 // The blacklisted logins should still be in the login DB. 458 // The blacklisted logins should still be in the login DB.
456 EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsSamePasswordForms( 459 EXPECT_CALL(ld_return,
457 expected_blacklisted.get()))); 460 OnLoginDatabaseQueryDone(UnorderedPasswordFormElementsAre(
461 expected_blacklisted.get())));
458 } 462 }
459 463
460 LoginDatabaseQueryCallback(store->login_db(), false, &ld_return); 464 LoginDatabaseQueryCallback(store->login_db(), false, &ld_return);
461 465
462 // Wait for the login DB methods to execute. 466 // Wait for the login DB methods to execute.
463 base::RunLoop().RunUntilIdle(); 467 base::RunLoop().RunUntilIdle();
464 468
465 if (GetParam() == WORKING_BACKEND) { 469 if (GetParam() == WORKING_BACKEND) {
466 // If the migration succeeded, then not only should there be no logins left 470 // If the migration succeeded, then not only should there be no logins left
467 // in the login DB, but also the file should have been deleted and then 471 // in the login DB, but also the file should have been deleted and then
(...skipping 10 matching lines...) Expand all
478 482
479 INSTANTIATE_TEST_CASE_P(NoBackend, 483 INSTANTIATE_TEST_CASE_P(NoBackend,
480 PasswordStoreXTest, 484 PasswordStoreXTest,
481 testing::Values(NO_BACKEND)); 485 testing::Values(NO_BACKEND));
482 INSTANTIATE_TEST_CASE_P(FailingBackend, 486 INSTANTIATE_TEST_CASE_P(FailingBackend,
483 PasswordStoreXTest, 487 PasswordStoreXTest,
484 testing::Values(FAILING_BACKEND)); 488 testing::Values(FAILING_BACKEND));
485 INSTANTIATE_TEST_CASE_P(WorkingBackend, 489 INSTANTIATE_TEST_CASE_P(WorkingBackend,
486 PasswordStoreXTest, 490 PasswordStoreXTest,
487 testing::Values(WORKING_BACKEND)); 491 testing::Values(WORKING_BACKEND));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698