| OLD | NEW |
| 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" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
| 8 #include <string> | 11 #include <string> |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/guid.h" | 16 #include "base/guid.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 20 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 21 #include "components/autofill/core/browser/autofill_experiments.h" | 23 #include "components/autofill/core/browser/autofill_experiments.h" |
| 22 #include "components/autofill/core/browser/autofill_profile.h" | 24 #include "components/autofill/core/browser/autofill_profile.h" |
| 23 #include "components/autofill/core/browser/autofill_test_utils.h" | 25 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 24 #include "components/autofill/core/browser/field_types.h" | 26 #include "components/autofill/core/browser/field_types.h" |
| 25 #include "components/autofill/core/browser/form_structure.h" | 27 #include "components/autofill/core/browser/form_structure.h" |
| 26 #include "components/autofill/core/browser/personal_data_manager.h" | |
| 27 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 28 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 28 #include "components/autofill/core/browser/webdata/autofill_table.h" | 29 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 29 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 30 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 30 #include "components/autofill/core/common/autofill_pref_names.h" | 31 #include "components/autofill/core/common/autofill_pref_names.h" |
| 31 #include "components/autofill/core/common/autofill_switches.h" | 32 #include "components/autofill/core/common/autofill_switches.h" |
| 32 #include "components/autofill/core/common/form_data.h" | 33 #include "components/autofill/core/common/form_data.h" |
| 33 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 34 #include "components/signin/core/browser/account_tracker_service.h" | 35 #include "components/signin/core/browser/account_tracker_service.h" |
| 35 #include "components/signin/core/browser/fake_signin_manager.h" | 36 #include "components/signin/core/browser/fake_signin_manager.h" |
| 36 #include "components/signin/core/browser/test_signin_client.h" | 37 #include "components/signin/core/browser/test_signin_client.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Setup account tracker. | 112 // Setup account tracker. |
| 112 signin_client_.reset(new TestSigninClient(prefs_.get())); | 113 signin_client_.reset(new TestSigninClient(prefs_.get())); |
| 113 account_tracker_.reset(new AccountTrackerService()); | 114 account_tracker_.reset(new AccountTrackerService()); |
| 114 account_tracker_->Initialize(signin_client_.get()); | 115 account_tracker_->Initialize(signin_client_.get()); |
| 115 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), | 116 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), |
| 116 account_tracker_.get())); | 117 account_tracker_.get())); |
| 117 signin_manager_->Initialize(prefs_.get()); | 118 signin_manager_->Initialize(prefs_.get()); |
| 118 | 119 |
| 119 // Hacky: hold onto a pointer but pass ownership. | 120 // Hacky: hold onto a pointer but pass ownership. |
| 120 autofill_table_ = new AutofillTable; | 121 autofill_table_ = new AutofillTable; |
| 121 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(autofill_table_)); | 122 web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_)); |
| 122 web_database_->LoadDatabase(); | 123 web_database_->LoadDatabase(); |
| 123 autofill_database_service_ = new AutofillWebDataService( | 124 autofill_database_service_ = new AutofillWebDataService( |
| 124 web_database_, base::ThreadTaskRunnerHandle::Get(), | 125 web_database_, base::ThreadTaskRunnerHandle::Get(), |
| 125 base::ThreadTaskRunnerHandle::Get(), | 126 base::ThreadTaskRunnerHandle::Get(), |
| 126 WebDataServiceBase::ProfileErrorCallback()); | 127 WebDataServiceBase::ProfileErrorCallback()); |
| 127 autofill_database_service_->Init(); | 128 autofill_database_service_->Init(); |
| 128 | 129 |
| 129 test::DisableSystemServices(prefs_.get()); | 130 test::DisableSystemServices(prefs_.get()); |
| 130 ResetPersonalDataManager(USER_MODE_NORMAL); | 131 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 131 | 132 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 261 } |
| 261 | 262 |
| 262 // Helper methods that simply forward the call to the private member (to avoid | 263 // Helper methods that simply forward the call to the private member (to avoid |
| 263 // having to friend every test that needs to access the private | 264 // having to friend every test that needs to access the private |
| 264 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). | 265 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). |
| 265 bool ImportAddressProfiles(const FormStructure& form) { | 266 bool ImportAddressProfiles(const FormStructure& form) { |
| 266 return personal_data_->ImportAddressProfiles(form); | 267 return personal_data_->ImportAddressProfiles(form); |
| 267 } | 268 } |
| 268 bool ImportCreditCard(const FormStructure& form, | 269 bool ImportCreditCard(const FormStructure& form, |
| 269 bool should_return_local_card, | 270 bool should_return_local_card, |
| 270 scoped_ptr<CreditCard>* imported_credit_card) { | 271 std::unique_ptr<CreditCard>* imported_credit_card) { |
| 271 return personal_data_->ImportCreditCard(form, should_return_local_card, | 272 return personal_data_->ImportCreditCard(form, should_return_local_card, |
| 272 imported_credit_card); | 273 imported_credit_card); |
| 273 } | 274 } |
| 274 | 275 |
| 275 // Sets up the profile order field trial group and parameter. Sets up the | 276 // Sets up the profile order field trial group and parameter. Sets up the |
| 276 // suggestions limit parameter to |limit_param|. | 277 // suggestions limit parameter to |limit_param|. |
| 277 void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) { | 278 void EnableAutofillProfileLimitFieldTrial(const std::string& limit_param) { |
| 278 DCHECK(!limit_param.empty()); | 279 DCHECK(!limit_param.empty()); |
| 279 | 280 |
| 280 // Clear the existing |field_trial_list_| and variation parameters. | 281 // Clear the existing |field_trial_list_| and variation parameters. |
| 281 field_trial_list_.reset(NULL); | 282 field_trial_list_.reset(NULL); |
| 282 field_trial_list_.reset( | 283 field_trial_list_.reset( |
| 283 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); | 284 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); |
| 284 variations::testing::ClearAllVariationParams(); | 285 variations::testing::ClearAllVariationParams(); |
| 285 | 286 |
| 286 std::map<std::string, std::string> params; | 287 std::map<std::string, std::string> params; |
| 287 params[kFrecencyFieldTrialLimitParam] = limit_param; | 288 params[kFrecencyFieldTrialLimitParam] = limit_param; |
| 288 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN", | 289 variations::AssociateVariationParams(kFrecencyFieldTrialName, "LimitToN", |
| 289 params); | 290 params); |
| 290 | 291 |
| 291 field_trial_ = base::FieldTrialList::CreateFieldTrial( | 292 field_trial_ = base::FieldTrialList::CreateFieldTrial( |
| 292 kFrecencyFieldTrialName, "LimitToN"); | 293 kFrecencyFieldTrialName, "LimitToN"); |
| 293 field_trial_->group(); | 294 field_trial_->group(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 // The temporary directory should be deleted at the end to ensure that | 297 // The temporary directory should be deleted at the end to ensure that |
| 297 // files are not used anymore and deletion succeeds. | 298 // files are not used anymore and deletion succeeds. |
| 298 base::ScopedTempDir temp_dir_; | 299 base::ScopedTempDir temp_dir_; |
| 299 base::MessageLoopForUI message_loop_; | 300 base::MessageLoopForUI message_loop_; |
| 300 scoped_ptr<PrefService> prefs_; | 301 std::unique_ptr<PrefService> prefs_; |
| 301 scoped_ptr<AccountTrackerService> account_tracker_; | 302 std::unique_ptr<AccountTrackerService> account_tracker_; |
| 302 scoped_ptr<FakeSigninManagerBase> signin_manager_; | 303 std::unique_ptr<FakeSigninManagerBase> signin_manager_; |
| 303 scoped_ptr<TestSigninClient> signin_client_; | 304 std::unique_ptr<TestSigninClient> signin_client_; |
| 304 scoped_refptr<AutofillWebDataService> autofill_database_service_; | 305 scoped_refptr<AutofillWebDataService> autofill_database_service_; |
| 305 scoped_refptr<WebDatabaseService> web_database_; | 306 scoped_refptr<WebDatabaseService> web_database_; |
| 306 AutofillTable* autofill_table_; // weak ref | 307 AutofillTable* autofill_table_; // weak ref |
| 307 PersonalDataLoadedObserverMock personal_data_observer_; | 308 PersonalDataLoadedObserverMock personal_data_observer_; |
| 308 scoped_ptr<PersonalDataManager> personal_data_; | 309 std::unique_ptr<PersonalDataManager> personal_data_; |
| 309 | 310 |
| 310 scoped_ptr<base::FieldTrialList> field_trial_list_; | 311 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| 311 scoped_refptr<base::FieldTrial> field_trial_; | 312 scoped_refptr<base::FieldTrial> field_trial_; |
| 312 }; | 313 }; |
| 313 | 314 |
| 314 TEST_F(PersonalDataManagerTest, AddProfile) { | 315 TEST_F(PersonalDataManagerTest, AddProfile) { |
| 315 // Add profile0 to the database. | 316 // Add profile0 to the database. |
| 316 AutofillProfile profile0(test::GetFullProfile()); | 317 AutofillProfile profile0(test::GetFullProfile()); |
| 317 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); | 318 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); |
| 318 personal_data_->AddProfile(profile0); | 319 personal_data_->AddProfile(profile0); |
| 319 | 320 |
| 320 // Reload the database. | 321 // Reload the database. |
| (...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 | 1952 |
| 1952 // Tests that a valid credit card is extracted. | 1953 // Tests that a valid credit card is extracted. |
| 1953 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { | 1954 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { |
| 1954 // Add a single valid credit card form. | 1955 // Add a single valid credit card form. |
| 1955 FormData form; | 1956 FormData form; |
| 1956 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 1957 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 1957 "2011"); | 1958 "2011"); |
| 1958 | 1959 |
| 1959 FormStructure form_structure(form); | 1960 FormStructure form_structure(form); |
| 1960 form_structure.DetermineHeuristicTypes(); | 1961 form_structure.DetermineHeuristicTypes(); |
| 1961 scoped_ptr<CreditCard> imported_credit_card; | 1962 std::unique_ptr<CreditCard> imported_credit_card; |
| 1962 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 1963 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 1963 ASSERT_TRUE(imported_credit_card); | 1964 ASSERT_TRUE(imported_credit_card); |
| 1964 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1965 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1965 | 1966 |
| 1966 // Verify that the web database has been updated and the notification sent. | 1967 // Verify that the web database has been updated and the notification sent. |
| 1967 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 1968 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 1968 .WillOnce(QuitMainMessageLoop()); | 1969 .WillOnce(QuitMainMessageLoop()); |
| 1969 base::MessageLoop::current()->Run(); | 1970 base::MessageLoop::current()->Run(); |
| 1970 | 1971 |
| 1971 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 1972 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 1972 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 1973 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 1973 "2011"); | 1974 "2011"); |
| 1974 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1975 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1975 ASSERT_EQ(1U, results.size()); | 1976 ASSERT_EQ(1U, results.size()); |
| 1976 EXPECT_EQ(0, expected.Compare(*results[0])); | 1977 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1977 } | 1978 } |
| 1978 | 1979 |
| 1979 // Tests that an invalid credit card is not extracted. | 1980 // Tests that an invalid credit card is not extracted. |
| 1980 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { | 1981 TEST_F(PersonalDataManagerTest, ImportCreditCard_Invalid) { |
| 1981 FormData form; | 1982 FormData form; |
| 1982 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", | 1983 AddFullCreditCardForm(&form, "Jim Johansen", "1000000000000000", "02", |
| 1983 "2012"); | 1984 "2012"); |
| 1984 | 1985 |
| 1985 FormStructure form_structure(form); | 1986 FormStructure form_structure(form); |
| 1986 form_structure.DetermineHeuristicTypes(); | 1987 form_structure.DetermineHeuristicTypes(); |
| 1987 scoped_ptr<CreditCard> imported_credit_card; | 1988 std::unique_ptr<CreditCard> imported_credit_card; |
| 1988 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 1989 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 1989 ASSERT_FALSE(imported_credit_card); | 1990 ASSERT_FALSE(imported_credit_card); |
| 1990 | 1991 |
| 1991 // Since no refresh is expected, reload the data from the database to make | 1992 // Since no refresh is expected, reload the data from the database to make |
| 1992 // sure no changes were written out. | 1993 // sure no changes were written out. |
| 1993 ResetPersonalDataManager(USER_MODE_NORMAL); | 1994 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 1994 | 1995 |
| 1995 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 1996 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1996 ASSERT_EQ(0U, results.size()); | 1997 ASSERT_EQ(0U, results.size()); |
| 1997 } | 1998 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2011 values.push_back(ASCIIToUTF16("3")); | 2012 values.push_back(ASCIIToUTF16("3")); |
| 2012 std::vector<base::string16> contents; | 2013 std::vector<base::string16> contents; |
| 2013 contents.push_back(ASCIIToUTF16("Jan (1)")); | 2014 contents.push_back(ASCIIToUTF16("Jan (1)")); |
| 2014 contents.push_back(ASCIIToUTF16("Feb (2)")); | 2015 contents.push_back(ASCIIToUTF16("Feb (2)")); |
| 2015 contents.push_back(ASCIIToUTF16("Mar (3)")); | 2016 contents.push_back(ASCIIToUTF16("Mar (3)")); |
| 2016 form.fields[2].option_values = values; | 2017 form.fields[2].option_values = values; |
| 2017 form.fields[2].option_contents = contents; | 2018 form.fields[2].option_contents = contents; |
| 2018 | 2019 |
| 2019 FormStructure form_structure(form); | 2020 FormStructure form_structure(form); |
| 2020 form_structure.DetermineHeuristicTypes(); | 2021 form_structure.DetermineHeuristicTypes(); |
| 2021 scoped_ptr<CreditCard> imported_credit_card; | 2022 std::unique_ptr<CreditCard> imported_credit_card; |
| 2022 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2023 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2023 ASSERT_TRUE(imported_credit_card); | 2024 ASSERT_TRUE(imported_credit_card); |
| 2024 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2025 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2025 | 2026 |
| 2026 // Verify that the web database has been updated and the notification sent. | 2027 // Verify that the web database has been updated and the notification sent. |
| 2027 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2028 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2028 .WillOnce(QuitMainMessageLoop()); | 2029 .WillOnce(QuitMainMessageLoop()); |
| 2029 base::MessageLoop::current()->Run(); | 2030 base::MessageLoop::current()->Run(); |
| 2030 | 2031 |
| 2031 // See that the invalid option text was converted to the right value. | 2032 // See that the invalid option text was converted to the right value. |
| 2032 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2033 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2033 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", | 2034 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", |
| 2034 "2011"); | 2035 "2011"); |
| 2035 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2036 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2036 ASSERT_EQ(1U, results.size()); | 2037 ASSERT_EQ(1U, results.size()); |
| 2037 EXPECT_EQ(0, expected.Compare(*results[0])); | 2038 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2038 } | 2039 } |
| 2039 | 2040 |
| 2040 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { | 2041 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { |
| 2041 // Start with a single valid credit card form. | 2042 // Start with a single valid credit card form. |
| 2042 FormData form1; | 2043 FormData form1; |
| 2043 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2044 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2044 "2011"); | 2045 "2011"); |
| 2045 | 2046 |
| 2046 FormStructure form_structure1(form1); | 2047 FormStructure form_structure1(form1); |
| 2047 form_structure1.DetermineHeuristicTypes(); | 2048 form_structure1.DetermineHeuristicTypes(); |
| 2048 scoped_ptr<CreditCard> imported_credit_card; | 2049 std::unique_ptr<CreditCard> imported_credit_card; |
| 2049 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2050 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2050 ASSERT_TRUE(imported_credit_card); | 2051 ASSERT_TRUE(imported_credit_card); |
| 2051 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2052 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2052 | 2053 |
| 2053 // Verify that the web database has been updated and the notification sent. | 2054 // Verify that the web database has been updated and the notification sent. |
| 2054 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2055 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2055 .WillOnce(QuitMainMessageLoop()); | 2056 .WillOnce(QuitMainMessageLoop()); |
| 2056 base::MessageLoop::current()->Run(); | 2057 base::MessageLoop::current()->Run(); |
| 2057 | 2058 |
| 2058 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2059 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2059 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", | 2060 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", |
| 2060 "2011"); | 2061 "2011"); |
| 2061 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2062 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2062 ASSERT_EQ(1U, results.size()); | 2063 ASSERT_EQ(1U, results.size()); |
| 2063 EXPECT_EQ(0, expected.Compare(*results[0])); | 2064 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2064 | 2065 |
| 2065 // Add a second different valid credit card. | 2066 // Add a second different valid credit card. |
| 2066 FormData form2; | 2067 FormData form2; |
| 2067 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2012"); | 2068 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "2012"); |
| 2068 | 2069 |
| 2069 FormStructure form_structure2(form2); | 2070 FormStructure form_structure2(form2); |
| 2070 form_structure2.DetermineHeuristicTypes(); | 2071 form_structure2.DetermineHeuristicTypes(); |
| 2071 scoped_ptr<CreditCard> imported_credit_card2; | 2072 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2072 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2073 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2073 ASSERT_TRUE(imported_credit_card2); | 2074 ASSERT_TRUE(imported_credit_card2); |
| 2074 personal_data_->SaveImportedCreditCard(*imported_credit_card2); | 2075 personal_data_->SaveImportedCreditCard(*imported_credit_card2); |
| 2075 | 2076 |
| 2076 // Verify that the web database has been updated and the notification sent. | 2077 // Verify that the web database has been updated and the notification sent. |
| 2077 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2078 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2078 .WillOnce(QuitMainMessageLoop()); | 2079 .WillOnce(QuitMainMessageLoop()); |
| 2079 base::MessageLoop::current()->Run(); | 2080 base::MessageLoop::current()->Run(); |
| 2080 | 2081 |
| 2081 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2082 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2100 | 2101 |
| 2101 // Type the same data as the masked card into a form. | 2102 // Type the same data as the masked card into a form. |
| 2102 FormData form; | 2103 FormData form; |
| 2103 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", | 2104 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", |
| 2104 "2010"); | 2105 "2010"); |
| 2105 | 2106 |
| 2106 // The card should be offered to be saved locally because it only matches the | 2107 // The card should be offered to be saved locally because it only matches the |
| 2107 // masked server card. | 2108 // masked server card. |
| 2108 FormStructure form_structure(form); | 2109 FormStructure form_structure(form); |
| 2109 form_structure.DetermineHeuristicTypes(); | 2110 form_structure.DetermineHeuristicTypes(); |
| 2110 scoped_ptr<CreditCard> imported_credit_card; | 2111 std::unique_ptr<CreditCard> imported_credit_card; |
| 2111 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2112 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2112 ASSERT_TRUE(imported_credit_card); | 2113 ASSERT_TRUE(imported_credit_card); |
| 2113 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2114 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2114 | 2115 |
| 2115 // Verify that the web database has been updated and the notification sent. | 2116 // Verify that the web database has been updated and the notification sent. |
| 2116 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2117 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2117 .WillOnce(QuitMainMessageLoop()); | 2118 .WillOnce(QuitMainMessageLoop()); |
| 2118 base::MessageLoop::current()->Run(); | 2119 base::MessageLoop::current()->Run(); |
| 2119 } | 2120 } |
| 2120 | 2121 |
| 2121 // Tests that a credit card is not extracted because it matches a full server | 2122 // Tests that a credit card is not extracted because it matches a full server |
| 2122 // card. | 2123 // card. |
| 2123 TEST_F(PersonalDataManagerTest, | 2124 TEST_F(PersonalDataManagerTest, |
| 2124 ImportCreditCard_DuplicateServerCards_FullCard) { | 2125 ImportCreditCard_DuplicateServerCards_FullCard) { |
| 2125 // Add a full server card. | 2126 // Add a full server card. |
| 2126 std::vector<CreditCard> server_cards; | 2127 std::vector<CreditCard> server_cards; |
| 2127 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 2128 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
| 2128 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 2129 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
| 2129 "347666888555" /* American Express */, "04", "2015"); | 2130 "347666888555" /* American Express */, "04", "2015"); |
| 2130 test::SetServerCreditCards(autofill_table_, server_cards); | 2131 test::SetServerCreditCards(autofill_table_, server_cards); |
| 2131 | 2132 |
| 2132 // Type the same data as the unmasked card into a form. | 2133 // Type the same data as the unmasked card into a form. |
| 2133 FormData form; | 2134 FormData form; |
| 2134 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2015"); | 2135 AddFullCreditCardForm(&form, "Clyde Barrow", "347666888555", "04", "2015"); |
| 2135 | 2136 |
| 2136 // The card should not be offered to be saved locally because it only matches | 2137 // The card should not be offered to be saved locally because it only matches |
| 2137 // the full server card. | 2138 // the full server card. |
| 2138 FormStructure form_structure(form); | 2139 FormStructure form_structure(form); |
| 2139 form_structure.DetermineHeuristicTypes(); | 2140 form_structure.DetermineHeuristicTypes(); |
| 2140 scoped_ptr<CreditCard> imported_credit_card; | 2141 std::unique_ptr<CreditCard> imported_credit_card; |
| 2141 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2142 EXPECT_FALSE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2142 ASSERT_FALSE(imported_credit_card); | 2143 ASSERT_FALSE(imported_credit_card); |
| 2143 } | 2144 } |
| 2144 | 2145 |
| 2145 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { | 2146 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCreditCardWithConflict) { |
| 2146 // Start with a single valid credit card form. | 2147 // Start with a single valid credit card form. |
| 2147 FormData form1; | 2148 FormData form1; |
| 2148 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2149 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2149 "2011"); | 2150 "2011"); |
| 2150 | 2151 |
| 2151 FormStructure form_structure1(form1); | 2152 FormStructure form_structure1(form1); |
| 2152 form_structure1.DetermineHeuristicTypes(); | 2153 form_structure1.DetermineHeuristicTypes(); |
| 2153 scoped_ptr<CreditCard> imported_credit_card; | 2154 std::unique_ptr<CreditCard> imported_credit_card; |
| 2154 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2155 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2155 ASSERT_TRUE(imported_credit_card); | 2156 ASSERT_TRUE(imported_credit_card); |
| 2156 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2157 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2157 | 2158 |
| 2158 // Verify that the web database has been updated and the notification sent. | 2159 // Verify that the web database has been updated and the notification sent. |
| 2159 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2160 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2160 .WillOnce(QuitMainMessageLoop()); | 2161 .WillOnce(QuitMainMessageLoop()); |
| 2161 base::MessageLoop::current()->Run(); | 2162 base::MessageLoop::current()->Run(); |
| 2162 | 2163 |
| 2163 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2164 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2164 test::SetCreditCardInfo(&expected, | 2165 test::SetCreditCardInfo(&expected, |
| 2165 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2166 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2166 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2167 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2167 ASSERT_EQ(1U, results.size()); | 2168 ASSERT_EQ(1U, results.size()); |
| 2168 EXPECT_EQ(0, expected.Compare(*results[0])); | 2169 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2169 | 2170 |
| 2170 // Add a second different valid credit card where the year is different but | 2171 // Add a second different valid credit card where the year is different but |
| 2171 // the credit card number matches. | 2172 // the credit card number matches. |
| 2172 FormData form2; | 2173 FormData form2; |
| 2173 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2174 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2174 /* different year */ "2012"); | 2175 /* different year */ "2012"); |
| 2175 | 2176 |
| 2176 FormStructure form_structure2(form2); | 2177 FormStructure form_structure2(form2); |
| 2177 form_structure2.DetermineHeuristicTypes(); | 2178 form_structure2.DetermineHeuristicTypes(); |
| 2178 scoped_ptr<CreditCard> imported_credit_card2; | 2179 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2179 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2180 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2180 EXPECT_FALSE(imported_credit_card2); | 2181 EXPECT_FALSE(imported_credit_card2); |
| 2181 | 2182 |
| 2182 // Verify that the web database has been updated and the notification sent. | 2183 // Verify that the web database has been updated and the notification sent. |
| 2183 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2184 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2184 .WillOnce(QuitMainMessageLoop()); | 2185 .WillOnce(QuitMainMessageLoop()); |
| 2185 base::MessageLoop::current()->Run(); | 2186 base::MessageLoop::current()->Run(); |
| 2186 | 2187 |
| 2187 // Expect that the newer information is saved. In this case the year is | 2188 // Expect that the newer information is saved. In this case the year is |
| 2188 // updated to "2012". | 2189 // updated to "2012". |
| 2189 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2190 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2190 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", | 2191 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", |
| 2191 "2012"); | 2192 "2012"); |
| 2192 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2193 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2193 ASSERT_EQ(1U, results2.size()); | 2194 ASSERT_EQ(1U, results2.size()); |
| 2194 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2195 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2195 } | 2196 } |
| 2196 | 2197 |
| 2197 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { | 2198 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { |
| 2198 // Start with a single valid credit card form. | 2199 // Start with a single valid credit card form. |
| 2199 FormData form1; | 2200 FormData form1; |
| 2200 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2201 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2201 "2011"); | 2202 "2011"); |
| 2202 | 2203 |
| 2203 FormStructure form_structure1(form1); | 2204 FormStructure form_structure1(form1); |
| 2204 form_structure1.DetermineHeuristicTypes(); | 2205 form_structure1.DetermineHeuristicTypes(); |
| 2205 scoped_ptr<CreditCard> imported_credit_card; | 2206 std::unique_ptr<CreditCard> imported_credit_card; |
| 2206 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2207 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2207 ASSERT_TRUE(imported_credit_card); | 2208 ASSERT_TRUE(imported_credit_card); |
| 2208 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2209 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2209 | 2210 |
| 2210 // Verify that the web database has been updated and the notification sent. | 2211 // Verify that the web database has been updated and the notification sent. |
| 2211 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2212 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2212 .WillOnce(QuitMainMessageLoop()); | 2213 .WillOnce(QuitMainMessageLoop()); |
| 2213 base::MessageLoop::current()->Run(); | 2214 base::MessageLoop::current()->Run(); |
| 2214 | 2215 |
| 2215 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2216 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2216 test::SetCreditCardInfo(&expected, | 2217 test::SetCreditCardInfo(&expected, |
| 2217 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2218 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2218 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2219 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2219 ASSERT_EQ(1U, results.size()); | 2220 ASSERT_EQ(1U, results.size()); |
| 2220 EXPECT_EQ(0, expected.Compare(*results[0])); | 2221 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2221 | 2222 |
| 2222 // Add a second different valid credit card where the year is different but | 2223 // Add a second different valid credit card where the year is different but |
| 2223 // the credit card number matches. | 2224 // the credit card number matches. |
| 2224 FormData form2; | 2225 FormData form2; |
| 2225 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2226 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2226 /* different year */ "2012"); | 2227 /* different year */ "2012"); |
| 2227 | 2228 |
| 2228 FormStructure form_structure2(form2); | 2229 FormStructure form_structure2(form2); |
| 2229 form_structure2.DetermineHeuristicTypes(); | 2230 form_structure2.DetermineHeuristicTypes(); |
| 2230 scoped_ptr<CreditCard> imported_credit_card2; | 2231 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2231 EXPECT_TRUE(ImportCreditCard(form_structure2, | 2232 EXPECT_TRUE(ImportCreditCard(form_structure2, |
| 2232 /* should_return_local_card= */ true, | 2233 /* should_return_local_card= */ true, |
| 2233 &imported_credit_card2)); | 2234 &imported_credit_card2)); |
| 2234 // The local card is returned after an update. | 2235 // The local card is returned after an update. |
| 2235 EXPECT_TRUE(imported_credit_card2); | 2236 EXPECT_TRUE(imported_credit_card2); |
| 2236 | 2237 |
| 2237 // Verify that the web database has been updated and the notification sent. | 2238 // Verify that the web database has been updated and the notification sent. |
| 2238 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2239 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2239 .WillOnce(QuitMainMessageLoop()); | 2240 .WillOnce(QuitMainMessageLoop()); |
| 2240 base::MessageLoop::current()->Run(); | 2241 base::MessageLoop::current()->Run(); |
| 2241 | 2242 |
| 2242 // Expect that the newer information is saved. In this case the year is | 2243 // Expect that the newer information is saved. In this case the year is |
| 2243 // updated to "2012". | 2244 // updated to "2012". |
| 2244 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2245 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2245 test::SetCreditCardInfo(&expected2, | 2246 test::SetCreditCardInfo(&expected2, |
| 2246 "Biggie Smalls", "4111111111111111", "01", "2012"); | 2247 "Biggie Smalls", "4111111111111111", "01", "2012"); |
| 2247 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2248 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2248 ASSERT_EQ(1U, results2.size()); | 2249 ASSERT_EQ(1U, results2.size()); |
| 2249 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2250 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2250 } | 2251 } |
| 2251 | 2252 |
| 2252 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { | 2253 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { |
| 2253 // Start with a single valid credit card form. | 2254 // Start with a single valid credit card form. |
| 2254 FormData form1; | 2255 FormData form1; |
| 2255 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2256 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2256 "2011"); | 2257 "2011"); |
| 2257 | 2258 |
| 2258 FormStructure form_structure1(form1); | 2259 FormStructure form_structure1(form1); |
| 2259 form_structure1.DetermineHeuristicTypes(); | 2260 form_structure1.DetermineHeuristicTypes(); |
| 2260 scoped_ptr<CreditCard> imported_credit_card; | 2261 std::unique_ptr<CreditCard> imported_credit_card; |
| 2261 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2262 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2262 ASSERT_TRUE(imported_credit_card); | 2263 ASSERT_TRUE(imported_credit_card); |
| 2263 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2264 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2264 | 2265 |
| 2265 // Verify that the web database has been updated and the notification sent. | 2266 // Verify that the web database has been updated and the notification sent. |
| 2266 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2267 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2267 .WillOnce(QuitMainMessageLoop()); | 2268 .WillOnce(QuitMainMessageLoop()); |
| 2268 base::MessageLoop::current()->Run(); | 2269 base::MessageLoop::current()->Run(); |
| 2269 | 2270 |
| 2270 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2271 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2271 test::SetCreditCardInfo(&expected, | 2272 test::SetCreditCardInfo(&expected, |
| 2272 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2273 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2273 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2274 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2274 ASSERT_EQ(1U, results.size()); | 2275 ASSERT_EQ(1U, results.size()); |
| 2275 EXPECT_EQ(0, expected.Compare(*results[0])); | 2276 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2276 | 2277 |
| 2277 // Add a second credit card with no number. | 2278 // Add a second credit card with no number. |
| 2278 FormData form2; | 2279 FormData form2; |
| 2279 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", | 2280 AddFullCreditCardForm(&form2, "Biggie Smalls", /* no number */ nullptr, "01", |
| 2280 "2012"); | 2281 "2012"); |
| 2281 | 2282 |
| 2282 FormStructure form_structure2(form2); | 2283 FormStructure form_structure2(form2); |
| 2283 form_structure2.DetermineHeuristicTypes(); | 2284 form_structure2.DetermineHeuristicTypes(); |
| 2284 scoped_ptr<CreditCard> imported_credit_card2; | 2285 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2285 EXPECT_FALSE( | 2286 EXPECT_FALSE( |
| 2286 ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2287 ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2287 EXPECT_FALSE(imported_credit_card2); | 2288 EXPECT_FALSE(imported_credit_card2); |
| 2288 | 2289 |
| 2289 // Since no refresh is expected, reload the data from the database to make | 2290 // Since no refresh is expected, reload the data from the database to make |
| 2290 // sure no changes were written out. | 2291 // sure no changes were written out. |
| 2291 ResetPersonalDataManager(USER_MODE_NORMAL); | 2292 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2292 | 2293 |
| 2293 // No change is expected. | 2294 // No change is expected. |
| 2294 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2295 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2295 test::SetCreditCardInfo(&expected2, | 2296 test::SetCreditCardInfo(&expected2, |
| 2296 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2297 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2297 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2298 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2298 ASSERT_EQ(1U, results2.size()); | 2299 ASSERT_EQ(1U, results2.size()); |
| 2299 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2300 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2300 } | 2301 } |
| 2301 | 2302 |
| 2302 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { | 2303 TEST_F(PersonalDataManagerTest, ImportCreditCard_MissingInfoInNew) { |
| 2303 // Start with a single valid credit card form. | 2304 // Start with a single valid credit card form. |
| 2304 FormData form1; | 2305 FormData form1; |
| 2305 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2306 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2306 "2011"); | 2307 "2011"); |
| 2307 | 2308 |
| 2308 FormStructure form_structure1(form1); | 2309 FormStructure form_structure1(form1); |
| 2309 form_structure1.DetermineHeuristicTypes(); | 2310 form_structure1.DetermineHeuristicTypes(); |
| 2310 scoped_ptr<CreditCard> imported_credit_card; | 2311 std::unique_ptr<CreditCard> imported_credit_card; |
| 2311 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); | 2312 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); |
| 2312 ASSERT_TRUE(imported_credit_card); | 2313 ASSERT_TRUE(imported_credit_card); |
| 2313 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2314 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2314 | 2315 |
| 2315 // Verify that the web database has been updated and the notification sent. | 2316 // Verify that the web database has been updated and the notification sent. |
| 2316 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2317 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2317 .WillOnce(QuitMainMessageLoop()); | 2318 .WillOnce(QuitMainMessageLoop()); |
| 2318 base::MessageLoop::current()->Run(); | 2319 base::MessageLoop::current()->Run(); |
| 2319 | 2320 |
| 2320 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | 2321 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); |
| 2321 test::SetCreditCardInfo(&expected, | 2322 test::SetCreditCardInfo(&expected, |
| 2322 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2323 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2323 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2324 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2324 ASSERT_EQ(1U, results.size()); | 2325 ASSERT_EQ(1U, results.size()); |
| 2325 EXPECT_EQ(0, expected.Compare(*results[0])); | 2326 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 2326 | 2327 |
| 2327 // Add a second different valid credit card where the name is missing but | 2328 // Add a second different valid credit card where the name is missing but |
| 2328 // the credit card number matches. | 2329 // the credit card number matches. |
| 2329 FormData form2; | 2330 FormData form2; |
| 2330 AddFullCreditCardForm(&form2, /* missing name */ nullptr, | 2331 AddFullCreditCardForm(&form2, /* missing name */ nullptr, |
| 2331 "4111-1111-1111-1111", "01", "2011"); | 2332 "4111-1111-1111-1111", "01", "2011"); |
| 2332 | 2333 |
| 2333 FormStructure form_structure2(form2); | 2334 FormStructure form_structure2(form2); |
| 2334 form_structure2.DetermineHeuristicTypes(); | 2335 form_structure2.DetermineHeuristicTypes(); |
| 2335 scoped_ptr<CreditCard> imported_credit_card2; | 2336 std::unique_ptr<CreditCard> imported_credit_card2; |
| 2336 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); | 2337 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); |
| 2337 EXPECT_FALSE(imported_credit_card2); | 2338 EXPECT_FALSE(imported_credit_card2); |
| 2338 | 2339 |
| 2339 // Since no refresh is expected, reload the data from the database to make | 2340 // Since no refresh is expected, reload the data from the database to make |
| 2340 // sure no changes were written out. | 2341 // sure no changes were written out. |
| 2341 ResetPersonalDataManager(USER_MODE_NORMAL); | 2342 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2342 | 2343 |
| 2343 // No change is expected. | 2344 // No change is expected. |
| 2344 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2345 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
| 2345 test::SetCreditCardInfo(&expected2, | 2346 test::SetCreditCardInfo(&expected2, |
| 2346 "Biggie Smalls", "4111111111111111", "01", "2011"); | 2347 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 2347 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2348 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2348 ASSERT_EQ(1U, results2.size()); | 2349 ASSERT_EQ(1U, results2.size()); |
| 2349 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 2350 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 2350 | 2351 |
| 2351 // Add a third credit card where the expiration date is missing. | 2352 // Add a third credit card where the expiration date is missing. |
| 2352 FormData form3; | 2353 FormData form3; |
| 2353 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", | 2354 AddFullCreditCardForm(&form3, "Johnny McEnroe", "5555555555554444", |
| 2354 /* no month */ nullptr, | 2355 /* no month */ nullptr, |
| 2355 /* no year */ nullptr); | 2356 /* no year */ nullptr); |
| 2356 | 2357 |
| 2357 FormStructure form_structure3(form3); | 2358 FormStructure form_structure3(form3); |
| 2358 form_structure3.DetermineHeuristicTypes(); | 2359 form_structure3.DetermineHeuristicTypes(); |
| 2359 scoped_ptr<CreditCard> imported_credit_card3; | 2360 std::unique_ptr<CreditCard> imported_credit_card3; |
| 2360 EXPECT_FALSE( | 2361 EXPECT_FALSE( |
| 2361 ImportCreditCard(form_structure3, false, &imported_credit_card3)); | 2362 ImportCreditCard(form_structure3, false, &imported_credit_card3)); |
| 2362 ASSERT_FALSE(imported_credit_card3); | 2363 ASSERT_FALSE(imported_credit_card3); |
| 2363 | 2364 |
| 2364 // Since no refresh is expected, reload the data from the database to make | 2365 // Since no refresh is expected, reload the data from the database to make |
| 2365 // sure no changes were written out. | 2366 // sure no changes were written out. |
| 2366 ResetPersonalDataManager(USER_MODE_NORMAL); | 2367 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2367 | 2368 |
| 2368 // No change is expected. | 2369 // No change is expected. |
| 2369 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); | 2370 CreditCard expected3(base::GenerateGUID(), "https://www.example.com"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2392 EXPECT_EQ(saved_credit_card, *results1[0]); | 2393 EXPECT_EQ(saved_credit_card, *results1[0]); |
| 2393 | 2394 |
| 2394 // Add a second different valid credit card where the year is different but | 2395 // Add a second different valid credit card where the year is different but |
| 2395 // the credit card number matches. | 2396 // the credit card number matches. |
| 2396 FormData form; | 2397 FormData form; |
| 2397 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2398 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2398 /* different year */ "2012"); | 2399 /* different year */ "2012"); |
| 2399 | 2400 |
| 2400 FormStructure form_structure(form); | 2401 FormStructure form_structure(form); |
| 2401 form_structure.DetermineHeuristicTypes(); | 2402 form_structure.DetermineHeuristicTypes(); |
| 2402 scoped_ptr<CreditCard> imported_credit_card; | 2403 std::unique_ptr<CreditCard> imported_credit_card; |
| 2403 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2404 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2404 EXPECT_FALSE(imported_credit_card); | 2405 EXPECT_FALSE(imported_credit_card); |
| 2405 | 2406 |
| 2406 // Verify that the web database has been updated and the notification sent. | 2407 // Verify that the web database has been updated and the notification sent. |
| 2407 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2408 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2408 .WillOnce(QuitMainMessageLoop()); | 2409 .WillOnce(QuitMainMessageLoop()); |
| 2409 base::MessageLoop::current()->Run(); | 2410 base::MessageLoop::current()->Run(); |
| 2410 | 2411 |
| 2411 // Expect that the newer information is saved. In this case the year is | 2412 // Expect that the newer information is saved. In this case the year is |
| 2412 // added to the existing credit card. | 2413 // added to the existing credit card. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2437 ASSERT_EQ(1U, results1.size()); | 2438 ASSERT_EQ(1U, results1.size()); |
| 2438 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 2439 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); |
| 2439 | 2440 |
| 2440 // Import the same card info, but with different separators in the number. | 2441 // Import the same card info, but with different separators in the number. |
| 2441 FormData form; | 2442 FormData form; |
| 2442 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2443 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2443 "2011"); | 2444 "2011"); |
| 2444 | 2445 |
| 2445 FormStructure form_structure(form); | 2446 FormStructure form_structure(form); |
| 2446 form_structure.DetermineHeuristicTypes(); | 2447 form_structure.DetermineHeuristicTypes(); |
| 2447 scoped_ptr<CreditCard> imported_credit_card; | 2448 std::unique_ptr<CreditCard> imported_credit_card; |
| 2448 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2449 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2449 EXPECT_FALSE(imported_credit_card); | 2450 EXPECT_FALSE(imported_credit_card); |
| 2450 | 2451 |
| 2451 // Since no refresh is expected, reload the data from the database to make | 2452 // Since no refresh is expected, reload the data from the database to make |
| 2452 // sure no changes were written out. | 2453 // sure no changes were written out. |
| 2453 ResetPersonalDataManager(USER_MODE_NORMAL); | 2454 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2454 | 2455 |
| 2455 // Expect that no new card is saved. | 2456 // Expect that no new card is saved. |
| 2456 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); | 2457 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 2457 ASSERT_EQ(1U, results2.size()); | 2458 ASSERT_EQ(1U, results2.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2476 .WillOnce(QuitMainMessageLoop()); | 2477 .WillOnce(QuitMainMessageLoop()); |
| 2477 base::MessageLoop::current()->Run(); | 2478 base::MessageLoop::current()->Run(); |
| 2478 | 2479 |
| 2479 // Simulate a form submission with conflicting expiration year. | 2480 // Simulate a form submission with conflicting expiration year. |
| 2480 FormData form; | 2481 FormData form; |
| 2481 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", | 2482 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", |
| 2482 /* different year */ "2012"); | 2483 /* different year */ "2012"); |
| 2483 | 2484 |
| 2484 FormStructure form_structure(form); | 2485 FormStructure form_structure(form); |
| 2485 form_structure.DetermineHeuristicTypes(); | 2486 form_structure.DetermineHeuristicTypes(); |
| 2486 scoped_ptr<CreditCard> imported_credit_card; | 2487 std::unique_ptr<CreditCard> imported_credit_card; |
| 2487 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | 2488 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); |
| 2488 ASSERT_FALSE(imported_credit_card); | 2489 ASSERT_FALSE(imported_credit_card); |
| 2489 | 2490 |
| 2490 // Since no refresh is expected, reload the data from the database to make | 2491 // Since no refresh is expected, reload the data from the database to make |
| 2491 // sure no changes were written out. | 2492 // sure no changes were written out. |
| 2492 ResetPersonalDataManager(USER_MODE_NORMAL); | 2493 ResetPersonalDataManager(USER_MODE_NORMAL); |
| 2493 | 2494 |
| 2494 // Expect that the saved credit card is not modified. | 2495 // Expect that the saved credit card is not modified. |
| 2495 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | 2496 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2496 ASSERT_EQ(1U, results.size()); | 2497 ASSERT_EQ(1U, results.size()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2523 form.fields.push_back(field); | 2524 form.fields.push_back(field); |
| 2524 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); | 2525 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
| 2525 form.fields.push_back(field); | 2526 form.fields.push_back(field); |
| 2526 | 2527 |
| 2527 // Credit card section. | 2528 // Credit card section. |
| 2528 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2529 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2529 "2011"); | 2530 "2011"); |
| 2530 | 2531 |
| 2531 FormStructure form_structure(form); | 2532 FormStructure form_structure(form); |
| 2532 form_structure.DetermineHeuristicTypes(); | 2533 form_structure.DetermineHeuristicTypes(); |
| 2533 scoped_ptr<CreditCard> imported_credit_card; | 2534 std::unique_ptr<CreditCard> imported_credit_card; |
| 2534 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, | 2535 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, |
| 2535 &imported_credit_card)); | 2536 &imported_credit_card)); |
| 2536 ASSERT_TRUE(imported_credit_card); | 2537 ASSERT_TRUE(imported_credit_card); |
| 2537 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2538 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2538 | 2539 |
| 2539 // Verify that the web database has been updated and the notification sent. | 2540 // Verify that the web database has been updated and the notification sent. |
| 2540 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2541 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2541 .WillOnce(QuitMainMessageLoop()); | 2542 .WillOnce(QuitMainMessageLoop()); |
| 2542 base::MessageLoop::current()->Run(); | 2543 base::MessageLoop::current()->Run(); |
| 2543 | 2544 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 form.fields.push_back(field); | 2602 form.fields.push_back(field); |
| 2602 test::CreateTestFormField("Country:", "country", "USA", "text", &field); | 2603 test::CreateTestFormField("Country:", "country", "USA", "text", &field); |
| 2603 form.fields.push_back(field); | 2604 form.fields.push_back(field); |
| 2604 | 2605 |
| 2605 // Credit card section. | 2606 // Credit card section. |
| 2606 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", | 2607 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", |
| 2607 "2011"); | 2608 "2011"); |
| 2608 | 2609 |
| 2609 FormStructure form_structure(form); | 2610 FormStructure form_structure(form); |
| 2610 form_structure.DetermineHeuristicTypes(); | 2611 form_structure.DetermineHeuristicTypes(); |
| 2611 scoped_ptr<CreditCard> imported_credit_card; | 2612 std::unique_ptr<CreditCard> imported_credit_card; |
| 2612 // Still returns true because the credit card import was successful. | 2613 // Still returns true because the credit card import was successful. |
| 2613 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, | 2614 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, |
| 2614 &imported_credit_card)); | 2615 &imported_credit_card)); |
| 2615 ASSERT_TRUE(imported_credit_card); | 2616 ASSERT_TRUE(imported_credit_card); |
| 2616 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 2617 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 2617 | 2618 |
| 2618 // Verify that the web database has been updated and the notification sent. | 2619 // Verify that the web database has been updated and the notification sent. |
| 2619 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 2620 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 2620 .WillOnce(QuitMainMessageLoop()); | 2621 .WillOnce(QuitMainMessageLoop()); |
| 2621 base::MessageLoop::current()->Run(); | 2622 base::MessageLoop::current()->Run(); |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3822 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881", | 3823 test::CreateTestFormField("Card Number:", "card_number", "4012888888881881", |
| 3823 "text", &field); | 3824 "text", &field); |
| 3824 form1.fields.push_back(field); | 3825 form1.fields.push_back(field); |
| 3825 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 3826 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
| 3826 form1.fields.push_back(field); | 3827 form1.fields.push_back(field); |
| 3827 test::CreateTestFormField("Exp Year:", "exp_year", "2017", "text", &field); | 3828 test::CreateTestFormField("Exp Year:", "exp_year", "2017", "text", &field); |
| 3828 form1.fields.push_back(field); | 3829 form1.fields.push_back(field); |
| 3829 | 3830 |
| 3830 FormStructure form_structure1(form1); | 3831 FormStructure form_structure1(form1); |
| 3831 form_structure1.DetermineHeuristicTypes(); | 3832 form_structure1.DetermineHeuristicTypes(); |
| 3832 scoped_ptr<CreditCard> imported_credit_card; | 3833 std::unique_ptr<CreditCard> imported_credit_card; |
| 3833 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, | 3834 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, false, |
| 3834 &imported_credit_card)); | 3835 &imported_credit_card)); |
| 3835 EXPECT_FALSE(imported_credit_card); | 3836 EXPECT_FALSE(imported_credit_card); |
| 3836 | 3837 |
| 3837 // A user re-types (or fills with) an unmasked card. Don't offer to save | 3838 // A user re-types (or fills with) an unmasked card. Don't offer to save |
| 3838 // here, either. Since it's unmasked, we know for certain that it's the same | 3839 // here, either. Since it's unmasked, we know for certain that it's the same |
| 3839 // card. | 3840 // card. |
| 3840 FormData form2; | 3841 FormData form2; |
| 3841 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", | 3842 test::CreateTestFormField("Name on card:", "name_on_card", "Clyde Barrow", |
| 3842 "text", &field); | 3843 "text", &field); |
| 3843 form2.fields.push_back(field); | 3844 form2.fields.push_back(field); |
| 3844 test::CreateTestFormField("Card Number:", "card_number", "347666888555", | 3845 test::CreateTestFormField("Card Number:", "card_number", "347666888555", |
| 3845 "text", &field); | 3846 "text", &field); |
| 3846 form2.fields.push_back(field); | 3847 form2.fields.push_back(field); |
| 3847 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); | 3848 test::CreateTestFormField("Exp Month:", "exp_month", "04", "text", &field); |
| 3848 form2.fields.push_back(field); | 3849 form2.fields.push_back(field); |
| 3849 test::CreateTestFormField("Exp Year:", "exp_year", "2015", "text", &field); | 3850 test::CreateTestFormField("Exp Year:", "exp_year", "2015", "text", &field); |
| 3850 form2.fields.push_back(field); | 3851 form2.fields.push_back(field); |
| 3851 | 3852 |
| 3852 FormStructure form_structure2(form2); | 3853 FormStructure form_structure2(form2); |
| 3853 form_structure2.DetermineHeuristicTypes(); | 3854 form_structure2.DetermineHeuristicTypes(); |
| 3854 scoped_ptr<CreditCard> imported_credit_card2; | 3855 std::unique_ptr<CreditCard> imported_credit_card2; |
| 3855 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, | 3856 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, |
| 3856 &imported_credit_card2)); | 3857 &imported_credit_card2)); |
| 3857 EXPECT_FALSE(imported_credit_card2); | 3858 EXPECT_FALSE(imported_credit_card2); |
| 3858 } | 3859 } |
| 3859 | 3860 |
| 3860 // Tests the SaveImportedProfile method with different profiles to make sure the | 3861 // Tests the SaveImportedProfile method with different profiles to make sure the |
| 3861 // merge logic works correctly. | 3862 // merge logic works correctly. |
| 3862 TEST_F(PersonalDataManagerTest, SaveImportedProfile) { | 3863 TEST_F(PersonalDataManagerTest, SaveImportedProfile) { |
| 3863 typedef struct { | 3864 typedef struct { |
| 3864 autofill::ServerFieldType field_type; | 3865 autofill::ServerFieldType field_type; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4028 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4029 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4029 base::Time::Now() - saved_profiles.front()->use_date()); | 4030 base::Time::Now() - saved_profiles.front()->use_date()); |
| 4030 } | 4031 } |
| 4031 | 4032 |
| 4032 // Erase the profiles for the next test. | 4033 // Erase the profiles for the next test. |
| 4033 ResetProfiles(); | 4034 ResetProfiles(); |
| 4034 } | 4035 } |
| 4035 } | 4036 } |
| 4036 | 4037 |
| 4037 } // namespace autofill | 4038 } // namespace autofill |
| OLD | NEW |