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

Side by Side 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: Adding profile and credit card deleteion 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 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 AutofillProfile* GetProfileWithGUID(const char* guid) { 79 AutofillProfile* GetProfileWithGUID(const char* guid) {
80 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); 80 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin();
81 it != web_profiles_.end(); ++it) { 81 it != web_profiles_.end(); ++it) {
82 if (!(*it)->guid().compare(guid)) 82 if (!(*it)->guid().compare(guid))
83 return *it; 83 return *it;
84 } 84 }
85 return NULL; 85 return NULL;
86 } 86 }
87 87
88 CreditCard* GetCreditCardWithGUID(const char* guid) {
89 for (std::vector<CreditCard *>::iterator it = credit_cards_.begin();
90 it != credit_cards_.end(); ++it){
91 if (!(*it)->guid().compare(guid))
92 return *it;
93 }
94 return NULL;
95 }
96
88 void AddProfile(AutofillProfile* profile) { 97 void AddProfile(AutofillProfile* profile) {
89 web_profiles_->push_back(profile); 98 web_profiles_->push_back(profile);
90 } 99 }
91 100
92 void AddCreditCard(CreditCard* credit_card) { 101 void AddCreditCard(CreditCard* credit_card) {
93 credit_cards_->push_back(credit_card); 102 credit_cards_->push_back(credit_card);
94 } 103 }
95 104
105 virtual void RemoveProfile(const std::string& guid) OVERRIDE {
106 AutofillProfile* profile = GetProfileWithGUID(guid.c_str());
107
108 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin();
109 it != web_profiles_.end(); ++it){
110 if (*it == profile) {
111 web_profiles_.erase(it);
112 return;
113 }
114 }
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.
115 }
116
117 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE {
118 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str());
119
120 for (std::vector<CreditCard *>::iterator it = credit_cards_.begin();
121 it != credit_cards_.end(); ++it){
122 if (*it == credit_card) {
123 credit_cards_.erase(it);
124 return;
125 }
126 }
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.
127 }
128
96 void ClearAutofillProfiles() { 129 void ClearAutofillProfiles() {
97 web_profiles_.reset(); 130 web_profiles_.reset();
98 } 131 }
99 132
100 void ClearCreditCards() { 133 void ClearCreditCards() {
101 credit_cards_.reset(); 134 credit_cards_.reset();
102 } 135 }
103 136
104 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { 137 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) {
105 ClearCreditCards(); 138 ClearCreditCards();
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 534 }
502 535
503 const std::string GetSubmittedFormSignature() { 536 const std::string GetSubmittedFormSignature() {
504 return submitted_form_signature_; 537 return submitted_form_signature_;
505 } 538 }
506 539
507 AutofillProfile* GetProfileWithGUID(const char* guid) { 540 AutofillProfile* GetProfileWithGUID(const char* guid) {
508 return personal_data_->GetProfileWithGUID(guid); 541 return personal_data_->GetProfileWithGUID(guid);
509 } 542 }
510 543
544 CreditCard* GetCreditCardWithGUID(const char* guid) {
545 return personal_data_->GetCreditCardWithGUID(guid);
546 }
547
511 void AddProfile(AutofillProfile* profile) { 548 void AddProfile(AutofillProfile* profile) {
512 personal_data_->AddProfile(profile); 549 personal_data_->AddProfile(profile);
513 } 550 }
514 551
515 void AddCreditCard(CreditCard* credit_card) { 552 void AddCreditCard(CreditCard* credit_card) {
516 personal_data_->AddCreditCard(credit_card); 553 personal_data_->AddCreditCard(credit_card);
517 } 554 }
518 555
519 int GetPackedCreditCardID(int credit_card_id) { 556 int GetPackedCreditCardID(int credit_card_id) {
520 std::string credit_card_guid = 557 std::string credit_card_guid =
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2923 autofill_manager_->ClearSentStates(); 2960 autofill_manager_->ClearSentStates();
2924 2961
2925 // When a new render_view is created, we send the state even if it's the 2962 // When a new render_view is created, we send the state even if it's the
2926 // same. 2963 // same.
2927 UpdatePasswordSyncState(true); 2964 UpdatePasswordSyncState(true);
2928 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); 2965 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2929 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); 2966 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2930 autofill_manager_->ClearSentStates(); 2967 autofill_manager_->ClearSentStates();
2931 } 2968 }
2932 2969
2970 TEST_F(AutofillManagerTest, RemoveProfile) {
2971 // Add and remove an Autofill profile.
2972 AutofillProfile* profile = new AutofillProfile;
2973 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.
2974 profile->set_guid(guid.c_str());
2975 autofill_manager_->AddProfile(profile);
2976
2977 GUIDPair guid_pair(guid, 1);
2978 GUIDPair empty(std::string(), 0);
2979 int id = PackGUIDs(empty, guid_pair);
2980
2981 autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
2982
2983 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.
2984 }
2985
2986 TEST_F(AutofillManagerTest, RemoveCreditCard){
2987 // 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.
2988 CreditCard* credit_card = new CreditCard;
2989 std::string guid = "00000000-0000-0000-0000-000000100007";
2990 credit_card->set_guid(guid.c_str());
2991 autofill_manager_->AddCreditCard(credit_card);
2992
2993 GUIDPair guid_pair(guid, 1);
2994 GUIDPair empty(std::string(), 0);
2995 int id = PackGUIDs(guid_pair, empty);
2996
2997 autofill_manager_->RemoveAutofillProfileOrCreditCard(id);
2998
2999 EXPECT_EQ(NULL, autofill_manager_->GetCreditCardWithGUID(guid.c_str()));
3000 }
3001
2933 namespace { 3002 namespace {
2934 3003
2935 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 3004 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
2936 public: 3005 public:
2937 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, 3006 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper,
2938 AutofillManager* autofill_manager) 3007 AutofillManager* autofill_manager)
2939 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} 3008 : TestAutofillExternalDelegate(wrapper, autofill_manager) {}
2940 virtual ~MockAutofillExternalDelegate() {} 3009 virtual ~MockAutofillExternalDelegate() {}
2941 3010
2942 MOCK_METHOD5(OnQuery, void(int query_id, 3011 MOCK_METHOD5(OnQuery, void(int query_id,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 3059
2991 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); 3060 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager();
2992 EXPECT_TRUE(autofill_manager->external_delegate()); 3061 EXPECT_TRUE(autofill_manager->external_delegate());
2993 3062
2994 AutocompleteHistoryManager* autocomplete_history_manager = 3063 AutocompleteHistoryManager* autocomplete_history_manager =
2995 contents_wrapper()->autocomplete_history_manager(); 3064 contents_wrapper()->autocomplete_history_manager();
2996 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); 3065 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
2997 } 3066 }
2998 3067
2999 #endif // OS_ANDROID 3068 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698