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

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

Issue 2744933004: [Autofill] Rewrite Autofill unitttests to use INSTANTIATE_TEST_CASE_P (Closed)
Patch Set: remove commented test case. Created 3 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 "components/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 EXPECT_EQ(std::mismatch(results_copy.begin(), 113 EXPECT_EQ(std::mismatch(results_copy.begin(),
114 results_copy.end(), 114 results_copy.end(),
115 expectations_copy.begin(), 115 expectations_copy.begin(),
116 ElementsEqual<T>).first, 116 ElementsEqual<T>).first,
117 results_copy.end()); 117 results_copy.end());
118 } 118 }
119 119
120 } // anonymous namespace 120 } // anonymous namespace
121 121
122 class PersonalDataManagerTest : public testing::Test { 122 class PersonalDataManagerTestBase {
123 protected: 123 protected:
124 PersonalDataManagerTest() : autofill_table_(nullptr) {} 124 PersonalDataManagerTestBase() : autofill_table_(nullptr) {}
125
126 void SetUp() override {
127 OSCryptMocker::SetUpWithSingleton();
128 prefs_ = test::PrefServiceForTesting();
129 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
130 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB");
131 web_database_ =
132 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(),
133 base::ThreadTaskRunnerHandle::Get());
134
135 // Setup account tracker.
136 signin_client_.reset(new TestSigninClient(prefs_.get()));
137 account_tracker_.reset(new AccountTrackerService());
138 account_tracker_->Initialize(signin_client_.get());
139 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(),
140 account_tracker_.get()));
141 signin_manager_->Initialize(prefs_.get());
142
143 // Hacky: hold onto a pointer but pass ownership.
144 autofill_table_ = new AutofillTable;
145 web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_));
146 web_database_->LoadDatabase();
147 autofill_database_service_ = new AutofillWebDataService(
148 web_database_, base::ThreadTaskRunnerHandle::Get(),
149 base::ThreadTaskRunnerHandle::Get(),
150 WebDataServiceBase::ProfileErrorCallback());
151 autofill_database_service_->Init();
152
153 test::DisableSystemServices(prefs_.get());
154 ResetPersonalDataManager(USER_MODE_NORMAL);
155
156 // Reset the deduping pref to its default value.
157 personal_data_->pref_service_->SetInteger(
158 prefs::kAutofillLastVersionDeduped, 0);
159 personal_data_->pref_service_->SetBoolean(
160 prefs::kAutofillProfileUseDatesFixed, false);
161 }
162
163 void TearDown() override {
164 // Order of destruction is important as AutofillManager relies on
165 // PersonalDataManager to be around when it gets destroyed.
166 signin_manager_->Shutdown();
167 signin_manager_.reset();
168
169 account_tracker_->Shutdown();
170 account_tracker_.reset();
171 signin_client_.reset();
172
173 test::DisableSystemServices(prefs_.get());
174 OSCryptMocker::TearDown();
175 }
176 125
177 void ResetPersonalDataManager(UserMode user_mode) { 126 void ResetPersonalDataManager(UserMode user_mode) {
178 bool is_incognito = (user_mode == USER_MODE_INCOGNITO); 127 bool is_incognito = (user_mode == USER_MODE_INCOGNITO);
179 personal_data_.reset(new PersonalDataManager("en")); 128 personal_data_.reset(new PersonalDataManager("en"));
180 personal_data_->Init( 129 personal_data_->Init(
181 scoped_refptr<AutofillWebDataService>(autofill_database_service_), 130 scoped_refptr<AutofillWebDataService>(autofill_database_service_),
182 prefs_.get(), 131 prefs_.get(),
183 account_tracker_.get(), 132 account_tracker_.get(),
184 signin_manager_.get(), 133 signin_manager_.get(),
185 is_incognito); 134 is_incognito);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 std::unique_ptr<TestSigninClient> signin_client_; 293 std::unique_ptr<TestSigninClient> signin_client_;
345 scoped_refptr<AutofillWebDataService> autofill_database_service_; 294 scoped_refptr<AutofillWebDataService> autofill_database_service_;
346 scoped_refptr<WebDatabaseService> web_database_; 295 scoped_refptr<WebDatabaseService> web_database_;
347 AutofillTable* autofill_table_; // weak ref 296 AutofillTable* autofill_table_; // weak ref
348 PersonalDataLoadedObserverMock personal_data_observer_; 297 PersonalDataLoadedObserverMock personal_data_observer_;
349 std::unique_ptr<PersonalDataManager> personal_data_; 298 std::unique_ptr<PersonalDataManager> personal_data_;
350 299
351 variations::testing::VariationParamsManager variation_params_; 300 variations::testing::VariationParamsManager variation_params_;
352 }; 301 };
353 302
303 class PersonalDataManagerTest : public PersonalDataManagerTestBase,
304 public testing::Test {
305 void SetUp() override {
306 OSCryptMocker::SetUpWithSingleton();
307 prefs_ = test::PrefServiceForTesting();
308 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
309 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB");
310 web_database_ =
311 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(),
312 base::ThreadTaskRunnerHandle::Get());
313
314 // Setup account tracker.
315 signin_client_.reset(new TestSigninClient(prefs_.get()));
316 account_tracker_.reset(new AccountTrackerService());
317 account_tracker_->Initialize(signin_client_.get());
318 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(),
319 account_tracker_.get()));
320 signin_manager_->Initialize(prefs_.get());
321
322 // Hacky: hold onto a pointer but pass ownership.
323 autofill_table_ = new AutofillTable;
324 web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_));
325 web_database_->LoadDatabase();
326 autofill_database_service_ = new AutofillWebDataService(
327 web_database_, base::ThreadTaskRunnerHandle::Get(),
328 base::ThreadTaskRunnerHandle::Get(),
329 WebDataServiceBase::ProfileErrorCallback());
330 autofill_database_service_->Init();
331
332 test::DisableSystemServices(prefs_.get());
333 ResetPersonalDataManager(USER_MODE_NORMAL);
334
335 // Reset the deduping pref to its default value.
336 personal_data_->pref_service_->SetInteger(
337 prefs::kAutofillLastVersionDeduped, 0);
338 personal_data_->pref_service_->SetBoolean(
339 prefs::kAutofillProfileUseDatesFixed, false);
340 }
341
342 void TearDown() override {
343 // Order of destruction is important as AutofillManager relies on
344 // PersonalDataManager to be around when it gets destroyed.
345 signin_manager_->Shutdown();
346 signin_manager_.reset();
347
348 account_tracker_->Shutdown();
349 account_tracker_.reset();
350 signin_client_.reset();
351
352 test::DisableSystemServices(prefs_.get());
353 OSCryptMocker::TearDown();
354 }
355 };
356
354 TEST_F(PersonalDataManagerTest, AddProfile) { 357 TEST_F(PersonalDataManagerTest, AddProfile) {
355 // Add profile0 to the database. 358 // Add profile0 to the database.
356 AutofillProfile profile0(test::GetFullProfile()); 359 AutofillProfile profile0(test::GetFullProfile());
357 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); 360 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com"));
358 personal_data_->AddProfile(profile0); 361 personal_data_->AddProfile(profile0);
359 362
360 // Reload the database. 363 // Reload the database.
361 ResetPersonalDataManager(USER_MODE_NORMAL); 364 ResetPersonalDataManager(USER_MODE_NORMAL);
362 365
363 // Verify the addition. 366 // Verify the addition.
(...skipping 3799 matching lines...) Expand 10 before | Expand all | Expand 10 after
4163 FormStructure form_structure2(form2); 4166 FormStructure form_structure2(form2);
4164 form_structure2.DetermineHeuristicTypes(); 4167 form_structure2.DetermineHeuristicTypes();
4165 std::unique_ptr<CreditCard> imported_credit_card2; 4168 std::unique_ptr<CreditCard> imported_credit_card2;
4166 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, 4169 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false,
4167 &imported_credit_card2)); 4170 &imported_credit_card2));
4168 EXPECT_FALSE(imported_credit_card2); 4171 EXPECT_FALSE(imported_credit_card2);
4169 } 4172 }
4170 4173
4171 // Tests the SaveImportedProfile method with different profiles to make sure the 4174 // Tests the SaveImportedProfile method with different profiles to make sure the
4172 // merge logic works correctly. 4175 // merge logic works correctly.
4173 TEST_F(PersonalDataManagerTest, SaveImportedProfile) { 4176 typedef struct {
4174 typedef struct { 4177 autofill::ServerFieldType field_type;
4175 autofill::ServerFieldType field_type; 4178 std::string field_value;
4176 std::string field_value;
4177 } ProfileField; 4179 } ProfileField;
4178 4180
4179 typedef std::vector<ProfileField> ProfileFields; 4181 typedef std::vector<ProfileField> ProfileFields;
4180 4182
4181 typedef struct { 4183 typedef struct {
4182 // Each test starts with a default pre-existing profile and applies these 4184 // Each test starts with a default pre-existing profile and applies these
4183 // changes to it. 4185 // changes to it.
4184 ProfileFields changes_to_original; 4186 ProfileFields changes_to_original;
4185 // Each test saves a second profile. Applies these changes to the default 4187 // Each test saves a second profile. Applies these changes to the default
4186 // values before saving. 4188 // values before saving.
4187 ProfileFields changes_to_new; 4189 ProfileFields changes_to_new;
4188 // For tests with profile merging, makes sure that these fields' values are 4190 // For tests with profile merging, makes sure that these fields' values are
4189 // the ones we expect (depending on the test). 4191 // the ones we expect (depending on the test).
4190 ProfileFields changed_field_values; 4192 ProfileFields changed_field_values;
4191 } TestCase; 4193 } SaveImportedProfileTestCase;
4192 4194
4193 TestCase test_cases[] = { 4195 class SaveImportedProfileTest
4194 // Test that saving an identical profile except for the name results in 4196 : public PersonalDataManagerTestBase,
4195 // two profiles being saved. 4197 public testing::TestWithParam<SaveImportedProfileTestCase> {
4196 {ProfileFields(), {{NAME_FIRST, "Marionette"}}}, 4198 public:
4199 SaveImportedProfileTest() {}
4200 ~SaveImportedProfileTest() override {}
4197 4201
4198 // Test that saving an identical profile except with the middle name 4202 void SetUp() override {
4199 // initial instead of the full middle name results in the profiles 4203 OSCryptMocker::SetUpWithSingleton();
4200 // getting merged and the full middle name being kept. 4204 prefs_ = test::PrefServiceForTesting();
4201 {ProfileFields(), 4205 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
4202 {{NAME_MIDDLE, "M"}}, 4206 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB");
4203 {{NAME_MIDDLE, "Mitchell"}, {NAME_FULL, "Marion Mitchell Morrison"}}}, 4207 web_database_ =
4208 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(),
4209 base::ThreadTaskRunnerHandle::Get());
4204 4210
4205 // Test that saving an identical profile except with the full middle name 4211 // Setup account tracker.
4206 // instead of the middle name initial results in the profiles getting 4212 signin_client_.reset(new TestSigninClient(prefs_.get()));
4207 // merged and the full middle name replacing the initial. 4213 account_tracker_.reset(new AccountTrackerService());
4208 {{{NAME_MIDDLE, "M"}}, 4214 account_tracker_->Initialize(signin_client_.get());
4209 {{NAME_MIDDLE, "Mitchell"}}, 4215 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(),
4210 {{NAME_MIDDLE, "Mitchell"}}}, 4216 account_tracker_.get()));
4217 signin_manager_->Initialize(prefs_.get());
4211 4218
4212 // Test that saving an identical profile except with no middle name 4219 // Hacky: hold onto a pointer but pass ownership.
4213 // results in the profiles getting merged and the full middle name being 4220 autofill_table_ = new AutofillTable;
4214 // kept. 4221 web_database_->AddTable(
4215 {ProfileFields(), {{NAME_MIDDLE, ""}}, {{NAME_MIDDLE, "Mitchell"}}}, 4222 std::unique_ptr<WebDatabaseTable>(autofill_table_));
4223 web_database_->LoadDatabase();
4224 autofill_database_service_ = new AutofillWebDataService(
4225 web_database_, base::ThreadTaskRunnerHandle::Get(),
4226 base::ThreadTaskRunnerHandle::Get(),
4227 WebDataServiceBase::ProfileErrorCallback());
4228 autofill_database_service_->Init();
4216 4229
4217 // Test that saving an identical profile except with a middle name initial 4230 test::DisableSystemServices(prefs_.get());
4218 // results in the profiles getting merged and the middle name initial 4231 ResetPersonalDataManager(USER_MODE_NORMAL);
4219 // being saved.
4220 {{{NAME_MIDDLE, ""}}, {{NAME_MIDDLE, "M"}}, {{NAME_MIDDLE, "M"}}},
4221 4232
4222 // Test that saving an identical profile except with a middle name 4233 // Reset the deduping pref to its default value.
4223 // results in the profiles getting merged and the full middle name being 4234 personal_data_->pref_service_->SetInteger(
4224 // saved. 4235 prefs::kAutofillLastVersionDeduped, 0);
4225 {{{NAME_MIDDLE, ""}}, 4236 personal_data_->pref_service_->SetBoolean(
4226 {{NAME_MIDDLE, "Mitchell"}}, 4237 prefs::kAutofillProfileUseDatesFixed, false);
4227 {{NAME_MIDDLE, "Mitchell"}}}, 4238 }
4228 4239
4229 // Test that saving a identical profile except with the full name set 4240 void TearDown() override {
4230 // instead of the name parts results in the two profiles being merged and 4241 // Order of destruction is important as AutofillManager relies on
4231 // all the name parts kept and the full name being added. 4242 // PersonalDataManager to be around when it gets destroyed.
4232 { 4243 signin_manager_->Shutdown();
4233 { 4244 signin_manager_.reset();
4234 {NAME_FIRST, "Marion"},
4235 {NAME_MIDDLE, "Mitchell"},
4236 {NAME_LAST, "Morrison"},
4237 {NAME_FULL, ""},
4238 },
4239 {
4240 {NAME_FIRST, ""},
4241 {NAME_MIDDLE, ""},
4242 {NAME_LAST, ""},
4243 {NAME_FULL, "Marion Mitchell Morrison"},
4244 },
4245 {
4246 {NAME_FIRST, "Marion"},
4247 {NAME_MIDDLE, "Mitchell"},
4248 {NAME_LAST, "Morrison"},
4249 {NAME_FULL, "Marion Mitchell Morrison"},
4250 },
4251 },
4252 4245
4253 // Test that saving a identical profile except with the name parts set 4246 account_tracker_->Shutdown();
4254 // instead of the full name results in the two profiles being merged and 4247 account_tracker_.reset();
4255 // the full name being kept and all the name parts being added. 4248 signin_client_.reset();
4256 {
4257 {
4258 {NAME_FIRST, ""},
4259 {NAME_MIDDLE, ""},
4260 {NAME_LAST, ""},
4261 {NAME_FULL, "Marion Mitchell Morrison"},
4262 },
4263 {
4264 {NAME_FIRST, "Marion"},
4265 {NAME_MIDDLE, "Mitchell"},
4266 {NAME_LAST, "Morrison"},
4267 {NAME_FULL, ""},
4268 },
4269 {
4270 {NAME_FIRST, "Marion"},
4271 {NAME_MIDDLE, "Mitchell"},
4272 {NAME_LAST, "Morrison"},
4273 {NAME_FULL, "Marion Mitchell Morrison"},
4274 },
4275 },
4276 4249
4277 // Test that saving a profile that has only a full name set does not get 4250 test::DisableSystemServices(prefs_.get());
4278 // merged with a profile with only the name parts set if the names are 4251 OSCryptMocker::TearDown();
4279 // different. 4252 }
4280 {
4281 {
4282 {NAME_FIRST, "Marion"},
4283 {NAME_MIDDLE, "Mitchell"},
4284 {NAME_LAST, "Morrison"},
4285 {NAME_FULL, ""},
4286 },
4287 {
4288 {NAME_FIRST, ""},
4289 {NAME_MIDDLE, ""},
4290 {NAME_LAST, ""},
4291 {NAME_FULL, "John Thompson Smith"},
4292 },
4293 },
4294
4295 // Test that saving a profile that has only the name parts set does not
4296 // get merged with a profile with only the full name set if the names are
4297 // different.
4298 {
4299 {
4300 {NAME_FIRST, ""},
4301 {NAME_MIDDLE, ""},
4302 {NAME_LAST, ""},
4303 {NAME_FULL, "John Thompson Smith"},
4304 },
4305 {
4306 {NAME_FIRST, "Marion"},
4307 {NAME_MIDDLE, "Mitchell"},
4308 {NAME_LAST, "Morrison"},
4309 {NAME_FULL, ""},
4310 },
4311 },
4312
4313 // Test that saving an identical profile except for the first address line
4314 // results in two profiles being saved.
4315 {ProfileFields(), {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}},
4316
4317 // Test that saving an identical profile except for the second address
4318 // line results in two profiles being saved.
4319 {ProfileFields(), {{ADDRESS_HOME_LINE2, "unit 7"}}},
4320
4321 // Tests that saving an identical profile that has a new piece of
4322 // information (company name) results in a merge and that the original
4323 // empty value gets overwritten by the new information.
4324 {{{COMPANY_NAME, ""}}, ProfileFields(), {{COMPANY_NAME, "Fox"}}},
4325
4326 // Tests that saving an identical profile except a loss of information
4327 // results in a merge but the original value is not overwritten (no
4328 // information loss).
4329 {ProfileFields(), {{COMPANY_NAME, ""}}, {{COMPANY_NAME, "Fox"}}},
4330
4331 // Tests that saving an identical profile except a slightly different
4332 // postal code results in a merge with the new value kept.
4333 {{{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4334 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4335 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4336 {{{ADDRESS_HOME_ZIP, "R2C0A1"}},
4337 {{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4338 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}},
4339 {{{ADDRESS_HOME_ZIP, "r2c 0a1"}},
4340 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4341 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4342
4343 // Tests that saving an identical profile plus a new piece of information
4344 // on the address line 2 results in a merge and that the original empty
4345 // value gets overwritten by the new information.
4346 {{{ADDRESS_HOME_LINE2, ""}},
4347 ProfileFields(),
4348 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4349
4350 // Tests that saving an identical profile except a loss of information on
4351 // the address line 2 results in a merge but that the original value gets
4352 // not overwritten (no information loss).
4353 {ProfileFields(),
4354 {{ADDRESS_HOME_LINE2, ""}},
4355 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4356
4357 // Tests that saving an identical except with more punctuation in the fist
4358 // address line, while the second is empty, results in a merge and that
4359 // the original address gets overwritten.
4360 {{{ADDRESS_HOME_LINE2, ""}},
4361 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4362 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}},
4363
4364 // Tests that saving an identical profile except with less punctuation in
4365 // the fist address line, while the second is empty, results in a merge
4366 // and that the longer address is retained.
4367 {{{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4368 {{ADDRESS_HOME_LINE2, ""}},
4369 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}},
4370
4371 // Tests that saving an identical profile except additional punctuation in
4372 // the two address lines results in a merge and that the newer address
4373 // is retained.
4374 {ProfileFields(),
4375 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}},
4376 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}}},
4377
4378 // Tests that saving an identical profile except less punctuation in the
4379 // two address lines results in a merge and that the newer address is
4380 // retained.
4381 {{{ADDRESS_HOME_LINE1, "123, Zoo St."}, {ADDRESS_HOME_LINE2, "unit. 5"}},
4382 ProfileFields(),
4383 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4384
4385 // Tests that saving an identical profile with accented characters in
4386 // the two address lines results in a merge and that the newer address
4387 // is retained.
4388 {ProfileFields(),
4389 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}},
4390 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}}},
4391
4392 // Tests that saving an identical profile without accented characters in
4393 // the two address lines results in a merge and that the newer address
4394 // is retained.
4395 {{{ADDRESS_HOME_LINE1, "123 Zôö St"}, {ADDRESS_HOME_LINE2, "üñìt 5"}},
4396 ProfileFields(),
4397 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4398
4399 // Tests that saving an identical profile except that the address line 1
4400 // is in the address line 2 results in a merge and that the multi-lne
4401 // address is retained.
4402 {ProfileFields(),
4403 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}},
4404 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4405
4406 // Tests that saving an identical profile except that the address line 2
4407 // contains part of the old address line 1 results in a merge and that the
4408 // original address lines of the reference profile get overwritten.
4409 {{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, {ADDRESS_HOME_LINE2, ""}},
4410 ProfileFields(),
4411 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, {ADDRESS_HOME_LINE2, "unit 5"}}},
4412
4413 // Tests that saving an identical profile except that the state is the
4414 // abbreviation instead of the full form results in a merge and that the
4415 // original state gets overwritten.
4416 {{{ADDRESS_HOME_STATE, "California"}},
4417 ProfileFields(),
4418 {{ADDRESS_HOME_STATE, "CA"}}},
4419
4420 // Tests that saving an identical profile except that the state is the
4421 // full form instead of the abbreviation results in a merge and that the
4422 // abbreviated state is retained.
4423 {ProfileFields(),
4424 {{ADDRESS_HOME_STATE, "California"}},
4425 {{ADDRESS_HOME_STATE, "CA"}}},
4426
4427 // Tests that saving and identical profile except that the company name
4428 // has different punctuation and case results in a merge and that the
4429 // syntax of the new profile replaces the old one.
4430 {{{COMPANY_NAME, "Stark inc"}},
4431 {{COMPANY_NAME, "Stark Inc."}},
4432 {{COMPANY_NAME, "Stark Inc."}}},
4433 }; 4253 };
4434 4254
4435 // Create the test clock. 4255 TEST_P(SaveImportedProfileTest, SaveImportedProfile) {
4436 TestAutofillClock test_clock; 4256 // Create the test clock.
4437 4257 TestAutofillClock test_clock;
4438 for (TestCase test_case : test_cases) { 4258 auto test_case = GetParam();
4439 // Set the time to a specific value. 4259 // Set the time to a specific value.
4440 test_clock.SetNow(kArbitraryTime); 4260 test_clock.SetNow(kArbitraryTime);
4441 4261
4442 SetupReferenceProfile(); 4262 SetupReferenceProfile();
4443 const std::vector<AutofillProfile*>& initial_profiles = 4263 const std::vector<AutofillProfile*>& initial_profiles =
4444 personal_data_->GetProfiles(); 4264 personal_data_->GetProfiles();
4445 4265
4446 // Apply changes to the original profile (if applicable). 4266 // Apply changes to the original profile (if applicable).
4447 for (ProfileField change : test_case.changes_to_original) { 4267 for (ProfileField change : test_case.changes_to_original) {
4448 initial_profiles.front()->SetRawInfo( 4268 initial_profiles.front()->SetRawInfo(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 // Verify that the merged profile's use count, use date and modification 4303 // Verify that the merged profile's use count, use date and modification
4484 // date were properly updated. 4304 // date were properly updated.
4485 EXPECT_EQ(1U, saved_profiles.front()->use_count()); 4305 EXPECT_EQ(1U, saved_profiles.front()->use_count());
4486 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date()); 4306 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date());
4487 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date()); 4307 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date());
4488 } 4308 }
4489 4309
4490 // Erase the profiles for the next test. 4310 // Erase the profiles for the next test.
4491 ResetProfiles(); 4311 ResetProfiles();
4492 } 4312 }
4313
4314 INSTANTIATE_TEST_CASE_P(
4315 PersonalDataManagerTest,
4316 SaveImportedProfileTest,
4317 testing::Values(
4318 // Test that saving an identical profile except for the name results
4319 // in two profiles being saved.
4320 SaveImportedProfileTestCase{ProfileFields(),
4321 {{NAME_FIRST, "Marionette"}}},
4322
4323 // Test that saving an identical profile except with the middle name
4324 // initial instead of the full middle name results in the profiles
4325 // getting merged and the full middle name being kept.
4326 SaveImportedProfileTestCase{
4327 ProfileFields(),
4328 {{NAME_MIDDLE, "M"}},
4329 {{NAME_MIDDLE, "Mitchell"},
4330 {NAME_FULL, "Marion Mitchell Morrison"}}},
4331
4332 // Test that saving an identical profile except with the full middle
4333 // name instead of the middle name initial results in the profiles
4334 // getting merged and the full middle name replacing the initial.
4335 SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}},
4336 {{NAME_MIDDLE, "Mitchell"}},
4337 {{NAME_MIDDLE, "Mitchell"}}},
4338
4339 // Test that saving an identical profile except with no middle name
4340 // results in the profiles getting merged and the full middle name
4341 // being kept.
4342 SaveImportedProfileTestCase{ProfileFields(),
4343 {{NAME_MIDDLE, ""}},
4344 {{NAME_MIDDLE, "Mitchell"}}},
4345
4346 // Test that saving an identical profile except with a middle name
4347 // initial results in the profiles getting merged and the middle name
4348 // initial being saved.
4349 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4350 {{NAME_MIDDLE, "M"}},
4351 {{NAME_MIDDLE, "M"}}},
4352
4353 // Test that saving an identical profile except with a middle name
4354 // results in the profiles getting merged and the full middle name
4355 // being saved.
4356 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4357 {{NAME_MIDDLE, "Mitchell"}},
4358 {{NAME_MIDDLE, "Mitchell"}}},
4359
4360 // Test that saving a identical profile except with the full name set
4361 // instead of the name parts results in the two profiles being merged
4362 // and all the name parts kept and the full name being added.
4363 SaveImportedProfileTestCase{
4364 {
4365 {NAME_FIRST, "Marion"},
4366 {NAME_MIDDLE, "Mitchell"},
4367 {NAME_LAST, "Morrison"},
4368 {NAME_FULL, ""},
4369 },
4370 {
4371 {NAME_FIRST, ""},
4372 {NAME_MIDDLE, ""},
4373 {NAME_LAST, ""},
4374 {NAME_FULL, "Marion Mitchell Morrison"},
4375 },
4376 {
4377 {NAME_FIRST, "Marion"},
4378 {NAME_MIDDLE, "Mitchell"},
4379 {NAME_LAST, "Morrison"},
4380 {NAME_FULL, "Marion Mitchell Morrison"},
4381 },
4382 },
4383
4384 // Test that saving a identical profile except with the name parts set
4385 // instead of the full name results in the two profiles being merged
4386 // and the full name being kept and all the name parts being added.
4387 SaveImportedProfileTestCase{
4388 {
4389 {NAME_FIRST, ""},
4390 {NAME_MIDDLE, ""},
4391 {NAME_LAST, ""},
4392 {NAME_FULL, "Marion Mitchell Morrison"},
4393 },
4394 {
4395 {NAME_FIRST, "Marion"},
4396 {NAME_MIDDLE, "Mitchell"},
4397 {NAME_LAST, "Morrison"},
4398 {NAME_FULL, ""},
4399 },
4400 {
4401 {NAME_FIRST, "Marion"},
4402 {NAME_MIDDLE, "Mitchell"},
4403 {NAME_LAST, "Morrison"},
4404 {NAME_FULL, "Marion Mitchell Morrison"},
4405 },
4406 },
4407
4408 // Test that saving a profile that has only a full name set does not
4409 // get merged with a profile with only the name parts set if the names
4410 // are different.
4411 SaveImportedProfileTestCase{
4412 {
4413 {NAME_FIRST, "Marion"},
4414 {NAME_MIDDLE, "Mitchell"},
4415 {NAME_LAST, "Morrison"},
4416 {NAME_FULL, ""},
4417 },
4418 {
4419 {NAME_FIRST, ""},
4420 {NAME_MIDDLE, ""},
4421 {NAME_LAST, ""},
4422 {NAME_FULL, "John Thompson Smith"},
4423 },
4424 },
4425
4426 // Test that saving a profile that has only the name parts set does
4427 // not get merged with a profile with only the full name set if the
4428 // names are different.
4429 SaveImportedProfileTestCase{
4430 {
4431 {NAME_FIRST, ""},
4432 {NAME_MIDDLE, ""},
4433 {NAME_LAST, ""},
4434 {NAME_FULL, "John Thompson Smith"},
4435 },
4436 {
4437 {NAME_FIRST, "Marion"},
4438 {NAME_MIDDLE, "Mitchell"},
4439 {NAME_LAST, "Morrison"},
4440 {NAME_FULL, ""},
4441 },
4442 },
4443
4444 // Test that saving an identical profile except for the first address
4445 // line results in two profiles being saved.
4446 SaveImportedProfileTestCase{
4447 ProfileFields(),
4448 {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}},
4449
4450 // Test that saving an identical profile except for the second address
4451 // line results in two profiles being saved.
4452 SaveImportedProfileTestCase{ProfileFields(),
4453 {{ADDRESS_HOME_LINE2, "unit 7"}}},
4454
4455 // Tests that saving an identical profile that has a new piece of
4456 // information (company name) results in a merge and that the original
4457 // empty value gets overwritten by the new information.
4458 SaveImportedProfileTestCase{{{COMPANY_NAME, ""}},
4459 ProfileFields(),
4460 {{COMPANY_NAME, "Fox"}}},
4461
4462 // Tests that saving an identical profile except a loss of information
4463 // results in a merge but the original value is not overwritten (no
4464 // information loss).
4465 SaveImportedProfileTestCase{ProfileFields(),
4466 {{COMPANY_NAME, ""}},
4467 {{COMPANY_NAME, "Fox"}}},
4468
4469 // Tests that saving an identical profile except a slightly different
4470 // postal code results in a merge with the new value kept.
4471 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4472 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4473 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4474 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}},
4475 {{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4476 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}},
4477 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}},
4478 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4479 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4480
4481 // Tests that saving an identical profile plus a new piece of
4482 // information on the address line 2 results in a merge and that the
4483 // original empty value gets overwritten by the new information.
4484 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}},
4485 ProfileFields(),
4486 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4487
4488 // Tests that saving an identical profile except a loss of information
4489 // on the address line 2 results in a merge but that the original
4490 // value gets not overwritten (no information loss).
4491 SaveImportedProfileTestCase{ProfileFields(),
4492 {{ADDRESS_HOME_LINE2, ""}},
4493 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4494
4495 // Tests that saving an identical except with more punctuation in the
4496 // fist address line, while the second is empty, results in a merge
4497 // and that the original address gets overwritten.
4498 SaveImportedProfileTestCase{
4499 {{ADDRESS_HOME_LINE2, ""}},
4500 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4501 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}},
4502
4503 // Tests that saving an identical profile except with less punctuation
4504 // in the fist address line, while the second is empty, results in a
4505 // merge and that the longer address is retained.
4506 SaveImportedProfileTestCase{
4507 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4508 {{ADDRESS_HOME_LINE2, ""}},
4509 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}},
4510
4511 // Tests that saving an identical profile except additional
4512 // punctuation in the two address lines results in a merge and that
4513 // the newer address is retained.
4514 SaveImportedProfileTestCase{ProfileFields(),
4515 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4516 {ADDRESS_HOME_LINE2, "unit. 5"}},
4517 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4518 {ADDRESS_HOME_LINE2, "unit. 5"}}},
4519
4520 // Tests that saving an identical profile except less punctuation in
4521 // the two address lines results in a merge and that the newer address
4522 // is retained.
4523 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."},
4524 {ADDRESS_HOME_LINE2, "unit. 5"}},
4525 ProfileFields(),
4526 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4527 {ADDRESS_HOME_LINE2, "unit 5"}}},
4528
4529 // Tests that saving an identical profile with accented characters in
4530 // the two address lines results in a merge and that the newer address
4531 // is retained.
4532 SaveImportedProfileTestCase{ProfileFields(),
4533 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4534 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4535 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4536 {ADDRESS_HOME_LINE2, "üñìt 5"}}},
4537
4538 // Tests that saving an identical profile without accented characters
4539 // in the two address lines results in a merge and that the newer
4540 // address is retained.
4541 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"},
4542 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4543 ProfileFields(),
4544 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4545 {ADDRESS_HOME_LINE2, "unit 5"}}},
4546
4547 // Tests that saving an identical profile except that the address line
4548 // 1 is in the address line 2 results in a merge and that the
4549 // multi-lne address is retained.
4550 SaveImportedProfileTestCase{
4551 ProfileFields(),
4552 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4553 {ADDRESS_HOME_LINE2, ""}},
4554 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4555 {ADDRESS_HOME_LINE2, "unit 5"}}},
4556
4557 // Tests that saving an identical profile except that the address line
4558 // 2 contains part of the old address line 1 results in a merge and
4559 // that the original address lines of the reference profile get
4560 // overwritten.
4561 SaveImportedProfileTestCase{
4562 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4563 {ADDRESS_HOME_LINE2, ""}},
4564 ProfileFields(),
4565 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4566 {ADDRESS_HOME_LINE2, "unit 5"}}},
4567
4568 // Tests that saving an identical profile except that the state is the
4569 // abbreviation instead of the full form results in a merge and that
4570 // the original state gets overwritten.
4571 SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}},
4572 ProfileFields(),
4573 {{ADDRESS_HOME_STATE, "CA"}}},
4574
4575 // Tests that saving an identical profile except that the state is the
4576 // full form instead of the abbreviation results in a merge and that
4577 // the abbreviated state is retained.
4578 SaveImportedProfileTestCase{ProfileFields(),
4579 {{ADDRESS_HOME_STATE, "California"}},
4580 {{ADDRESS_HOME_STATE, "CA"}}},
4581
4582 // Tests that saving and identical profile except that the company
4583 // name has different punctuation and case results in a merge and that
4584 // the syntax of the new profile replaces the old one.
4585 SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}},
4586 {{COMPANY_NAME, "Stark Inc."}},
4587 {{COMPANY_NAME, "Stark Inc."}}}));
4588
4589 // Tests that MergeProfile tries to merge the imported profile into the
4590 // existing profile in decreasing order of frecency.
4591 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
4592 // Create two very similar profiles except with different company names.
4593 std::unique_ptr<AutofillProfile> profile1 =
4594 base::MakeUnique<AutofillProfile>(base::GenerateGUID(),
4595 "https://www.example.com");
4596 test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson",
4597 "homer.simpson@abc.com", "SNP",
4598 "742 Evergreen Terrace", "", "Springfield", "IL",
4599 "91601", "US", "12345678910");
4600 AutofillProfile* profile2 =
4601 new AutofillProfile(base::GenerateGUID(), "https://www.example.com");
4602 test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson",
4603 "homer.simpson@abc.com", "Fox",
4604 "742 Evergreen Terrace", "", "Springfield", "IL",
4605 "91601", "US", "12345678910");
4606
4607 // Give the "Fox" profile a bigger frecency score.
4608 profile2->set_use_count(15);
4609
4610 // Create the |existing_profiles| vector.
4611 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles;
4612 existing_profiles.push_back(std::move(profile1));
4613 existing_profiles.push_back(base::WrapUnique(profile2));
4614
4615 // Create a new imported profile with no company name.
4616 AutofillProfile imported_profile(base::GenerateGUID(),
4617 "https://www.example.com");
4618 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
4619 "homer.simpson@abc.com", "", "742 Evergreen Terrace",
4620 "", "Springfield", "IL", "91601", "US", "12345678910");
4621
4622 // Merge the imported profile into the existing profiles.
4623 std::vector<AutofillProfile> profiles;
4624 std::string guid = personal_data_->MergeProfile(
4625 imported_profile, &existing_profiles, "US-EN", &profiles);
4626
4627 // The new profile should be merged into the "fox" profile.
4628 EXPECT_EQ(profile2->guid(), guid);
4493 } 4629 }
4494 4630
4495 // Tests that MergeProfile tries to merge the imported profile into the
4496 // existing profile in decreasing order of frecency.
4497 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
4498 // Create two very similar profiles except with different company names.
4499 std::unique_ptr<AutofillProfile> profile1 = base::MakeUnique<AutofillProfile>(
4500 base::GenerateGUID(), "https://www.example.com");
4501 test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson",
4502 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
4503 "", "Springfield", "IL", "91601", "US", "12345678910");
4504 AutofillProfile* profile2 =
4505 new AutofillProfile(base::GenerateGUID(), "https://www.example.com");
4506 test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson",
4507 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace",
4508 "", "Springfield", "IL", "91601", "US", "12345678910");
4509
4510 // Give the "Fox" profile a bigger frecency score.
4511 profile2->set_use_count(15);
4512
4513 // Create the |existing_profiles| vector.
4514 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles;
4515 existing_profiles.push_back(std::move(profile1));
4516 existing_profiles.push_back(base::WrapUnique(profile2));
4517
4518 // Create a new imported profile with no company name.
4519 AutofillProfile imported_profile(base::GenerateGUID(),
4520 "https://www.example.com");
4521 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
4522 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4523 "Springfield", "IL", "91601", "US", "12345678910");
4524
4525 // Merge the imported profile into the existing profiles.
4526 std::vector<AutofillProfile> profiles;
4527 std::string guid = personal_data_->MergeProfile(
4528 imported_profile, &existing_profiles, "US-EN", &profiles);
4529
4530 // The new profile should be merged into the "fox" profile.
4531 EXPECT_EQ(profile2->guid(), guid);
4532 }
4533
4534 // Tests that MergeProfile produces a merged profile with the expected usage 4631 // Tests that MergeProfile produces a merged profile with the expected usage
4535 // statistics. 4632 // statistics.
4536 // Flaky on TSan, see crbug.com/686226. 4633 // Flaky on TSan, see crbug.com/686226.
4537 #if defined(THREAD_SANITIZER) 4634 #if defined(THREAD_SANITIZER)
4538 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats 4635 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats
4539 #else 4636 #else
4540 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats 4637 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats
4541 #endif 4638 #endif
4542 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { 4639 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) {
4543 // Create the test clock and set the time to a specific value. 4640 // Create the test clock and set the time to a specific value.
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
6115 // to the converted address. 6212 // to the converted address.
6116 EXPECT_EQ(profiles[0]->guid(), 6213 EXPECT_EQ(profiles[0]->guid(),
6117 personal_data_->GetCreditCards()[0]->billing_address_id()); 6214 personal_data_->GetCreditCards()[0]->billing_address_id());
6118 // Make sure that the billing address id of the new server card still refers 6215 // Make sure that the billing address id of the new server card still refers
6119 // to the converted address. 6216 // to the converted address.
6120 EXPECT_EQ(profiles[0]->guid(), 6217 EXPECT_EQ(profiles[0]->guid(),
6121 personal_data_->GetCreditCards()[1]->billing_address_id()); 6218 personal_data_->GetCreditCards()[1]->billing_address_id());
6122 } 6219 }
6123 6220
6124 } // namespace autofill 6221 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698