| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 589 } |
| 584 | 590 |
| 585 AutofillProfile* GetProfileWithGUID(const char* guid) { | 591 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 586 return personal_data_->GetProfileWithGUID(guid); | 592 return personal_data_->GetProfileWithGUID(guid); |
| 587 } | 593 } |
| 588 | 594 |
| 589 CreditCard* GetCreditCardWithGUID(const char* guid) { | 595 CreditCard* GetCreditCardWithGUID(const char* guid) { |
| 590 return personal_data_->GetCreditCardWithGUID(guid); | 596 return personal_data_->GetCreditCardWithGUID(guid); |
| 591 } | 597 } |
| 592 | 598 |
| 593 void AddProfile(AutofillProfile* profile) { | 599 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
| 594 personal_data_->AddProfile(profile); | 600 personal_data_->AddProfile(std::move(profile)); |
| 595 } | 601 } |
| 596 | 602 |
| 597 void AddCreditCard(CreditCard* credit_card) { | 603 void AddCreditCard(std::unique_ptr<CreditCard> credit_card) { |
| 598 personal_data_->AddCreditCard(credit_card); | 604 personal_data_->AddCreditCard(std::move(credit_card)); |
| 599 } | 605 } |
| 600 | 606 |
| 601 int GetPackedCreditCardID(int credit_card_id) { | 607 int GetPackedCreditCardID(int credit_card_id) { |
| 602 std::string credit_card_guid = | 608 std::string credit_card_guid = |
| 603 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 609 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 604 | 610 |
| 605 return MakeFrontendID(credit_card_guid, std::string()); | 611 return MakeFrontendID(credit_card_guid, std::string()); |
| 606 } | 612 } |
| 607 | 613 |
| 608 void AddSeenForm(FormStructure* form) { | 614 void AddSeenForm(std::unique_ptr<FormStructure> form) { |
| 609 form_structures()->push_back(form); | 615 form_structures()->push_back(std::move(form)); |
| 610 } | 616 } |
| 611 | 617 |
| 612 void ClearFormStructures() { | 618 void ClearFormStructures() { |
| 613 form_structures()->clear(); | 619 form_structures()->clear(); |
| 614 } | 620 } |
| 615 | 621 |
| 616 private: | 622 private: |
| 617 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { | 623 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { |
| 618 credit_card_was_uploaded_ = true; | 624 credit_card_was_uploaded_ = true; |
| 619 }; | 625 }; |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 test::CreateTestAddressFormData(&form); | 1271 test::CreateTestAddressFormData(&form); |
| 1266 std::vector<FormData> forms(1, form); | 1272 std::vector<FormData> forms(1, form); |
| 1267 FormsSeen(forms); | 1273 FormsSeen(forms); |
| 1268 | 1274 |
| 1269 // First name is already autofilled which will make the section appear as | 1275 // First name is already autofilled which will make the section appear as |
| 1270 // "already autofilled". | 1276 // "already autofilled". |
| 1271 form.fields[0].is_autofilled = true; | 1277 form.fields[0].is_autofilled = true; |
| 1272 | 1278 |
| 1273 // Two profiles have the same last name, and the third shares the same first | 1279 // Two profiles have the same last name, and the third shares the same first |
| 1274 // letter for last name. | 1280 // letter for last name. |
| 1275 AutofillProfile* profile1 = new AutofillProfile; | 1281 std::unique_ptr<AutofillProfile> profile1 = |
| 1282 base::MakeUnique<AutofillProfile>(); |
| 1276 profile1->set_guid("00000000-0000-0000-0000-000000000103"); | 1283 profile1->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1277 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); | 1284 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); |
| 1278 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 1285 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 1279 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1286 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1280 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 1287 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 1281 autofill_manager_->AddProfile(profile1); | 1288 autofill_manager_->AddProfile(std::move(profile1)); |
| 1282 | 1289 |
| 1283 AutofillProfile* profile2 = new AutofillProfile; | 1290 std::unique_ptr<AutofillProfile> profile2 = |
| 1291 base::MakeUnique<AutofillProfile>(); |
| 1284 profile2->set_guid("00000000-0000-0000-0000-000000000124"); | 1292 profile2->set_guid("00000000-0000-0000-0000-000000000124"); |
| 1285 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); | 1293 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); |
| 1286 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 1294 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 1287 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1295 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1288 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 1296 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 1289 autofill_manager_->AddProfile(profile2); | 1297 autofill_manager_->AddProfile(std::move(profile2)); |
| 1290 | 1298 |
| 1291 AutofillProfile* profile3 = new AutofillProfile; | 1299 std::unique_ptr<AutofillProfile> profile3 = |
| 1300 base::MakeUnique<AutofillProfile>(); |
| 1292 profile3->set_guid("00000000-0000-0000-0000-000000000126"); | 1301 profile3->set_guid("00000000-0000-0000-0000-000000000126"); |
| 1293 profile3->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Aaron"), "en-US"); | 1302 profile3->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Aaron"), "en-US"); |
| 1294 profile3->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Googler"), "en-US"); | 1303 profile3->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Googler"), "en-US"); |
| 1295 profile3->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 1304 profile3->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 1296 ASCIIToUTF16("1600 Amphitheater pkwy"), "en-US"); | 1305 ASCIIToUTF16("1600 Amphitheater pkwy"), "en-US"); |
| 1297 autofill_manager_->AddProfile(profile3); | 1306 autofill_manager_->AddProfile(std::move(profile3)); |
| 1298 | 1307 |
| 1299 FormFieldData field; | 1308 FormFieldData field; |
| 1300 test::CreateTestFormField("Last Name", "lastname", "G", "text", &field); | 1309 test::CreateTestFormField("Last Name", "lastname", "G", "text", &field); |
| 1301 GetAutofillSuggestions(form, field); | 1310 GetAutofillSuggestions(form, field); |
| 1302 | 1311 |
| 1303 // Test that we sent the right values to the external delegate. No labels, | 1312 // Test that we sent the right values to the external delegate. No labels, |
| 1304 // with duplicate values "Grimes" merged. | 1313 // with duplicate values "Grimes" merged. |
| 1305 external_delegate_->CheckSuggestions( | 1314 external_delegate_->CheckSuggestions( |
| 1306 kDefaultPageID, Suggestion("Googler", "" /* no label */, "", 1), | 1315 kDefaultPageID, Suggestion("Googler", "" /* no label */, "", 1), |
| 1307 Suggestion("Grimes", "" /* no label */, "", 2)); | 1316 Suggestion("Grimes", "" /* no label */, "", 2)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 | 1366 |
| 1358 // Test that we cull duplicate profile suggestions. | 1367 // Test that we cull duplicate profile suggestions. |
| 1359 TEST_F(AutofillManagerTest, GetProfileSuggestions_WithDuplicates) { | 1368 TEST_F(AutofillManagerTest, GetProfileSuggestions_WithDuplicates) { |
| 1360 // Set up our form data. | 1369 // Set up our form data. |
| 1361 FormData form; | 1370 FormData form; |
| 1362 test::CreateTestAddressFormData(&form); | 1371 test::CreateTestAddressFormData(&form); |
| 1363 std::vector<FormData> forms(1, form); | 1372 std::vector<FormData> forms(1, form); |
| 1364 FormsSeen(forms); | 1373 FormsSeen(forms); |
| 1365 | 1374 |
| 1366 // Add a duplicate profile. | 1375 // Add a duplicate profile. |
| 1367 AutofillProfile* duplicate_profile = | 1376 std::unique_ptr<AutofillProfile> duplicate_profile = |
| 1368 new AutofillProfile( | 1377 base::MakeUnique<AutofillProfile>(*(autofill_manager_->GetProfileWithGUID( |
| 1369 *(autofill_manager_->GetProfileWithGUID( | 1378 "00000000-0000-0000-0000-000000000001"))); |
| 1370 "00000000-0000-0000-0000-000000000001"))); | 1379 autofill_manager_->AddProfile(std::move(duplicate_profile)); |
| 1371 autofill_manager_->AddProfile(duplicate_profile); | |
| 1372 | 1380 |
| 1373 const FormFieldData& field = form.fields[0]; | 1381 const FormFieldData& field = form.fields[0]; |
| 1374 GetAutofillSuggestions(form, field); | 1382 GetAutofillSuggestions(form, field); |
| 1375 | 1383 |
| 1376 // Test that we sent the right values to the external delegate. | 1384 // Test that we sent the right values to the external delegate. |
| 1377 external_delegate_->CheckSuggestions( | 1385 external_delegate_->CheckSuggestions( |
| 1378 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1386 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1379 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1387 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1380 } | 1388 } |
| 1381 | 1389 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | 1474 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1467 "8765", | 1475 "8765", |
| 1468 "10/98", kMasterCard, | 1476 "10/98", kMasterCard, |
| 1469 autofill_manager_->GetPackedCreditCardID(5))); | 1477 autofill_manager_->GetPackedCreditCardID(5))); |
| 1470 } | 1478 } |
| 1471 | 1479 |
| 1472 // Test that we return all credit card profile suggestions when the triggering | 1480 // Test that we return all credit card profile suggestions when the triggering |
| 1473 // field has stop characters in it and some input. | 1481 // field has stop characters in it and some input. |
| 1474 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { | 1482 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1475 // Add a credit card with particular numbers that we will attempt to recall. | 1483 // Add a credit card with particular numbers that we will attempt to recall. |
| 1476 CreditCard* credit_card = new CreditCard; | 1484 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 1477 test::SetCreditCardInfo(credit_card, "John Smith", | 1485 test::SetCreditCardInfo(credit_card.get(), "John Smith", |
| 1478 "5255667890123123", // Mastercard | 1486 "5255667890123123", // Mastercard |
| 1479 "08", "2017"); | 1487 "08", "2017"); |
| 1480 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1488 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1481 autofill_manager_->AddCreditCard(credit_card); | 1489 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 1482 | 1490 |
| 1483 // Set up our form data. | 1491 // Set up our form data. |
| 1484 FormData form; | 1492 FormData form; |
| 1485 CreateTestCreditCardFormData(&form, true, false); | 1493 CreateTestCreditCardFormData(&form, true, false); |
| 1486 std::vector<FormData> forms(1, form); | 1494 std::vector<FormData> forms(1, form); |
| 1487 FormsSeen(forms); | 1495 FormsSeen(forms); |
| 1488 | 1496 |
| 1489 FormFieldData field = form.fields[1]; | 1497 FormFieldData field = form.fields[1]; |
| 1490 | 1498 |
| 1491 field.value = ASCIIToUTF16("5255-66__-____-____"); | 1499 field.value = ASCIIToUTF16("5255-66__-____-____"); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 GetAutofillSuggestions(form, field); | 1585 GetAutofillSuggestions(form, field); |
| 1578 // Autocomplete suggestions are queried, but not Autofill. | 1586 // Autocomplete suggestions are queried, but not Autofill. |
| 1579 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1587 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1580 } | 1588 } |
| 1581 | 1589 |
| 1582 // Test that we return all credit card suggestions in the case that two cards | 1590 // Test that we return all credit card suggestions in the case that two cards |
| 1583 // have the same obfuscated number. | 1591 // have the same obfuscated number. |
| 1584 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1592 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1585 // Add a credit card with the same obfuscated number as Elvis's. | 1593 // Add a credit card with the same obfuscated number as Elvis's. |
| 1586 // |credit_card| will be owned by the mock PersonalDataManager. | 1594 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1587 CreditCard* credit_card = new CreditCard; | 1595 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 1588 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1596 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 1589 "5231567890123456", // Mastercard | 1597 "5231567890123456", // Mastercard |
| 1590 "05", "2999"); | 1598 "05", "2999"); |
| 1591 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1599 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1592 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1600 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 1593 autofill_manager_->AddCreditCard(credit_card); | 1601 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 1594 | 1602 |
| 1595 // Set up our form data. | 1603 // Set up our form data. |
| 1596 FormData form; | 1604 FormData form; |
| 1597 CreateTestCreditCardFormData(&form, true, false); | 1605 CreateTestCreditCardFormData(&form, true, false); |
| 1598 std::vector<FormData> forms(1, form); | 1606 std::vector<FormData> forms(1, form); |
| 1599 FormsSeen(forms); | 1607 FormsSeen(forms); |
| 1600 | 1608 |
| 1601 FormFieldData field = form.fields[1]; | 1609 FormFieldData field = form.fields[1]; |
| 1602 GetAutofillSuggestions(form, field); | 1610 GetAutofillSuggestions(form, field); |
| 1603 | 1611 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 // Test that we do not return duplicate values drawn from multiple profiles when | 1746 // Test that we do not return duplicate values drawn from multiple profiles when |
| 1739 // filling an already filled field. | 1747 // filling an already filled field. |
| 1740 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 1748 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
| 1741 // Set up our form data. | 1749 // Set up our form data. |
| 1742 FormData form; | 1750 FormData form; |
| 1743 test::CreateTestAddressFormData(&form); | 1751 test::CreateTestAddressFormData(&form); |
| 1744 std::vector<FormData> forms(1, form); | 1752 std::vector<FormData> forms(1, form); |
| 1745 FormsSeen(forms); | 1753 FormsSeen(forms); |
| 1746 | 1754 |
| 1747 // |profile| will be owned by the mock PersonalDataManager. | 1755 // |profile| will be owned by the mock PersonalDataManager. |
| 1748 AutofillProfile* profile = new AutofillProfile; | 1756 std::unique_ptr<AutofillProfile> profile = |
| 1749 test::SetProfileInfo( | 1757 base::MakeUnique<AutofillProfile>(); |
| 1750 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); | 1758 test::SetProfileInfo(profile.get(), "Elvis", "", "", "", "", "", "", "", "", |
| 1759 "", "", ""); |
| 1751 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1760 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1752 autofill_manager_->AddProfile(profile); | 1761 autofill_manager_->AddProfile(std::move(profile)); |
| 1753 | 1762 |
| 1754 FormFieldData& field = form.fields[0]; | 1763 FormFieldData& field = form.fields[0]; |
| 1755 field.is_autofilled = true; | 1764 field.is_autofilled = true; |
| 1756 field.value = ASCIIToUTF16("Elvis"); | 1765 field.value = ASCIIToUTF16("Elvis"); |
| 1757 GetAutofillSuggestions(form, field); | 1766 GetAutofillSuggestions(form, field); |
| 1758 | 1767 |
| 1759 // Test that we sent the right values to the external delegate. | 1768 // Test that we sent the right values to the external delegate. |
| 1760 external_delegate_->CheckSuggestions( | 1769 external_delegate_->CheckSuggestions( |
| 1761 kDefaultPageID, | 1770 kDefaultPageID, |
| 1762 Suggestion("Elvis", "", "", 1)); | 1771 Suggestion("Elvis", "", "", 1)); |
| 1763 } | 1772 } |
| 1764 | 1773 |
| 1765 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { | 1774 TEST_F(AutofillManagerTest, GetProfileSuggestions_FancyPhone) { |
| 1766 // Set up our form data. | 1775 // Set up our form data. |
| 1767 FormData form; | 1776 FormData form; |
| 1768 test::CreateTestAddressFormData(&form); | 1777 test::CreateTestAddressFormData(&form); |
| 1769 std::vector<FormData> forms(1, form); | 1778 std::vector<FormData> forms(1, form); |
| 1770 FormsSeen(forms); | 1779 FormsSeen(forms); |
| 1771 | 1780 |
| 1772 AutofillProfile* profile = new AutofillProfile; | 1781 std::unique_ptr<AutofillProfile> profile = |
| 1782 base::MakeUnique<AutofillProfile>(); |
| 1773 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1783 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1774 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), | 1784 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 1775 "en-US"); | 1785 "en-US"); |
| 1776 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, | 1786 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1777 ASCIIToUTF16("1800PRAIRIE")); | 1787 ASCIIToUTF16("1800PRAIRIE")); |
| 1778 autofill_manager_->AddProfile(profile); | 1788 autofill_manager_->AddProfile(std::move(profile)); |
| 1779 | 1789 |
| 1780 const FormFieldData& field = form.fields[9]; | 1790 const FormFieldData& field = form.fields[9]; |
| 1781 GetAutofillSuggestions(form, field); | 1791 GetAutofillSuggestions(form, field); |
| 1782 | 1792 |
| 1783 // Test that we sent the right values to the external delegate. Inferred | 1793 // Test that we sent the right values to the external delegate. Inferred |
| 1784 // labels include the most private field of those that would be filled. | 1794 // labels include the most private field of those that would be filled. |
| 1785 external_delegate_->CheckSuggestions( | 1795 external_delegate_->CheckSuggestions( |
| 1786 kDefaultPageID, | 1796 kDefaultPageID, |
| 1787 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE | 1797 Suggestion("18007724743", "Natty Bumppo", "", 1), // 1800PRAIRIE |
| 1788 Suggestion("23456789012", "123 Apple St.", "", 2), | 1798 Suggestion("23456789012", "123 Apple St.", "", 2), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1812 test::CreateTestFormField( | 1822 test::CreateTestFormField( |
| 1813 test_fields[i].label, test_fields[i].name, "", "text", &field); | 1823 test_fields[i].label, test_fields[i].name, "", "text", &field); |
| 1814 field.max_length = test_fields[i].max_length; | 1824 field.max_length = test_fields[i].max_length; |
| 1815 field.autocomplete_attribute = std::string(); | 1825 field.autocomplete_attribute = std::string(); |
| 1816 form.fields.push_back(field); | 1826 form.fields.push_back(field); |
| 1817 } | 1827 } |
| 1818 | 1828 |
| 1819 std::vector<FormData> forms(1, form); | 1829 std::vector<FormData> forms(1, form); |
| 1820 FormsSeen(forms); | 1830 FormsSeen(forms); |
| 1821 | 1831 |
| 1822 AutofillProfile* profile = new AutofillProfile; | 1832 std::unique_ptr<AutofillProfile> profile = |
| 1833 base::MakeUnique<AutofillProfile>(); |
| 1823 profile->set_guid("00000000-0000-0000-0000-000000000104"); | 1834 profile->set_guid("00000000-0000-0000-0000-000000000104"); |
| 1824 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); | 1835 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1800FLOWERS")); |
| 1825 personal_data_.ClearAutofillProfiles(); | 1836 personal_data_.ClearAutofillProfiles(); |
| 1826 autofill_manager_->AddProfile(profile); | 1837 autofill_manager_->AddProfile(std::move(profile)); |
| 1827 | 1838 |
| 1828 const FormFieldData& phone_prefix = form.fields[2]; | 1839 const FormFieldData& phone_prefix = form.fields[2]; |
| 1829 GetAutofillSuggestions(form, phone_prefix); | 1840 GetAutofillSuggestions(form, phone_prefix); |
| 1830 | 1841 |
| 1831 // Test that we sent the right prefix values to the external delegate. | 1842 // Test that we sent the right prefix values to the external delegate. |
| 1832 external_delegate_->CheckSuggestions(kDefaultPageID, | 1843 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 1833 Suggestion("356", "1800FLOWERS", "", 1)); | 1844 Suggestion("356", "1800FLOWERS", "", 1)); |
| 1834 | 1845 |
| 1835 const FormFieldData& phone_suffix = form.fields[3]; | 1846 const FormFieldData& phone_suffix = form.fields[3]; |
| 1836 GetAutofillSuggestions(form, phone_suffix); | 1847 GetAutofillSuggestions(form, phone_suffix); |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3205 // signature of the queried form and apply type predictions. | 3216 // signature of the queried form and apply type predictions. |
| 3206 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) { | 3217 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) { |
| 3207 // Set up our form data. | 3218 // Set up our form data. |
| 3208 FormData form; | 3219 FormData form; |
| 3209 test::CreateTestAddressFormData(&form); | 3220 test::CreateTestAddressFormData(&form); |
| 3210 | 3221 |
| 3211 // Simulate having seen this form on page load. | 3222 // Simulate having seen this form on page load. |
| 3212 // |form_structure| will be owned by |autofill_manager_|. | 3223 // |form_structure| will be owned by |autofill_manager_|. |
| 3213 TestFormStructure* form_structure = new TestFormStructure(form); | 3224 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3214 form_structure->DetermineHeuristicTypes(); | 3225 form_structure->DetermineHeuristicTypes(); |
| 3215 autofill_manager_->AddSeenForm(form_structure); | 3226 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3216 | 3227 |
| 3217 // Similarly, a second form. | 3228 // Similarly, a second form. |
| 3218 FormData form2; | 3229 FormData form2; |
| 3219 form2.name = ASCIIToUTF16("MyForm"); | 3230 form2.name = ASCIIToUTF16("MyForm"); |
| 3220 form2.origin = GURL("http://myform.com/form.html"); | 3231 form2.origin = GURL("http://myform.com/form.html"); |
| 3221 form2.action = GURL("http://myform.com/submit.html"); | 3232 form2.action = GURL("http://myform.com/submit.html"); |
| 3222 | 3233 |
| 3223 FormFieldData field; | 3234 FormFieldData field; |
| 3224 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | 3235 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 3225 form2.fields.push_back(field); | 3236 form2.fields.push_back(field); |
| 3226 | 3237 |
| 3227 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); | 3238 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); |
| 3228 form2.fields.push_back(field); | 3239 form2.fields.push_back(field); |
| 3229 | 3240 |
| 3230 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); | 3241 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); |
| 3231 form2.fields.push_back(field); | 3242 form2.fields.push_back(field); |
| 3232 | 3243 |
| 3233 TestFormStructure* form_structure2 = new TestFormStructure(form2); | 3244 TestFormStructure* form_structure2 = new TestFormStructure(form2); |
| 3234 form_structure2->DetermineHeuristicTypes(); | 3245 form_structure2->DetermineHeuristicTypes(); |
| 3235 autofill_manager_->AddSeenForm(form_structure2); | 3246 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure2)); |
| 3236 | 3247 |
| 3237 AutofillQueryResponseContents response; | 3248 AutofillQueryResponseContents response; |
| 3238 response.add_field()->set_autofill_type(3); | 3249 response.add_field()->set_autofill_type(3); |
| 3239 for (int i = 0; i < 7; ++i) { | 3250 for (int i = 0; i < 7; ++i) { |
| 3240 response.add_field()->set_autofill_type(0); | 3251 response.add_field()->set_autofill_type(0); |
| 3241 } | 3252 } |
| 3242 response.add_field()->set_autofill_type(3); | 3253 response.add_field()->set_autofill_type(3); |
| 3243 response.add_field()->set_autofill_type(2); | 3254 response.add_field()->set_autofill_type(2); |
| 3244 response.add_field()->set_autofill_type(61); | 3255 response.add_field()->set_autofill_type(61); |
| 3245 response.add_field()->set_autofill_type(5); | 3256 response.add_field()->set_autofill_type(5); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3278 // response received. | 3289 // response received. |
| 3279 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { | 3290 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { |
| 3280 // Set up our form data. | 3291 // Set up our form data. |
| 3281 FormData form; | 3292 FormData form; |
| 3282 test::CreateTestAddressFormData(&form); | 3293 test::CreateTestAddressFormData(&form); |
| 3283 | 3294 |
| 3284 // Simulate having seen this form on page load. | 3295 // Simulate having seen this form on page load. |
| 3285 // |form_structure| will be owned by |autofill_manager_|. | 3296 // |form_structure| will be owned by |autofill_manager_|. |
| 3286 TestFormStructure* form_structure = new TestFormStructure(form); | 3297 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3287 form_structure->DetermineHeuristicTypes(); | 3298 form_structure->DetermineHeuristicTypes(); |
| 3288 autofill_manager_->AddSeenForm(form_structure); | 3299 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3289 | 3300 |
| 3290 AutofillQueryResponseContents response; | 3301 AutofillQueryResponseContents response; |
| 3291 response.add_field()->set_autofill_type(3); | 3302 response.add_field()->set_autofill_type(3); |
| 3292 for (int i = 0; i < 7; ++i) { | 3303 for (int i = 0; i < 7; ++i) { |
| 3293 response.add_field()->set_autofill_type(0); | 3304 response.add_field()->set_autofill_type(0); |
| 3294 } | 3305 } |
| 3295 response.add_field()->set_autofill_type(3); | 3306 response.add_field()->set_autofill_type(3); |
| 3296 response.add_field()->set_autofill_type(2); | 3307 response.add_field()->set_autofill_type(2); |
| 3297 response.add_field()->set_autofill_type(61); | 3308 response.add_field()->set_autofill_type(61); |
| 3298 | 3309 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3324 TestFormStructure* form_structure = new TestFormStructure(form); | 3335 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3325 form_structure->DetermineHeuristicTypes(); | 3336 form_structure->DetermineHeuristicTypes(); |
| 3326 | 3337 |
| 3327 // Clear the heuristic types, and instead set the appropriate server types. | 3338 // Clear the heuristic types, and instead set the appropriate server types. |
| 3328 std::vector<ServerFieldType> heuristic_types, server_types; | 3339 std::vector<ServerFieldType> heuristic_types, server_types; |
| 3329 for (size_t i = 0; i < form.fields.size(); ++i) { | 3340 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 3330 heuristic_types.push_back(UNKNOWN_TYPE); | 3341 heuristic_types.push_back(UNKNOWN_TYPE); |
| 3331 server_types.push_back(form_structure->field(i)->heuristic_type()); | 3342 server_types.push_back(form_structure->field(i)->heuristic_type()); |
| 3332 } | 3343 } |
| 3333 form_structure->SetFieldTypes(heuristic_types, server_types); | 3344 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 3334 autofill_manager_->AddSeenForm(form_structure); | 3345 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); |
| 3335 | 3346 |
| 3336 // Fill the form. | 3347 // Fill the form. |
| 3337 const char guid[] = "00000000-0000-0000-0000-000000000001"; | 3348 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 3338 int response_page_id = 0; | 3349 int response_page_id = 0; |
| 3339 FormData response_data; | 3350 FormData response_data; |
| 3340 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 3351 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 3341 MakeFrontendID(std::string(), guid), | 3352 MakeFrontendID(std::string(), guid), |
| 3342 &response_page_id, &response_data); | 3353 &response_page_id, &response_data); |
| 3343 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, | 3354 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, |
| 3344 false); | 3355 false); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3874 possible_types.find(test_fields[i].expected_upload_type)); | 3885 possible_types.find(test_fields[i].expected_upload_type)); |
| 3875 } else { | 3886 } else { |
| 3876 EXPECT_EQ(2U, possible_types.size()); | 3887 EXPECT_EQ(2U, possible_types.size()); |
| 3877 } | 3888 } |
| 3878 } | 3889 } |
| 3879 } | 3890 } |
| 3880 } | 3891 } |
| 3881 | 3892 |
| 3882 TEST_F(AutofillManagerTest, RemoveProfile) { | 3893 TEST_F(AutofillManagerTest, RemoveProfile) { |
| 3883 // Add and remove an Autofill profile. | 3894 // Add and remove an Autofill profile. |
| 3884 AutofillProfile* profile = new AutofillProfile; | 3895 std::unique_ptr<AutofillProfile> profile = |
| 3896 base::MakeUnique<AutofillProfile>(); |
| 3885 const char guid[] = "00000000-0000-0000-0000-000000000102"; | 3897 const char guid[] = "00000000-0000-0000-0000-000000000102"; |
| 3886 profile->set_guid(guid); | 3898 profile->set_guid(guid); |
| 3887 autofill_manager_->AddProfile(profile); | 3899 autofill_manager_->AddProfile(std::move(profile)); |
| 3888 | 3900 |
| 3889 int id = MakeFrontendID(std::string(), guid); | 3901 int id = MakeFrontendID(std::string(), guid); |
| 3890 | 3902 |
| 3891 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3903 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 3892 | 3904 |
| 3893 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid)); | 3905 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid)); |
| 3894 } | 3906 } |
| 3895 | 3907 |
| 3896 TEST_F(AutofillManagerTest, RemoveCreditCard) { | 3908 TEST_F(AutofillManagerTest, RemoveCreditCard) { |
| 3897 // Add and remove an Autofill credit card. | 3909 // Add and remove an Autofill credit card. |
| 3898 CreditCard* credit_card = new CreditCard; | 3910 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 3899 const char guid[] = "00000000-0000-0000-0000-000000100007"; | 3911 const char guid[] = "00000000-0000-0000-0000-000000100007"; |
| 3900 credit_card->set_guid(guid); | 3912 credit_card->set_guid(guid); |
| 3901 autofill_manager_->AddCreditCard(credit_card); | 3913 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 3902 | 3914 |
| 3903 int id = MakeFrontendID(guid, std::string()); | 3915 int id = MakeFrontendID(guid, std::string()); |
| 3904 | 3916 |
| 3905 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3917 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 3906 | 3918 |
| 3907 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid)); | 3919 EXPECT_FALSE(autofill_manager_->GetCreditCardWithGUID(guid)); |
| 3908 } | 3920 } |
| 3909 | 3921 |
| 3910 // Test our external delegate is called at the right time. | 3922 // Test our external delegate is called at the right time. |
| 3911 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3923 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| (...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5053 // Token matching is currently behind a flag. | 5065 // Token matching is currently behind a flag. |
| 5054 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 5066 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 5055 switches::kEnableSuggestionsWithSubstringMatch); | 5067 switches::kEnableSuggestionsWithSubstringMatch); |
| 5056 | 5068 |
| 5057 // Set up our form data. | 5069 // Set up our form data. |
| 5058 FormData form; | 5070 FormData form; |
| 5059 test::CreateTestAddressFormData(&form); | 5071 test::CreateTestAddressFormData(&form); |
| 5060 std::vector<FormData> forms(1, form); | 5072 std::vector<FormData> forms(1, form); |
| 5061 FormsSeen(forms); | 5073 FormsSeen(forms); |
| 5062 | 5074 |
| 5063 AutofillProfile* profile1 = new AutofillProfile; | 5075 std::unique_ptr<AutofillProfile> profile1 = |
| 5076 base::MakeUnique<AutofillProfile>(); |
| 5064 profile1->set_guid("00000000-0000-0000-0000-000000000103"); | 5077 profile1->set_guid("00000000-0000-0000-0000-000000000103"); |
| 5065 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); | 5078 profile1->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Robin"), "en-US"); |
| 5066 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), | 5079 profile1->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Adam Smith"), |
| 5067 "en-US"); | 5080 "en-US"); |
| 5068 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 5081 profile1->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 5069 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 5082 profile1->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 5070 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 5083 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 5071 autofill_manager_->AddProfile(profile1); | 5084 autofill_manager_->AddProfile(std::move(profile1)); |
| 5072 | 5085 |
| 5073 AutofillProfile* profile2 = new AutofillProfile; | 5086 std::unique_ptr<AutofillProfile> profile2 = |
| 5087 base::MakeUnique<AutofillProfile>(); |
| 5074 profile2->set_guid("00000000-0000-0000-0000-000000000124"); | 5088 profile2->set_guid("00000000-0000-0000-0000-000000000124"); |
| 5075 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); | 5089 profile2->SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Carl"), "en-US"); |
| 5076 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), | 5090 profile2->SetInfo(AutofillType(NAME_MIDDLE), ASCIIToUTF16("Shawn Smith"), |
| 5077 "en-US"); | 5091 "en-US"); |
| 5078 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); | 5092 profile2->SetInfo(AutofillType(NAME_LAST), ASCIIToUTF16("Grimes"), "en-US"); |
| 5079 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 5093 profile2->SetInfo(AutofillType(ADDRESS_HOME_LINE1), |
| 5080 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); | 5094 ASCIIToUTF16("1234 Smith Blvd."), "en-US"); |
| 5081 autofill_manager_->AddProfile(profile2); | 5095 autofill_manager_->AddProfile(std::move(profile2)); |
| 5082 | 5096 |
| 5083 FormFieldData field; | 5097 FormFieldData field; |
| 5084 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); | 5098 test::CreateTestFormField("Middle Name", "middlename", "S", "text", &field); |
| 5085 GetAutofillSuggestions(form, field); | 5099 GetAutofillSuggestions(form, field); |
| 5086 | 5100 |
| 5087 external_delegate_->CheckSuggestions( | 5101 external_delegate_->CheckSuggestions( |
| 5088 kDefaultPageID, | 5102 kDefaultPageID, |
| 5089 Suggestion("Shawn Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", | 5103 Suggestion("Shawn Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", |
| 5090 1), | 5104 1), |
| 5091 Suggestion("Adam Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", | 5105 Suggestion("Adam Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5214 FormsSeen(mixed_forms); | 5228 FormsSeen(mixed_forms); |
| 5215 | 5229 |
| 5216 // Suggestions should always be displayed. | 5230 // Suggestions should always be displayed. |
| 5217 for (const FormFieldData& field : mixed_form.fields) { | 5231 for (const FormFieldData& field : mixed_form.fields) { |
| 5218 GetAutofillSuggestions(mixed_form, field); | 5232 GetAutofillSuggestions(mixed_form, field); |
| 5219 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5233 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5220 } | 5234 } |
| 5221 } | 5235 } |
| 5222 | 5236 |
| 5223 } // namespace autofill | 5237 } // namespace autofill |
| OLD | NEW |