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

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

Issue 8354028: Use base::IgnoreReturn<bool>( instead of base::IgnoreReturn(base::Callback<bool(void)>(. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 489 }
490 490
491 TEST_F(NativeBackendKWalletTest, BasicAddLogin) { 491 TEST_F(NativeBackendKWalletTest, BasicAddLogin) {
492 // Pretend that the migration has already taken place. 492 // Pretend that the migration has already taken place.
493 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 493 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
494 494
495 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 495 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
496 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 496 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
497 497
498 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 498 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
499 base::IgnoreReturn(base::Callback<bool(void)>( 499 base::IgnoreReturn<bool>(base::Bind(
500 base::Bind(&NativeBackendKWalletStub::AddLogin, 500 &NativeBackendKWalletStub::AddLogin,
501 base::Unretained(&backend), form_google_)))); 501 base::Unretained(&backend), form_google_)));
502 502
503 RunDBThread(); 503 RunDBThread();
504 504
505 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 505 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
506 506
507 std::vector<const PasswordForm*> forms; 507 std::vector<const PasswordForm*> forms;
508 forms.push_back(&form_google_); 508 forms.push_back(&form_google_);
509 ExpectationArray expected; 509 ExpectationArray expected;
510 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 510 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
511 CheckPasswordForms("Chrome Form Data (42)", expected); 511 CheckPasswordForms("Chrome Form Data (42)", expected);
512 } 512 }
513 513
514 TEST_F(NativeBackendKWalletTest, BasicListLogins) { 514 TEST_F(NativeBackendKWalletTest, BasicListLogins) {
515 // Pretend that the migration has already taken place. 515 // Pretend that the migration has already taken place.
516 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 516 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
517 517
518 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 518 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
519 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 519 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
520 520
521 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 521 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
522 base::IgnoreReturn(base::Callback<bool(void)>( 522 base::IgnoreReturn<bool>(base::Bind(
523 base::Bind(&NativeBackendKWalletStub::AddLogin, 523 &NativeBackendKWalletStub::AddLogin,
524 base::Unretained(&backend), form_google_)))); 524 base::Unretained(&backend), form_google_)));
525 525
526 std::vector<PasswordForm*> form_list; 526 std::vector<PasswordForm*> form_list;
527 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 527 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
528 base::IgnoreReturn(base::Callback<bool(void)>( 528 base::IgnoreReturn<bool>(base::Bind(
529 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 529 &NativeBackendKWalletStub::GetAutofillableLogins,
530 base::Unretained(&backend), &form_list)))); 530 base::Unretained(&backend), &form_list)));
531 531
532 RunDBThread(); 532 RunDBThread();
533 533
534 // Quick check that we got something back. 534 // Quick check that we got something back.
535 EXPECT_EQ(1u, form_list.size()); 535 EXPECT_EQ(1u, form_list.size());
536 STLDeleteElements(&form_list); 536 STLDeleteElements(&form_list);
537 537
538 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 538 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
539 539
540 std::vector<const PasswordForm*> forms; 540 std::vector<const PasswordForm*> forms;
541 forms.push_back(&form_google_); 541 forms.push_back(&form_google_);
542 ExpectationArray expected; 542 ExpectationArray expected;
543 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 543 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
544 CheckPasswordForms("Chrome Form Data (42)", expected); 544 CheckPasswordForms("Chrome Form Data (42)", expected);
545 } 545 }
546 546
547 TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { 547 TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) {
548 // Pretend that the migration has already taken place. 548 // Pretend that the migration has already taken place.
549 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 549 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
550 550
551 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 551 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
552 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 552 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
553 553
554 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 554 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
555 base::IgnoreReturn(base::Callback<bool(void)>( 555 base::IgnoreReturn<bool>(base::Bind(
556 base::Bind(&NativeBackendKWalletStub::AddLogin, 556 &NativeBackendKWalletStub::AddLogin,
557 base::Unretained(&backend), form_google_)))); 557 base::Unretained(&backend), form_google_)));
558 558
559 RunDBThread(); 559 RunDBThread();
560 560
561 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 561 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
562 562
563 std::vector<const PasswordForm*> forms; 563 std::vector<const PasswordForm*> forms;
564 forms.push_back(&form_google_); 564 forms.push_back(&form_google_);
565 ExpectationArray expected; 565 ExpectationArray expected;
566 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 566 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
567 CheckPasswordForms("Chrome Form Data (42)", expected); 567 CheckPasswordForms("Chrome Form Data (42)", expected);
568 568
569 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 569 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
570 base::IgnoreReturn(base::Callback<bool(void)>( 570 base::IgnoreReturn<bool>(base::Bind(
571 base::Bind(&NativeBackendKWalletStub::RemoveLogin, 571 &NativeBackendKWalletStub::RemoveLogin,
572 base::Unretained(&backend), form_google_)))); 572 base::Unretained(&backend), form_google_)));
573 573
574 RunDBThread(); 574 RunDBThread();
575 575
576 expected.clear(); 576 expected.clear();
577 CheckPasswordForms("Chrome Form Data (42)", expected); 577 CheckPasswordForms("Chrome Form Data (42)", expected);
578 } 578 }
579 579
580 TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { 580 TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) {
581 // Pretend that the migration has already taken place. 581 // Pretend that the migration has already taken place.
582 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 582 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
583 583
584 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 584 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
585 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 585 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
586 586
587 // First add an unrelated login. 587 // First add an unrelated login.
588 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 588 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
589 base::IgnoreReturn(base::Callback<bool(void)>( 589 base::IgnoreReturn<bool>(base::Bind(
590 base::Bind(&NativeBackendKWalletStub::AddLogin, 590 &NativeBackendKWalletStub::AddLogin,
591 base::Unretained(&backend), form_google_)))); 591 base::Unretained(&backend), form_google_)));
592 592
593 RunDBThread(); 593 RunDBThread();
594 594
595 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 595 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
596 596
597 std::vector<const PasswordForm*> forms; 597 std::vector<const PasswordForm*> forms;
598 forms.push_back(&form_google_); 598 forms.push_back(&form_google_);
599 ExpectationArray expected; 599 ExpectationArray expected;
600 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 600 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
601 CheckPasswordForms("Chrome Form Data (42)", expected); 601 CheckPasswordForms("Chrome Form Data (42)", expected);
602 602
603 // Attempt to remove a login that doesn't exist. 603 // Attempt to remove a login that doesn't exist.
604 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 604 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
605 base::IgnoreReturn(base::Callback<bool(void)>( 605 base::IgnoreReturn<bool>(base::Bind(
606 base::Bind(&NativeBackendKWalletStub::RemoveLogin, 606 &NativeBackendKWalletStub::RemoveLogin,
607 base::Unretained(&backend), form_isc_)))); 607 base::Unretained(&backend), form_isc_)));
608 608
609 // Make sure we can still get the first form back. 609 // Make sure we can still get the first form back.
610 std::vector<PasswordForm*> form_list; 610 std::vector<PasswordForm*> form_list;
611 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 611 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
612 base::IgnoreReturn(base::Callback<bool(void)>( 612 base::IgnoreReturn<bool>(base::Bind(
613 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 613 &NativeBackendKWalletStub::GetAutofillableLogins,
614 base::Unretained(&backend), &form_list)))); 614 base::Unretained(&backend), &form_list)));
615 615
616 RunDBThread(); 616 RunDBThread();
617 617
618 // Quick check that we got something back. 618 // Quick check that we got something back.
619 EXPECT_EQ(1u, form_list.size()); 619 EXPECT_EQ(1u, form_list.size());
620 STLDeleteElements(&form_list); 620 STLDeleteElements(&form_list);
621 621
622 CheckPasswordForms("Chrome Form Data (42)", expected); 622 CheckPasswordForms("Chrome Form Data (42)", expected);
623 } 623 }
624 624
625 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { 625 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) {
626 // Pretend that the migration has already taken place. 626 // Pretend that the migration has already taken place.
627 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 627 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
628 628
629 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 629 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
630 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 630 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
631 631
632 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 632 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
633 base::IgnoreReturn(base::Callback<bool(void)>( 633 base::IgnoreReturn<bool>(base::Bind(
634 base::Bind(&NativeBackendKWalletStub::AddLogin, 634 &NativeBackendKWalletStub::AddLogin,
635 base::Unretained(&backend), form_google_)))); 635 base::Unretained(&backend), form_google_)));
636 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 636 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
637 base::IgnoreReturn(base::Callback<bool(void)>( 637 base::IgnoreReturn<bool>(base::Bind(
638 base::Bind(&NativeBackendKWalletStub::AddLogin, 638 &NativeBackendKWalletStub::AddLogin,
639 base::Unretained(&backend), form_google_)))); 639 base::Unretained(&backend), form_google_)));
640 640
641 RunDBThread(); 641 RunDBThread();
642 642
643 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 643 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
644 644
645 std::vector<const PasswordForm*> forms; 645 std::vector<const PasswordForm*> forms;
646 forms.push_back(&form_google_); 646 forms.push_back(&form_google_);
647 ExpectationArray expected; 647 ExpectationArray expected;
648 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 648 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
649 CheckPasswordForms("Chrome Form Data (42)", expected); 649 CheckPasswordForms("Chrome Form Data (42)", expected);
650 } 650 }
651 651
652 TEST_F(NativeBackendKWalletTest, ListLoginsAppends) { 652 TEST_F(NativeBackendKWalletTest, ListLoginsAppends) {
653 // Pretend that the migration has already taken place. 653 // Pretend that the migration has already taken place.
654 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 654 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
655 655
656 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 656 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
657 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 657 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
658 658
659 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 659 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
660 base::IgnoreReturn(base::Callback<bool(void)>( 660 base::IgnoreReturn<bool>(base::Bind(
661 base::Bind(&NativeBackendKWalletStub::AddLogin, 661 &NativeBackendKWalletStub::AddLogin,
662 base::Unretained(&backend), form_google_)))); 662 base::Unretained(&backend), form_google_)));
663 663
664 // Send the same request twice with the same list both times. 664 // Send the same request twice with the same list both times.
665 std::vector<PasswordForm*> form_list; 665 std::vector<PasswordForm*> form_list;
666 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 666 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
667 base::IgnoreReturn(base::Callback<bool(void)>( 667 base::IgnoreReturn<bool>(base::Bind(
668 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 668 &NativeBackendKWalletStub::GetAutofillableLogins,
669 base::Unretained(&backend), &form_list)))); 669 base::Unretained(&backend), &form_list)));
670 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 670 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
671 base::IgnoreReturn(base::Callback<bool(void)>( 671 base::IgnoreReturn<bool>(base::Bind(
672 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 672 &NativeBackendKWalletStub::GetAutofillableLogins,
673 base::Unretained(&backend), &form_list)))); 673 base::Unretained(&backend), &form_list)));
674 674
675 RunDBThread(); 675 RunDBThread();
676 676
677 // Quick check that we got two results back. 677 // Quick check that we got two results back.
678 EXPECT_EQ(2u, form_list.size()); 678 EXPECT_EQ(2u, form_list.size());
679 STLDeleteElements(&form_list); 679 STLDeleteElements(&form_list);
680 680
681 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 681 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
682 682
683 std::vector<const PasswordForm*> forms; 683 std::vector<const PasswordForm*> forms;
684 forms.push_back(&form_google_); 684 forms.push_back(&form_google_);
685 ExpectationArray expected; 685 ExpectationArray expected;
686 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 686 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
687 CheckPasswordForms("Chrome Form Data (42)", expected); 687 CheckPasswordForms("Chrome Form Data (42)", expected);
688 } 688 }
689 689
690 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. 690 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point.
691 // (For example tests for storing >1 password per realm pickle.) 691 // (For example tests for storing >1 password per realm pickle.)
692 692
693 TEST_F(NativeBackendKWalletTest, MigrateOneLogin) { 693 TEST_F(NativeBackendKWalletTest, MigrateOneLogin) {
694 // Reject attempts to migrate so we can populate the store. 694 // Reject attempts to migrate so we can populate the store.
695 wallet_.set_reject_local_folders(true); 695 wallet_.set_reject_local_folders(true);
696 696
697 { 697 {
698 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 698 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
699 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 699 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
700 700
701 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 701 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
702 base::IgnoreReturn(base::Callback<bool(void)>( 702 base::IgnoreReturn<bool>(base::Bind(
703 base::Bind(&NativeBackendKWalletStub::AddLogin, 703 &NativeBackendKWalletStub::AddLogin,
704 base::Unretained(&backend), form_google_)))); 704 base::Unretained(&backend), form_google_)));
705 705
706 // Make sure we can get the form back even when migration is failing. 706 // Make sure we can get the form back even when migration is failing.
707 std::vector<PasswordForm*> form_list; 707 std::vector<PasswordForm*> form_list;
708 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 708 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
709 base::IgnoreReturn(base::Callback<bool(void)>( 709 base::IgnoreReturn<bool>(base::Bind(
710 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 710 &NativeBackendKWalletStub::GetAutofillableLogins,
711 base::Unretained(&backend), &form_list)))); 711 base::Unretained(&backend), &form_list)));
712 712
713 RunDBThread(); 713 RunDBThread();
714 714
715 // Quick check that we got something back. 715 // Quick check that we got something back.
716 EXPECT_EQ(1u, form_list.size()); 716 EXPECT_EQ(1u, form_list.size());
717 STLDeleteElements(&form_list); 717 STLDeleteElements(&form_list);
718 } 718 }
719 719
720 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); 720 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
721 721
722 std::vector<const PasswordForm*> forms; 722 std::vector<const PasswordForm*> forms;
723 forms.push_back(&form_google_); 723 forms.push_back(&form_google_);
724 ExpectationArray expected; 724 ExpectationArray expected;
725 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 725 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
726 CheckPasswordForms("Chrome Form Data", expected); 726 CheckPasswordForms("Chrome Form Data", expected);
727 727
728 // Now allow the migration. 728 // Now allow the migration.
729 wallet_.set_reject_local_folders(false); 729 wallet_.set_reject_local_folders(false);
730 730
731 { 731 {
732 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 732 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
733 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 733 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
734 734
735 // Trigger the migration by looking something up. 735 // Trigger the migration by looking something up.
736 std::vector<PasswordForm*> form_list; 736 std::vector<PasswordForm*> form_list;
737 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 737 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
738 base::IgnoreReturn(base::Callback<bool(void)>( 738 base::IgnoreReturn<bool>(base::Bind(
739 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 739 &NativeBackendKWalletStub::GetAutofillableLogins,
740 base::Unretained(&backend), &form_list)))); 740 base::Unretained(&backend), &form_list)));
741 741
742 RunDBThread(); 742 RunDBThread();
743 743
744 // Quick check that we got something back. 744 // Quick check that we got something back.
745 EXPECT_EQ(1u, form_list.size()); 745 EXPECT_EQ(1u, form_list.size());
746 STLDeleteElements(&form_list); 746 STLDeleteElements(&form_list);
747 } 747 }
748 748
749 CheckPasswordForms("Chrome Form Data", expected); 749 CheckPasswordForms("Chrome Form Data", expected);
750 CheckPasswordForms("Chrome Form Data (42)", expected); 750 CheckPasswordForms("Chrome Form Data (42)", expected);
751 751
752 // Check that we have set the persistent preference. 752 // Check that we have set the persistent preference.
753 EXPECT_TRUE( 753 EXPECT_TRUE(
754 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 754 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
755 } 755 }
756 756
757 TEST_F(NativeBackendKWalletTest, MigrateToMultipleProfiles) { 757 TEST_F(NativeBackendKWalletTest, MigrateToMultipleProfiles) {
758 // Reject attempts to migrate so we can populate the store. 758 // Reject attempts to migrate so we can populate the store.
759 wallet_.set_reject_local_folders(true); 759 wallet_.set_reject_local_folders(true);
760 760
761 { 761 {
762 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 762 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
763 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 763 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
764 764
765 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 765 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
766 base::IgnoreReturn(base::Callback<bool(void)>( 766 base::IgnoreReturn<bool>(base::Bind(
767 base::Bind(&NativeBackendKWalletStub::AddLogin, 767 &NativeBackendKWalletStub::AddLogin,
768 base::Unretained(&backend), form_google_)))); 768 base::Unretained(&backend), form_google_)));
769 769
770 RunDBThread(); 770 RunDBThread();
771 } 771 }
772 772
773 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); 773 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
774 774
775 std::vector<const PasswordForm*> forms; 775 std::vector<const PasswordForm*> forms;
776 forms.push_back(&form_google_); 776 forms.push_back(&form_google_);
777 ExpectationArray expected; 777 ExpectationArray expected;
778 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 778 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
779 CheckPasswordForms("Chrome Form Data", expected); 779 CheckPasswordForms("Chrome Form Data", expected);
780 780
781 // Now allow the migration. 781 // Now allow the migration.
782 wallet_.set_reject_local_folders(false); 782 wallet_.set_reject_local_folders(false);
783 783
784 { 784 {
785 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 785 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
786 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 786 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
787 787
788 // Trigger the migration by looking something up. 788 // Trigger the migration by looking something up.
789 std::vector<PasswordForm*> form_list; 789 std::vector<PasswordForm*> form_list;
790 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 790 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
791 base::IgnoreReturn(base::Callback<bool(void)>( 791 base::IgnoreReturn<bool>(base::Bind(
792 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 792 &NativeBackendKWalletStub::GetAutofillableLogins,
793 base::Unretained(&backend), &form_list)))); 793 base::Unretained(&backend), &form_list)));
794 794
795 RunDBThread(); 795 RunDBThread();
796 796
797 // Quick check that we got something back. 797 // Quick check that we got something back.
798 EXPECT_EQ(1u, form_list.size()); 798 EXPECT_EQ(1u, form_list.size());
799 STLDeleteElements(&form_list); 799 STLDeleteElements(&form_list);
800 } 800 }
801 801
802 CheckPasswordForms("Chrome Form Data", expected); 802 CheckPasswordForms("Chrome Form Data", expected);
803 CheckPasswordForms("Chrome Form Data (42)", expected); 803 CheckPasswordForms("Chrome Form Data (42)", expected);
804 804
805 // Check that we have set the persistent preference. 805 // Check that we have set the persistent preference.
806 EXPECT_TRUE( 806 EXPECT_TRUE(
807 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 807 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
808 808
809 // Normally we'd actually have a different profile. But in the test just reset 809 // Normally we'd actually have a different profile. But in the test just reset
810 // the profile's persistent pref; we pass in the local profile id anyway. 810 // the profile's persistent pref; we pass in the local profile id anyway.
811 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); 811 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
812 812
813 { 813 {
814 NativeBackendKWalletStub backend(24, profile_.GetPrefs()); 814 NativeBackendKWalletStub backend(24, profile_.GetPrefs());
815 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 815 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
816 816
817 // Trigger the migration by looking something up. 817 // Trigger the migration by looking something up.
818 std::vector<PasswordForm*> form_list; 818 std::vector<PasswordForm*> form_list;
819 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 819 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
820 base::IgnoreReturn(base::Callback<bool(void)>( 820 base::IgnoreReturn<bool>(base::Bind(
821 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 821 &NativeBackendKWalletStub::GetAutofillableLogins,
822 base::Unretained(&backend), &form_list)))); 822 base::Unretained(&backend), &form_list)));
823 823
824 RunDBThread(); 824 RunDBThread();
825 825
826 // Quick check that we got something back. 826 // Quick check that we got something back.
827 EXPECT_EQ(1u, form_list.size()); 827 EXPECT_EQ(1u, form_list.size());
828 STLDeleteElements(&form_list); 828 STLDeleteElements(&form_list);
829 } 829 }
830 830
831 CheckPasswordForms("Chrome Form Data", expected); 831 CheckPasswordForms("Chrome Form Data", expected);
832 CheckPasswordForms("Chrome Form Data (42)", expected); 832 CheckPasswordForms("Chrome Form Data (42)", expected);
833 CheckPasswordForms("Chrome Form Data (24)", expected); 833 CheckPasswordForms("Chrome Form Data (24)", expected);
834 } 834 }
835 835
836 TEST_F(NativeBackendKWalletTest, NoMigrationWithPrefSet) { 836 TEST_F(NativeBackendKWalletTest, NoMigrationWithPrefSet) {
837 // Reject attempts to migrate so we can populate the store. 837 // Reject attempts to migrate so we can populate the store.
838 wallet_.set_reject_local_folders(true); 838 wallet_.set_reject_local_folders(true);
839 839
840 { 840 {
841 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 841 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
842 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 842 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
843 843
844 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 844 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
845 base::IgnoreReturn(base::Callback<bool(void)>( 845 base::IgnoreReturn<bool>(base::Bind(
846 base::Bind(&NativeBackendKWalletStub::AddLogin, 846 &NativeBackendKWalletStub::AddLogin,
847 base::Unretained(&backend), form_google_)))); 847 base::Unretained(&backend), form_google_)));
848 848
849 RunDBThread(); 849 RunDBThread();
850 } 850 }
851 851
852 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); 852 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
853 853
854 std::vector<const PasswordForm*> forms; 854 std::vector<const PasswordForm*> forms;
855 forms.push_back(&form_google_); 855 forms.push_back(&form_google_);
856 ExpectationArray expected; 856 ExpectationArray expected;
857 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 857 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
858 CheckPasswordForms("Chrome Form Data", expected); 858 CheckPasswordForms("Chrome Form Data", expected);
859 859
860 // Now allow migration, but also pretend that the it has already taken place. 860 // Now allow migration, but also pretend that the it has already taken place.
861 wallet_.set_reject_local_folders(false); 861 wallet_.set_reject_local_folders(false);
862 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 862 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
863 863
864 { 864 {
865 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 865 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
866 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 866 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
867 867
868 // Trigger the migration by adding a new login. 868 // Trigger the migration by adding a new login.
869 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 869 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
870 base::IgnoreReturn(base::Callback<bool(void)>( 870 base::IgnoreReturn<bool>(base::Bind(
871 base::Bind(&NativeBackendKWalletStub::AddLogin, 871 &NativeBackendKWalletStub::AddLogin,
872 base::Unretained(&backend), form_isc_)))); 872 base::Unretained(&backend), form_isc_)));
873 873
874 // Look up all logins; we expect only the one we added. 874 // Look up all logins; we expect only the one we added.
875 std::vector<PasswordForm*> form_list; 875 std::vector<PasswordForm*> form_list;
876 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 876 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
877 base::IgnoreReturn(base::Callback<bool(void)>( 877 base::IgnoreReturn<bool>(base::Bind(
878 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 878 &NativeBackendKWalletStub::GetAutofillableLogins,
879 base::Unretained(&backend), &form_list)))); 879 base::Unretained(&backend), &form_list)));
880 880
881 RunDBThread(); 881 RunDBThread();
882 882
883 // Quick check that we got the right thing back. 883 // Quick check that we got the right thing back.
884 EXPECT_EQ(1u, form_list.size()); 884 EXPECT_EQ(1u, form_list.size());
885 if (form_list.size() > 0) 885 if (form_list.size() > 0)
886 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); 886 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm);
887 STLDeleteElements(&form_list); 887 STLDeleteElements(&form_list);
888 } 888 }
889 889
890 CheckPasswordForms("Chrome Form Data", expected); 890 CheckPasswordForms("Chrome Form Data", expected);
891 891
892 forms[0] = &form_isc_; 892 forms[0] = &form_isc_;
893 expected.clear(); 893 expected.clear();
894 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms)); 894 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms));
895 CheckPasswordForms("Chrome Form Data (42)", expected); 895 CheckPasswordForms("Chrome Form Data (42)", expected);
896 } 896 }
897 897
898 TEST_F(NativeBackendKWalletTest, DeleteMigratedPasswordIsIsolated) { 898 TEST_F(NativeBackendKWalletTest, DeleteMigratedPasswordIsIsolated) {
899 // Reject attempts to migrate so we can populate the store. 899 // Reject attempts to migrate so we can populate the store.
900 wallet_.set_reject_local_folders(true); 900 wallet_.set_reject_local_folders(true);
901 901
902 { 902 {
903 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 903 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
904 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 904 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
905 905
906 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 906 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
907 base::IgnoreReturn(base::Callback<bool(void)>( 907 base::IgnoreReturn<bool>(base::Bind(
908 base::Bind(&NativeBackendKWalletStub::AddLogin, 908 &NativeBackendKWalletStub::AddLogin,
909 base::Unretained(&backend), form_google_)))); 909 base::Unretained(&backend), form_google_)));
910 910
911 RunDBThread(); 911 RunDBThread();
912 } 912 }
913 913
914 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); 914 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
915 915
916 std::vector<const PasswordForm*> forms; 916 std::vector<const PasswordForm*> forms;
917 forms.push_back(&form_google_); 917 forms.push_back(&form_google_);
918 ExpectationArray expected; 918 ExpectationArray expected;
919 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 919 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
920 CheckPasswordForms("Chrome Form Data", expected); 920 CheckPasswordForms("Chrome Form Data", expected);
921 921
922 // Now allow the migration. 922 // Now allow the migration.
923 wallet_.set_reject_local_folders(false); 923 wallet_.set_reject_local_folders(false);
924 924
925 { 925 {
926 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); 926 NativeBackendKWalletStub backend(42, profile_.GetPrefs());
927 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 927 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
928 928
929 // Trigger the migration by looking something up. 929 // Trigger the migration by looking something up.
930 std::vector<PasswordForm*> form_list; 930 std::vector<PasswordForm*> form_list;
931 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 931 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
932 base::IgnoreReturn(base::Callback<bool(void)>( 932 base::IgnoreReturn<bool>(base::Bind(
933 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 933 &NativeBackendKWalletStub::GetAutofillableLogins,
934 base::Unretained(&backend), &form_list)))); 934 base::Unretained(&backend), &form_list)));
935 935
936 RunDBThread(); 936 RunDBThread();
937 937
938 // Quick check that we got something back. 938 // Quick check that we got something back.
939 EXPECT_EQ(1u, form_list.size()); 939 EXPECT_EQ(1u, form_list.size());
940 STLDeleteElements(&form_list); 940 STLDeleteElements(&form_list);
941 } 941 }
942 942
943 CheckPasswordForms("Chrome Form Data", expected); 943 CheckPasswordForms("Chrome Form Data", expected);
944 CheckPasswordForms("Chrome Form Data (42)", expected); 944 CheckPasswordForms("Chrome Form Data (42)", expected);
945 945
946 // Check that we have set the persistent preference. 946 // Check that we have set the persistent preference.
947 EXPECT_TRUE( 947 EXPECT_TRUE(
948 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 948 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
949 949
950 // Normally we'd actually have a different profile. But in the test just reset 950 // Normally we'd actually have a different profile. But in the test just reset
951 // the profile's persistent pref; we pass in the local profile id anyway. 951 // the profile's persistent pref; we pass in the local profile id anyway.
952 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); 952 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
953 953
954 { 954 {
955 NativeBackendKWalletStub backend(24, profile_.GetPrefs()); 955 NativeBackendKWalletStub backend(24, profile_.GetPrefs());
956 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 956 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
957 957
958 // Trigger the migration by looking something up. 958 // Trigger the migration by looking something up.
959 std::vector<PasswordForm*> form_list; 959 std::vector<PasswordForm*> form_list;
960 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 960 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
961 base::IgnoreReturn(base::Callback<bool(void)>( 961 base::IgnoreReturn<bool>(base::Bind(
962 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 962 &NativeBackendKWalletStub::GetAutofillableLogins,
963 base::Unretained(&backend), &form_list)))); 963 base::Unretained(&backend), &form_list)));
964 964
965 RunDBThread(); 965 RunDBThread();
966 966
967 // Quick check that we got something back. 967 // Quick check that we got something back.
968 EXPECT_EQ(1u, form_list.size()); 968 EXPECT_EQ(1u, form_list.size());
969 STLDeleteElements(&form_list); 969 STLDeleteElements(&form_list);
970 970
971 // There should be three passwords now. 971 // There should be three passwords now.
972 CheckPasswordForms("Chrome Form Data", expected); 972 CheckPasswordForms("Chrome Form Data", expected);
973 CheckPasswordForms("Chrome Form Data (42)", expected); 973 CheckPasswordForms("Chrome Form Data (42)", expected);
974 CheckPasswordForms("Chrome Form Data (24)", expected); 974 CheckPasswordForms("Chrome Form Data (24)", expected);
975 975
976 // Now delete the password from this second profile. 976 // Now delete the password from this second profile.
977 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 977 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
978 base::IgnoreReturn(base::Callback<bool(void)>( 978 base::IgnoreReturn<bool>(base::Bind(
979 base::Bind(&NativeBackendKWalletStub::RemoveLogin, 979 &NativeBackendKWalletStub::RemoveLogin,
980 base::Unretained(&backend), form_google_)))); 980 base::Unretained(&backend), form_google_)));
981 981
982 RunDBThread(); 982 RunDBThread();
983 983
984 // The other two copies of the password in different profiles should remain. 984 // The other two copies of the password in different profiles should remain.
985 CheckPasswordForms("Chrome Form Data", expected); 985 CheckPasswordForms("Chrome Form Data", expected);
986 CheckPasswordForms("Chrome Form Data (42)", expected); 986 CheckPasswordForms("Chrome Form Data (42)", expected);
987 expected.clear(); 987 expected.clear();
988 CheckPasswordForms("Chrome Form Data (24)", expected); 988 CheckPasswordForms("Chrome Form Data (24)", expected);
989 } 989 }
990 } 990 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698