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

Unified Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 10073018: Add Delete Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_manager_unittest.cc
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index bfef7ff99f916c816185e53b8d825ea4541d84bd..61c869e021949d68d896aa61b7e59a92200a3e88 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
#include <vector>
#include "base/command_line.h"
@@ -86,6 +87,15 @@ class TestPersonalDataManager : public PersonalDataManager {
return NULL;
}
+ CreditCard* GetCreditCardWithGUID(const char* guid) {
+ for (std::vector<CreditCard *>::iterator it = credit_cards_.begin();
+ it != credit_cards_.end(); ++it){
+ if (!(*it)->guid().compare(guid))
+ return *it;
+ }
+ return NULL;
+ }
+
void AddProfile(AutofillProfile* profile) {
web_profiles_->push_back(profile);
}
@@ -94,6 +104,22 @@ class TestPersonalDataManager : public PersonalDataManager {
credit_cards_->push_back(credit_card);
}
+ virtual void RemoveProfile(const std::string& guid) OVERRIDE {
+ AutofillProfile* profile = GetProfileWithGUID(guid.c_str());
+
+ web_profiles_.erase(
+ std::remove(web_profiles_.begin(), web_profiles_.end(), profile),
+ web_profiles_.end());
Ilya Sherman 2012/04/19 21:01:57 nit: Isn't just """std::remove(web_profiles_.begin
csharp 2012/04/20 15:03:18 I don't believe so. std::remove (as I understand i
Ilya Sherman 2012/04/20 21:30:48 Ah, I think you're right -- sorry 'bout that. I g
+ }
+
+ virtual void RemoveCreditCard(const std::string& guid) OVERRIDE {
+ CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str());
+
+ credit_cards_.erase(
+ std::remove(credit_cards_.begin(), credit_cards_.end(), credit_card),
+ credit_cards_.end());
+ }
+
void ClearAutofillProfiles() {
web_profiles_.reset();
}
@@ -509,6 +535,10 @@ class TestAutofillManager : public AutofillManager {
return personal_data_->GetProfileWithGUID(guid);
}
+ CreditCard* GetCreditCardWithGUID(const char* guid) {
+ return personal_data_->GetCreditCardWithGUID(guid);
+ }
+
void AddProfile(AutofillProfile* profile) {
personal_data_->AddProfile(profile);
}
@@ -2932,6 +2962,38 @@ TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
autofill_manager_->ClearSentStates();
}
+TEST_F(AutofillManagerTest, RemoveProfile) {
+ // Add and remove an Autofill profile.
+ AutofillProfile* profile = new AutofillProfile;
+ std::string guid = "00000000-0000-0000-0000-000000000102";
+ profile->set_guid(guid.c_str());
+ autofill_manager_->AddProfile(profile);
+
+ GUIDPair guid_pair(guid, 1);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(empty, guid_pair);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
+}
+
+TEST_F(AutofillManagerTest, RemoveCreditCard){
+ // Add and remove an Autofill credit card.
+ CreditCard* credit_card = new CreditCard;
+ std::string guid = "00000000-0000-0000-0000-000000100007";
+ credit_card->set_guid(guid.c_str());
+ autofill_manager_->AddCreditCard(credit_card);
+
+ GUIDPair guid_pair(guid, 1);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(guid_pair, empty);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str()));
+}
+
namespace {
class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {

Powered by Google App Engine
This is Rietveld 408576698