Chromium Code Reviews| 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 0d4cebbf77e134ea16def44ddc4c2cf7997cdb2a..17e08cd7e35a8f139681a1e3a69f7403aae976e9 100644 |
| --- a/chrome/browser/autofill/autofill_manager_unittest.cc |
| +++ b/chrome/browser/autofill/autofill_manager_unittest.cc |
| @@ -85,6 +85,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); |
| } |
| @@ -93,6 +102,30 @@ class TestPersonalDataManager : public PersonalDataManager { |
| credit_cards_->push_back(credit_card); |
| } |
| + virtual void RemoveProfile(const std::string& guid) OVERRIDE { |
| + AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); |
| + |
| + for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); |
| + it != web_profiles_.end(); ++it){ |
| + if (*it == profile) { |
| + web_profiles_.erase(it); |
| + return; |
| + } |
| + } |
|
Ilya Sherman
2012/04/18 18:12:51
nit: Perhaps replace this loop with a call to std:
csharp
2012/04/19 15:33:24
Done.
|
| + } |
| + |
| + virtual void RemoveCreditCard(const std::string& guid) OVERRIDE { |
| + CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); |
| + |
| + for (std::vector<CreditCard *>::iterator it = credit_cards_.begin(); |
| + it != credit_cards_.end(); ++it){ |
| + if (*it == credit_card) { |
| + credit_cards_.erase(it); |
| + return; |
| + } |
| + } |
|
Ilya Sherman
2012/04/18 18:12:51
nit: Perhaps replace this loop with a call to std:
csharp
2012/04/19 15:33:24
Done.
|
| + } |
| + |
| void ClearAutofillProfiles() { |
| web_profiles_.reset(); |
| } |
| @@ -508,6 +541,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); |
| } |
| @@ -2930,6 +2967,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"; |
|
Ilya Sherman
2012/04/18 18:12:51
nit: Missing space between the = sign and the quot
csharp
2012/04/19 15:33:24
Done.
|
| + 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_EQ(NULL, autofill_manager_->GetProfileWithGUID(guid.c_str())); |
|
Ilya Sherman
2012/04/18 18:12:51
nit: I don't think this compiles on all platforms.
csharp
2012/04/19 15:33:24
Done.
|
| +} |
| + |
| +TEST_F(AutofillManagerTest, RemoveCreditCard){ |
| + // Add and remove and Autofill credit card. |
|
Ilya Sherman
2012/04/18 18:12:51
nit: "remove and" -> "remove an"
csharp
2012/04/19 15:33:24
Done.
|
| + 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_EQ(NULL, autofill_manager_->GetCreditCardWithGUID(guid.c_str())); |
| +} |
| + |
| namespace { |
| class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |