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

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: Rebase 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
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_popup_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8962b2d7a47baf5850d117feef2960496661b7f3..2f3ae8137a9932fb6ea42eefbc9792c9d670ad4a 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"
@@ -39,11 +40,11 @@
#include "ipc/ipc_test_sink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/rect.h"
#include "webkit/forms/form_data.h"
#include "webkit/forms/form_field.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
using content::BrowserThread;
using content::WebContents;
@@ -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());
+ }
+
+ 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);
}
@@ -2943,6 +2973,57 @@ TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
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, 0);
+ 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, 0);
+ GUIDPair empty(std::string(), 0);
+ int id = PackGUIDs(guid_pair, empty);
+
+ autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
+
+ EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid.c_str()));
+}
+
+TEST_F(AutofillManagerTest, RemoveProfileVariant) {
+ // 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);
+
+ // TODO(csharp): Currently variants should not be deleted, but once they are
+ // update these expectations.
+ // http://crbug.com/124211
+ EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
+}
+
namespace {
class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_popup_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698