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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Addressed comments Created 3 years, 10 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>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
19 #include "base/guid.h" 19 #include "base/guid.h"
20 #include "base/i18n/time_formatting.h"
20 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/test/histogram_tester.h" 25 #include "base/test/histogram_tester.h"
26 #include "base/test/simple_test_clock.h" 26 #include "base/test/simple_test_clock.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "build/build_config.h" 29 #include "build/build_config.h"
30 #include "components/autofill/core/browser/autofill_experiments.h" 30 #include "components/autofill/core/browser/autofill_experiments.h"
31 #include "components/autofill/core/browser/autofill_metrics.h" 31 #include "components/autofill/core/browser/autofill_metrics.h"
32 #include "components/autofill/core/browser/autofill_profile.h" 32 #include "components/autofill/core/browser/autofill_profile.h"
33 #include "components/autofill/core/browser/autofill_test_utils.h" 33 #include "components/autofill/core/browser/autofill_test_utils.h"
34 #include "components/autofill/core/browser/field_types.h" 34 #include "components/autofill/core/browser/field_types.h"
35 #include "components/autofill/core/browser/form_structure.h" 35 #include "components/autofill/core/browser/form_structure.h"
36 #include "components/autofill/core/browser/personal_data_manager_observer.h" 36 #include "components/autofill/core/browser/personal_data_manager_observer.h"
37 #include "components/autofill/core/browser/test_autofill_clock.h" 37 #include "components/autofill/core/browser/test_autofill_clock.h"
38 #include "components/autofill/core/browser/webdata/autofill_table.h" 38 #include "components/autofill/core/browser/webdata/autofill_table.h"
39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
40 #include "components/autofill/core/common/autofill_clock.h" 40 #include "components/autofill/core/common/autofill_clock.h"
41 #include "components/autofill/core/common/autofill_constants.h" 41 #include "components/autofill/core/common/autofill_constants.h"
42 #include "components/autofill/core/common/autofill_pref_names.h" 42 #include "components/autofill/core/common/autofill_pref_names.h"
43 #include "components/autofill/core/common/autofill_switches.h" 43 #include "components/autofill/core/common/autofill_switches.h"
44 #include "components/autofill/core/common/form_data.h" 44 #include "components/autofill/core/common/form_data.h"
45 #include "components/os_crypt/os_crypt_mocker.h" 45 #include "components/os_crypt/os_crypt_mocker.h"
46 #include "components/prefs/pref_service.h" 46 #include "components/prefs/pref_service.h"
47 #include "components/signin/core/browser/account_tracker_service.h" 47 #include "components/signin/core/browser/account_tracker_service.h"
48 #include "components/signin/core/browser/fake_signin_manager.h" 48 #include "components/signin/core/browser/fake_signin_manager.h"
49 #include "components/signin/core/browser/test_signin_client.h" 49 #include "components/signin/core/browser/test_signin_client.h"
50 #include "components/signin/core/common/signin_pref_names.h" 50 #include "components/signin/core/common/signin_pref_names.h"
51 #include "components/variations/entropy_provider.h" 51 #include "components/variations/variations_params_manager.h"
52 #include "components/variations/variations_associated_data.h"
53 #include "components/webdata/common/web_data_service_base.h" 52 #include "components/webdata/common/web_data_service_base.h"
54 #include "components/webdata/common/web_database_service.h" 53 #include "components/webdata/common/web_database_service.h"
55 #include "testing/gmock/include/gmock/gmock.h" 54 #include "testing/gmock/include/gmock/gmock.h"
56 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
57 56
58 using base::ASCIIToUTF16; 57 using base::ASCIIToUTF16;
59 using base::UTF8ToUTF16; 58 using base::UTF8ToUTF16;
60 59
61 namespace autofill { 60 namespace autofill {
62 namespace { 61 namespace {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 web_database_->LoadDatabase(); 146 web_database_->LoadDatabase();
148 autofill_database_service_ = new AutofillWebDataService( 147 autofill_database_service_ = new AutofillWebDataService(
149 web_database_, base::ThreadTaskRunnerHandle::Get(), 148 web_database_, base::ThreadTaskRunnerHandle::Get(),
150 base::ThreadTaskRunnerHandle::Get(), 149 base::ThreadTaskRunnerHandle::Get(),
151 WebDataServiceBase::ProfileErrorCallback()); 150 WebDataServiceBase::ProfileErrorCallback());
152 autofill_database_service_->Init(); 151 autofill_database_service_->Init();
153 152
154 test::DisableSystemServices(prefs_.get()); 153 test::DisableSystemServices(prefs_.get());
155 ResetPersonalDataManager(USER_MODE_NORMAL); 154 ResetPersonalDataManager(USER_MODE_NORMAL);
156 155
157 // There are no field trials enabled by default.
158 field_trial_list_.reset();
159
160 // Reset the deduping pref to its default value. 156 // Reset the deduping pref to its default value.
161 personal_data_->pref_service_->SetInteger( 157 personal_data_->pref_service_->SetInteger(
162 prefs::kAutofillLastVersionDeduped, 0); 158 prefs::kAutofillLastVersionDeduped, 0);
163 personal_data_->pref_service_->SetBoolean( 159 personal_data_->pref_service_->SetBoolean(
164 prefs::kAutofillProfileUseDatesFixed, false); 160 prefs::kAutofillProfileUseDatesFixed, false);
165 } 161 }
166 162
167 void TearDown() override { 163 void TearDown() override {
168 // Order of destruction is important as AutofillManager relies on 164 // Order of destruction is important as AutofillManager relies on
169 // PersonalDataManager to be around when it gets destroyed. 165 // PersonalDataManager to be around when it gets destroyed.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 bool ImportAddressProfiles(const FormStructure& form) { 302 bool ImportAddressProfiles(const FormStructure& form) {
307 return personal_data_->ImportAddressProfiles(form); 303 return personal_data_->ImportAddressProfiles(form);
308 } 304 }
309 bool ImportCreditCard(const FormStructure& form, 305 bool ImportCreditCard(const FormStructure& form,
310 bool should_return_local_card, 306 bool should_return_local_card,
311 std::unique_ptr<CreditCard>* imported_credit_card) { 307 std::unique_ptr<CreditCard>* imported_credit_card) {
312 return personal_data_->ImportCreditCard(form, should_return_local_card, 308 return personal_data_->ImportCreditCard(form, should_return_local_card,
313 imported_credit_card); 309 imported_credit_card);
314 } 310 }
315 311
316 // Sets up the profile order field trial group and parameter. Sets up the
317 // suggestions limit parameter to |limit_param|.
318 void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) {
319 DCHECK(!limit_param.empty());
320
321 // Clear the existing |field_trial_list_| and variation parameters.
322 field_trial_list_.reset(NULL);
323 field_trial_list_.reset(
324 new base::FieldTrialList(
325 base::MakeUnique<metrics::SHA1EntropyProvider>("foo")));
326 variations::testing::ClearAllVariationParams();
327
328 std::map<std::string, std::string> params;
329 params[kFrecencyFieldTrialLimitParam] = limit_param;
330 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN",
331 params);
332
333 field_trial_ = base::FieldTrialList::CreateFieldTrial(
334 kFrecencyFieldTrialName, "LimitToN");
335 field_trial_->group();
336 }
337
338 void SubmitFormAndExpectImportedCardWithData(const FormData& form, 312 void SubmitFormAndExpectImportedCardWithData(const FormData& form,
339 const char* exp_name, 313 const char* exp_name,
340 const char* exp_cc_num, 314 const char* exp_cc_num,
341 const char* exp_cc_month, 315 const char* exp_cc_month,
342 const char* exp_cc_year) { 316 const char* exp_cc_year) {
343 FormStructure form_structure(form); 317 FormStructure form_structure(form);
344 form_structure.DetermineHeuristicTypes(); 318 form_structure.DetermineHeuristicTypes();
345 std::unique_ptr<CreditCard> imported_credit_card; 319 std::unique_ptr<CreditCard> imported_credit_card;
346 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 320 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
347 ASSERT_TRUE(imported_credit_card); 321 ASSERT_TRUE(imported_credit_card);
(...skipping 19 matching lines...) Expand all
367 std::unique_ptr<PrefService> prefs_; 341 std::unique_ptr<PrefService> prefs_;
368 std::unique_ptr<AccountTrackerService> account_tracker_; 342 std::unique_ptr<AccountTrackerService> account_tracker_;
369 std::unique_ptr<FakeSigninManagerBase> signin_manager_; 343 std::unique_ptr<FakeSigninManagerBase> signin_manager_;
370 std::unique_ptr<TestSigninClient> signin_client_; 344 std::unique_ptr<TestSigninClient> signin_client_;
371 scoped_refptr<AutofillWebDataService> autofill_database_service_; 345 scoped_refptr<AutofillWebDataService> autofill_database_service_;
372 scoped_refptr<WebDatabaseService> web_database_; 346 scoped_refptr<WebDatabaseService> web_database_;
373 AutofillTable* autofill_table_; // weak ref 347 AutofillTable* autofill_table_; // weak ref
374 PersonalDataLoadedObserverMock personal_data_observer_; 348 PersonalDataLoadedObserverMock personal_data_observer_;
375 std::unique_ptr<PersonalDataManager> personal_data_; 349 std::unique_ptr<PersonalDataManager> personal_data_;
376 350
377 std::unique_ptr<base::FieldTrialList> field_trial_list_; 351 variations::testing::VariationParamsManager variation_params_;
378 scoped_refptr<base::FieldTrial> field_trial_;
379 }; 352 };
380 353
381 TEST_F(PersonalDataManagerTest, AddProfile) { 354 TEST_F(PersonalDataManagerTest, AddProfile) {
382 // Add profile0 to the database. 355 // Add profile0 to the database.
383 AutofillProfile profile0(test::GetFullProfile()); 356 AutofillProfile profile0(test::GetFullProfile());
384 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); 357 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com"));
385 personal_data_->AddProfile(profile0); 358 personal_data_->AddProfile(profile0);
386 359
387 // Reload the database. 360 // Reload the database.
388 ResetPersonalDataManager(USER_MODE_NORMAL); 361 ResetPersonalDataManager(USER_MODE_NORMAL);
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3449 3422
3450 ResetPersonalDataManager(USER_MODE_NORMAL); 3423 ResetPersonalDataManager(USER_MODE_NORMAL);
3451 3424
3452 // Verify that all the profiles are suggested. 3425 // Verify that all the profiles are suggested.
3453 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions( 3426 std::vector<Suggestion> suggestions = personal_data_->GetProfileSuggestions(
3454 AutofillType(NAME_FIRST), base::string16(), false, 3427 AutofillType(NAME_FIRST), base::string16(), false,
3455 std::vector<ServerFieldType>()); 3428 std::vector<ServerFieldType>());
3456 EXPECT_EQ(3U, suggestions.size()); 3429 EXPECT_EQ(3U, suggestions.size());
3457 3430
3458 // Verify that only two profiles are suggested. 3431 // Verify that only two profiles are suggested.
3459 EnableAutofillProfileLimitFieldTrial("2"); 3432 variation_params_.SetVariationParams(kFrecencyFieldTrialName,
3433 {{kFrecencyFieldTrialLimitParam, "2"}});
3460 3434
3461 suggestions = personal_data_->GetProfileSuggestions( 3435 suggestions = personal_data_->GetProfileSuggestions(
3462 AutofillType(NAME_FIRST), base::string16(), false, 3436 AutofillType(NAME_FIRST), base::string16(), false,
3463 std::vector<ServerFieldType>()); 3437 std::vector<ServerFieldType>());
3464 EXPECT_EQ(2U, suggestions.size()); 3438 EXPECT_EQ(2U, suggestions.size());
3465 } 3439 }
3466 3440
3467 // Tests that GetProfileSuggestions returns the right number of profile 3441 // Tests that GetProfileSuggestions returns the right number of profile
3468 // suggestions when the limit to three field trial is set and there are less 3442 // suggestions when the limit to three field trial is set and there are less
3469 // than three profiles. 3443 // than three profiles.
3470 TEST_F(PersonalDataManagerTest, 3444 TEST_F(PersonalDataManagerTest,
3471 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) { 3445 GetProfileSuggestions_LimitIsMoreThanProfileSuggestions) {
3472 EnableAutofillProfileLimitFieldTrial("3"); 3446 variation_params_.SetVariationParams(kFrecencyFieldTrialName,
3447 {{kFrecencyFieldTrialLimitParam, "3"}});
3473 3448
3474 // Set up 2 different profiles. 3449 // Set up 2 different profiles.
3475 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 3450 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
3476 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison", 3451 test::SetProfileInfo(&profile1, "Marion1", "Mitchell", "Morrison",
3477 "johnwayne@me.xyz", "Fox", 3452 "johnwayne@me.xyz", "Fox",
3478 "123 Zoo St.\nSecond Line\nThird line", "unit 5", 3453 "123 Zoo St.\nSecond Line\nThird line", "unit 5",
3479 "Hollywood", "CA", "91601", "US", "12345678910"); 3454 "Hollywood", "CA", "91601", "US", "12345678910");
3480 personal_data_->AddProfile(profile1); 3455 personal_data_->AddProfile(profile1);
3481 3456
3482 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); 3457 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
(...skipping 2542 matching lines...) Expand 10 before | Expand all | Expand 10 after
6025 6000
6026 // Make sure that the billing address id of the two cards now point to the 6001 // Make sure that the billing address id of the two cards now point to the
6027 // converted profile. 6002 // converted profile.
6028 EXPECT_EQ(profiles[0]->guid(), 6003 EXPECT_EQ(profiles[0]->guid(),
6029 personal_data_->GetCreditCards()[0]->billing_address_id()); 6004 personal_data_->GetCreditCards()[0]->billing_address_id());
6030 EXPECT_EQ(profiles[0]->guid(), 6005 EXPECT_EQ(profiles[0]->guid(),
6031 personal_data_->GetCreditCards()[1]->billing_address_id()); 6006 personal_data_->GetCreditCards()[1]->billing_address_id());
6032 } 6007 }
6033 6008
6034 } // namespace autofill 6009 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | components/autofill_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698