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

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

Issue 2799883003: Switch from TestBrowserThread to TestBrowserThreadBundle in chrome. (Closed)
Patch Set: fix-string Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdarg.h> 5 #include <stdarg.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "chrome/browser/password_manager/native_backend_gnome_x.h" 22 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/autofill/core/common/password_form.h" 24 #include "components/autofill/core/common/password_form.h"
25 #include "components/password_manager/core/browser/psl_matching_helper.h" 25 #include "components/password_manager/core/browser/psl_matching_helper.h"
26 #include "components/password_manager/core/common/password_manager_pref_names.h" 26 #include "components/password_manager/core/common/password_manager_pref_names.h"
27 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h"
29 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 33
32 using autofill::PasswordForm; 34 using autofill::PasswordForm;
33 using base::UTF8ToUTF16; 35 using base::UTF8ToUTF16;
34 using base::UTF16ToUTF8; 36 using base::UTF16ToUTF8;
35 using content::BrowserThread; 37 using content::BrowserThread;
36 using password_manager::PasswordStore; 38 using password_manager::PasswordStore;
37 using password_manager::PasswordStoreChange; 39 using password_manager::PasswordStoreChange;
38 using password_manager::PasswordStoreChangeList; 40 using password_manager::PasswordStoreChangeList;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 enum UpdateType { // Used in CheckPSLUpdate(). 355 enum UpdateType { // Used in CheckPSLUpdate().
354 UPDATE_BY_UPDATELOGIN, 356 UPDATE_BY_UPDATELOGIN,
355 UPDATE_BY_ADDLOGIN, 357 UPDATE_BY_ADDLOGIN,
356 }; 358 };
357 enum RemoveBetweenMethod { // Used in CheckRemoveLoginsBetween(). 359 enum RemoveBetweenMethod { // Used in CheckRemoveLoginsBetween().
358 CREATED, 360 CREATED,
359 SYNCED, 361 SYNCED,
360 }; 362 };
361 363
362 NativeBackendGnomeTest() 364 NativeBackendGnomeTest()
363 : ui_thread_(BrowserThread::UI, &message_loop_), 365 : test_browser_thread_bundle_(
364 db_thread_(BrowserThread::DB) { 366 content::TestBrowserThreadBundle::REAL_DB_THREAD) {}
365 }
366 367
367 void SetUp() override { 368 void SetUp() override {
368 ASSERT_TRUE(db_thread_.Start());
369
370 ASSERT_TRUE(MockGnomeKeyringLoader::LoadMockGnomeKeyring()); 369 ASSERT_TRUE(MockGnomeKeyringLoader::LoadMockGnomeKeyring());
371 370
372 form_google_.origin = GURL("http://www.google.com/"); 371 form_google_.origin = GURL("http://www.google.com/");
373 form_google_.action = GURL("http://www.google.com/login"); 372 form_google_.action = GURL("http://www.google.com/login");
374 form_google_.username_element = UTF8ToUTF16("user"); 373 form_google_.username_element = UTF8ToUTF16("user");
375 form_google_.username_value = UTF8ToUTF16("joeschmoe"); 374 form_google_.username_value = UTF8ToUTF16("joeschmoe");
376 form_google_.password_element = UTF8ToUTF16("pass"); 375 form_google_.password_element = UTF8ToUTF16("pass");
377 form_google_.password_value = UTF8ToUTF16("seekrit"); 376 form_google_.password_value = UTF8ToUTF16("seekrit");
378 form_google_.submit_element = UTF8ToUTF16("submit"); 377 form_google_.submit_element = UTF8ToUTF16("submit");
379 form_google_.signon_realm = "http://www.google.com/"; 378 form_google_.signon_realm = "http://www.google.com/";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 form_isc_.date_synced = base::Time::Now(); 416 form_isc_.date_synced = base::Time::Now();
418 417
419 other_auth_.origin = GURL("http://www.example.com/"); 418 other_auth_.origin = GURL("http://www.example.com/");
420 other_auth_.username_value = UTF8ToUTF16("username"); 419 other_auth_.username_value = UTF8ToUTF16("username");
421 other_auth_.password_value = UTF8ToUTF16("pass"); 420 other_auth_.password_value = UTF8ToUTF16("pass");
422 other_auth_.signon_realm = "http://www.example.com/Realm"; 421 other_auth_.signon_realm = "http://www.example.com/Realm";
423 other_auth_.date_created = base::Time::Now(); 422 other_auth_.date_created = base::Time::Now();
424 other_auth_.date_synced = base::Time::Now(); 423 other_auth_.date_synced = base::Time::Now();
425 } 424 }
426 425
427 void TearDown() override {
428 base::ThreadTaskRunnerHandle::Get()->PostTask(
429 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
430 base::RunLoop().Run();
431 db_thread_.Stop();
432 }
433
434 void RunBothThreads() {
435 // First we post a message to the DB thread that will run after all other
436 // messages that have been posted to the DB thread (we don't expect more
437 // to be posted), which posts a message to the UI thread to quit the loop.
438 // That way we can run both loops and be sure that the UI thread loop will
439 // quit so we can get on with the rest of the test.
440 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
441 base::BindOnce(&PostQuitTask, &message_loop_));
442 base::RunLoop().Run();
443 }
444
445 static void PostQuitTask(base::MessageLoop* loop) {
446 loop->task_runner()->PostTask(FROM_HERE,
447 base::MessageLoop::QuitWhenIdleClosure());
448 }
449
450 void CheckUint32Attribute(const MockKeyringItem* item, 426 void CheckUint32Attribute(const MockKeyringItem* item,
451 const std::string& attribute, 427 const std::string& attribute,
452 uint32_t value) { 428 uint32_t value) {
453 MockKeyringItem::attribute_map::const_iterator it = 429 MockKeyringItem::attribute_map::const_iterator it =
454 item->attributes.find(attribute); 430 item->attributes.find(attribute);
455 EXPECT_NE(item->attributes.end(), it); 431 EXPECT_NE(item->attributes.end(), it);
456 if (it != item->attributes.end()) { 432 if (it != item->attributes.end()) {
457 EXPECT_EQ(MockKeyringItem::ItemAttribute::UINT32, it->second.type); 433 EXPECT_EQ(MockKeyringItem::ItemAttribute::UINT32, it->second.type);
458 EXPECT_EQ(value, it->second.value_uint32); 434 EXPECT_EQ(value, it->second.value_uint32);
459 } 435 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 std::vector<std::unique_ptr<PasswordForm>> form_list; 518 std::vector<std::unique_ptr<PasswordForm>> form_list;
543 BrowserThread::PostTaskAndReplyWithResult( 519 BrowserThread::PostTaskAndReplyWithResult(
544 BrowserThread::DB, 520 BrowserThread::DB,
545 FROM_HERE, 521 FROM_HERE,
546 base::Bind(&NativeBackendGnome::GetLogins, 522 base::Bind(&NativeBackendGnome::GetLogins,
547 base::Unretained(&backend), 523 base::Unretained(&backend),
548 target_form, 524 target_form,
549 &form_list), 525 &form_list),
550 base::Bind(&CheckTrue)); 526 base::Bind(&CheckTrue));
551 527
552 RunBothThreads(); 528 content::RunAllPendingInMessageLoop(BrowserThread::DB);
553 529
554 EXPECT_EQ(1u, mock_keyring_items.size()); 530 EXPECT_EQ(1u, mock_keyring_items.size());
555 if (mock_keyring_items.size() > 0) 531 if (mock_keyring_items.size() > 0)
556 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321"); 532 CheckMockKeyringItem(&mock_keyring_items[0], credentials, "chrome-321");
557 mock_keyring_items.clear(); 533 mock_keyring_items.clear();
558 534
559 if (form_list.empty()) 535 if (form_list.empty())
560 return false; 536 return false;
561 EXPECT_EQ(1u, form_list.size()); 537 EXPECT_EQ(1u, form_list.size());
562 if (result) 538 if (result)
(...skipping 27 matching lines...) Expand all
590 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; 566 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL};
591 std::vector<std::unique_ptr<PasswordForm>> form_list; 567 std::vector<std::unique_ptr<PasswordForm>> form_list;
592 BrowserThread::PostTaskAndReplyWithResult( 568 BrowserThread::PostTaskAndReplyWithResult(
593 BrowserThread::DB, 569 BrowserThread::DB,
594 FROM_HERE, 570 FROM_HERE,
595 base::Bind(&NativeBackendGnome::GetLogins, 571 base::Bind(&NativeBackendGnome::GetLogins,
596 base::Unretained(&backend), 572 base::Unretained(&backend),
597 m_facebook_lookup, 573 m_facebook_lookup,
598 &form_list), 574 &form_list),
599 base::Bind(&CheckTrue)); 575 base::Bind(&CheckTrue));
600 RunBothThreads(); 576 content::RunAllPendingInMessageLoop(BrowserThread::DB);
601 EXPECT_EQ(1u, mock_keyring_items.size()); 577 EXPECT_EQ(1u, mock_keyring_items.size());
602 EXPECT_EQ(1u, form_list.size()); 578 EXPECT_EQ(1u, form_list.size());
603 PasswordForm m_facebook = *form_list[0]; 579 PasswordForm m_facebook = *form_list[0];
604 form_list.clear(); 580 form_list.clear();
605 m_facebook.origin = kMobileURL; 581 m_facebook.origin = kMobileURL;
606 m_facebook.signon_realm = kMobileURL.spec(); 582 m_facebook.signon_realm = kMobileURL.spec();
607 583
608 // Add the PSL-matched copy to saved logins. 584 // Add the PSL-matched copy to saved logins.
609 BrowserThread::PostTask( 585 BrowserThread::PostTask(
610 BrowserThread::DB, FROM_HERE, 586 BrowserThread::DB, FROM_HERE,
611 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 587 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
612 base::Unretained(&backend), m_facebook)); 588 base::Unretained(&backend), m_facebook));
613 RunBothThreads(); 589 content::RunAllPendingInMessageLoop(BrowserThread::DB);
614 EXPECT_EQ(2u, mock_keyring_items.size()); 590 EXPECT_EQ(2u, mock_keyring_items.size());
615 591
616 // Update www.facebook.com login. 592 // Update www.facebook.com login.
617 PasswordForm new_facebook(form_facebook_); 593 PasswordForm new_facebook(form_facebook_);
618 const base::string16 kOldPassword(form_facebook_.password_value); 594 const base::string16 kOldPassword(form_facebook_.password_value);
619 const base::string16 kNewPassword(UTF8ToUTF16("new_b")); 595 const base::string16 kNewPassword(UTF8ToUTF16("new_b"));
620 EXPECT_NE(kOldPassword, kNewPassword); 596 EXPECT_NE(kOldPassword, kNewPassword);
621 new_facebook.password_value = kNewPassword; 597 new_facebook.password_value = kNewPassword;
622 PasswordStoreChangeList changes; 598 PasswordStoreChangeList changes;
623 PasswordStoreChangeList expected_changes; 599 PasswordStoreChangeList expected_changes;
(...skipping 19 matching lines...) Expand all
643 BrowserThread::PostTaskAndReplyWithResult( 619 BrowserThread::PostTaskAndReplyWithResult(
644 BrowserThread::DB, 620 BrowserThread::DB,
645 FROM_HERE, 621 FROM_HERE,
646 base::Bind(&NativeBackendGnome::AddLogin, 622 base::Bind(&NativeBackendGnome::AddLogin,
647 base::Unretained(&backend), 623 base::Unretained(&backend),
648 new_facebook), 624 new_facebook),
649 base::Bind(&CheckPasswordChanges, expected_changes)); 625 base::Bind(&CheckPasswordChanges, expected_changes));
650 break; 626 break;
651 } 627 }
652 628
653 RunBothThreads(); 629 content::RunAllPendingInMessageLoop(BrowserThread::DB);
654 EXPECT_EQ(2u, mock_keyring_items.size()); 630 EXPECT_EQ(2u, mock_keyring_items.size());
655 631
656 // Check that m.facebook.com login was not modified by the update. 632 // Check that m.facebook.com login was not modified by the update.
657 BrowserThread::PostTaskAndReplyWithResult( 633 BrowserThread::PostTaskAndReplyWithResult(
658 BrowserThread::DB, 634 BrowserThread::DB,
659 FROM_HERE, 635 FROM_HERE,
660 base::Bind(&NativeBackendGnome::GetLogins, 636 base::Bind(&NativeBackendGnome::GetLogins,
661 base::Unretained(&backend), 637 base::Unretained(&backend),
662 m_facebook_lookup, 638 m_facebook_lookup,
663 &form_list), 639 &form_list),
664 base::Bind(&CheckTrue)); 640 base::Bind(&CheckTrue));
665 RunBothThreads(); 641 content::RunAllPendingInMessageLoop(BrowserThread::DB);
666 // There should be two results -- the exact one, and the PSL-matched one. 642 // There should be two results -- the exact one, and the PSL-matched one.
667 EXPECT_EQ(2u, form_list.size()); 643 EXPECT_EQ(2u, form_list.size());
668 size_t index_non_psl = 0; 644 size_t index_non_psl = 0;
669 if (form_list[index_non_psl]->is_public_suffix_match) 645 if (form_list[index_non_psl]->is_public_suffix_match)
670 index_non_psl = 1; 646 index_non_psl = 1;
671 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin); 647 EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin);
672 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm); 648 EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm);
673 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value); 649 EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value);
674 form_list.clear(); 650 form_list.clear();
675 651
676 // Check that www.facebook.com login was modified by the update. 652 // Check that www.facebook.com login was modified by the update.
677 BrowserThread::PostTaskAndReplyWithResult( 653 BrowserThread::PostTaskAndReplyWithResult(
678 BrowserThread::DB, FROM_HERE, 654 BrowserThread::DB, FROM_HERE,
679 base::Bind(&NativeBackendGnome::GetLogins, base::Unretained(&backend), 655 base::Bind(&NativeBackendGnome::GetLogins, base::Unretained(&backend),
680 PasswordStore::FormDigest(form_facebook_), &form_list), 656 PasswordStore::FormDigest(form_facebook_), &form_list),
681 base::Bind(&CheckTrue)); 657 base::Bind(&CheckTrue));
682 RunBothThreads(); 658 content::RunAllPendingInMessageLoop(BrowserThread::DB);
683 // There should be two results -- the exact one, and the PSL-matched one. 659 // There should be two results -- the exact one, and the PSL-matched one.
684 EXPECT_EQ(2u, form_list.size()); 660 EXPECT_EQ(2u, form_list.size());
685 index_non_psl = 0; 661 index_non_psl = 0;
686 if (form_list[index_non_psl]->is_public_suffix_match) 662 if (form_list[index_non_psl]->is_public_suffix_match)
687 index_non_psl = 1; 663 index_non_psl = 1;
688 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin); 664 EXPECT_EQ(form_facebook_.origin, form_list[index_non_psl]->origin);
689 EXPECT_EQ(form_facebook_.signon_realm, 665 EXPECT_EQ(form_facebook_.signon_realm,
690 form_list[index_non_psl]->signon_realm); 666 form_list[index_non_psl]->signon_realm);
691 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); 667 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
692 } 668 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 BrowserThread::PostTaskAndReplyWithResult( 724 BrowserThread::PostTaskAndReplyWithResult(
749 BrowserThread::DB, 725 BrowserThread::DB,
750 FROM_HERE, 726 FROM_HERE,
751 base::Bind(method, 727 base::Bind(method,
752 base::Unretained(&backend), 728 base::Unretained(&backend),
753 base::Time(), 729 base::Time(),
754 next_day, 730 next_day,
755 &changes), 731 &changes),
756 base::Bind( 732 base::Bind(
757 &CheckPasswordChangesWithResult, &expected_changes, &changes)); 733 &CheckPasswordChangesWithResult, &expected_changes, &changes));
758 RunBothThreads(); 734 content::RunAllPendingInMessageLoop(BrowserThread::DB);
759 735
760 EXPECT_EQ(1u, mock_keyring_items.size()); 736 EXPECT_EQ(1u, mock_keyring_items.size());
761 if (mock_keyring_items.size() > 0) 737 if (mock_keyring_items.size() > 0)
762 CheckMockKeyringItem(&mock_keyring_items[0], form_isc_, "chrome-42"); 738 CheckMockKeyringItem(&mock_keyring_items[0], form_isc_, "chrome-42");
763 739
764 // Remove form_isc_. 740 // Remove form_isc_.
765 expected_changes.clear(); 741 expected_changes.clear();
766 expected_changes.push_back( 742 expected_changes.push_back(
767 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); 743 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_));
768 BrowserThread::PostTaskAndReplyWithResult( 744 BrowserThread::PostTaskAndReplyWithResult(
769 BrowserThread::DB, 745 BrowserThread::DB,
770 FROM_HERE, 746 FROM_HERE,
771 base::Bind(method, 747 base::Bind(method,
772 base::Unretained(&backend), 748 base::Unretained(&backend),
773 next_day, 749 next_day,
774 base::Time(), 750 base::Time(),
775 &changes), 751 &changes),
776 base::Bind( 752 base::Bind(
777 &CheckPasswordChangesWithResult, &expected_changes, &changes)); 753 &CheckPasswordChangesWithResult, &expected_changes, &changes));
778 RunBothThreads(); 754 content::RunAllPendingInMessageLoop(BrowserThread::DB);
779 755
780 EXPECT_EQ(0u, mock_keyring_items.size()); 756 EXPECT_EQ(0u, mock_keyring_items.size());
781 } 757 }
782 758
783 base::MessageLoopForUI message_loop_; 759 content::TestBrowserThreadBundle test_browser_thread_bundle_;
784 content::TestBrowserThread ui_thread_;
785 content::TestBrowserThread db_thread_;
786 760
787 // Provide some test forms to avoid having to set them up in each test. 761 // Provide some test forms to avoid having to set them up in each test.
788 PasswordForm form_google_; 762 PasswordForm form_google_;
789 PasswordForm form_facebook_; 763 PasswordForm form_facebook_;
790 PasswordForm form_isc_; 764 PasswordForm form_isc_;
791 PasswordForm other_auth_; 765 PasswordForm other_auth_;
792 }; 766 };
793 767
794 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { 768 TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
795 NativeBackendGnome backend(42); 769 NativeBackendGnome backend(42);
796 backend.Init(); 770 backend.Init();
797 771
798 BrowserThread::PostTaskAndReplyWithResult( 772 BrowserThread::PostTaskAndReplyWithResult(
799 BrowserThread::DB, FROM_HERE, 773 BrowserThread::DB, FROM_HERE,
800 base::Bind(&NativeBackendGnome::AddLogin, 774 base::Bind(&NativeBackendGnome::AddLogin,
801 base::Unretained(&backend), form_google_), 775 base::Unretained(&backend), form_google_),
802 base::Bind(&CheckPasswordChanges, 776 base::Bind(&CheckPasswordChanges,
803 PasswordStoreChangeList(1, PasswordStoreChange( 777 PasswordStoreChangeList(1, PasswordStoreChange(
804 PasswordStoreChange::ADD, form_google_)))); 778 PasswordStoreChange::ADD, form_google_))));
805 779
806 RunBothThreads(); 780 content::RunAllPendingInMessageLoop(BrowserThread::DB);
807 781
808 EXPECT_EQ(1u, mock_keyring_items.size()); 782 EXPECT_EQ(1u, mock_keyring_items.size());
809 if (mock_keyring_items.size() > 0) 783 if (mock_keyring_items.size() > 0)
810 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 784 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
811 } 785 }
812 786
813 TEST_F(NativeBackendGnomeTest, BasicListLogins) { 787 TEST_F(NativeBackendGnomeTest, BasicListLogins) {
814 NativeBackendGnome backend(42); 788 NativeBackendGnome backend(42);
815 backend.Init(); 789 backend.Init();
816 790
817 BrowserThread::PostTask( 791 BrowserThread::PostTask(
818 BrowserThread::DB, FROM_HERE, 792 BrowserThread::DB, FROM_HERE,
819 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 793 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
820 base::Unretained(&backend), form_google_)); 794 base::Unretained(&backend), form_google_));
821 795
822 std::vector<std::unique_ptr<PasswordForm>> form_list; 796 std::vector<std::unique_ptr<PasswordForm>> form_list;
823 BrowserThread::PostTaskAndReplyWithResult( 797 BrowserThread::PostTaskAndReplyWithResult(
824 BrowserThread::DB, FROM_HERE, 798 BrowserThread::DB, FROM_HERE,
825 base::Bind(&NativeBackendGnome::GetAutofillableLogins, 799 base::Bind(&NativeBackendGnome::GetAutofillableLogins,
826 base::Unretained(&backend), &form_list), 800 base::Unretained(&backend), &form_list),
827 base::Bind(&CheckTrue)); 801 base::Bind(&CheckTrue));
828 802
829 RunBothThreads(); 803 content::RunAllPendingInMessageLoop(BrowserThread::DB);
830 804
831 // Quick check that we got something back. 805 // Quick check that we got something back.
832 EXPECT_EQ(1u, form_list.size()); 806 EXPECT_EQ(1u, form_list.size());
833 807
834 EXPECT_EQ(1u, mock_keyring_items.size()); 808 EXPECT_EQ(1u, mock_keyring_items.size());
835 if (mock_keyring_items.size() > 0) 809 if (mock_keyring_items.size() > 0)
836 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 810 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
837 } 811 }
838 812
839 // Save a password for www.facebook.com and see it suggested for m.facebook.com. 813 // Save a password for www.facebook.com and see it suggested for m.facebook.com.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) { 900 TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) {
927 NativeBackendGnome backend(42); 901 NativeBackendGnome backend(42);
928 backend.Init(); 902 backend.Init();
929 903
930 // First add google login. 904 // First add google login.
931 BrowserThread::PostTask( 905 BrowserThread::PostTask(
932 BrowserThread::DB, FROM_HERE, 906 BrowserThread::DB, FROM_HERE,
933 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 907 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
934 base::Unretained(&backend), form_google_)); 908 base::Unretained(&backend), form_google_));
935 909
936 RunBothThreads(); 910 content::RunAllPendingInMessageLoop(BrowserThread::DB);
937 911
938 PasswordForm new_form_google(form_google_); 912 PasswordForm new_form_google(form_google_);
939 new_form_google.times_used = 1; 913 new_form_google.times_used = 1;
940 new_form_google.action = GURL("http://www.google.com/different/login"); 914 new_form_google.action = GURL("http://www.google.com/different/login");
941 915
942 EXPECT_EQ(1u, mock_keyring_items.size()); 916 EXPECT_EQ(1u, mock_keyring_items.size());
943 if (mock_keyring_items.size() > 0) 917 if (mock_keyring_items.size() > 0)
944 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 918 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
945 919
946 // Update login 920 // Update login
947 PasswordStoreChangeList changes; 921 PasswordStoreChangeList changes;
948 PasswordStoreChangeList expected_changes( 922 PasswordStoreChangeList expected_changes(
949 1, PasswordStoreChange(PasswordStoreChange::UPDATE, new_form_google)); 923 1, PasswordStoreChange(PasswordStoreChange::UPDATE, new_form_google));
950 BrowserThread::PostTaskAndReplyWithResult( 924 BrowserThread::PostTaskAndReplyWithResult(
951 BrowserThread::DB, FROM_HERE, 925 BrowserThread::DB, FROM_HERE,
952 base::Bind(&NativeBackendGnome::UpdateLogin, 926 base::Bind(&NativeBackendGnome::UpdateLogin,
953 base::Unretained(&backend), 927 base::Unretained(&backend),
954 new_form_google, 928 new_form_google,
955 &changes), 929 &changes),
956 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 930 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
957 RunBothThreads(); 931 content::RunAllPendingInMessageLoop(BrowserThread::DB);
958 932
959 EXPECT_EQ(1u, mock_keyring_items.size()); 933 EXPECT_EQ(1u, mock_keyring_items.size());
960 if (mock_keyring_items.size() > 0) 934 if (mock_keyring_items.size() > 0)
961 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42"); 935 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42");
962 } 936 }
963 937
964 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { 938 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) {
965 NativeBackendGnome backend(42); 939 NativeBackendGnome backend(42);
966 backend.Init(); 940 backend.Init();
967 941
968 BrowserThread::PostTask( 942 BrowserThread::PostTask(
969 BrowserThread::DB, FROM_HERE, 943 BrowserThread::DB, FROM_HERE,
970 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 944 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
971 base::Unretained(&backend), form_google_)); 945 base::Unretained(&backend), form_google_));
972 946
973 RunBothThreads(); 947 content::RunAllPendingInMessageLoop(BrowserThread::DB);
974 948
975 EXPECT_EQ(1u, mock_keyring_items.size()); 949 EXPECT_EQ(1u, mock_keyring_items.size());
976 if (mock_keyring_items.size() > 0) 950 if (mock_keyring_items.size() > 0)
977 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 951 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
978 952
979 PasswordStoreChangeList changes; 953 PasswordStoreChangeList changes;
980 PasswordStoreChangeList expected_changes( 954 PasswordStoreChangeList expected_changes(
981 1, PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); 955 1, PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_));
982 BrowserThread::PostTaskAndReplyWithResult( 956 BrowserThread::PostTaskAndReplyWithResult(
983 BrowserThread::DB, FROM_HERE, 957 BrowserThread::DB, FROM_HERE,
984 base::Bind(&NativeBackendGnome::RemoveLogin, 958 base::Bind(&NativeBackendGnome::RemoveLogin,
985 base::Unretained(&backend), form_google_, &changes), 959 base::Unretained(&backend), form_google_, &changes),
986 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 960 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
987 961
988 RunBothThreads(); 962 content::RunAllPendingInMessageLoop(BrowserThread::DB);
989 963
990 EXPECT_EQ(0u, mock_keyring_items.size()); 964 EXPECT_EQ(0u, mock_keyring_items.size());
991 } 965 }
992 966
993 // Verify fix for http://crbug.com/408783. 967 // Verify fix for http://crbug.com/408783.
994 TEST_F(NativeBackendGnomeTest, RemoveLoginActionMismatch) { 968 TEST_F(NativeBackendGnomeTest, RemoveLoginActionMismatch) {
995 NativeBackendGnome backend(42); 969 NativeBackendGnome backend(42);
996 backend.Init(); 970 backend.Init();
997 971
998 BrowserThread::PostTask( 972 BrowserThread::PostTask(
999 BrowserThread::DB, FROM_HERE, 973 BrowserThread::DB, FROM_HERE,
1000 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 974 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1001 base::Unretained(&backend), form_google_)); 975 base::Unretained(&backend), form_google_));
1002 976
1003 RunBothThreads(); 977 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1004 978
1005 EXPECT_EQ(1u, mock_keyring_items.size()); 979 EXPECT_EQ(1u, mock_keyring_items.size());
1006 if (mock_keyring_items.size() > 0) 980 if (mock_keyring_items.size() > 0)
1007 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 981 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1008 982
1009 // Action url match not required for removal. 983 // Action url match not required for removal.
1010 form_google_.action = GURL("https://some.other.url.com/path"); 984 form_google_.action = GURL("https://some.other.url.com/path");
1011 985
1012 PasswordStoreChangeList changes; 986 PasswordStoreChangeList changes;
1013 PasswordStoreChangeList expected_changes( 987 PasswordStoreChangeList expected_changes(
1014 1, PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); 988 1, PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_));
1015 BrowserThread::PostTaskAndReplyWithResult( 989 BrowserThread::PostTaskAndReplyWithResult(
1016 BrowserThread::DB, FROM_HERE, 990 BrowserThread::DB, FROM_HERE,
1017 base::Bind(&NativeBackendGnome::RemoveLogin, 991 base::Bind(&NativeBackendGnome::RemoveLogin,
1018 base::Unretained(&backend), form_google_, &changes), 992 base::Unretained(&backend), form_google_, &changes),
1019 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 993 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
1020 994
1021 RunBothThreads(); 995 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1022 996
1023 EXPECT_EQ(0u, mock_keyring_items.size()); 997 EXPECT_EQ(0u, mock_keyring_items.size());
1024 } 998 }
1025 999
1026 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { 1000 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
1027 NativeBackendGnome backend(42); 1001 NativeBackendGnome backend(42);
1028 backend.Init(); 1002 backend.Init();
1029 1003
1030 // First add an unrelated login. 1004 // First add an unrelated login.
1031 BrowserThread::PostTask( 1005 BrowserThread::PostTask(
1032 BrowserThread::DB, FROM_HERE, 1006 BrowserThread::DB, FROM_HERE,
1033 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1007 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1034 base::Unretained(&backend), form_google_)); 1008 base::Unretained(&backend), form_google_));
1035 1009
1036 RunBothThreads(); 1010 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1037 1011
1038 EXPECT_EQ(1u, mock_keyring_items.size()); 1012 EXPECT_EQ(1u, mock_keyring_items.size());
1039 if (mock_keyring_items.size() > 0) 1013 if (mock_keyring_items.size() > 0)
1040 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1014 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1041 1015
1042 // Attempt to remove a login that doesn't exist. 1016 // Attempt to remove a login that doesn't exist.
1043 PasswordStoreChangeList changes; 1017 PasswordStoreChangeList changes;
1044 BrowserThread::PostTaskAndReplyWithResult( 1018 BrowserThread::PostTaskAndReplyWithResult(
1045 BrowserThread::DB, FROM_HERE, 1019 BrowserThread::DB, FROM_HERE,
1046 base::Bind(&NativeBackendGnome::RemoveLogin, 1020 base::Bind(&NativeBackendGnome::RemoveLogin,
1047 base::Unretained(&backend), form_isc_, &changes), 1021 base::Unretained(&backend), form_isc_, &changes),
1048 base::Bind(&CheckPasswordChangesWithResult, 1022 base::Bind(&CheckPasswordChangesWithResult,
1049 base::Owned(new PasswordStoreChangeList), &changes)); 1023 base::Owned(new PasswordStoreChangeList), &changes));
1050 1024
1051 // Make sure we can still get the first form back. 1025 // Make sure we can still get the first form back.
1052 std::vector<std::unique_ptr<PasswordForm>> form_list; 1026 std::vector<std::unique_ptr<PasswordForm>> form_list;
1053 BrowserThread::PostTaskAndReplyWithResult( 1027 BrowserThread::PostTaskAndReplyWithResult(
1054 BrowserThread::DB, FROM_HERE, 1028 BrowserThread::DB, FROM_HERE,
1055 base::Bind(&NativeBackendGnome::GetAutofillableLogins, 1029 base::Bind(&NativeBackendGnome::GetAutofillableLogins,
1056 base::Unretained(&backend), &form_list), 1030 base::Unretained(&backend), &form_list),
1057 base::Bind(&CheckTrue)); 1031 base::Bind(&CheckTrue));
1058 1032
1059 RunBothThreads(); 1033 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1060 1034
1061 // Quick check that we got something back. 1035 // Quick check that we got something back.
1062 EXPECT_EQ(1u, form_list.size()); 1036 EXPECT_EQ(1u, form_list.size());
1063 1037
1064 EXPECT_EQ(1u, mock_keyring_items.size()); 1038 EXPECT_EQ(1u, mock_keyring_items.size());
1065 if (mock_keyring_items.size() > 0) 1039 if (mock_keyring_items.size() > 0)
1066 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1040 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1067 } 1041 }
1068 1042
1069 TEST_F(NativeBackendGnomeTest, UpdateNonexistentLogin) { 1043 TEST_F(NativeBackendGnomeTest, UpdateNonexistentLogin) {
1070 NativeBackendGnome backend(42); 1044 NativeBackendGnome backend(42);
1071 backend.Init(); 1045 backend.Init();
1072 1046
1073 // First add an unrelated login. 1047 // First add an unrelated login.
1074 BrowserThread::PostTask( 1048 BrowserThread::PostTask(
1075 BrowserThread::DB, FROM_HERE, 1049 BrowserThread::DB, FROM_HERE,
1076 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1050 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1077 base::Unretained(&backend), form_google_)); 1051 base::Unretained(&backend), form_google_));
1078 1052
1079 RunBothThreads(); 1053 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1080 1054
1081 EXPECT_EQ(1u, mock_keyring_items.size()); 1055 EXPECT_EQ(1u, mock_keyring_items.size());
1082 if (mock_keyring_items.size() > 0) 1056 if (mock_keyring_items.size() > 0)
1083 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1057 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1084 1058
1085 // Attempt to update a login that doesn't exist. 1059 // Attempt to update a login that doesn't exist.
1086 PasswordStoreChangeList changes; 1060 PasswordStoreChangeList changes;
1087 BrowserThread::PostTaskAndReplyWithResult( 1061 BrowserThread::PostTaskAndReplyWithResult(
1088 BrowserThread::DB, FROM_HERE, 1062 BrowserThread::DB, FROM_HERE,
1089 base::Bind(&NativeBackendGnome::UpdateLogin, 1063 base::Bind(&NativeBackendGnome::UpdateLogin,
1090 base::Unretained(&backend), 1064 base::Unretained(&backend),
1091 form_isc_, 1065 form_isc_,
1092 &changes), 1066 &changes),
1093 base::Bind(&CheckPasswordChangesWithResult, 1067 base::Bind(&CheckPasswordChangesWithResult,
1094 base::Owned(new PasswordStoreChangeList), &changes)); 1068 base::Owned(new PasswordStoreChangeList), &changes));
1095 RunBothThreads(); 1069 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1096 1070
1097 EXPECT_EQ(1u, mock_keyring_items.size()); 1071 EXPECT_EQ(1u, mock_keyring_items.size());
1098 if (mock_keyring_items.size() > 0) 1072 if (mock_keyring_items.size() > 0)
1099 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1073 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1100 } 1074 }
1101 1075
1102 TEST_F(NativeBackendGnomeTest, UpdateSameLogin) { 1076 TEST_F(NativeBackendGnomeTest, UpdateSameLogin) {
1103 NativeBackendGnome backend(42); 1077 NativeBackendGnome backend(42);
1104 backend.Init(); 1078 backend.Init();
1105 1079
1106 // First add an unrelated login. 1080 // First add an unrelated login.
1107 BrowserThread::PostTask( 1081 BrowserThread::PostTask(
1108 BrowserThread::DB, FROM_HERE, 1082 BrowserThread::DB, FROM_HERE,
1109 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1083 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1110 base::Unretained(&backend), form_google_)); 1084 base::Unretained(&backend), form_google_));
1111 RunBothThreads(); 1085 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1112 1086
1113 EXPECT_EQ(1u, mock_keyring_items.size()); 1087 EXPECT_EQ(1u, mock_keyring_items.size());
1114 if (mock_keyring_items.size() > 0) 1088 if (mock_keyring_items.size() > 0)
1115 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1089 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1116 1090
1117 // Attempt to update the same login without changing anything. 1091 // Attempt to update the same login without changing anything.
1118 PasswordStoreChangeList changes; 1092 PasswordStoreChangeList changes;
1119 PasswordStoreChangeList expected_changes; 1093 PasswordStoreChangeList expected_changes;
1120 BrowserThread::PostTaskAndReplyWithResult( 1094 BrowserThread::PostTaskAndReplyWithResult(
1121 BrowserThread::DB, FROM_HERE, 1095 BrowserThread::DB, FROM_HERE,
1122 base::Bind(&NativeBackendGnome::UpdateLogin, 1096 base::Bind(&NativeBackendGnome::UpdateLogin,
1123 base::Unretained(&backend), 1097 base::Unretained(&backend),
1124 form_google_, 1098 form_google_,
1125 &changes), 1099 &changes),
1126 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 1100 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
1127 RunBothThreads(); 1101 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1128 1102
1129 EXPECT_EQ(1u, mock_keyring_items.size()); 1103 EXPECT_EQ(1u, mock_keyring_items.size());
1130 if (mock_keyring_items.size() > 0) 1104 if (mock_keyring_items.size() > 0)
1131 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1105 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1132 } 1106 }
1133 1107
1134 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { 1108 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) {
1135 NativeBackendGnome backend(42); 1109 NativeBackendGnome backend(42);
1136 backend.Init(); 1110 backend.Init();
1137 1111
(...skipping 13 matching lines...) Expand all
1151 form_google_.submit_element = UTF8ToUTF16("submit2"); 1125 form_google_.submit_element = UTF8ToUTF16("submit2");
1152 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, 1126 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD,
1153 form_google_)); 1127 form_google_));
1154 1128
1155 BrowserThread::PostTaskAndReplyWithResult( 1129 BrowserThread::PostTaskAndReplyWithResult(
1156 BrowserThread::DB, FROM_HERE, 1130 BrowserThread::DB, FROM_HERE,
1157 base::Bind(&NativeBackendGnome::AddLogin, 1131 base::Bind(&NativeBackendGnome::AddLogin,
1158 base::Unretained(&backend), form_google_), 1132 base::Unretained(&backend), form_google_),
1159 base::Bind(&CheckPasswordChanges, changes)); 1133 base::Bind(&CheckPasswordChanges, changes));
1160 1134
1161 RunBothThreads(); 1135 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1162 1136
1163 EXPECT_EQ(1u, mock_keyring_items.size()); 1137 EXPECT_EQ(1u, mock_keyring_items.size());
1164 if (mock_keyring_items.size() > 0) 1138 if (mock_keyring_items.size() > 0)
1165 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1139 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1166 } 1140 }
1167 1141
1168 TEST_F(NativeBackendGnomeTest, AndroidCredentials) { 1142 TEST_F(NativeBackendGnomeTest, AndroidCredentials) {
1169 NativeBackendGnome backend(42); 1143 NativeBackendGnome backend(42);
1170 backend.Init(); 1144 backend.Init();
1171 1145
(...skipping 15 matching lines...) Expand all
1187 PasswordStoreChange::ADD, saved_android_form)))); 1161 PasswordStoreChange::ADD, saved_android_form))));
1188 1162
1189 std::vector<std::unique_ptr<PasswordForm>> form_list; 1163 std::vector<std::unique_ptr<PasswordForm>> form_list;
1190 BrowserThread::PostTaskAndReplyWithResult( 1164 BrowserThread::PostTaskAndReplyWithResult(
1191 BrowserThread::DB, FROM_HERE, 1165 BrowserThread::DB, FROM_HERE,
1192 base::Bind(&NativeBackendGnome::GetLogins, 1166 base::Bind(&NativeBackendGnome::GetLogins,
1193 base::Unretained(&backend), observed_android_form, 1167 base::Unretained(&backend), observed_android_form,
1194 &form_list), 1168 &form_list),
1195 base::Bind(&CheckTrue)); 1169 base::Bind(&CheckTrue));
1196 1170
1197 RunBothThreads(); 1171 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1198 1172
1199 EXPECT_EQ(1u, form_list.size()); 1173 EXPECT_EQ(1u, form_list.size());
1200 EXPECT_EQ(saved_android_form, *form_list[0]); 1174 EXPECT_EQ(saved_android_form, *form_list[0]);
1201 } 1175 }
1202 1176
1203 TEST_F(NativeBackendGnomeTest, RemoveLoginsCreatedBetween) { 1177 TEST_F(NativeBackendGnomeTest, RemoveLoginsCreatedBetween) {
1204 CheckRemoveLoginsBetween(CREATED); 1178 CheckRemoveLoginsBetween(CREATED);
1205 } 1179 }
1206 1180
1207 TEST_F(NativeBackendGnomeTest, RemoveLoginsSyncedBetween) { 1181 TEST_F(NativeBackendGnomeTest, RemoveLoginsSyncedBetween) {
1208 CheckRemoveLoginsBetween(SYNCED); 1182 CheckRemoveLoginsBetween(SYNCED);
1209 } 1183 }
1210 1184
1211 TEST_F(NativeBackendGnomeTest, DisableAutoSignInForOrigins) { 1185 TEST_F(NativeBackendGnomeTest, DisableAutoSignInForOrigins) {
1212 NativeBackendGnome backend(42); 1186 NativeBackendGnome backend(42);
1213 backend.Init(); 1187 backend.Init();
1214 form_google_.skip_zero_click = false; 1188 form_google_.skip_zero_click = false;
1215 form_facebook_.skip_zero_click = false; 1189 form_facebook_.skip_zero_click = false;
1216 1190
1217 BrowserThread::PostTask( 1191 BrowserThread::PostTask(
1218 BrowserThread::DB, FROM_HERE, 1192 BrowserThread::DB, FROM_HERE,
1219 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1193 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1220 base::Unretained(&backend), form_google_)); 1194 base::Unretained(&backend), form_google_));
1221 BrowserThread::PostTask( 1195 BrowserThread::PostTask(
1222 BrowserThread::DB, FROM_HERE, 1196 BrowserThread::DB, FROM_HERE,
1223 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1197 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1224 base::Unretained(&backend), form_facebook_)); 1198 base::Unretained(&backend), form_facebook_));
1225 1199
1226 RunBothThreads(); 1200 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1227 1201
1228 EXPECT_EQ(2u, mock_keyring_items.size()); 1202 EXPECT_EQ(2u, mock_keyring_items.size());
1229 for (const auto& item : mock_keyring_items) 1203 for (const auto& item : mock_keyring_items)
1230 CheckUint32Attribute(&item, "should_skip_zero_click", 0); 1204 CheckUint32Attribute(&item, "should_skip_zero_click", 0);
1231 1205
1232 // Set the canonical forms to the updated value for the following comparison. 1206 // Set the canonical forms to the updated value for the following comparison.
1233 form_google_.skip_zero_click = true; 1207 form_google_.skip_zero_click = true;
1234 form_facebook_.skip_zero_click = true; 1208 form_facebook_.skip_zero_click = true;
1235 PasswordStoreChangeList expected_changes; 1209 PasswordStoreChangeList expected_changes;
1236 expected_changes.push_back( 1210 expected_changes.push_back(
1237 PasswordStoreChange(PasswordStoreChange::UPDATE, form_facebook_)); 1211 PasswordStoreChange(PasswordStoreChange::UPDATE, form_facebook_));
1238 1212
1239 PasswordStoreChangeList changes; 1213 PasswordStoreChangeList changes;
1240 BrowserThread::PostTaskAndReplyWithResult( 1214 BrowserThread::PostTaskAndReplyWithResult(
1241 BrowserThread::DB, FROM_HERE, 1215 BrowserThread::DB, FROM_HERE,
1242 base::Bind( 1216 base::Bind(
1243 &NativeBackendGnome::DisableAutoSignInForOrigins, 1217 &NativeBackendGnome::DisableAutoSignInForOrigins,
1244 base::Unretained(&backend), 1218 base::Unretained(&backend),
1245 base::Bind( 1219 base::Bind(
1246 static_cast<bool (*)(const GURL&, const GURL&)>(operator==), 1220 static_cast<bool (*)(const GURL&, const GURL&)>(operator==),
1247 form_facebook_.origin), 1221 form_facebook_.origin),
1248 &changes), 1222 &changes),
1249 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 1223 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
1250 RunBothThreads(); 1224 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1251 1225
1252 EXPECT_EQ(2u, mock_keyring_items.size()); 1226 EXPECT_EQ(2u, mock_keyring_items.size());
1253 CheckStringAttribute( 1227 CheckStringAttribute(
1254 &mock_keyring_items[0], "origin_url", form_google_.origin.spec()); 1228 &mock_keyring_items[0], "origin_url", form_google_.origin.spec());
1255 CheckUint32Attribute(&mock_keyring_items[0], "should_skip_zero_click", 0); 1229 CheckUint32Attribute(&mock_keyring_items[0], "should_skip_zero_click", 0);
1256 CheckStringAttribute( 1230 CheckStringAttribute(
1257 &mock_keyring_items[1], "origin_url", form_facebook_.origin.spec()); 1231 &mock_keyring_items[1], "origin_url", form_facebook_.origin.spec());
1258 CheckUint32Attribute(&mock_keyring_items[1], "should_skip_zero_click", 1); 1232 CheckUint32Attribute(&mock_keyring_items[1], "should_skip_zero_click", 1);
1259 } 1233 }
1260 1234
1261 TEST_F(NativeBackendGnomeTest, ReadDuplicateForms) { 1235 TEST_F(NativeBackendGnomeTest, ReadDuplicateForms) {
1262 NativeBackendGnome backend(42); 1236 NativeBackendGnome backend(42);
1263 backend.Init(); 1237 backend.Init();
1264 1238
1265 // Add 2 slightly different password forms. 1239 // Add 2 slightly different password forms.
1266 const char unique_string[] = "unique_unique_string"; 1240 const char unique_string[] = "unique_unique_string";
1267 const char unique_string_replacement[] = "uniKue_unique_string"; 1241 const char unique_string_replacement[] = "uniKue_unique_string";
1268 form_google_.origin = 1242 form_google_.origin =
1269 GURL(std::string("http://www.google.com/") + unique_string); 1243 GURL(std::string("http://www.google.com/") + unique_string);
1270 BrowserThread::PostTask( 1244 BrowserThread::PostTask(
1271 BrowserThread::DB, FROM_HERE, 1245 BrowserThread::DB, FROM_HERE,
1272 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1246 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1273 base::Unretained(&backend), form_google_)); 1247 base::Unretained(&backend), form_google_));
1274 form_google_.origin = 1248 form_google_.origin =
1275 GURL(std::string("http://www.google.com/") + unique_string_replacement); 1249 GURL(std::string("http://www.google.com/") + unique_string_replacement);
1276 BrowserThread::PostTask( 1250 BrowserThread::PostTask(
1277 BrowserThread::DB, FROM_HERE, 1251 BrowserThread::DB, FROM_HERE,
1278 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1252 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1279 base::Unretained(&backend), form_google_)); 1253 base::Unretained(&backend), form_google_));
1280 RunBothThreads(); 1254 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1281 1255
1282 // Read the raw value back. Change the |unique_string| to 1256 // Read the raw value back. Change the |unique_string| to
1283 // |unique_string_replacement| so the forms become unique. 1257 // |unique_string_replacement| so the forms become unique.
1284 ASSERT_EQ(2u, mock_keyring_items.size()); 1258 ASSERT_EQ(2u, mock_keyring_items.size());
1285 MockKeyringItem::attribute_map::iterator it = 1259 MockKeyringItem::attribute_map::iterator it =
1286 mock_keyring_items[0].attributes.find("origin_url"); 1260 mock_keyring_items[0].attributes.find("origin_url");
1287 ASSERT_NE(mock_keyring_items[0].attributes.end(), it); 1261 ASSERT_NE(mock_keyring_items[0].attributes.end(), it);
1288 size_t position = it->second.value_string.find(unique_string); 1262 size_t position = it->second.value_string.find(unique_string);
1289 ASSERT_NE(std::string::npos, position) << it->second.value_string; 1263 ASSERT_NE(std::string::npos, position) << it->second.value_string;
1290 it->second.value_string.replace( 1264 it->second.value_string.replace(
1291 position, std::string(unique_string_replacement).length(), 1265 position, std::string(unique_string_replacement).length(),
1292 unique_string_replacement); 1266 unique_string_replacement);
1293 1267
1294 // Now test that GetAutofillableLogins returns only one form. 1268 // Now test that GetAutofillableLogins returns only one form.
1295 std::vector<std::unique_ptr<PasswordForm>> form_list; 1269 std::vector<std::unique_ptr<PasswordForm>> form_list;
1296 BrowserThread::PostTaskAndReplyWithResult( 1270 BrowserThread::PostTaskAndReplyWithResult(
1297 BrowserThread::DB, FROM_HERE, 1271 BrowserThread::DB, FROM_HERE,
1298 base::Bind(&NativeBackendGnome::GetAutofillableLogins, 1272 base::Bind(&NativeBackendGnome::GetAutofillableLogins,
1299 base::Unretained(&backend), &form_list), 1273 base::Unretained(&backend), &form_list),
1300 base::Bind(&CheckTrue)); 1274 base::Bind(&CheckTrue));
1301 RunBothThreads(); 1275 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1302 1276
1303 EXPECT_EQ(1u, form_list.size()); 1277 EXPECT_EQ(1u, form_list.size());
1304 EXPECT_EQ(form_google_, *form_list[0]); 1278 EXPECT_EQ(form_google_, *form_list[0]);
1305 1279
1306 EXPECT_EQ(1u, mock_keyring_items.size()); 1280 EXPECT_EQ(1u, mock_keyring_items.size());
1307 if (mock_keyring_items.size() > 0) 1281 if (mock_keyring_items.size() > 0)
1308 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 1282 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
1309 } 1283 }
1310 1284
1311 TEST_F(NativeBackendGnomeTest, GetAllLogins) { 1285 TEST_F(NativeBackendGnomeTest, GetAllLogins) {
(...skipping 10 matching lines...) Expand all
1322 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin), 1296 base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
1323 base::Unretained(&backend), form_facebook_)); 1297 base::Unretained(&backend), form_facebook_));
1324 1298
1325 std::vector<std::unique_ptr<PasswordForm>> form_list; 1299 std::vector<std::unique_ptr<PasswordForm>> form_list;
1326 BrowserThread::PostTaskAndReplyWithResult( 1300 BrowserThread::PostTaskAndReplyWithResult(
1327 BrowserThread::DB, FROM_HERE, 1301 BrowserThread::DB, FROM_HERE,
1328 base::Bind(&NativeBackendGnome::GetAllLogins, base::Unretained(&backend), 1302 base::Bind(&NativeBackendGnome::GetAllLogins, base::Unretained(&backend),
1329 &form_list), 1303 &form_list),
1330 base::Bind(&CheckTrue)); 1304 base::Bind(&CheckTrue));
1331 1305
1332 RunBothThreads(); 1306 content::RunAllPendingInMessageLoop(BrowserThread::DB);
1333 1307
1334 EXPECT_EQ(2u, form_list.size()); 1308 EXPECT_EQ(2u, form_list.size());
1335 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), 1309 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_),
1336 Pointee(form_facebook_))); 1310 Pointee(form_facebook_)));
1337 } 1311 }
1338 1312
1339 // TODO(mdm): add more basic tests here at some point. 1313 // TODO(mdm): add more basic tests here at some point.
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_unittest.cc ('k') | chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698