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

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

Issue 951883002: [Password Manager Cleanup] Replaces NULL -> nullptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Vaclav's comments. Created 5 years, 10 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 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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // format for the app string. This way we can add them easily to migrate. 136 // format for the app string. This way we can add them easily to migrate.
137 if (mock_keyring_reject_local_ids) { 137 if (mock_keyring_reject_local_ids) {
138 MockKeyringItem::attribute_map::iterator it = 138 MockKeyringItem::attribute_map::iterator it =
139 item->attributes.find("application"); 139 item->attributes.find("application");
140 if (it != item->attributes.end() && 140 if (it != item->attributes.end() &&
141 it->second.type == MockKeyringItem::ItemAttribute::STRING && 141 it->second.type == MockKeyringItem::ItemAttribute::STRING &&
142 base::StringPiece(it->second.value_string).starts_with("chrome-")) { 142 base::StringPiece(it->second.value_string).starts_with("chrome-")) {
143 mock_keyring_items.pop_back(); 143 mock_keyring_items.pop_back();
144 // GnomeKeyringResult, data 144 // GnomeKeyringResult, data
145 callback(GNOME_KEYRING_RESULT_IO_ERROR, data); 145 callback(GNOME_KEYRING_RESULT_IO_ERROR, data);
146 return NULL; 146 return nullptr;
147 } 147 }
148 } 148 }
149 // GnomeKeyringResult, data 149 // GnomeKeyringResult, data
150 callback(GNOME_KEYRING_RESULT_OK, data); 150 callback(GNOME_KEYRING_RESULT_OK, data);
151 return NULL; 151 return nullptr;
152 } 152 }
153 153
154 gpointer mock_gnome_keyring_delete_password( 154 gpointer mock_gnome_keyring_delete_password(
155 const GnomeKeyringPasswordSchema* schema, 155 const GnomeKeyringPasswordSchema* schema,
156 GnomeKeyringOperationDoneCallback callback, 156 GnomeKeyringOperationDoneCallback callback,
157 gpointer data, 157 gpointer data,
158 GDestroyNotify destroy_data, 158 GDestroyNotify destroy_data,
159 ...) { 159 ...) {
160 MockKeyringItem::attribute_query query; 160 MockKeyringItem::attribute_query query;
161 va_list ap; 161 va_list ap;
(...skipping 18 matching lines...) Expand all
180 const MockKeyringItem* item = &mock_keyring_items[i - 1]; 180 const MockKeyringItem* item = &mock_keyring_items[i - 1];
181 if (item->Matches(query)) { 181 if (item->Matches(query)) {
182 VLOG(1) << "Deleting item with origin " << item->display_name; 182 VLOG(1) << "Deleting item with origin " << item->display_name;
183 mock_keyring_items.erase(mock_keyring_items.begin() + (i - 1)); 183 mock_keyring_items.erase(mock_keyring_items.begin() + (i - 1));
184 deleted = true; 184 deleted = true;
185 } 185 }
186 } 186 }
187 // GnomeKeyringResult, data 187 // GnomeKeyringResult, data
188 callback(deleted ? GNOME_KEYRING_RESULT_OK 188 callback(deleted ? GNOME_KEYRING_RESULT_OK
189 : GNOME_KEYRING_RESULT_NO_MATCH, data); 189 : GNOME_KEYRING_RESULT_NO_MATCH, data);
190 return NULL; 190 return nullptr;
191 } 191 }
192 192
193 gpointer mock_gnome_keyring_find_items( 193 gpointer mock_gnome_keyring_find_items(
194 GnomeKeyringItemType type, 194 GnomeKeyringItemType type,
195 GnomeKeyringAttributeList* attributes, 195 GnomeKeyringAttributeList* attributes,
196 GnomeKeyringOperationGetListCallback callback, 196 GnomeKeyringOperationGetListCallback callback,
197 gpointer data, 197 gpointer data,
198 GDestroyNotify destroy_data) { 198 GDestroyNotify destroy_data) {
199 MockKeyringItem::attribute_query query; 199 MockKeyringItem::attribute_query query;
200 for (size_t i = 0; i < attributes->len; ++i) { 200 for (size_t i = 0; i < attributes->len; ++i) {
201 GnomeKeyringAttribute attribute = 201 GnomeKeyringAttribute attribute =
202 g_array_index(attributes, GnomeKeyringAttribute, i); 202 g_array_index(attributes, GnomeKeyringAttribute, i);
203 if (attribute.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) { 203 if (attribute.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
204 query.push_back( 204 query.push_back(
205 make_pair(std::string(attribute.name), 205 make_pair(std::string(attribute.name),
206 MockKeyringItem::ItemAttribute(attribute.value.string))); 206 MockKeyringItem::ItemAttribute(attribute.value.string)));
207 VLOG(1) << "Querying with item attribute " << attribute.name 207 VLOG(1) << "Querying with item attribute " << attribute.name
208 << ", value '" << query.back().second.value_string << "'"; 208 << ", value '" << query.back().second.value_string << "'";
209 } else { 209 } else {
210 query.push_back( 210 query.push_back(
211 make_pair(std::string(attribute.name), 211 make_pair(std::string(attribute.name),
212 MockKeyringItem::ItemAttribute(attribute.value.integer))); 212 MockKeyringItem::ItemAttribute(attribute.value.integer)));
213 VLOG(1) << "Querying with item attribute " << attribute.name << ", value " 213 VLOG(1) << "Querying with item attribute " << attribute.name << ", value "
214 << query.back().second.value_uint32; 214 << query.back().second.value_uint32;
215 } 215 }
216 } 216 }
217 // Find matches and add them to a list of results. 217 // Find matches and add them to a list of results.
218 GList* results = NULL; 218 GList* results = nullptr;
219 for (size_t i = 0; i < mock_keyring_items.size(); ++i) { 219 for (size_t i = 0; i < mock_keyring_items.size(); ++i) {
220 const MockKeyringItem* item = &mock_keyring_items[i]; 220 const MockKeyringItem* item = &mock_keyring_items[i];
221 if (item->Matches(query)) { 221 if (item->Matches(query)) {
222 GnomeKeyringFound* found = new GnomeKeyringFound; 222 GnomeKeyringFound* found = new GnomeKeyringFound;
223 found->keyring = strdup(item->keyring.c_str()); 223 found->keyring = strdup(item->keyring.c_str());
224 found->item_id = i; 224 found->item_id = i;
225 found->attributes = gnome_keyring_attribute_list_new(); 225 found->attributes = gnome_keyring_attribute_list_new();
226 for (MockKeyringItem::attribute_map::const_iterator it = 226 for (MockKeyringItem::attribute_map::const_iterator it =
227 item->attributes.begin(); 227 item->attributes.begin();
228 it != item->attributes.end(); 228 it != item->attributes.end();
(...skipping 19 matching lines...) Expand all
248 GList* element = g_list_first(results); 248 GList* element = g_list_first(results);
249 while (element) { 249 while (element) {
250 GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(element->data); 250 GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(element->data);
251 free(found->keyring); 251 free(found->keyring);
252 gnome_keyring_attribute_list_free(found->attributes); 252 gnome_keyring_attribute_list_free(found->attributes);
253 free(found->secret); 253 free(found->secret);
254 delete found; 254 delete found;
255 element = g_list_next(element); 255 element = g_list_next(element);
256 } 256 }
257 g_list_free(results); 257 g_list_free(results);
258 return NULL; 258 return nullptr;
259 } 259 }
260 260
261 const gchar* mock_gnome_keyring_result_to_message(GnomeKeyringResult res) { 261 const gchar* mock_gnome_keyring_result_to_message(GnomeKeyringResult res) {
262 return "mock keyring simulating failure"; 262 return "mock keyring simulating failure";
263 } 263 }
264 264
265 // Inherit to get access to protected fields. 265 // Inherit to get access to protected fields.
266 class MockGnomeKeyringLoader : public GnomeKeyringLoader { 266 class MockGnomeKeyringLoader : public GnomeKeyringLoader {
267 public: 267 public:
268 static bool LoadMockGnomeKeyring() { 268 static bool LoadMockGnomeKeyring() {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 form_list[index_non_psl]->signon_realm); 645 form_list[index_non_psl]->signon_realm);
646 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value); 646 EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
647 } 647 }
648 648
649 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) { 649 void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) {
650 other_auth_.scheme = scheme; 650 other_auth_.scheme = scheme;
651 651
652 // Don't match a non-HTML form with an HTML form. 652 // Don't match a non-HTML form with an HTML form.
653 EXPECT_FALSE(CheckCredentialAvailability( 653 EXPECT_FALSE(CheckCredentialAvailability(
654 other_auth_, GURL("http://www.example.com"), 654 other_auth_, GURL("http://www.example.com"),
655 PasswordForm::SCHEME_HTML, NULL)); 655 PasswordForm::SCHEME_HTML, nullptr));
656 // Don't match an HTML form with non-HTML auth form. 656 // Don't match an HTML form with non-HTML auth form.
657 EXPECT_FALSE(CheckCredentialAvailability( 657 EXPECT_FALSE(CheckCredentialAvailability(
658 form_google_, GURL("http://www.google.com/"), scheme, NULL)); 658 form_google_, GURL("http://www.google.com/"), scheme, nullptr));
659 // Don't match two different non-HTML auth forms with different origin. 659 // Don't match two different non-HTML auth forms with different origin.
660 EXPECT_FALSE(CheckCredentialAvailability( 660 EXPECT_FALSE(CheckCredentialAvailability(
661 other_auth_, GURL("http://first.example.com"), scheme, NULL)); 661 other_auth_, GURL("http://first.example.com"), scheme, nullptr));
662 // Do match non-HTML forms from the same origin. 662 // Do match non-HTML forms from the same origin.
663 EXPECT_TRUE(CheckCredentialAvailability( 663 EXPECT_TRUE(CheckCredentialAvailability(
664 other_auth_, GURL("http://www.example.com/"), scheme, NULL)); 664 other_auth_, GURL("http://www.example.com/"), scheme, nullptr));
665 } 665 }
666 666
667 void CheckRemoveLoginsBetween(RemoveBetweenMethod date_to_test) { 667 void CheckRemoveLoginsBetween(RemoveBetweenMethod date_to_test) {
668 NativeBackendGnome backend(42); 668 NativeBackendGnome backend(42);
669 backend.Init(); 669 backend.Init();
670 670
671 base::Time now = base::Time::Now(); 671 base::Time now = base::Time::Now();
672 base::Time next_day = now + base::TimeDelta::FromDays(1); 672 base::Time next_day = now + base::TimeDelta::FromDays(1);
673 form_google_.date_synced = base::Time(); 673 form_google_.date_synced = base::Time();
674 form_isc_.date_synced = base::Time(); 674 form_isc_.date_synced = base::Time();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 form_facebook_, kMobileURL, PasswordForm::SCHEME_HTML, &result)); 800 form_facebook_, kMobileURL, PasswordForm::SCHEME_HTML, &result));
801 EXPECT_EQ(kMobileURL, result.origin); 801 EXPECT_EQ(kMobileURL, result.origin);
802 EXPECT_EQ(kMobileURL.spec(), result.signon_realm); 802 EXPECT_EQ(kMobileURL.spec(), result.signon_realm);
803 } 803 }
804 804
805 // Save a password for www.facebook.com and see it not suggested for 805 // Save a password for www.facebook.com and see it not suggested for
806 // m-facebook.com. 806 // m-facebook.com.
807 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) { 807 TEST_F(NativeBackendGnomeTest, PSLMatchingNegativeDomainMismatch) {
808 EXPECT_FALSE(CheckCredentialAvailability( 808 EXPECT_FALSE(CheckCredentialAvailability(
809 form_facebook_, GURL("http://m-facebook.com/"), 809 form_facebook_, GURL("http://m-facebook.com/"),
810 PasswordForm::SCHEME_HTML, NULL)); 810 PasswordForm::SCHEME_HTML, nullptr));
811 } 811 }
812 812
813 // Test PSL matching is off for domains excluded from it. 813 // Test PSL matching is off for domains excluded from it.
814 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { 814 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) {
815 EXPECT_FALSE(CheckCredentialAvailability( 815 EXPECT_FALSE(CheckCredentialAvailability(
816 form_google_, GURL("http://one.google.com/"), 816 form_google_, GURL("http://one.google.com/"),
817 PasswordForm::SCHEME_HTML, NULL)); 817 PasswordForm::SCHEME_HTML, nullptr));
818 } 818 }
819 819
820 // Make sure PSL matches aren't available for non-HTML forms. 820 // Make sure PSL matches aren't available for non-HTML forms.
821 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledForNonHTMLForms) { 821 TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledForNonHTMLForms) {
822 CheckMatchingWithScheme(PasswordForm::SCHEME_BASIC); 822 CheckMatchingWithScheme(PasswordForm::SCHEME_BASIC);
823 CheckMatchingWithScheme(PasswordForm::SCHEME_DIGEST); 823 CheckMatchingWithScheme(PasswordForm::SCHEME_DIGEST);
824 CheckMatchingWithScheme(PasswordForm::SCHEME_OTHER); 824 CheckMatchingWithScheme(PasswordForm::SCHEME_OTHER);
825 825
826 } 826 }
827 827
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 1099
1100 TEST_F(NativeBackendGnomeTest, RemoveLoginsCreatedBetween) { 1100 TEST_F(NativeBackendGnomeTest, RemoveLoginsCreatedBetween) {
1101 CheckRemoveLoginsBetween(CREATED); 1101 CheckRemoveLoginsBetween(CREATED);
1102 } 1102 }
1103 1103
1104 TEST_F(NativeBackendGnomeTest, RemoveLoginsSyncedBetween) { 1104 TEST_F(NativeBackendGnomeTest, RemoveLoginsSyncedBetween) {
1105 CheckRemoveLoginsBetween(SYNCED); 1105 CheckRemoveLoginsBetween(SYNCED);
1106 } 1106 }
1107 1107
1108 // TODO(mdm): add more basic tests here at some point. 1108 // 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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698