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

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

Issue 906973007: PasswordStore: Clean up expectations about rewriting vectors of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Linux compile Created 5 years, 9 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 VLOG(1) << "Adding item attribute " << name << ", value '" << value 144 VLOG(1) << "Adding item attribute " << name << ", value '" << value
145 << "'"; 145 << "'";
146 } else { 146 } else {
147 uint32_t intvalue = va_arg(ap, uint32_t); 147 uint32_t intvalue = va_arg(ap, uint32_t);
148 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue; 148 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue;
149 value = g_strdup_printf("%u", intvalue); 149 value = g_strdup_printf("%u", intvalue);
150 } 150 }
151 g_hash_table_insert(attributes, g_strdup(name), value); 151 g_hash_table_insert(attributes, g_strdup(name), value);
152 } 152 }
153 va_end(ap); 153 va_end(ap);
154 for (uint32_t i = 0; i < global_mock_libsecret_items->size();) 154
155 if (Matches((*global_mock_libsecret_items)[i], attributes)) { 155 ScopedVector<MockSecretItem> kept_mock_libsecret_items;
156 global_mock_libsecret_items->erase(global_mock_libsecret_items->begin() + 156 kept_mock_libsecret_items.reserve(global_mock_libsecret_items->size());
157 i); 157 for (auto& item : *global_mock_libsecret_items) {
158 } else { 158 if (!Matches(item, attributes)) {
159 ++i; 159 kept_mock_libsecret_items.push_back(item);
160 item = nullptr;
160 } 161 }
162 }
163 global_mock_libsecret_items->swap(kept_mock_libsecret_items);
164
161 g_hash_table_unref(attributes); 165 g_hash_table_unref(attributes);
162 return true; 166 return true;
163 } 167 }
164 168
165 MockSecretValue* mock_secret_item_get_secret(MockSecretItem* self) { 169 MockSecretValue* mock_secret_item_get_secret(MockSecretItem* self) {
166 return self->value; 170 return self->value;
167 } 171 }
168 172
169 const gchar* mock_secret_value_get_text(MockSecretValue* value) { 173 const gchar* mock_secret_value_get_text(MockSecretValue* value) {
170 return value->password; 174 return value->password;
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 793
790 actual_changes = backend.AddLogin(form_google_); 794 actual_changes = backend.AddLogin(form_google_);
791 CheckPasswordChanges(expected_changes, actual_changes); 795 CheckPasswordChanges(expected_changes, actual_changes);
792 796
793 EXPECT_EQ(1u, global_mock_libsecret_items->size()); 797 EXPECT_EQ(1u, global_mock_libsecret_items->size());
794 if (!global_mock_libsecret_items->empty()) 798 if (!global_mock_libsecret_items->empty())
795 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, 799 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
796 "chrome-42"); 800 "chrome-42");
797 } 801 }
798 802
799 TEST_F(NativeBackendLibsecretTest, ListLoginsAppends) {
800 NativeBackendLibsecret backend(42);
801
802 backend.AddLogin(form_google_);
803
804 // Send the same request twice with the same list both times.
805 ScopedVector<autofill::PasswordForm> form_list;
806 backend.GetAutofillableLogins(&form_list);
807 backend.GetAutofillableLogins(&form_list);
808
809 // Quick check that we got two results back.
810 EXPECT_EQ(2u, form_list.size());
811 form_list.clear();
812
813 EXPECT_EQ(1u, global_mock_libsecret_items->size());
814 if (!global_mock_libsecret_items->empty())
815 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
816 "chrome-42");
817 }
818
819 TEST_F(NativeBackendLibsecretTest, AndroidCredentials) { 803 TEST_F(NativeBackendLibsecretTest, AndroidCredentials) {
820 NativeBackendLibsecret backend(42); 804 NativeBackendLibsecret backend(42);
821 backend.Init(); 805 backend.Init();
822 806
823 PasswordForm observed_android_form; 807 PasswordForm observed_android_form;
824 observed_android_form.scheme = PasswordForm::SCHEME_HTML; 808 observed_android_form.scheme = PasswordForm::SCHEME_HTML;
825 observed_android_form.signon_realm = 809 observed_android_form.signon_realm =
826 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; 810 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/";
827 PasswordForm saved_android_form = observed_android_form; 811 PasswordForm saved_android_form = observed_android_form;
828 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); 812 saved_android_form.username_value = base::UTF8ToUTF16("randomusername");
829 saved_android_form.password_value = base::UTF8ToUTF16("password"); 813 saved_android_form.password_value = base::UTF8ToUTF16("password");
830 saved_android_form.date_created = base::Time::Now(); 814 saved_android_form.date_created = base::Time::Now();
831 815
832 backend.AddLogin(saved_android_form); 816 backend.AddLogin(saved_android_form);
833 817
834 ScopedVector<autofill::PasswordForm> form_list; 818 ScopedVector<autofill::PasswordForm> form_list;
835 backend.GetAutofillableLogins(&form_list); 819 backend.GetAutofillableLogins(&form_list);
836 820
837 EXPECT_EQ(1u, form_list.size()); 821 EXPECT_EQ(1u, form_list.size());
838 EXPECT_EQ(saved_android_form, *form_list[0]); 822 EXPECT_EQ(saved_android_form, *form_list[0]);
839 } 823 }
840 824
841
842 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { 825 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) {
843 CheckRemoveLoginsBetween(CREATED); 826 CheckRemoveLoginsBetween(CREATED);
844 } 827 }
845 828
846 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { 829 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) {
847 CheckRemoveLoginsBetween(SYNCED); 830 CheckRemoveLoginsBetween(SYNCED);
848 } 831 }
849 832
850 TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) { 833 TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) {
851 // Absent attributes should be filled with default values. 834 // Absent attributes should be filled with default values.
852 NativeBackendLibsecret backend(42); 835 NativeBackendLibsecret backend(42);
853 836
854 backend.AddLogin(form_google_); 837 backend.AddLogin(form_google_);
855 838
856 EXPECT_EQ(1u, global_mock_libsecret_items->size()); 839 EXPECT_EQ(1u, global_mock_libsecret_items->size());
857 // Remove a string attribute. 840 // Remove a string attribute.
858 (*global_mock_libsecret_items)[0]->RemoveAttribute("avatar_url"); 841 (*global_mock_libsecret_items)[0]->RemoveAttribute("avatar_url");
859 // Remove an integer attribute. 842 // Remove an integer attribute.
860 (*global_mock_libsecret_items)[0]->RemoveAttribute("ssl_valid"); 843 (*global_mock_libsecret_items)[0]->RemoveAttribute("ssl_valid");
861 844
862 ScopedVector<autofill::PasswordForm> form_list; 845 ScopedVector<autofill::PasswordForm> form_list;
863 backend.GetAutofillableLogins(&form_list); 846 backend.GetAutofillableLogins(&form_list);
864 847
865 EXPECT_EQ(1u, form_list.size()); 848 EXPECT_EQ(1u, form_list.size());
866 EXPECT_EQ(GURL(""), form_list[0]->avatar_url); 849 EXPECT_EQ(GURL(""), form_list[0]->avatar_url);
867 EXPECT_FALSE(form_list[0]->ssl_valid); 850 EXPECT_FALSE(form_list[0]->ssl_valid);
868 } 851 }
869 852
870 // TODO(mdm): add more basic tests here at some point. 853 // TODO(mdm): add more basic tests here at some point.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698