| 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 <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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 } // anonymous namespace | 120 } // anonymous namespace |
| 121 | 121 |
| 122 // Obscure magic: we need to declare storage for this constant because we use it | 122 // Obscure magic: we need to declare storage for this constant because we use it |
| 123 // in ways that require its address in this test, but not in the actual code. | 123 // in ways that require its address in this test, but not in the actual code. |
| 124 const int NativeBackendKWallet::kInvalidKWalletHandle; | 124 const int NativeBackendKWallet::kInvalidKWalletHandle; |
| 125 | 125 |
| 126 // Subclass NativeBackendKWallet to promote some members to public for testing. | 126 // Subclass NativeBackendKWallet to promote some members to public for testing. |
| 127 class NativeBackendKWalletStub : public NativeBackendKWallet { | 127 class NativeBackendKWalletStub : public NativeBackendKWallet { |
| 128 public: | 128 public: |
| 129 NativeBackendKWalletStub(LocalProfileId id, PrefService* pref_service) | 129 explicit NativeBackendKWalletStub(LocalProfileId id) |
| 130 : NativeBackendKWallet(id, pref_service) { | 130 : NativeBackendKWallet(id) { |
| 131 } | 131 } |
| 132 using NativeBackendKWallet::InitWithBus; | 132 using NativeBackendKWallet::InitWithBus; |
| 133 using NativeBackendKWallet::kInvalidKWalletHandle; | 133 using NativeBackendKWallet::kInvalidKWalletHandle; |
| 134 using NativeBackendKWallet::DeserializeValue; | 134 using NativeBackendKWallet::DeserializeValue; |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // Provide some test forms to avoid having to set them up in each test. | 137 // Provide some test forms to avoid having to set them up in each test. |
| 138 class NativeBackendKWalletTestBase : public testing::Test { | 138 class NativeBackendKWalletTestBase : public testing::Test { |
| 139 protected: | 139 protected: |
| 140 NativeBackendKWalletTestBase() { | 140 NativeBackendKWalletTestBase() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Utilities to help verify sets of expectations. | 219 // Utilities to help verify sets of expectations. |
| 220 typedef std::vector< | 220 typedef std::vector< |
| 221 std::pair<std::string, | 221 std::pair<std::string, |
| 222 std::vector<const PasswordForm*> > > ExpectationArray; | 222 std::vector<const PasswordForm*> > > ExpectationArray; |
| 223 void CheckPasswordForms(const std::string& folder, | 223 void CheckPasswordForms(const std::string& folder, |
| 224 const ExpectationArray& sorted_expected); | 224 const ExpectationArray& sorted_expected); |
| 225 | 225 |
| 226 base::MessageLoopForUI message_loop_; | 226 base::MessageLoopForUI message_loop_; |
| 227 content::TestBrowserThread ui_thread_; | 227 content::TestBrowserThread ui_thread_; |
| 228 content::TestBrowserThread db_thread_; | 228 content::TestBrowserThread db_thread_; |
| 229 TestingProfile profile_; | |
| 230 | 229 |
| 231 scoped_refptr<dbus::MockBus> mock_session_bus_; | 230 scoped_refptr<dbus::MockBus> mock_session_bus_; |
| 232 scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_; | 231 scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_; |
| 233 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_; | 232 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_; |
| 234 | 233 |
| 235 int klauncher_ret_; | 234 int klauncher_ret_; |
| 236 std::string klauncher_error_; | 235 std::string klauncher_error_; |
| 237 bool klauncher_contacted_; | 236 bool klauncher_contacted_; |
| 238 | 237 |
| 239 bool kwallet_runnable_; | 238 bool kwallet_runnable_; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 NativeBackendKWalletStub::DeserializeValue(entries[i], pickle, &forms); | 464 NativeBackendKWalletStub::DeserializeValue(entries[i], pickle, &forms); |
| 466 const std::vector<const PasswordForm*>& expect = sorted_expected[i].second; | 465 const std::vector<const PasswordForm*>& expect = sorted_expected[i].second; |
| 467 EXPECT_EQ(expect.size(), forms.size()); | 466 EXPECT_EQ(expect.size(), forms.size()); |
| 468 for (size_t j = 0; j < forms.size() && j < expect.size(); ++j) | 467 for (size_t j = 0; j < forms.size() && j < expect.size(); ++j) |
| 469 CheckPasswordForm(*expect[j], *forms[j]); | 468 CheckPasswordForm(*expect[j], *forms[j]); |
| 470 STLDeleteElements(&forms); | 469 STLDeleteElements(&forms); |
| 471 } | 470 } |
| 472 } | 471 } |
| 473 | 472 |
| 474 TEST_F(NativeBackendKWalletTest, NotEnabled) { | 473 TEST_F(NativeBackendKWalletTest, NotEnabled) { |
| 475 NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); | 474 NativeBackendKWalletStub kwallet(42); |
| 476 kwallet_enabled_ = false; | 475 kwallet_enabled_ = false; |
| 477 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); | 476 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); |
| 478 EXPECT_FALSE(klauncher_contacted_); | 477 EXPECT_FALSE(klauncher_contacted_); |
| 479 } | 478 } |
| 480 | 479 |
| 481 TEST_F(NativeBackendKWalletTest, NotRunnable) { | 480 TEST_F(NativeBackendKWalletTest, NotRunnable) { |
| 482 NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); | 481 NativeBackendKWalletStub kwallet(42); |
| 483 kwallet_runnable_ = false; | 482 kwallet_runnable_ = false; |
| 484 kwallet_running_ = false; | 483 kwallet_running_ = false; |
| 485 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); | 484 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); |
| 486 EXPECT_TRUE(klauncher_contacted_); | 485 EXPECT_TRUE(klauncher_contacted_); |
| 487 } | 486 } |
| 488 | 487 |
| 489 TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) { | 488 TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) { |
| 490 NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); | 489 NativeBackendKWalletStub kwallet(42); |
| 491 kwallet_running_ = false; | 490 kwallet_running_ = false; |
| 492 kwallet_enabled_ = false; | 491 kwallet_enabled_ = false; |
| 493 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); | 492 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); |
| 494 EXPECT_TRUE(klauncher_contacted_); | 493 EXPECT_TRUE(klauncher_contacted_); |
| 495 } | 494 } |
| 496 | 495 |
| 497 TEST_F(NativeBackendKWalletTest, NotRunning) { | 496 TEST_F(NativeBackendKWalletTest, NotRunning) { |
| 498 NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); | 497 NativeBackendKWalletStub kwallet(42); |
| 499 kwallet_running_ = false; | 498 kwallet_running_ = false; |
| 500 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); | 499 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); |
| 501 EXPECT_TRUE(klauncher_contacted_); | 500 EXPECT_TRUE(klauncher_contacted_); |
| 502 } | 501 } |
| 503 | 502 |
| 504 TEST_F(NativeBackendKWalletTest, BasicStartup) { | 503 TEST_F(NativeBackendKWalletTest, BasicStartup) { |
| 505 NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); | 504 NativeBackendKWalletStub kwallet(42); |
| 506 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); | 505 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); |
| 507 EXPECT_FALSE(klauncher_contacted_); | 506 EXPECT_FALSE(klauncher_contacted_); |
| 508 } | 507 } |
| 509 | 508 |
| 510 TEST_F(NativeBackendKWalletTest, BasicAddLogin) { | 509 TEST_F(NativeBackendKWalletTest, BasicAddLogin) { |
| 511 // Pretend that the migration has already taken place. | 510 NativeBackendKWalletStub backend(42); |
| 512 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 513 | |
| 514 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 515 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 511 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 516 | 512 |
| 517 BrowserThread::PostTask( | 513 BrowserThread::PostTask( |
| 518 BrowserThread::DB, FROM_HERE, | 514 BrowserThread::DB, FROM_HERE, |
| 519 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 515 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 520 base::Unretained(&backend), form_google_)); | 516 base::Unretained(&backend), form_google_)); |
| 521 | 517 |
| 522 RunDBThread(); | 518 RunDBThread(); |
| 523 | 519 |
| 524 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 520 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
| 525 | 521 |
| 526 std::vector<const PasswordForm*> forms; | 522 std::vector<const PasswordForm*> forms; |
| 527 forms.push_back(&form_google_); | 523 forms.push_back(&form_google_); |
| 528 ExpectationArray expected; | 524 ExpectationArray expected; |
| 529 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 525 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
| 530 CheckPasswordForms("Chrome Form Data (42)", expected); | 526 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 531 } | 527 } |
| 532 | 528 |
| 533 TEST_F(NativeBackendKWalletTest, BasicListLogins) { | 529 TEST_F(NativeBackendKWalletTest, BasicListLogins) { |
| 534 // Pretend that the migration has already taken place. | 530 NativeBackendKWalletStub backend(42); |
| 535 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 536 | |
| 537 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 538 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 531 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 539 | 532 |
| 540 BrowserThread::PostTask( | 533 BrowserThread::PostTask( |
| 541 BrowserThread::DB, FROM_HERE, | 534 BrowserThread::DB, FROM_HERE, |
| 542 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 535 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 543 base::Unretained(&backend), form_google_)); | 536 base::Unretained(&backend), form_google_)); |
| 544 | 537 |
| 545 std::vector<PasswordForm*> form_list; | 538 std::vector<PasswordForm*> form_list; |
| 546 BrowserThread::PostTask( | 539 BrowserThread::PostTask( |
| 547 BrowserThread::DB, FROM_HERE, | 540 BrowserThread::DB, FROM_HERE, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 558 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 551 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
| 559 | 552 |
| 560 std::vector<const PasswordForm*> forms; | 553 std::vector<const PasswordForm*> forms; |
| 561 forms.push_back(&form_google_); | 554 forms.push_back(&form_google_); |
| 562 ExpectationArray expected; | 555 ExpectationArray expected; |
| 563 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 556 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
| 564 CheckPasswordForms("Chrome Form Data (42)", expected); | 557 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 565 } | 558 } |
| 566 | 559 |
| 567 TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { | 560 TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { |
| 568 // Pretend that the migration has already taken place. | 561 NativeBackendKWalletStub backend(42); |
| 569 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 570 | |
| 571 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 572 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 562 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 573 | 563 |
| 574 BrowserThread::PostTask( | 564 BrowserThread::PostTask( |
| 575 BrowserThread::DB, FROM_HERE, | 565 BrowserThread::DB, FROM_HERE, |
| 576 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 566 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 577 base::Unretained(&backend), form_google_)); | 567 base::Unretained(&backend), form_google_)); |
| 578 | 568 |
| 579 RunDBThread(); | 569 RunDBThread(); |
| 580 | 570 |
| 581 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 571 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
| 582 | 572 |
| 583 std::vector<const PasswordForm*> forms; | 573 std::vector<const PasswordForm*> forms; |
| 584 forms.push_back(&form_google_); | 574 forms.push_back(&form_google_); |
| 585 ExpectationArray expected; | 575 ExpectationArray expected; |
| 586 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 576 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
| 587 CheckPasswordForms("Chrome Form Data (42)", expected); | 577 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 588 | 578 |
| 589 BrowserThread::PostTask( | 579 BrowserThread::PostTask( |
| 590 BrowserThread::DB, FROM_HERE, | 580 BrowserThread::DB, FROM_HERE, |
| 591 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::RemoveLogin), | 581 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::RemoveLogin), |
| 592 base::Unretained(&backend), form_google_)); | 582 base::Unretained(&backend), form_google_)); |
| 593 | 583 |
| 594 RunDBThread(); | 584 RunDBThread(); |
| 595 | 585 |
| 596 expected.clear(); | 586 expected.clear(); |
| 597 CheckPasswordForms("Chrome Form Data (42)", expected); | 587 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 598 } | 588 } |
| 599 | 589 |
| 600 TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { | 590 TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { |
| 601 // Pretend that the migration has already taken place. | 591 NativeBackendKWalletStub backend(42); |
| 602 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 603 | |
| 604 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 605 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 592 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 606 | 593 |
| 607 // First add an unrelated login. | 594 // First add an unrelated login. |
| 608 BrowserThread::PostTask( | 595 BrowserThread::PostTask( |
| 609 BrowserThread::DB, FROM_HERE, | 596 BrowserThread::DB, FROM_HERE, |
| 610 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 597 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 611 base::Unretained(&backend), form_google_)); | 598 base::Unretained(&backend), form_google_)); |
| 612 | 599 |
| 613 RunDBThread(); | 600 RunDBThread(); |
| 614 | 601 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 637 RunDBThread(); | 624 RunDBThread(); |
| 638 | 625 |
| 639 // Quick check that we got something back. | 626 // Quick check that we got something back. |
| 640 EXPECT_EQ(1u, form_list.size()); | 627 EXPECT_EQ(1u, form_list.size()); |
| 641 STLDeleteElements(&form_list); | 628 STLDeleteElements(&form_list); |
| 642 | 629 |
| 643 CheckPasswordForms("Chrome Form Data (42)", expected); | 630 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 644 } | 631 } |
| 645 | 632 |
| 646 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { | 633 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { |
| 647 // Pretend that the migration has already taken place. | 634 NativeBackendKWalletStub backend(42); |
| 648 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 649 | |
| 650 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 651 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 635 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 652 | 636 |
| 653 BrowserThread::PostTask( | 637 BrowserThread::PostTask( |
| 654 BrowserThread::DB, FROM_HERE, | 638 BrowserThread::DB, FROM_HERE, |
| 655 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 639 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 656 base::Unretained(&backend), form_google_)); | 640 base::Unretained(&backend), form_google_)); |
| 657 BrowserThread::PostTask( | 641 BrowserThread::PostTask( |
| 658 BrowserThread::DB, FROM_HERE, | 642 BrowserThread::DB, FROM_HERE, |
| 659 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 643 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 660 base::Unretained(&backend), form_google_)); | 644 base::Unretained(&backend), form_google_)); |
| 661 | 645 |
| 662 RunDBThread(); | 646 RunDBThread(); |
| 663 | 647 |
| 664 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 648 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
| 665 | 649 |
| 666 std::vector<const PasswordForm*> forms; | 650 std::vector<const PasswordForm*> forms; |
| 667 forms.push_back(&form_google_); | 651 forms.push_back(&form_google_); |
| 668 ExpectationArray expected; | 652 ExpectationArray expected; |
| 669 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 653 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
| 670 CheckPasswordForms("Chrome Form Data (42)", expected); | 654 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 671 } | 655 } |
| 672 | 656 |
| 673 TEST_F(NativeBackendKWalletTest, ListLoginsAppends) { | 657 TEST_F(NativeBackendKWalletTest, ListLoginsAppends) { |
| 674 // Pretend that the migration has already taken place. | 658 NativeBackendKWalletStub backend(42); |
| 675 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 676 | |
| 677 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 678 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 659 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 679 | 660 |
| 680 BrowserThread::PostTask( | 661 BrowserThread::PostTask( |
| 681 BrowserThread::DB, FROM_HERE, | 662 BrowserThread::DB, FROM_HERE, |
| 682 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 663 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 683 base::Unretained(&backend), form_google_)); | 664 base::Unretained(&backend), form_google_)); |
| 684 | 665 |
| 685 // Send the same request twice with the same list both times. | 666 // Send the same request twice with the same list both times. |
| 686 std::vector<PasswordForm*> form_list; | 667 std::vector<PasswordForm*> form_list; |
| 687 BrowserThread::PostTask( | 668 BrowserThread::PostTask( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 703 | 684 |
| 704 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 685 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
| 705 | 686 |
| 706 std::vector<const PasswordForm*> forms; | 687 std::vector<const PasswordForm*> forms; |
| 707 forms.push_back(&form_google_); | 688 forms.push_back(&form_google_); |
| 708 ExpectationArray expected; | 689 ExpectationArray expected; |
| 709 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 690 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
| 710 CheckPasswordForms("Chrome Form Data (42)", expected); | 691 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 711 } | 692 } |
| 712 | 693 |
| 713 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. | 694 // TODO(mdm): add more basic tests here at some point. |
| 714 // (For example tests for storing >1 password per realm pickle.) | 695 // (For example tests for storing >1 password per realm pickle.) |
| 715 | 696 |
| 716 TEST_F(NativeBackendKWalletTest, DISABLED_MigrateOneLogin) { | |
| 717 // Reject attempts to migrate so we can populate the store. | |
| 718 wallet_.set_reject_local_folders(true); | |
| 719 | |
| 720 { | |
| 721 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 722 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 723 | |
| 724 BrowserThread::PostTask( | |
| 725 BrowserThread::DB, FROM_HERE, | |
| 726 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
| 727 base::Unretained(&backend), form_google_)); | |
| 728 | |
| 729 // Make sure we can get the form back even when migration is failing. | |
| 730 std::vector<PasswordForm*> form_list; | |
| 731 BrowserThread::PostTask( | |
| 732 BrowserThread::DB, FROM_HERE, | |
| 733 base::Bind( | |
| 734 base::IgnoreResult( | |
| 735 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 736 base::Unretained(&backend), &form_list)); | |
| 737 | |
| 738 RunDBThread(); | |
| 739 | |
| 740 // Quick check that we got something back. | |
| 741 EXPECT_EQ(1u, form_list.size()); | |
| 742 STLDeleteElements(&form_list); | |
| 743 } | |
| 744 | |
| 745 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); | |
| 746 | |
| 747 std::vector<const PasswordForm*> forms; | |
| 748 forms.push_back(&form_google_); | |
| 749 ExpectationArray expected; | |
| 750 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | |
| 751 CheckPasswordForms("Chrome Form Data", expected); | |
| 752 | |
| 753 // Now allow the migration. | |
| 754 wallet_.set_reject_local_folders(false); | |
| 755 | |
| 756 { | |
| 757 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 758 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 759 | |
| 760 // Trigger the migration by looking something up. | |
| 761 std::vector<PasswordForm*> form_list; | |
| 762 BrowserThread::PostTask( | |
| 763 BrowserThread::DB, FROM_HERE, | |
| 764 base::Bind( | |
| 765 base::IgnoreResult( | |
| 766 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 767 base::Unretained(&backend), &form_list)); | |
| 768 | |
| 769 RunDBThread(); | |
| 770 | |
| 771 // Quick check that we got something back. | |
| 772 EXPECT_EQ(1u, form_list.size()); | |
| 773 STLDeleteElements(&form_list); | |
| 774 } | |
| 775 | |
| 776 CheckPasswordForms("Chrome Form Data", expected); | |
| 777 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 778 | |
| 779 // Check that we have set the persistent preference. | |
| 780 EXPECT_TRUE( | |
| 781 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
| 782 } | |
| 783 | |
| 784 TEST_F(NativeBackendKWalletTest, DISABLED_MigrateToMultipleProfiles) { | |
| 785 // Reject attempts to migrate so we can populate the store. | |
| 786 wallet_.set_reject_local_folders(true); | |
| 787 | |
| 788 { | |
| 789 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 790 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 791 | |
| 792 BrowserThread::PostTask( | |
| 793 BrowserThread::DB, FROM_HERE, | |
| 794 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
| 795 base::Unretained(&backend), form_google_)); | |
| 796 | |
| 797 RunDBThread(); | |
| 798 } | |
| 799 | |
| 800 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); | |
| 801 | |
| 802 std::vector<const PasswordForm*> forms; | |
| 803 forms.push_back(&form_google_); | |
| 804 ExpectationArray expected; | |
| 805 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | |
| 806 CheckPasswordForms("Chrome Form Data", expected); | |
| 807 | |
| 808 // Now allow the migration. | |
| 809 wallet_.set_reject_local_folders(false); | |
| 810 | |
| 811 { | |
| 812 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 813 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 814 | |
| 815 // Trigger the migration by looking something up. | |
| 816 std::vector<PasswordForm*> form_list; | |
| 817 BrowserThread::PostTask( | |
| 818 BrowserThread::DB, FROM_HERE, | |
| 819 base::Bind( | |
| 820 base::IgnoreResult( | |
| 821 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 822 base::Unretained(&backend), &form_list)); | |
| 823 | |
| 824 RunDBThread(); | |
| 825 | |
| 826 // Quick check that we got something back. | |
| 827 EXPECT_EQ(1u, form_list.size()); | |
| 828 STLDeleteElements(&form_list); | |
| 829 } | |
| 830 | |
| 831 CheckPasswordForms("Chrome Form Data", expected); | |
| 832 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 833 | |
| 834 // Check that we have set the persistent preference. | |
| 835 EXPECT_TRUE( | |
| 836 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
| 837 | |
| 838 // Normally we'd actually have a different profile. But in the test just reset | |
| 839 // the profile's persistent pref; we pass in the local profile id anyway. | |
| 840 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | |
| 841 | |
| 842 { | |
| 843 NativeBackendKWalletStub backend(24, profile_.GetPrefs()); | |
| 844 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 845 | |
| 846 // Trigger the migration by looking something up. | |
| 847 std::vector<PasswordForm*> form_list; | |
| 848 BrowserThread::PostTask( | |
| 849 BrowserThread::DB, FROM_HERE, | |
| 850 base::Bind( | |
| 851 base::IgnoreResult( | |
| 852 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 853 base::Unretained(&backend), &form_list)); | |
| 854 | |
| 855 RunDBThread(); | |
| 856 | |
| 857 // Quick check that we got something back. | |
| 858 EXPECT_EQ(1u, form_list.size()); | |
| 859 STLDeleteElements(&form_list); | |
| 860 } | |
| 861 | |
| 862 CheckPasswordForms("Chrome Form Data", expected); | |
| 863 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 864 CheckPasswordForms("Chrome Form Data (24)", expected); | |
| 865 } | |
| 866 | |
| 867 TEST_F(NativeBackendKWalletTest, DISABLED_NoMigrationWithPrefSet) { | |
| 868 // Reject attempts to migrate so we can populate the store. | |
| 869 wallet_.set_reject_local_folders(true); | |
| 870 | |
| 871 { | |
| 872 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 873 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 874 | |
| 875 BrowserThread::PostTask( | |
| 876 BrowserThread::DB, FROM_HERE, | |
| 877 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
| 878 base::Unretained(&backend), form_google_)); | |
| 879 | |
| 880 RunDBThread(); | |
| 881 } | |
| 882 | |
| 883 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); | |
| 884 | |
| 885 std::vector<const PasswordForm*> forms; | |
| 886 forms.push_back(&form_google_); | |
| 887 ExpectationArray expected; | |
| 888 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | |
| 889 CheckPasswordForms("Chrome Form Data", expected); | |
| 890 | |
| 891 // Now allow migration, but also pretend that the it has already taken place. | |
| 892 wallet_.set_reject_local_folders(false); | |
| 893 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | |
| 894 | |
| 895 { | |
| 896 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 897 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 898 | |
| 899 // Trigger the migration by adding a new login. | |
| 900 BrowserThread::PostTask( | |
| 901 BrowserThread::DB, FROM_HERE, | |
| 902 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::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( | |
| 911 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 912 base::Unretained(&backend), &form_list)); | |
| 913 | |
| 914 RunDBThread(); | |
| 915 | |
| 916 // Quick check that we got the right thing back. | |
| 917 EXPECT_EQ(1u, form_list.size()); | |
| 918 if (form_list.size() > 0) | |
| 919 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); | |
| 920 STLDeleteElements(&form_list); | |
| 921 } | |
| 922 | |
| 923 CheckPasswordForms("Chrome Form Data", expected); | |
| 924 | |
| 925 forms[0] = &form_isc_; | |
| 926 expected.clear(); | |
| 927 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms)); | |
| 928 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 929 } | |
| 930 | |
| 931 TEST_F(NativeBackendKWalletTest, DISABLED_DeleteMigratedPasswordIsIsolated) { | |
| 932 // Reject attempts to migrate so we can populate the store. | |
| 933 wallet_.set_reject_local_folders(true); | |
| 934 | |
| 935 { | |
| 936 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 937 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 938 | |
| 939 BrowserThread::PostTask( | |
| 940 BrowserThread::DB, FROM_HERE, | |
| 941 base::Bind( | |
| 942 base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
| 943 base::Unretained(&backend), form_google_)); | |
| 944 | |
| 945 RunDBThread(); | |
| 946 } | |
| 947 | |
| 948 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)")); | |
| 949 | |
| 950 std::vector<const PasswordForm*> forms; | |
| 951 forms.push_back(&form_google_); | |
| 952 ExpectationArray expected; | |
| 953 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | |
| 954 CheckPasswordForms("Chrome Form Data", expected); | |
| 955 | |
| 956 // Now allow the migration. | |
| 957 wallet_.set_reject_local_folders(false); | |
| 958 | |
| 959 { | |
| 960 NativeBackendKWalletStub backend(42, profile_.GetPrefs()); | |
| 961 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 962 | |
| 963 // Trigger the migration by looking something up. | |
| 964 std::vector<PasswordForm*> form_list; | |
| 965 BrowserThread::PostTask( | |
| 966 BrowserThread::DB, FROM_HERE, | |
| 967 base::Bind( | |
| 968 base::IgnoreResult( | |
| 969 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 970 base::Unretained(&backend), &form_list)); | |
| 971 | |
| 972 RunDBThread(); | |
| 973 | |
| 974 // Quick check that we got something back. | |
| 975 EXPECT_EQ(1u, form_list.size()); | |
| 976 STLDeleteElements(&form_list); | |
| 977 } | |
| 978 | |
| 979 CheckPasswordForms("Chrome Form Data", expected); | |
| 980 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 981 | |
| 982 // Check that we have set the persistent preference. | |
| 983 EXPECT_TRUE( | |
| 984 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | |
| 985 | |
| 986 // Normally we'd actually have a different profile. But in the test just reset | |
| 987 // the profile's persistent pref; we pass in the local profile id anyway. | |
| 988 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | |
| 989 | |
| 990 { | |
| 991 NativeBackendKWalletStub backend(24, profile_.GetPrefs()); | |
| 992 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | |
| 993 | |
| 994 // Trigger the migration by looking something up. | |
| 995 std::vector<PasswordForm*> form_list; | |
| 996 BrowserThread::PostTask( | |
| 997 BrowserThread::DB, FROM_HERE, | |
| 998 base::Bind( | |
| 999 base::IgnoreResult( | |
| 1000 &NativeBackendKWalletStub::GetAutofillableLogins), | |
| 1001 base::Unretained(&backend), &form_list)); | |
| 1002 | |
| 1003 RunDBThread(); | |
| 1004 | |
| 1005 // Quick check that we got something back. | |
| 1006 EXPECT_EQ(1u, form_list.size()); | |
| 1007 STLDeleteElements(&form_list); | |
| 1008 | |
| 1009 // There should be three passwords now. | |
| 1010 CheckPasswordForms("Chrome Form Data", expected); | |
| 1011 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 1012 CheckPasswordForms("Chrome Form Data (24)", expected); | |
| 1013 | |
| 1014 // Now delete the password from this second profile. | |
| 1015 BrowserThread::PostTask( | |
| 1016 BrowserThread::DB, FROM_HERE, | |
| 1017 base::Bind( | |
| 1018 base::IgnoreResult(&NativeBackendKWalletStub::RemoveLogin), | |
| 1019 base::Unretained(&backend), form_google_)); | |
| 1020 | |
| 1021 RunDBThread(); | |
| 1022 | |
| 1023 // The other two copies of the password in different profiles should remain. | |
| 1024 CheckPasswordForms("Chrome Form Data", expected); | |
| 1025 CheckPasswordForms("Chrome Form Data (42)", expected); | |
| 1026 expected.clear(); | |
| 1027 CheckPasswordForms("Chrome Form Data (24)", expected); | |
| 1028 } | |
| 1029 } | |
| 1030 | |
| 1031 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { | 697 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { |
| 1032 protected: | 698 protected: |
| 1033 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); | 699 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); |
| 1034 void CreateVersion0Pickle(bool size_32, | 700 void CreateVersion0Pickle(bool size_32, |
| 1035 const PasswordForm& form, | 701 const PasswordForm& form, |
| 1036 Pickle* pickle); | 702 Pickle* pickle); |
| 1037 void CheckVersion1Pickle(); | 703 void CheckVersion1Pickle(); |
| 1038 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); | 704 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); |
| 1039 | 705 |
| 1040 private: | 706 private: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); | 792 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); |
| 1127 } | 793 } |
| 1128 | 794 |
| 1129 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { | 795 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { |
| 1130 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); | 796 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); |
| 1131 } | 797 } |
| 1132 | 798 |
| 1133 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { | 799 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { |
| 1134 CheckVersion1Pickle(); | 800 CheckVersion1Pickle(); |
| 1135 } | 801 } |
| OLD | NEW |