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

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 969103003: Don't save duplicates of wallet addresses to local Autofill. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make test work Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Reload the database. 178 // Reload the database.
179 ResetPersonalDataManager(USER_MODE_NORMAL); 179 ResetPersonalDataManager(USER_MODE_NORMAL);
180 180
181 // Verify the addition. 181 // Verify the addition.
182 std::vector<AutofillProfile*> profiles; 182 std::vector<AutofillProfile*> profiles;
183 profiles.push_back(&profile0); 183 profiles.push_back(&profile0);
184 profiles.push_back(&profile1); 184 profiles.push_back(&profile1);
185 ExpectSameElements(profiles, personal_data_->GetProfiles()); 185 ExpectSameElements(profiles, personal_data_->GetProfiles());
186 } 186 }
187 187
188 TEST_F(PersonalDataManagerTest, DontDuplicateServerProfile) {
189 EnableWalletCardImport();
190
191 std::vector<AutofillProfile> server_profiles;
192 server_profiles.push_back(
193 AutofillProfile(AutofillProfile::SERVER_PROFILE, "a123"));
194 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "",
195 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX",
196 "77401", "US", "");
197 // Wallet only provides a full name, so the above first and last names
198 // will be ignored when the profile is written to the DB.
199 server_profiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe"));
200 autofill_table_->SetServerProfiles(server_profiles);
201 personal_data_->Refresh();
202 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
203 .WillOnce(QuitMainMessageLoop());
204 base::MessageLoop::current()->Run();
205 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
206
207 // Add profile with identical values. Duplicates should not get saved.
208 AutofillProfile scraped_profile(base::GenerateGUID(),
209 "https://www.example.com");
210 test::SetProfileInfo(&scraped_profile, "John", "", "Doe", "", "ACME Corp",
211 "500 Oak View", "Apt 8", "Houston", "TX", "77401", "US",
212 "");
213 EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US"));
214 std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile);
215 EXPECT_NE(scraped_profile.guid(), saved_guid);
216
217 personal_data_->Refresh();
218 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
219 .WillOnce(QuitMainMessageLoop());
220 base::MessageLoop::current()->Run();
221
222 // Verify the non-addition.
223 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
224 EXPECT_EQ(0U, personal_data_->web_profiles().size());
225 }
226
188 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { 227 TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
189 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); 228 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com");
190 test::SetProfileInfo(&profile0, 229 test::SetProfileInfo(&profile0,
191 "Marion", "Mitchell", "Morrison", 230 "Marion", "Mitchell", "Morrison",
192 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 231 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
193 "91601", "US", "12345678910"); 232 "91601", "US", "12345678910");
194 233
195 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 234 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
196 test::SetProfileInfo(&profile1, 235 test::SetProfileInfo(&profile1,
197 "Josephine", "Alicia", "Saenz", 236 "Josephine", "Alicia", "Saenz",
(...skipping 2857 matching lines...) Expand 10 before | Expand all | Expand 10 after
3055 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); 3094 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date());
3056 3095
3057 EXPECT_EQ(0U, personal_data_->GetCreditCards()[1]->use_count()); 3096 EXPECT_EQ(0U, personal_data_->GetCreditCards()[1]->use_count());
3058 EXPECT_EQ(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); 3097 EXPECT_EQ(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
3059 3098
3060 EXPECT_EQ(1U, personal_data_->GetCreditCards()[2]->use_count()); 3099 EXPECT_EQ(1U, personal_data_->GetCreditCards()[2]->use_count());
3061 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); 3100 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date());
3062 } 3101 }
3063 3102
3064 } // namespace autofill 3103 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | components/autofill/core/browser/webdata/autofill_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698