| 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/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/feature_list.h" | 14 #include "base/feature_list.h" |
| 15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 19 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 20 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 21 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/test/histogram_tester.h" | 27 #include "base/test/histogram_tester.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 using PersonalDataManager::set_database; | 125 using PersonalDataManager::set_database; |
| 125 using PersonalDataManager::SetPrefService; | 126 using PersonalDataManager::SetPrefService; |
| 126 | 127 |
| 127 int num_times_save_imported_profile_called() { | 128 int num_times_save_imported_profile_called() { |
| 128 return num_times_save_imported_profile_called_; | 129 return num_times_save_imported_profile_called_; |
| 129 } | 130 } |
| 130 | 131 |
| 131 std::string SaveImportedProfile(const AutofillProfile& profile) override { | 132 std::string SaveImportedProfile(const AutofillProfile& profile) override { |
| 132 num_times_save_imported_profile_called_++; | 133 num_times_save_imported_profile_called_++; |
| 133 AutofillProfile* imported_profile = new AutofillProfile(profile); | 134 AddProfile(base::MakeUnique<AutofillProfile>(profile)); |
| 134 AddProfile(imported_profile); | |
| 135 return profile.guid(); | 135 return profile.guid(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 AutofillProfile* GetProfileWithGUID(const char* guid) { | 138 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 139 for (AutofillProfile* profile : GetProfiles()) { | 139 for (AutofillProfile* profile : GetProfiles()) { |
| 140 if (!profile->guid().compare(guid)) | 140 if (!profile->guid().compare(guid)) |
| 141 return profile; | 141 return profile; |
| 142 } | 142 } |
| 143 return NULL; | 143 return NULL; |
| 144 } | 144 } |
| 145 | 145 |
| 146 CreditCard* GetCreditCardWithGUID(const char* guid) { | 146 CreditCard* GetCreditCardWithGUID(const char* guid) { |
| 147 for (CreditCard* card : GetCreditCards()) { | 147 for (CreditCard* card : GetCreditCards()) { |
| 148 if (!card->guid().compare(guid)) | 148 if (!card->guid().compare(guid)) |
| 149 return card; | 149 return card; |
| 150 } | 150 } |
| 151 return NULL; | 151 return NULL; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void AddProfile(AutofillProfile* profile) { | 154 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
| 155 profile->set_modification_date(base::Time::Now()); | 155 profile->set_modification_date(base::Time::Now()); |
| 156 web_profiles_.push_back(profile); | 156 web_profiles_.push_back(std::move(profile)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void AddCreditCard(CreditCard* credit_card) { | 159 void AddCreditCard(std::unique_ptr<CreditCard> credit_card) { |
| 160 credit_card->set_modification_date(base::Time::Now()); | 160 credit_card->set_modification_date(base::Time::Now()); |
| 161 local_credit_cards_.push_back(credit_card); | 161 local_credit_cards_.push_back(std::move(credit_card)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void RecordUseOf(const AutofillDataModel& data_model) override { | 164 void RecordUseOf(const AutofillDataModel& data_model) override { |
| 165 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 165 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); |
| 166 if (credit_card) | 166 if (credit_card) |
| 167 credit_card->RecordAndLogUse(); | 167 credit_card->RecordAndLogUse(); |
| 168 | 168 |
| 169 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); | 169 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); |
| 170 if (profile) | 170 if (profile) |
| 171 profile->RecordAndLogUse(); | 171 profile->RecordAndLogUse(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void RemoveByGUID(const std::string& guid) override { | 174 void RemoveByGUID(const std::string& guid) override { |
| 175 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); | 175 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); |
| 176 if (credit_card) { | 176 if (credit_card) { |
| 177 local_credit_cards_.erase( | 177 local_credit_cards_.erase( |
| 178 std::find(local_credit_cards_.begin(), local_credit_cards_.end(), | 178 std::find_if(local_credit_cards_.begin(), local_credit_cards_.end(), |
| 179 credit_card)); | 179 [credit_card](const std::unique_ptr<CreditCard>& ptr) { |
| 180 return ptr.get() == credit_card; |
| 181 })); |
| 180 } | 182 } |
| 181 | 183 |
| 182 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); | 184 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); |
| 183 if (profile) { | 185 if (profile) { |
| 184 web_profiles_.erase( | 186 web_profiles_.erase( |
| 185 std::find(web_profiles_.begin(), web_profiles_.end(), profile)); | 187 std::find_if(web_profiles_.begin(), web_profiles_.end(), |
| 188 [profile](const std::unique_ptr<AutofillProfile>& ptr) { |
| 189 return ptr.get() == profile; |
| 190 })); |
| 186 } | 191 } |
| 187 } | 192 } |
| 188 | 193 |
| 189 void ClearAutofillProfiles() { | 194 void ClearAutofillProfiles() { |
| 190 web_profiles_.clear(); | 195 web_profiles_.clear(); |
| 191 } | 196 } |
| 192 | 197 |
| 193 void ClearCreditCards() { | 198 void ClearCreditCards() { |
| 194 local_credit_cards_.clear(); | 199 local_credit_cards_.clear(); |
| 195 } | 200 } |
| 196 | 201 |
| 197 // Create Elvis card with whitespace in the credit card number. | 202 // Create Elvis card with whitespace in the credit card number. |
| 198 void CreateTestCreditCardWithWhitespace() { | 203 void CreateTestCreditCardWithWhitespace() { |
| 199 ClearCreditCards(); | 204 ClearCreditCards(); |
| 200 CreditCard* credit_card = new CreditCard; | 205 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 201 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 206 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 202 "4234 5678 9012 3456", // Visa | 207 "4234 5678 9012 3456", // Visa |
| 203 "04", "2999"); | 208 "04", "2999"); |
| 204 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 209 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); |
| 205 local_credit_cards_.push_back(credit_card); | 210 local_credit_cards_.push_back(std::move(credit_card)); |
| 206 } | 211 } |
| 207 | 212 |
| 208 // Create Elvis card with separator characters in the credit card number. | 213 // Create Elvis card with separator characters in the credit card number. |
| 209 void CreateTestCreditCardWithSeparators() { | 214 void CreateTestCreditCardWithSeparators() { |
| 210 ClearCreditCards(); | 215 ClearCreditCards(); |
| 211 CreditCard* credit_card = new CreditCard; | 216 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 212 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 217 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 213 "4234-5678-9012-3456", // Visa | 218 "4234-5678-9012-3456", // Visa |
| 214 "04", "2999"); | 219 "04", "2999"); |
| 215 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | 220 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 216 local_credit_cards_.push_back(credit_card); | 221 local_credit_cards_.push_back(std::move(credit_card)); |
| 217 } | 222 } |
| 218 | 223 |
| 219 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 224 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 220 ClearCreditCards(); | 225 ClearCreditCards(); |
| 221 CreditCard* credit_card = new CreditCard; | 226 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 222 test::SetCreditCardInfo(credit_card, "Miku Hatsune", | 227 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune", |
| 223 "4234567890654321", // Visa | 228 "4234567890654321", // Visa |
| 224 month, year); | 229 month, year); |
| 225 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 230 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 226 local_credit_cards_.push_back(credit_card); | 231 local_credit_cards_.push_back(std::move(credit_card)); |
| 227 } | 232 } |
| 228 | 233 |
| 229 void CreateTestExpiredCreditCard() { | 234 void CreateTestExpiredCreditCard() { |
| 230 ClearCreditCards(); | 235 ClearCreditCards(); |
| 231 CreditCard* credit_card = new CreditCard; | 236 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 232 test::SetCreditCardInfo(credit_card, "Homer Simpson", | 237 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson", |
| 233 "4234567890654321", // Visa | 238 "4234567890654321", // Visa |
| 234 "05", "2000"); | 239 "05", "2000"); |
| 235 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | 240 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 236 local_credit_cards_.push_back(credit_card); | 241 local_credit_cards_.push_back(std::move(credit_card)); |
| 237 } | 242 } |
| 238 | 243 |
| 239 private: | 244 private: |
| 240 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { | 245 void CreateTestAutofillProfiles( |
| 241 AutofillProfile* profile = new AutofillProfile; | 246 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { |
| 242 test::SetProfileInfo(profile, "Elvis", "Aaron", | 247 std::unique_ptr<AutofillProfile> profile = |
| 243 "Presley", "theking@gmail.com", "RCA", | 248 base::MakeUnique<AutofillProfile>(); |
| 244 "3734 Elvis Presley Blvd.", "Apt. 10", | 249 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", |
| 245 "Memphis", "Tennessee", "38116", "US", | 250 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", |
| 251 "Apt. 10", "Memphis", "Tennessee", "38116", "US", |
| 246 "12345678901"); | 252 "12345678901"); |
| 247 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 253 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
| 248 profiles->push_back(profile); | 254 profiles->push_back(std::move(profile)); |
| 249 profile = new AutofillProfile; | 255 profile = base::MakeUnique<AutofillProfile>(); |
| 250 test::SetProfileInfo(profile, "Charles", "Hardin", | 256 test::SetProfileInfo(profile.get(), "Charles", "Hardin", "Holley", |
| 251 "Holley", "buddy@gmail.com", "Decca", | 257 "buddy@gmail.com", "Decca", "123 Apple St.", "unit 6", |
| 252 "123 Apple St.", "unit 6", "Lubbock", | 258 "Lubbock", "Texas", "79401", "US", "23456789012"); |
| 253 "Texas", "79401", "US", "23456789012"); | |
| 254 profile->set_guid("00000000-0000-0000-0000-000000000002"); | 259 profile->set_guid("00000000-0000-0000-0000-000000000002"); |
| 255 profiles->push_back(profile); | 260 profiles->push_back(std::move(profile)); |
| 256 profile = new AutofillProfile; | 261 profile = base::MakeUnique<AutofillProfile>(); |
| 257 test::SetProfileInfo( | 262 test::SetProfileInfo(profile.get(), "", "", "", "", "", "", "", "", "", "", |
| 258 profile, "", "", "", "", "", "", "", "", "", "", "", ""); | 263 "", ""); |
| 259 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 264 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 260 profiles->push_back(profile); | 265 profiles->push_back(std::move(profile)); |
| 261 } | 266 } |
| 262 | 267 |
| 263 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 268 void CreateTestCreditCards( |
| 264 CreditCard* credit_card = new CreditCard; | 269 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { |
| 265 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 270 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 271 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 266 "4234567890123456", // Visa | 272 "4234567890123456", // Visa |
| 267 "04", "2999"); | 273 "04", "2999"); |
| 268 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 274 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 269 credit_card->set_use_count(10); | 275 credit_card->set_use_count(10); |
| 270 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 276 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 271 credit_cards->push_back(credit_card); | 277 credit_cards->push_back(std::move(credit_card)); |
| 272 | 278 |
| 273 credit_card = new CreditCard; | 279 credit_card = base::MakeUnique<CreditCard>(); |
| 274 test::SetCreditCardInfo(credit_card, "Buddy Holly", | 280 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", |
| 275 "5187654321098765", // Mastercard | 281 "5187654321098765", // Mastercard |
| 276 "10", "2998"); | 282 "10", "2998"); |
| 277 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 283 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 278 credit_card->set_use_count(5); | 284 credit_card->set_use_count(5); |
| 279 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 285 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); |
| 280 credit_cards->push_back(credit_card); | 286 credit_cards->push_back(std::move(credit_card)); |
| 281 | 287 |
| 282 credit_card = new CreditCard; | 288 credit_card = base::MakeUnique<CreditCard>(); |
| 283 test::SetCreditCardInfo(credit_card, "", "", "", ""); | 289 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); |
| 284 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 290 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
| 285 credit_cards->push_back(credit_card); | 291 credit_cards->push_back(std::move(credit_card)); |
| 286 } | 292 } |
| 287 | 293 |
| 288 size_t num_times_save_imported_profile_called_; | 294 size_t num_times_save_imported_profile_called_; |
| 289 | 295 |
| 290 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 296 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 291 }; | 297 }; |
| 292 | 298 |
| 293 class TestAutofillDownloadManager : public AutofillDownloadManager { | 299 class TestAutofillDownloadManager : public AutofillDownloadManager { |
| 294 public: | 300 public: |
| 295 TestAutofillDownloadManager(AutofillDriver* driver, | 301 TestAutofillDownloadManager(AutofillDriver* driver, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 603 } |
| 598 | 604 |
| 599 AutofillProfile* GetProfileWithGUID(const char* guid) { | 605 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 600 return personal_data_->GetProfileWithGUID(guid); | 606 return personal_data_->GetProfileWithGUID(guid); |
| 601 } | 607 } |
| 602 | 608 |
| 603 CreditCard* GetCreditCardWithGUID(const char* guid) { | 609 CreditCard* GetCreditCardWithGUID(const char* guid) { |
| 604 return personal_data_->GetCreditCardWithGUID(guid); | 610 return personal_data_->GetCreditCardWithGUID(guid); |
| 605 } | 611 } |
| 606 | 612 |
| 607 void AddProfile(AutofillProfile* profile) { | 613 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
| 608 personal_data_->AddProfile(profile); | 614 personal_data_->AddProfile(std::move(profile)); |
| 609 } | 615 } |
| 610 | 616 |
| 611 void AddCreditCard(CreditCard* credit_card) { | 617 void AddCreditCard(std::unique_ptr<CreditCard> credit_card) { |
| 612 personal_data_->AddCreditCard(credit_card); | 618 personal_data_->AddCreditCard(std::move(credit_card)); |
| 613 } | 619 } |
| 614 | 620 |
| 615 int GetPackedCreditCardID(int credit_card_id) { | 621 int GetPackedCreditCardID(int credit_card_id) { |
| 616 std::string credit_card_guid = | 622 std::string credit_card_guid = |
| 617 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 623 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 618 | 624 |
| 619 return MakeFrontendID(credit_card_guid, std::string()); | 625 return MakeFrontendID(credit_card_guid, std::string()); |
| 620 } | 626 } |
| 621 | 627 |
| 622 void AddSeenForm(FormStructure* form) { | 628 void AddSeenForm(std::unique_ptr<FormStructure> form) { |
| 623 form_structures()->push_back(form); | 629 form_structures()->push_back(std::move(form)); |
| 624 } | 630 } |
| 625 | 631 |
| 626 void ClearFormStructures() { | 632 void ClearFormStructures() { |
| 627 form_structures()->clear(); | 633 form_structures()->clear(); |
| 628 } | 634 } |
| 629 | 635 |
| 630 private: | 636 private: |
| 631 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { | 637 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { |
| 632 credit_card_was_uploaded_ = true; | 638 credit_card_was_uploaded_ = true; |
| 633 }; | 639 }; |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 test::CreateTestAddressFormData(&form); | 1284 test::CreateTestAddressFormData(&form); |
| 1279 std::vector<FormData> forms(1, form); | 1285 std::vector<FormData> forms(1, form); |
| 1280 FormsSeen(forms); | 1286 FormsSeen(forms); |
| 1281 | 1287 |
| 1282 // First name is already autofilled which will make the section appear as | 1288 // First name is already autofilled which will make the section appear as |
| 1283 // "already autofilled". | 1289 // "already autofilled". |
| 1284 form.fields[0].is_autofilled = true; | 1290 form.fields[0].is_autofilled = true; |
| 1285 | 1291 |
| 1286 // Two profiles have the same last name, and the third shares the same first | 1292 // Two profiles have the same last name, and the third shares the same first |
| 1287 // letter for last name. | 1293 // letter for last name. |
| 1288 AutofillProfile* profile1 = new AutofillProfile; | 1294 std::unique_ptr<AutofillProfile> profile1 = |
| 1295 base::MakeUnique<AutofillProfile>(); |
| 1289 profile1->set_guid("00000000-0000-0000-0000-000000000103"); | 1296 profile1->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1290 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); | 1297 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); |
| 1291 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 1298 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 1292 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1299 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1293 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 1300 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 1294 autofill_manager_->AddProfile(profile1); | 1301 autofill_manager_->AddProfile(std::move(profile1)); |
| 1295 | 1302 |
| 1296 AutofillProfile* profile2 = new AutofillProfile; | 1303 std::unique_ptr<AutofillProfile> profile2 = |
| 1304 base::MakeUnique<AutofillProfile>(); |
| 1297 profile2->set_guid("00000000-0000-0000-0000-000000000124"); | 1305 profile2->set_guid("00000000-0000-0000-0000-000000000124"); |
| 1298 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); | 1306 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); |
| 1299 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 1307 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 1300 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1308 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1301 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 1309 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 1302 autofill_manager_->AddProfile(profile2); | 1310 autofill_manager_->AddProfile(std::move(profile2)); |
| 1303 | 1311 |
| 1304 AutofillProfile* profile3 = new AutofillProfile; | 1312 std::unique_ptr<AutofillProfile> profile3 = |
| 1313 base::MakeUnique<AutofillProfile>(); |
| 1305 profile3->set_guid("00000000-0000-0000-0000-000000000126"); | 1314 profile3->set_guid("00000000-0000-0000-0000-000000000126"); |
| 1306 profile3->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Aaron"), "en-US"); | 1315 profile3->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Aaron"), "en-US"); |
| 1307 profile3->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Googler"), "en-US"); | 1316 profile3->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Googler"), "en-US"); |
| 1308 profile3->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1317 profile3->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1309 ASCIIToUTF16("1600 Amphitheater pkwy"), "en-US"); | 1318 ASCIIToUTF16("1600 Amphitheater pkwy"), "en-US"); |
| 1310 autofill_manager_->AddProfile(profile3); | 1319 autofill_manager_->AddProfile(std::move(profile3)); |
| 1311 | 1320 |
| 1312 FormFieldData field; | 1321 FormFieldData field; |
| 1313 test::CreateTestFormField("Last Name", "lastname", "G", "text", &field); | 1322 test::CreateTestFormField("Last Name", "lastname", "G", "text", &field); |
| 1314 GetAutofillSuggestions(form, field); | 1323 GetAutofillSuggestions(form, field); |
| 1315 | 1324 |
| 1316 // Test that we sent the right values to the external delegate. No labels, | 1325 // Test that we sent the right values to the external delegate. No labels, |
| 1317 // with duplicate values "Grimes" merged. | 1326 // with duplicate values "Grimes" merged. |
| 1318 external_delegate_->CheckSuggestions( | 1327 external_delegate_->CheckSuggestions( |
| 1319 kDefaultPageID, Suggestion("Googler", "" /* no label */, "", 1), | 1328 kDefaultPageID, Suggestion("Googler", "" /* no label */, "", 1), |
| 1320 Suggestion("Grimes", "" /* no label */, "", 2)); | 1329 Suggestion("Grimes", "" /* no label */, "", 2)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 | 1379 |
| 1371 // Test that we cull duplicate profile suggestions. | 1380 // Test that we cull duplicate profile suggestions. |
| 1372 TEST_F(AutofillManagerTest, GetProfileSuggestions_WithDuplicates) { | 1381 TEST_F(AutofillManagerTest, GetProfileSuggestions_WithDuplicates) { |
| 1373 // Set up our form data. | 1382 // Set up our form data. |
| 1374 FormData form; | 1383 FormData form; |
| 1375 test::CreateTestAddressFormData(&form); | 1384 test::CreateTestAddressFormData(&form); |
| 1376 std::vector<FormData> forms(1, form); | 1385 std::vector<FormData> forms(1, form); |
| 1377 FormsSeen(forms); | 1386 FormsSeen(forms); |
| 1378 | 1387 |
| 1379 // Add a duplicate profile. | 1388 // Add a duplicate profile. |
| 1380 AutofillProfile* duplicate_profile = | 1389 std::unique_ptr<AutofillProfile> duplicate_profile = |
| 1381 new AutofillProfile( | 1390 base::MakeUnique<AutofillProfile>(*(autofill_manager_->GetProfileWithGUID( |
| 1382 *(autofill_manager_->GetProfileWithGUID( | 1391 "00000000-0000-0000-0000-000000000001"))); |
| 1383 "00000000-0000-0000-0000-000000000001"))); | 1392 autofill_manager_->AddProfile(std::move(duplicate_profile)); |
| 1384 autofill_manager_->AddProfile(duplicate_profile); | |
| 1385 | 1393 |
| 1386 const FormFieldData& field = form.fields[0]; | 1394 const FormFieldData& field = form.fields[0]; |
| 1387 GetAutofillSuggestions(form, field); | 1395 GetAutofillSuggestions(form, field); |
| 1388 | 1396 |
| 1389 // Test that we sent the right values to the external delegate. | 1397 // Test that we sent the right values to the external delegate. |
| 1390 external_delegate_->CheckSuggestions( | 1398 external_delegate_->CheckSuggestions( |
| 1391 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1399 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1392 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1400 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1393 } | 1401 } |
| 1394 | 1402 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | 1487 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1480 "8765", | 1488 "8765", |
| 1481 "10/98", kMasterCard, | 1489 "10/98", kMasterCard, |
| 1482 autofill_manager_->GetPackedCreditCardID(5))); | 1490 autofill_manager_->GetPackedCreditCardID(5))); |
| 1483 } | 1491 } |
| 1484 | 1492 |
| 1485 // Test that we return all credit card profile suggestions when the triggering | 1493 // Test that we return all credit card profile suggestions when the triggering |
| 1486 // field has stop characters in it and some input. | 1494 // field has stop characters in it and some input. |
| 1487 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { | 1495 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1488 // Add a credit card with particular numbers that we will attempt to recall. | 1496 // Add a credit card with particular numbers that we will attempt to recall. |
| 1489 CreditCard* credit_card = new CreditCard; | 1497 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 1490 test::SetCreditCardInfo(credit_card, "John Smith", | 1498 test::SetCreditCardInfo(credit_card.get(), "John Smith", |
| 1491 "5255667890123123", // Mastercard | 1499 "5255667890123123", // Mastercard |
| 1492 "08", "2017"); | 1500 "08", "2017"); |
| 1493 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1501 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1494 autofill_manager_->AddCreditCard(credit_card); | 1502 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 1495 | 1503 |
| 1496 // Set up our form data. | 1504 // Set up our form data. |
| 1497 FormData form; | 1505 FormData form; |
| 1498 CreateTestCreditCardFormData(&form, true, false); | 1506 CreateTestCreditCardFormData(&form, true, false); |
| 1499 std::vector<FormData> forms(1, form); | 1507 std::vector<FormData> forms(1, form); |
| 1500 FormsSeen(forms); | 1508 FormsSeen(forms); |
| 1501 | 1509 |
| 1502 FormFieldData field = form.fields[1]; | 1510 FormFieldData field = form.fields[1]; |
| 1503 | 1511 |
| 1504 field.value = ASCIIToUTF16("5255-66__-____-____"); | 1512 field.value = ASCIIToUTF16("5255-66__-____-____"); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 GetAutofillSuggestions(form, field); | 1626 GetAutofillSuggestions(form, field); |
| 1619 // Autocomplete suggestions are queried, but not Autofill. | 1627 // Autocomplete suggestions are queried, but not Autofill. |
| 1620 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1628 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1621 } | 1629 } |
| 1622 | 1630 |
| 1623 // Test that we return all credit card suggestions in the case that two cards | 1631 // Test that we return all credit card suggestions in the case that two cards |
| 1624 // have the same obfuscated number. | 1632 // have the same obfuscated number. |
| 1625 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1633 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1626 // Add a credit card with the same obfuscated number as Elvis's. | 1634 // Add a credit card with the same obfuscated number as Elvis's. |
| 1627 // |credit_card| will be owned by the mock PersonalDataManager. | 1635 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1628 CreditCard* credit_card = new CreditCard; | 1636 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 1629 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1637 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 1630 "5231567890123456", // Mastercard | 1638 "5231567890123456", // Mastercard |
| 1631 "05", "2999"); | 1639 "05", "2999"); |
| 1632 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1640 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1633 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1641 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 1634 autofill_manager_->AddCreditCard(credit_card); | 1642 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 1635 | 1643 |
| 1636 // Set up our form data. | 1644 // Set up our form data. |
| 1637 FormData form; | 1645 FormData form; |
| 1638 CreateTestCreditCardFormData(&form, true, false); | 1646 CreateTestCreditCardFormData(&form, true, false); |
| 1639 std::vector<FormData> forms(1, form); | 1647 std::vector<FormData> forms(1, form); |
| 1640 FormsSeen(forms); | 1648 FormsSeen(forms); |
| 1641 | 1649 |
| 1642 FormFieldData field = form.fields[1]; | 1650 FormFieldData field = form.fields[1]; |
| 1643 GetAutofillSuggestions(form, field); | 1651 GetAutofillSuggestions(form, field); |
| 1644 | 1652 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 // Test that we do not return duplicate values drawn from multiple profiles when | 1787 // Test that we do not return duplicate values drawn from multiple profiles when |
| 1780 // filling an already filled field. | 1788 // filling an already filled field. |
| 1781 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 1789 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
| 1782 // Set up our form data. | 1790 // Set up our form data. |
| 1783 FormData form; | 1791 FormData form; |
| 1784 test::CreateTestAddressFormData(&form); | 1792 test::CreateTestAddressFormData(&form); |
| 1785 std::vector<FormData> forms(1, form); | 1793 std::vector<FormData> forms(1, form); |
| 1786 FormsSeen(forms); | 1794 FormsSeen(forms); |
| 1787 | 1795 |
| 1788 // |profile| will be owned by the mock PersonalDataManager. | 1796 // |profile| will be owned by the mock PersonalDataManager. |
| 1789 AutofillProfile* profile = new AutofillProfile; | 1797 std::unique_ptr<AutofillProfile> profile = |
| 1790 test::SetProfileInfo( | 1798 base::MakeUnique<AutofillProfile>(); |
| 1791 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); | 1799 test::SetProfileInfo(profile.get(), "Elvis", "", "", "", "", "", "", "", "", |
| 1800 "", "", ""); |
| 1792 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1801 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1793 autofill_manager_->AddProfile(profile); | 1802 autofill_manager_->AddProfile(std::move(profile)); |
| 1794 | 1803 |
| 1795 FormFieldData& field = form.fields[0]; | 1804 FormFieldData& field = form.fields[0]; |
| 1796 field.is_autofilled = true; | 1805 field.is_autofilled = true; |
| 1797 field.value = ASCIIToUTF16("Elvis"); | 1806 field.value = ASCIIToUTF16("Elvis"); |
| 1798 GetAutofillSuggestions(form, field); | 1807 GetAutofillSuggestions(form, field); |
| 1799 | 1808 |
| 1800 // Test that we sent the right values to the external delegate. | 1809 // Test that we sent the right values to the external delegate. |
| 1801 external_delegate_->CheckSuggestions( | 1810 external_delegate_->CheckSuggestions( |
| 1802 kDefaultPageID, | 1811 kDefaultPageID, |
| 1803 Suggestion("Elvis", "", "", 1)); | 1812 Suggestion("Elvis", "", "", 1)); |
| 1804 } | 1813 } |
| 1805 | 1814 |
| 1806 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { | 1815 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { |
| 1807 // Set up our form data. | 1816 // Set up our form data. |
| 1808 FormData form; | 1817 FormData form; |
| 1809 test::CreateTestAddressFormData(&form); | 1818 test::CreateTestAddressFormData(&form); |
| 1810 std::vector<FormData> forms(1, form); | 1819 std::vector<FormData> forms(1, form); |
| 1811 FormsSeen(forms); | 1820 FormsSeen(forms); |
| 1812 | 1821 |
| 1813 AutofillProfile* profile = new AutofillProfile; | 1822 std::unique_ptr<AutofillProfile> profile = |
| 1823 base::MakeUnique<AutofillProfile>(); |
| 1814 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1824 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1815 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), | 1825 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 1816 "en-US"); | 1826 "en-US"); |
| 1817 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 1827 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1818 ASCIIToUTF16("1800PRAIRIE")); | 1828 ASCIIToUTF16("1800PRAIRIE")); |
| 1819 autofill_manager_->AddProfile(profile); | 1829 autofill_manager_->AddProfile(std::move(profile)); |
| 1820 | 1830 |
| 1821 const FormFieldData& field = form.fields[9]; | 1831 const FormFieldData& field = form.fields[9]; |
| 1822 GetAutofillSuggestions(form, field); | 1832 GetAutofillSuggestions(form, field); |
| 1823 | 1833 |
| 1824 // Test that we sent the right values to the external delegate. Inferred | 1834 // Test that we sent the right values to the external delegate. Inferred |
| 1825 // labels include the most private field of those that would be filled. | 1835 // labels include the most private field of those that would be filled. |
| 1826 external_delegate_->CheckSuggestions( | 1836 external_delegate_->CheckSuggestions( |
| 1827 kDefaultPageID, | 1837 kDefaultPageID, |
| 1828 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE | 1838 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE |
| 1829 Suggestion("23456789012", "123 Apple St.", "", 2), | 1839 Suggestion("23456789012", "123 Apple St.", "", 2), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1853 test::CreateTestFormField( | 1863 test::CreateTestFormField( |
| 1854 test_fields[i].label, test_fields[i].name, "", "text", &field); | 1864 test_fields[i].label, test_fields[i].name, "", "text", &field); |
| 1855 field.max_length = test_fields[i].max_length; | 1865 field.max_length = test_fields[i].max_length; |
| 1856 field.autocomplete_attribute = std::string(); | 1866 field.autocomplete_attribute = std::string(); |
| 1857 form.fields.push_back(field); | 1867 form.fields.push_back(field); |
| 1858 } | 1868 } |
| 1859 | 1869 |
| 1860 std::vector<FormData> forms(1, form); | 1870 std::vector<FormData> forms(1, form); |
| 1861 FormsSeen(forms); | 1871 FormsSeen(forms); |
| 1862 | 1872 |
| 1863 AutofillProfile* profile = new AutofillProfile; | 1873 std::unique_ptr<AutofillProfile> profile = |
| 1874 base::MakeUnique<AutofillProfile>(); |
| 1864 profile->set_guid("00000000-0000-0000-0000-000000000104"); | 1875 profile->set_guid("00000000-0000-0000-0000-000000000104"); |
| 1865 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); | 1876 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); |
| 1866 personal_data_.ClearAutofillProfiles(); | 1877 personal_data_.ClearAutofillProfiles(); |
| 1867 autofill_manager_->AddProfile(profile); | 1878 autofill_manager_->AddProfile(std::move(profile)); |
| 1868 | 1879 |
| 1869 const FormFieldData& phone_prefix = form.fields[2]; | 1880 const FormFieldData& phone_prefix = form.fields[2]; |
| 1870 GetAutofillSuggestions(form, phone_prefix); | 1881 GetAutofillSuggestions(form, phone_prefix); |
| 1871 | 1882 |
| 1872 // Test that we sent the right prefix values to the external delegate. | 1883 // Test that we sent the right prefix values to the external delegate. |
| 1873 external_delegate_->CheckSuggestions(kDefaultPageID, | 1884 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 1874 Suggestion("356", "1800FLOWERS", "", 1)); | 1885 Suggestion("356", "1800FLOWERS", "", 1)); |
| 1875 | 1886 |
| 1876 const FormFieldData& phone_suffix = form.fields[3]; | 1887 const FormFieldData& phone_suffix = form.fields[3]; |
| 1877 GetAutofillSuggestions(form, phone_suffix); | 1888 GetAutofillSuggestions(form, phone_suffix); |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3246 // signature of the queried form and apply type predictions. | 3257 // signature of the queried form and apply type predictions. |
| 3247 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) { | 3258 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) { |
| 3248 // Set up our form data. | 3259 // Set up our form data. |
| 3249 FormData form; | 3260 FormData form; |
| 3250 test::CreateTestAddressFormData(&form); | 3261 test::CreateTestAddressFormData(&form); |
| 3251 | 3262 |
| 3252 // Simulate having seen this form on page load. | 3263 // Simulate having seen this form on page load. |
| 3253 // |form_structure| will be owned by |autofill_manager_|. | 3264 // |form_structure| will be owned by |autofill_manager_|. |
| 3254 TestFormStructure* form_structure = new TestFormStructure(form); | 3265 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3255 form_structure->DetermineHeuristicTypes(); | 3266 form_structure->DetermineHeuristicTypes(); |
| 3256 autofill_manager_->AddSeenForm(form_structure); | 3267 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3257 | 3268 |
| 3258 // Similarly, a second form. | 3269 // Similarly, a second form. |
| 3259 FormData form2; | 3270 FormData form2; |
| 3260 form2.name = ASCIIToUTF16("MyForm"); | 3271 form2.name = ASCIIToUTF16("MyForm"); |
| 3261 form2.origin = GURL("http://myform.com/form.html"); | 3272 form2.origin = GURL("http://myform.com/form.html"); |
| 3262 form2.action = GURL("http://myform.com/submit.html"); | 3273 form2.action = GURL("http://myform.com/submit.html"); |
| 3263 | 3274 |
| 3264 FormFieldData field; | 3275 FormFieldData field; |
| 3265 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 3276 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 3266 form2.fields.push_back(field); | 3277 form2.fields.push_back(field); |
| 3267 | 3278 |
| 3268 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); | 3279 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); |
| 3269 form2.fields.push_back(field); | 3280 form2.fields.push_back(field); |
| 3270 | 3281 |
| 3271 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); | 3282 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); |
| 3272 form2.fields.push_back(field); | 3283 form2.fields.push_back(field); |
| 3273 | 3284 |
| 3274 TestFormStructure* form_structure2 = new TestFormStructure(form2); | 3285 TestFormStructure* form_structure2 = new TestFormStructure(form2); |
| 3275 form_structure2->DetermineHeuristicTypes(); | 3286 form_structure2->DetermineHeuristicTypes(); |
| 3276 autofill_manager_->AddSeenForm(form_structure2); | 3287 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure2)); |
| 3277 | 3288 |
| 3278 AutofillQueryResponseContents response; | 3289 AutofillQueryResponseContents response; |
| 3279 response.add_field()->set_autofill_type(3); | 3290 response.add_field()->set_autofill_type(3); |
| 3280 for (int i = 0; i < 7; ++i) { | 3291 for (int i = 0; i < 7; ++i) { |
| 3281 response.add_field()->set_autofill_type(0); | 3292 response.add_field()->set_autofill_type(0); |
| 3282 } | 3293 } |
| 3283 response.add_field()->set_autofill_type(3); | 3294 response.add_field()->set_autofill_type(3); |
| 3284 response.add_field()->set_autofill_type(2); | 3295 response.add_field()->set_autofill_type(2); |
| 3285 response.add_field()->set_autofill_type(61); | 3296 response.add_field()->set_autofill_type(61); |
| 3286 response.add_field()->set_autofill_type(5); | 3297 response.add_field()->set_autofill_type(5); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3319 // response received. | 3330 // response received. |
| 3320 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { | 3331 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { |
| 3321 // Set up our form data. | 3332 // Set up our form data. |
| 3322 FormData form; | 3333 FormData form; |
| 3323 test::CreateTestAddressFormData(&form); | 3334 test::CreateTestAddressFormData(&form); |
| 3324 | 3335 |
| 3325 // Simulate having seen this form on page load. | 3336 // Simulate having seen this form on page load. |
| 3326 // |form_structure| will be owned by |autofill_manager_|. | 3337 // |form_structure| will be owned by |autofill_manager_|. |
| 3327 TestFormStructure* form_structure = new TestFormStructure(form); | 3338 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3328 form_structure->DetermineHeuristicTypes(); | 3339 form_structure->DetermineHeuristicTypes(); |
| 3329 autofill_manager_->AddSeenForm(form_structure); | 3340 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3330 | 3341 |
| 3331 AutofillQueryResponseContents response; | 3342 AutofillQueryResponseContents response; |
| 3332 response.add_field()->set_autofill_type(3); | 3343 response.add_field()->set_autofill_type(3); |
| 3333 for (int i = 0; i < 7; ++i) { | 3344 for (int i = 0; i < 7; ++i) { |
| 3334 response.add_field()->set_autofill_type(0); | 3345 response.add_field()->set_autofill_type(0); |
| 3335 } | 3346 } |
| 3336 response.add_field()->set_autofill_type(3); | 3347 response.add_field()->set_autofill_type(3); |
| 3337 response.add_field()->set_autofill_type(2); | 3348 response.add_field()->set_autofill_type(2); |
| 3338 response.add_field()->set_autofill_type(61); | 3349 response.add_field()->set_autofill_type(61); |
| 3339 | 3350 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3365 TestFormStructure* form_structure = new TestFormStructure(form); | 3376 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3366 form_structure->DetermineHeuristicTypes(); | 3377 form_structure->DetermineHeuristicTypes(); |
| 3367 | 3378 |
| 3368 // Clear the heuristic types, and instead set the appropriate server types. | 3379 // Clear the heuristic types, and instead set the appropriate server types. |
| 3369 std::vector<ServerFieldType> heuristic_types, server_types; | 3380 std::vector<ServerFieldType> heuristic_types, server_types; |
| 3370 for (size_t i = 0; i < form.fields.size(); ++i) { | 3381 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 3371 heuristic_types.push_back(UNKNOWN_TYPE); | 3382 heuristic_types.push_back(UNKNOWN_TYPE); |
| 3372 server_types.push_back(form_structure->field(i)->heuristic_type()); | 3383 server_types.push_back(form_structure->field(i)->heuristic_type()); |
| 3373 } | 3384 } |
| 3374 form_structure->SetFieldTypes(heuristic_types, server_types); | 3385 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 3375 autofill_manager_->AddSeenForm(form_structure); | 3386 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3376 | 3387 |
| 3377 // Fill the form. | 3388 // Fill the form. |
| 3378 const char guid[] = "00000000-0000-0000-0000-000000000001"; | 3389 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 3379 int response_page_id = 0; | 3390 int response_page_id = 0; |
| 3380 FormData response_data; | 3391 FormData response_data; |
| 3381 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 3392 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 3382 MakeFrontendID(std::string(), guid), | 3393 MakeFrontendID(std::string(), guid), |
| 3383 &response_page_id, &response_data); | 3394 &response_page_id, &response_data); |
| 3384 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, | 3395 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, |
| 3385 false); | 3396 false); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3915 possible_types.find(test_fields[i].expected_upload_type)); | 3926 possible_types.find(test_fields[i].expected_upload_type)); |
| 3916 } else { | 3927 } else { |
| 3917 EXPECT_EQ(2U, possible_types.size()); | 3928 EXPECT_EQ(2U, possible_types.size()); |
| 3918 } | 3929 } |
| 3919 } | 3930 } |
| 3920 } | 3931 } |
| 3921 } | 3932 } |
| 3922 | 3933 |
| 3923 TEST_F(AutofillManagerTest, RemoveProfile) { | 3934 TEST_F(AutofillManagerTest, RemoveProfile) { |
| 3924 // Add and remove an Autofill profile. | 3935 // Add and remove an Autofill profile. |
| 3925 AutofillProfile* profile = new AutofillProfile; | 3936 std::unique_ptr<AutofillProfile> profile = |
| 3937 base::MakeUnique<AutofillProfile>(); |
| 3926 const char guid[] = "00000000-0000-0000-0000-000000000102"; | 3938 const char guid[] = "00000000-0000-0000-0000-000000000102"; |
| 3927 profile->set_guid(guid); | 3939 profile->set_guid(guid); |
| 3928 autofill_manager_->AddProfile(profile); | 3940 autofill_manager_->AddProfile(std::move(profile)); |
| 3929 | 3941 |
| 3930 int id = MakeFrontendID(std::string(), guid); | 3942 int id = MakeFrontendID(std::string(), guid); |
| 3931 | 3943 |
| 3932 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3944 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 3933 | 3945 |
| 3934 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid)); | 3946 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid)); |
| 3935 } | 3947 } |
| 3936 | 3948 |
| 3937 TEST_F(AutofillManagerTest, RemoveCreditCard) { | 3949 TEST_F(AutofillManagerTest, RemoveCreditCard) { |
| 3938 // Add and remove an Autofill credit card. | 3950 // Add and remove an Autofill credit card. |
| 3939 CreditCard* credit_card = new CreditCard; | 3951 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 3940 const char guid[] = "00000000-0000-0000-0000-000000100007"; | 3952 const char guid[] = "00000000-0000-0000-0000-000000100007"; |
| 3941 credit_card->set_guid(guid); | 3953 credit_card->set_guid(guid); |
| 3942 autofill_manager_->AddCreditCard(credit_card); | 3954 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 3943 | 3955 |
| 3944 int id = MakeFrontendID(guid, std::string()); | 3956 int id = MakeFrontendID(guid, std::string()); |
| 3945 | 3957 |
| 3946 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3958 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 3947 | 3959 |
| 3948 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid)); | 3960 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid)); |
| 3949 } | 3961 } |
| 3950 | 3962 |
| 3951 // Test our external delegate is called at the right time. | 3963 // Test our external delegate is called at the right time. |
| 3952 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3964 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| (...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5094 // Token matching is currently behind a flag. | 5106 // Token matching is currently behind a flag. |
| 5095 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 5107 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 5096 switches::kEnableSuggestionsWithSubstringMatch); | 5108 switches::kEnableSuggestionsWithSubstringMatch); |
| 5097 | 5109 |
| 5098 // Set up our form data. | 5110 // Set up our form data. |
| 5099 FormData form; | 5111 FormData form; |
| 5100 test::CreateTestAddressFormData(&form); | 5112 test::CreateTestAddressFormData(&form); |
| 5101 std::vector<FormData> forms(1, form); | 5113 std::vector<FormData> forms(1, form); |
| 5102 FormsSeen(forms); | 5114 FormsSeen(forms); |
| 5103 | 5115 |
| 5104 AutofillProfile* profile1 = new AutofillProfile; | 5116 std::unique_ptr<AutofillProfile> profile1 = |
| 5117 base::MakeUnique<AutofillProfile>(); |
| 5105 profile1->set_guid("00000000-0000-0000-0000-000000000103"); | 5118 profile1->set_guid("00000000-0000-0000-0000-000000000103"); |
| 5106 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); | 5119 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); |
| 5107 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), | 5120 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), |
| 5108 "en-US"); | 5121 "en-US"); |
| 5109 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 5122 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 5110 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 5123 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 5111 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 5124 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 5112 autofill_manager_->AddProfile(profile1); | 5125 autofill_manager_->AddProfile(std::move(profile1)); |
| 5113 | 5126 |
| 5114 AutofillProfile* profile2 = new AutofillProfile; | 5127 std::unique_ptr<AutofillProfile> profile2 = |
| 5128 base::MakeUnique<AutofillProfile>(); |
| 5115 profile2->set_guid("00000000-0000-0000-0000-000000000124"); | 5129 profile2->set_guid("00000000-0000-0000-0000-000000000124"); |
| 5116 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); | 5130 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); |
| 5117 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), | 5131 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), |
| 5118 "en-US"); | 5132 "en-US"); |
| 5119 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 5133 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 5120 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 5134 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 5121 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 5135 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 5122 autofill_manager_->AddProfile(profile2); | 5136 autofill_manager_->AddProfile(std::move(profile2)); |
| 5123 | 5137 |
| 5124 FormFieldData field; | 5138 FormFieldData field; |
| 5125 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); | 5139 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); |
| 5126 GetAutofillSuggestions(form, field); | 5140 GetAutofillSuggestions(form, field); |
| 5127 | 5141 |
| 5128 external_delegate_->CheckSuggestions( | 5142 external_delegate_->CheckSuggestions( |
| 5129 kDefaultPageID, | 5143 kDefaultPageID, |
| 5130 Suggestion("Shawn Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", | 5144 Suggestion("Shawn Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", |
| 5131 1), | 5145 1), |
| 5132 Suggestion("Adam Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", | 5146 Suggestion("Adam Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5287 | 5301 |
| 5288 // The driver should always be notified. | 5302 // The driver should always be notified. |
| 5289 for (const FormFieldData& field : form.fields) { | 5303 for (const FormFieldData& field : form.fields) { |
| 5290 GetAutofillSuggestions(form, field); | 5304 GetAutofillSuggestions(form, field); |
| 5291 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); | 5305 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); |
| 5292 autofill_driver_->ClearDidInteractWithCreditCardForm(); | 5306 autofill_driver_->ClearDidInteractWithCreditCardForm(); |
| 5293 } | 5307 } |
| 5294 } | 5308 } |
| 5295 | 5309 |
| 5296 } // namespace autofill | 5310 } // namespace autofill |
| OLD | NEW |