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

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

Issue 299443002: Password Login Database: report correct changes from UpdateLogin(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added UpdateNonexistentLogin tests Created 6 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 | Annotate | Revision Log
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 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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 const base::string16 kNewPassword(UTF8ToUTF16("new_b")); 549 const base::string16 kNewPassword(UTF8ToUTF16("new_b"));
550 EXPECT_NE(kOldPassword, kNewPassword); 550 EXPECT_NE(kOldPassword, kNewPassword);
551 new_facebook.password_value = kNewPassword; 551 new_facebook.password_value = kNewPassword;
552 switch (update_type) { 552 switch (update_type) {
553 case UPDATE_BY_UPDATELOGIN: 553 case UPDATE_BY_UPDATELOGIN:
554 BrowserThread::PostTask( 554 BrowserThread::PostTask(
555 BrowserThread::DB, 555 BrowserThread::DB,
556 FROM_HERE, 556 FROM_HERE,
557 base::Bind(base::IgnoreResult(&NativeBackendGnome::UpdateLogin), 557 base::Bind(base::IgnoreResult(&NativeBackendGnome::UpdateLogin),
558 base::Unretained(&backend), 558 base::Unretained(&backend),
559 new_facebook)); 559 new_facebook,
560 base::Owned(new PasswordStoreChangeList)));
560 break; 561 break;
561 case UPDATE_BY_ADDLOGIN: 562 case UPDATE_BY_ADDLOGIN:
562 BrowserThread::PostTask( 563 BrowserThread::PostTask(
563 BrowserThread::DB, 564 BrowserThread::DB,
564 FROM_HERE, 565 FROM_HERE,
565 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), 566 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
566 base::Unretained(&backend), 567 base::Unretained(&backend),
567 new_facebook)); 568 new_facebook));
568 break; 569 break;
569 } 570 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 747
747 PasswordForm new_form_google(form_google_); 748 PasswordForm new_form_google(form_google_);
748 new_form_google.times_used = 1; 749 new_form_google.times_used = 1;
749 new_form_google.action = GURL("http://www.google.com/different/login"); 750 new_form_google.action = GURL("http://www.google.com/different/login");
750 751
751 EXPECT_EQ(1u, mock_keyring_items.size()); 752 EXPECT_EQ(1u, mock_keyring_items.size());
752 if (mock_keyring_items.size() > 0) 753 if (mock_keyring_items.size() > 0)
753 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 754 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
754 755
755 // Update login 756 // Update login
757 PasswordStoreChangeList changes;
756 BrowserThread::PostTask( 758 BrowserThread::PostTask(
757 BrowserThread::DB, FROM_HERE, 759 BrowserThread::DB, FROM_HERE,
758 base::Bind(base::IgnoreResult(&NativeBackendGnome::UpdateLogin), 760 base::Bind(base::IgnoreResult(&NativeBackendGnome::UpdateLogin),
759 base::Unretained(&backend), new_form_google)); 761 base::Unretained(&backend),
762 new_form_google,
763 base::Unretained(&changes)));
760 764
761 RunBothThreads(); 765 RunBothThreads();
762 766
767 ASSERT_EQ(1u, changes.size());
768 EXPECT_EQ(PasswordStoreChange::UPDATE, changes.front().type());
769 EXPECT_EQ(new_form_google, changes.front().form());
763 EXPECT_EQ(1u, mock_keyring_items.size()); 770 EXPECT_EQ(1u, mock_keyring_items.size());
764 if (mock_keyring_items.size() > 0) 771 if (mock_keyring_items.size() > 0)
765 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42"); 772 CheckMockKeyringItem(&mock_keyring_items[0], new_form_google, "chrome-42");
766 } 773 }
767 774
768 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { 775 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) {
769 NativeBackendGnome backend(42); 776 NativeBackendGnome backend(42);
770 backend.Init(); 777 backend.Init();
771 778
772 BrowserThread::PostTask( 779 BrowserThread::PostTask(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 831
825 // Quick check that we got something back. 832 // Quick check that we got something back.
826 EXPECT_EQ(1u, form_list.size()); 833 EXPECT_EQ(1u, form_list.size());
827 STLDeleteElements(&form_list); 834 STLDeleteElements(&form_list);
828 835
829 EXPECT_EQ(1u, mock_keyring_items.size()); 836 EXPECT_EQ(1u, mock_keyring_items.size());
830 if (mock_keyring_items.size() > 0) 837 if (mock_keyring_items.size() > 0)
831 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 838 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
832 } 839 }
833 840
841 TEST_F(NativeBackendGnomeTest, UpdateNonexistentLogin) {
842 NativeBackendGnome backend(42);
843 backend.Init();
844
845 // First add an unrelated login.
846 BrowserThread::PostTask(
847 BrowserThread::DB, FROM_HERE,
848 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
849 base::Unretained(&backend), form_google_));
850
851 RunBothThreads();
852
853 EXPECT_EQ(1u, mock_keyring_items.size());
854 if (mock_keyring_items.size() > 0)
855 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
856
857 // Attempt to update a login that doesn't exist.
858 PasswordStoreChangeList changes;
859 BrowserThread::PostTask(
860 BrowserThread::DB, FROM_HERE,
861 base::Bind(base::IgnoreResult(&NativeBackendGnome::UpdateLogin),
862 base::Unretained(&backend),
863 form_isc_,
864 base::Unretained(&changes)));
865
866 RunBothThreads();
867
868 EXPECT_EQ(PasswordStoreChangeList(), changes);
869 EXPECT_EQ(1u, mock_keyring_items.size());
870 if (mock_keyring_items.size() > 0)
871 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
872 }
873
834 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { 874 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) {
835 NativeBackendGnome backend(42); 875 NativeBackendGnome backend(42);
836 backend.Init(); 876 backend.Init();
837 877
838 PasswordStoreChangeList changes; 878 PasswordStoreChangeList changes;
839 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, 879 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD,
840 form_google_)); 880 form_google_));
841 BrowserThread::PostTaskAndReplyWithResult( 881 BrowserThread::PostTaskAndReplyWithResult(
842 BrowserThread::DB, FROM_HERE, 882 BrowserThread::DB, FROM_HERE,
843 base::Bind(&NativeBackendGnome::AddLogin, 883 base::Bind(&NativeBackendGnome::AddLogin,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 // Quick check that we got two results back. 931 // Quick check that we got two results back.
892 EXPECT_EQ(2u, form_list.size()); 932 EXPECT_EQ(2u, form_list.size());
893 STLDeleteElements(&form_list); 933 STLDeleteElements(&form_list);
894 934
895 EXPECT_EQ(1u, mock_keyring_items.size()); 935 EXPECT_EQ(1u, mock_keyring_items.size());
896 if (mock_keyring_items.size() > 0) 936 if (mock_keyring_items.size() > 0)
897 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 937 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
898 } 938 }
899 939
900 // TODO(mdm): add more basic tests here at some point. 940 // TODO(mdm): add more basic tests here at some point.
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/native_backend_gnome_x.cc ('k') | chrome/browser/password_manager/native_backend_kwallet_x.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698