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

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

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

Powered by Google App Engine
This is Rietveld 408576698