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 <stdarg.h> | 5 #include <stdarg.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // Checks (using EXPECT_* macros), that |credentials| are accessible for | 399 // Checks (using EXPECT_* macros), that |credentials| are accessible for |
400 // filling in for a page with |origin| iff | 400 // filling in for a page with |origin| iff |
401 // |should_credential_be_available_to_url| is true. | 401 // |should_credential_be_available_to_url| is true. |
402 void CheckCredentialAvailability(const PasswordForm& credentials, | 402 void CheckCredentialAvailability(const PasswordForm& credentials, |
403 const std::string& url, | 403 const std::string& url, |
404 bool should_credential_be_available_to_url) { | 404 bool should_credential_be_available_to_url) { |
405 PSLMatchingHelper helper; | 405 PSLMatchingHelper helper; |
406 ASSERT_TRUE(helper.IsMatchingEnabled()) | 406 ASSERT_TRUE(helper.IsMatchingEnabled()) |
407 << "PSL matching needs to be enabled."; | 407 << "PSL matching needs to be enabled."; |
408 | 408 |
409 NativeBackendGnome backend(321, profile_.GetPrefs()); | 409 NativeBackendGnome backend(321); |
410 backend.Init(); | 410 backend.Init(); |
411 | 411 |
412 BrowserThread::PostTask( | 412 BrowserThread::PostTask( |
413 BrowserThread::DB, | 413 BrowserThread::DB, |
414 FROM_HERE, | 414 FROM_HERE, |
415 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 415 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
416 base::Unretained(&backend), | 416 base::Unretained(&backend), |
417 credentials)); | 417 credentials)); |
418 | 418 |
419 PasswordForm target_form; | 419 PasswordForm target_form; |
(...skipping 18 matching lines...) Expand all Loading... |
438 EXPECT_EQ(1u, form_list.size()); | 438 EXPECT_EQ(1u, form_list.size()); |
439 else | 439 else |
440 EXPECT_EQ(0u, form_list.size()); | 440 EXPECT_EQ(0u, form_list.size()); |
441 STLDeleteElements(&form_list); | 441 STLDeleteElements(&form_list); |
442 } | 442 } |
443 | 443 |
444 base::MessageLoopForUI message_loop_; | 444 base::MessageLoopForUI message_loop_; |
445 content::TestBrowserThread ui_thread_; | 445 content::TestBrowserThread ui_thread_; |
446 content::TestBrowserThread db_thread_; | 446 content::TestBrowserThread db_thread_; |
447 | 447 |
448 TestingProfile profile_; | |
449 | |
450 // Provide some test forms to avoid having to set them up in each test. | 448 // Provide some test forms to avoid having to set them up in each test. |
451 PasswordForm form_google_; | 449 PasswordForm form_google_; |
452 PasswordForm form_facebook_; | 450 PasswordForm form_facebook_; |
453 PasswordForm form_isc_; | 451 PasswordForm form_isc_; |
454 }; | 452 }; |
455 | 453 |
456 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { | 454 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { |
457 // Pretend that the migration has already taken place. | 455 NativeBackendGnome backend(42); |
458 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
459 | |
460 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
461 backend.Init(); | 456 backend.Init(); |
462 | 457 |
463 BrowserThread::PostTask( | 458 BrowserThread::PostTask( |
464 BrowserThread::DB, FROM_HERE, | 459 BrowserThread::DB, FROM_HERE, |
465 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 460 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
466 base::Unretained(&backend), form_google_)); | 461 base::Unretained(&backend), form_google_)); |
467 | 462 |
468 RunBothThreads(); | 463 RunBothThreads(); |
469 | 464 |
470 EXPECT_EQ(1u, mock_keyring_items.size()); | 465 EXPECT_EQ(1u, mock_keyring_items.size()); |
471 if (mock_keyring_items.size() > 0) | 466 if (mock_keyring_items.size() > 0) |
472 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 467 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
473 } | 468 } |
474 | 469 |
475 TEST_F(NativeBackendGnomeTest, BasicListLogins) { | 470 TEST_F(NativeBackendGnomeTest, BasicListLogins) { |
476 // Pretend that the migration has already taken place. | 471 NativeBackendGnome backend(42); |
477 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
478 | |
479 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
480 backend.Init(); | 472 backend.Init(); |
481 | 473 |
482 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
483 BrowserThread::DB, FROM_HERE, | 475 BrowserThread::DB, FROM_HERE, |
484 base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin), | 476 base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin), |
485 base::Unretained(&backend), form_google_)); | 477 base::Unretained(&backend), form_google_)); |
486 | 478 |
487 std::vector<PasswordForm*> form_list; | 479 std::vector<PasswordForm*> form_list; |
488 BrowserThread::PostTask( | 480 BrowserThread::PostTask( |
489 BrowserThread::DB, FROM_HERE, | 481 BrowserThread::DB, FROM_HERE, |
(...skipping 28 matching lines...) Expand all Loading... |
518 } | 510 } |
519 | 511 |
520 // Test PSL matching is off for domains excluded from it. | 512 // Test PSL matching is off for domains excluded from it. |
521 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { | 513 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { |
522 CheckCredentialAvailability(form_google_, | 514 CheckCredentialAvailability(form_google_, |
523 "http://one.google.com/", | 515 "http://one.google.com/", |
524 /*should_credential_be_available_to_url=*/false); | 516 /*should_credential_be_available_to_url=*/false); |
525 } | 517 } |
526 | 518 |
527 TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) { | 519 TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) { |
528 // Pretend that the migration has already taken place. | 520 NativeBackendGnome backend(42); |
529 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
530 | |
531 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
532 backend.Init(); | 521 backend.Init(); |
533 | 522 |
534 // First add google login. | 523 // First add google login. |
535 BrowserThread::PostTask( | 524 BrowserThread::PostTask( |
536 BrowserThread::DB, FROM_HERE, | 525 BrowserThread::DB, FROM_HERE, |
537 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 526 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
538 base::Unretained(&backend), form_google_)); | 527 base::Unretained(&backend), form_google_)); |
539 | 528 |
540 RunBothThreads(); | 529 RunBothThreads(); |
541 | 530 |
(...skipping 12 matching lines...) Expand all Loading... |
554 base::Unretained(&backend), new_form_google)); | 543 base::Unretained(&backend), new_form_google)); |
555 | 544 |
556 RunBothThreads(); | 545 RunBothThreads(); |
557 | 546 |
558 EXPECT_EQ(1u, mock_keyring_items.size()); | 547 EXPECT_EQ(1u, mock_keyring_items.size()); |
559 if (mock_keyring_items.size() > 0) | 548 if (mock_keyring_items.size() > 0) |
560 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42"); | 549 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42"); |
561 } | 550 } |
562 | 551 |
563 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { | 552 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { |
564 // Pretend that the migration has already taken place. | 553 NativeBackendGnome backend(42); |
565 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
566 | |
567 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
568 backend.Init(); | 554 backend.Init(); |
569 | 555 |
570 BrowserThread::PostTask( | 556 BrowserThread::PostTask( |
571 BrowserThread::DB, FROM_HERE, | 557 BrowserThread::DB, FROM_HERE, |
572 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 558 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
573 base::Unretained(&backend), form_google_)); | 559 base::Unretained(&backend), form_google_)); |
574 | 560 |
575 RunBothThreads(); | 561 RunBothThreads(); |
576 | 562 |
577 EXPECT_EQ(1u, mock_keyring_items.size()); | 563 EXPECT_EQ(1u, mock_keyring_items.size()); |
578 if (mock_keyring_items.size() > 0) | 564 if (mock_keyring_items.size() > 0) |
579 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 565 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
580 | 566 |
581 BrowserThread::PostTask( | 567 BrowserThread::PostTask( |
582 BrowserThread::DB, FROM_HERE, | 568 BrowserThread::DB, FROM_HERE, |
583 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | 569 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), |
584 base::Unretained(&backend), form_google_)); | 570 base::Unretained(&backend), form_google_)); |
585 | 571 |
586 RunBothThreads(); | 572 RunBothThreads(); |
587 | 573 |
588 EXPECT_EQ(0u, mock_keyring_items.size()); | 574 EXPECT_EQ(0u, mock_keyring_items.size()); |
589 } | 575 } |
590 | 576 |
591 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { | 577 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { |
592 // Pretend that the migration has already taken place. | 578 NativeBackendGnome backend(42); |
593 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
594 | |
595 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
596 backend.Init(); | 579 backend.Init(); |
597 | 580 |
598 // First add an unrelated login. | 581 // First add an unrelated login. |
599 BrowserThread::PostTask( | 582 BrowserThread::PostTask( |
600 BrowserThread::DB, FROM_HERE, | 583 BrowserThread::DB, FROM_HERE, |
601 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 584 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
602 base::Unretained(&backend), form_google_)); | 585 base::Unretained(&backend), form_google_)); |
603 | 586 |
604 RunBothThreads(); | 587 RunBothThreads(); |
605 | 588 |
(...skipping 20 matching lines...) Expand all Loading... |
626 // Quick check that we got something back. | 609 // Quick check that we got something back. |
627 EXPECT_EQ(1u, form_list.size()); | 610 EXPECT_EQ(1u, form_list.size()); |
628 STLDeleteElements(&form_list); | 611 STLDeleteElements(&form_list); |
629 | 612 |
630 EXPECT_EQ(1u, mock_keyring_items.size()); | 613 EXPECT_EQ(1u, mock_keyring_items.size()); |
631 if (mock_keyring_items.size() > 0) | 614 if (mock_keyring_items.size() > 0) |
632 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 615 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
633 } | 616 } |
634 | 617 |
635 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { | 618 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { |
636 // Pretend that the migration has already taken place. | 619 NativeBackendGnome backend(42); |
637 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
638 | |
639 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
640 backend.Init(); | 620 backend.Init(); |
641 | 621 |
642 BrowserThread::PostTask( | 622 BrowserThread::PostTask( |
643 BrowserThread::DB, FROM_HERE, | 623 BrowserThread::DB, FROM_HERE, |
644 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 624 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
645 base::Unretained(&backend), form_google_)); | 625 base::Unretained(&backend), form_google_)); |
646 BrowserThread::PostTask( | 626 BrowserThread::PostTask( |
647 BrowserThread::DB, FROM_HERE, | 627 BrowserThread::DB, FROM_HERE, |
648 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 628 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
649 base::Unretained(&backend), form_google_)); | 629 base::Unretained(&backend), form_google_)); |
650 | 630 |
651 RunBothThreads(); | 631 RunBothThreads(); |
652 | 632 |
653 EXPECT_EQ(1u, mock_keyring_items.size()); | 633 EXPECT_EQ(1u, mock_keyring_items.size()); |
654 if (mock_keyring_items.size() > 0) | 634 if (mock_keyring_items.size() > 0) |
655 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 635 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
656 } | 636 } |
657 | 637 |
658 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { | 638 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { |
659 // Pretend that the migration has already taken place. | 639 NativeBackendGnome backend(42); |
660 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
661 | |
662 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
663 backend.Init(); | 640 backend.Init(); |
664 | 641 |
665 BrowserThread::PostTask( | 642 BrowserThread::PostTask( |
666 BrowserThread::DB, FROM_HERE, | 643 BrowserThread::DB, FROM_HERE, |
667 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 644 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
668 base::Unretained(&backend), form_google_)); | 645 base::Unretained(&backend), form_google_)); |
669 | 646 |
670 // Send the same request twice with the same list both times. | 647 // Send the same request twice with the same list both times. |
671 std::vector<PasswordForm*> form_list; | 648 std::vector<PasswordForm*> form_list; |
672 BrowserThread::PostTask( | 649 BrowserThread::PostTask( |
(...skipping 11 matching lines...) Expand all Loading... |
684 | 661 |
685 // Quick check that we got two results back. | 662 // Quick check that we got two results back. |
686 EXPECT_EQ(2u, form_list.size()); | 663 EXPECT_EQ(2u, form_list.size()); |
687 STLDeleteElements(&form_list); | 664 STLDeleteElements(&form_list); |
688 | 665 |
689 EXPECT_EQ(1u, mock_keyring_items.size()); | 666 EXPECT_EQ(1u, mock_keyring_items.size()); |
690 if (mock_keyring_items.size() > 0) | 667 if (mock_keyring_items.size() > 0) |
691 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 668 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
692 } | 669 } |
693 | 670 |
694 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. | 671 // TODO(mdm): add more basic tests here at some point. |
695 | |
696 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { | |
697 // Reject attempts to migrate so we can populate the store. | |
698 mock_keyring_reject_local_ids = true; | |
699 | |
700 { | |
701 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
702 backend.Init(); | |
703 | |
704 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
705 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | |
706 base::Unretained(&backend), form_google_)); | |
707 | |
708 // Make sure we can get the form back even when migration is failing. | |
709 std::vector<PasswordForm*> form_list; | |
710 BrowserThread::PostTask( | |
711 BrowserThread::DB, FROM_HERE, | |
712 base::Bind( | |
713 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
714 base::Unretained(&backend), &form_list)); | |
715 | |
716 RunBothThreads(); | |
717 | |
718 // Quick check that we got something back. | |
719 EXPECT_EQ(1u, form_list.size()); | |
720 STLDeleteElements(&form_list); | |
721 } | |
722 | |
723 EXPECT_EQ(1u, mock_keyring_items.size()); | |
724 if (mock_keyring_items.size() > 0) | |
725 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
726 | |
727 // Now allow the migration. | |
728 mock_keyring_reject_local_ids = false; | |
729 | |
730 { | |
731 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
732 backend.Init(); | |
733 | |
734 // This should not trigger migration because there will be no results. | |
735 std::vector<PasswordForm*> form_list; | |
736 BrowserThread::PostTask( | |
737 BrowserThread::DB, FROM_HERE, | |
738 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins), | |
739 base::Unretained(&backend), &form_list)); | |
740 | |
741 RunBothThreads(); | |
742 | |
743 // Check that we got nothing back. | |
744 EXPECT_EQ(0u, form_list.size()); | |
745 STLDeleteElements(&form_list); | |
746 } | |
747 | |
748 // Check that the keyring is unmodified. | |
749 EXPECT_EQ(1u, mock_keyring_items.size()); | |
750 if (mock_keyring_items.size() > 0) | |
751 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
752 | |
753 // Check that we haven't set the persistent preference. | |
754 EXPECT_FALSE( | |
755 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
756 | |
757 { | |
758 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
759 backend.Init(); | |
760 | |
761 // Trigger the migration by looking something up. | |
762 std::vector<PasswordForm*> form_list; | |
763 BrowserThread::PostTask( | |
764 BrowserThread::DB, FROM_HERE, | |
765 base::Bind( | |
766 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
767 base::Unretained(&backend), &form_list)); | |
768 | |
769 RunBothThreads(); | |
770 | |
771 // Quick check that we got something back. | |
772 EXPECT_EQ(1u, form_list.size()); | |
773 STLDeleteElements(&form_list); | |
774 } | |
775 | |
776 EXPECT_EQ(2u, mock_keyring_items.size()); | |
777 if (mock_keyring_items.size() > 0) | |
778 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
779 if (mock_keyring_items.size() > 1) | |
780 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
781 | |
782 // Check that we have set the persistent preference. | |
783 EXPECT_TRUE( | |
784 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
785 } | |
786 | |
787 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { | |
788 // Reject attempts to migrate so we can populate the store. | |
789 mock_keyring_reject_local_ids = true; | |
790 | |
791 { | |
792 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
793 backend.Init(); | |
794 | |
795 BrowserThread::PostTask( | |
796 BrowserThread::DB, FROM_HERE, | |
797 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | |
798 base::Unretained(&backend), form_google_)); | |
799 | |
800 RunBothThreads(); | |
801 } | |
802 | |
803 EXPECT_EQ(1u, mock_keyring_items.size()); | |
804 if (mock_keyring_items.size() > 0) | |
805 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
806 | |
807 // Now allow the migration. | |
808 mock_keyring_reject_local_ids = false; | |
809 | |
810 { | |
811 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
812 backend.Init(); | |
813 | |
814 // Trigger the migration by looking something up. | |
815 std::vector<PasswordForm*> form_list; | |
816 BrowserThread::PostTask( | |
817 BrowserThread::DB, FROM_HERE, | |
818 base::Bind( | |
819 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
820 base::Unretained(&backend), &form_list)); | |
821 | |
822 RunBothThreads(); | |
823 | |
824 // Quick check that we got something back. | |
825 EXPECT_EQ(1u, form_list.size()); | |
826 STLDeleteElements(&form_list); | |
827 } | |
828 | |
829 EXPECT_EQ(2u, mock_keyring_items.size()); | |
830 if (mock_keyring_items.size() > 0) | |
831 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
832 if (mock_keyring_items.size() > 1) | |
833 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
834 | |
835 // Check that we have set the persistent preference. | |
836 EXPECT_TRUE( | |
837 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
838 | |
839 // Normally we'd actually have a different profile. But in the test just reset | |
840 // the profile's persistent pref; we pass in the local profile id anyway. | |
841 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | |
842 | |
843 { | |
844 NativeBackendGnome backend(24, profile_.GetPrefs()); | |
845 backend.Init(); | |
846 | |
847 // Trigger the migration by looking something up. | |
848 std::vector<PasswordForm*> form_list; | |
849 BrowserThread::PostTask( | |
850 BrowserThread::DB, FROM_HERE, | |
851 base::Bind( | |
852 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
853 base::Unretained(&backend), &form_list)); | |
854 | |
855 RunBothThreads(); | |
856 | |
857 // Quick check that we got something back. | |
858 EXPECT_EQ(1u, form_list.size()); | |
859 STLDeleteElements(&form_list); | |
860 } | |
861 | |
862 EXPECT_EQ(3u, mock_keyring_items.size()); | |
863 if (mock_keyring_items.size() > 0) | |
864 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
865 if (mock_keyring_items.size() > 1) | |
866 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
867 if (mock_keyring_items.size() > 2) | |
868 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); | |
869 } | |
870 | |
871 TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { | |
872 // Reject attempts to migrate so we can populate the store. | |
873 mock_keyring_reject_local_ids = true; | |
874 | |
875 { | |
876 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
877 backend.Init(); | |
878 | |
879 BrowserThread::PostTask( | |
880 BrowserThread::DB, FROM_HERE, | |
881 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | |
882 base::Unretained(&backend), form_google_)); | |
883 | |
884 RunBothThreads(); | |
885 } | |
886 | |
887 EXPECT_EQ(1u, mock_keyring_items.size()); | |
888 if (mock_keyring_items.size() > 0) | |
889 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
890 | |
891 // Now allow migration, but also pretend that the it has already taken place. | |
892 mock_keyring_reject_local_ids = false; | |
893 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
894 | |
895 { | |
896 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
897 backend.Init(); | |
898 | |
899 // Trigger the migration by adding a new login. | |
900 BrowserThread::PostTask( | |
901 BrowserThread::DB, FROM_HERE, | |
902 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | |
903 base::Unretained(&backend), form_isc_)); | |
904 | |
905 // Look up all logins; we expect only the one we added. | |
906 std::vector<PasswordForm*> form_list; | |
907 BrowserThread::PostTask( | |
908 BrowserThread::DB, FROM_HERE, | |
909 base::Bind( | |
910 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
911 base::Unretained(&backend), &form_list)); | |
912 | |
913 RunBothThreads(); | |
914 | |
915 // Quick check that we got the right thing back. | |
916 EXPECT_EQ(1u, form_list.size()); | |
917 if (form_list.size() > 0) | |
918 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); | |
919 STLDeleteElements(&form_list); | |
920 } | |
921 | |
922 EXPECT_EQ(2u, mock_keyring_items.size()); | |
923 if (mock_keyring_items.size() > 0) | |
924 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
925 if (mock_keyring_items.size() > 1) | |
926 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); | |
927 } | |
928 | |
929 TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { | |
930 // Reject attempts to migrate so we can populate the store. | |
931 mock_keyring_reject_local_ids = true; | |
932 | |
933 { | |
934 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
935 backend.Init(); | |
936 | |
937 BrowserThread::PostTask( | |
938 BrowserThread::DB, FROM_HERE, | |
939 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | |
940 base::Unretained(&backend), form_google_)); | |
941 | |
942 RunBothThreads(); | |
943 } | |
944 | |
945 EXPECT_EQ(1u, mock_keyring_items.size()); | |
946 if (mock_keyring_items.size() > 0) | |
947 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
948 | |
949 // Now allow the migration. | |
950 mock_keyring_reject_local_ids = false; | |
951 | |
952 { | |
953 NativeBackendGnome backend(42, profile_.GetPrefs()); | |
954 backend.Init(); | |
955 | |
956 // Trigger the migration by looking something up. | |
957 std::vector<PasswordForm*> form_list; | |
958 BrowserThread::PostTask( | |
959 BrowserThread::DB, FROM_HERE, | |
960 base::Bind( | |
961 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
962 base::Unretained(&backend), &form_list)); | |
963 | |
964 RunBothThreads(); | |
965 | |
966 // Quick check that we got something back. | |
967 EXPECT_EQ(1u, form_list.size()); | |
968 STLDeleteElements(&form_list); | |
969 } | |
970 | |
971 EXPECT_EQ(2u, mock_keyring_items.size()); | |
972 if (mock_keyring_items.size() > 0) | |
973 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
974 if (mock_keyring_items.size() > 1) | |
975 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
976 | |
977 // Check that we have set the persistent preference. | |
978 EXPECT_TRUE( | |
979 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
980 | |
981 // Normally we'd actually have a different profile. But in the test just reset | |
982 // the profile's persistent pref; we pass in the local profile id anyway. | |
983 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | |
984 | |
985 { | |
986 NativeBackendGnome backend(24, profile_.GetPrefs()); | |
987 backend.Init(); | |
988 | |
989 // Trigger the migration by looking something up. | |
990 std::vector<PasswordForm*> form_list; | |
991 BrowserThread::PostTask( | |
992 BrowserThread::DB, FROM_HERE, | |
993 base::Bind( | |
994 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | |
995 base::Unretained(&backend), &form_list)); | |
996 | |
997 RunBothThreads(); | |
998 | |
999 // Quick check that we got something back. | |
1000 EXPECT_EQ(1u, form_list.size()); | |
1001 STLDeleteElements(&form_list); | |
1002 | |
1003 // There should be three passwords now. | |
1004 EXPECT_EQ(3u, mock_keyring_items.size()); | |
1005 if (mock_keyring_items.size() > 0) | |
1006 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
1007 if (mock_keyring_items.size() > 1) | |
1008 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
1009 if (mock_keyring_items.size() > 2) | |
1010 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); | |
1011 | |
1012 // Now delete the password from this second profile. | |
1013 BrowserThread::PostTask( | |
1014 BrowserThread::DB, FROM_HERE, | |
1015 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | |
1016 base::Unretained(&backend), form_google_)); | |
1017 | |
1018 RunBothThreads(); | |
1019 | |
1020 // The other two copies of the password in different profiles should remain. | |
1021 EXPECT_EQ(2u, mock_keyring_items.size()); | |
1022 if (mock_keyring_items.size() > 0) | |
1023 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | |
1024 if (mock_keyring_items.size() > 1) | |
1025 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | |
1026 } | |
1027 } | |
OLD | NEW |