| 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> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 void ClearCreditCards() { | 184 void ClearCreditCards() { |
| 185 local_credit_cards_.clear(); | 185 local_credit_cards_.clear(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Create Elvis card with whitespace in the credit card number. | 188 // Create Elvis card with whitespace in the credit card number. |
| 189 void CreateTestCreditCardWithWhitespace() { | 189 void CreateTestCreditCardWithWhitespace() { |
| 190 ClearCreditCards(); | 190 ClearCreditCards(); |
| 191 CreditCard* credit_card = new CreditCard; | 191 CreditCard* credit_card = new CreditCard; |
| 192 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 192 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 193 "4234 5678 9012 3456", // Visa | 193 "4234 5678 9012 3456", // Visa |
| 194 "04", "2012"); | 194 "04", "2999"); |
| 195 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 195 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); |
| 196 local_credit_cards_.push_back(credit_card); | 196 local_credit_cards_.push_back(credit_card); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Create Elvis card with separator characters in the credit card number. | 199 // Create Elvis card with separator characters in the credit card number. |
| 200 void CreateTestCreditCardWithSeparators() { | 200 void CreateTestCreditCardWithSeparators() { |
| 201 ClearCreditCards(); | 201 ClearCreditCards(); |
| 202 CreditCard* credit_card = new CreditCard; | 202 CreditCard* credit_card = new CreditCard; |
| 203 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 203 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 204 "4234-5678-9012-3456", // Visa | 204 "4234-5678-9012-3456", // Visa |
| 205 "04", "2012"); | 205 "04", "2999"); |
| 206 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | 206 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 207 local_credit_cards_.push_back(credit_card); | 207 local_credit_cards_.push_back(credit_card); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 210 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 211 ClearCreditCards(); | 211 ClearCreditCards(); |
| 212 CreditCard* credit_card = new CreditCard; | 212 CreditCard* credit_card = new CreditCard; |
| 213 test::SetCreditCardInfo(credit_card, "Miku Hatsune", | 213 test::SetCreditCardInfo(credit_card, "Miku Hatsune", |
| 214 "4234567890654321", // Visa | 214 "4234567890654321", // Visa |
| 215 month, year); | 215 month, year); |
| 216 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 216 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 217 local_credit_cards_.push_back(credit_card); | 217 local_credit_cards_.push_back(credit_card); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void CreateTestExpiredCreditCard() { |
| 221 ClearCreditCards(); |
| 222 CreditCard* credit_card = new CreditCard; |
| 223 test::SetCreditCardInfo(credit_card, "Homer Simpson", |
| 224 "4234567890654321", // Visa |
| 225 "05", "2000"); |
| 226 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 227 local_credit_cards_.push_back(credit_card); |
| 228 } |
| 229 |
| 220 private: | 230 private: |
| 221 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { | 231 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { |
| 222 AutofillProfile* profile = new AutofillProfile; | 232 AutofillProfile* profile = new AutofillProfile; |
| 223 test::SetProfileInfo(profile, "Elvis", "Aaron", | 233 test::SetProfileInfo(profile, "Elvis", "Aaron", |
| 224 "Presley", "theking@gmail.com", "RCA", | 234 "Presley", "theking@gmail.com", "RCA", |
| 225 "3734 Elvis Presley Blvd.", "Apt. 10", | 235 "3734 Elvis Presley Blvd.", "Apt. 10", |
| 226 "Memphis", "Tennessee", "38116", "US", | 236 "Memphis", "Tennessee", "38116", "US", |
| 227 "12345678901"); | 237 "12345678901"); |
| 228 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 238 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
| 229 profiles->push_back(profile); | 239 profiles->push_back(profile); |
| 230 profile = new AutofillProfile; | 240 profile = new AutofillProfile; |
| 231 test::SetProfileInfo(profile, "Charles", "Hardin", | 241 test::SetProfileInfo(profile, "Charles", "Hardin", |
| 232 "Holley", "buddy@gmail.com", "Decca", | 242 "Holley", "buddy@gmail.com", "Decca", |
| 233 "123 Apple St.", "unit 6", "Lubbock", | 243 "123 Apple St.", "unit 6", "Lubbock", |
| 234 "Texas", "79401", "US", "23456789012"); | 244 "Texas", "79401", "US", "23456789012"); |
| 235 profile->set_guid("00000000-0000-0000-0000-000000000002"); | 245 profile->set_guid("00000000-0000-0000-0000-000000000002"); |
| 236 profiles->push_back(profile); | 246 profiles->push_back(profile); |
| 237 profile = new AutofillProfile; | 247 profile = new AutofillProfile; |
| 238 test::SetProfileInfo( | 248 test::SetProfileInfo( |
| 239 profile, "", "", "", "", "", "", "", "", "", "", "", ""); | 249 profile, "", "", "", "", "", "", "", "", "", "", "", ""); |
| 240 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 250 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 241 profiles->push_back(profile); | 251 profiles->push_back(profile); |
| 242 } | 252 } |
| 243 | 253 |
| 244 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { | 254 void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) { |
| 245 CreditCard* credit_card = new CreditCard; | 255 CreditCard* credit_card = new CreditCard; |
| 246 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 256 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 247 "4234567890123456", // Visa | 257 "4234567890123456", // Visa |
| 248 "04", "2012"); | 258 "04", "2999"); |
| 249 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 259 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 250 credit_card->set_use_count(10); | 260 credit_card->set_use_count(10); |
| 251 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 261 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 252 credit_cards->push_back(credit_card); | 262 credit_cards->push_back(credit_card); |
| 253 | 263 |
| 254 credit_card = new CreditCard; | 264 credit_card = new CreditCard; |
| 255 test::SetCreditCardInfo(credit_card, "Buddy Holly", | 265 test::SetCreditCardInfo(credit_card, "Buddy Holly", |
| 256 "5187654321098765", // Mastercard | 266 "5187654321098765", // Mastercard |
| 257 "10", "2014"); | 267 "10", "2998"); |
| 258 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 268 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 259 credit_card->set_use_count(5); | 269 credit_card->set_use_count(5); |
| 260 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 270 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); |
| 261 credit_cards->push_back(credit_card); | 271 credit_cards->push_back(credit_card); |
| 262 | 272 |
| 263 credit_card = new CreditCard; | 273 credit_card = new CreditCard; |
| 264 test::SetCreditCardInfo(credit_card, "", "", "", ""); | 274 test::SetCreditCardInfo(credit_card, "", "", "", ""); |
| 265 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 275 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
| 266 credit_cards->push_back(credit_card); | 276 credit_cards->push_back(credit_card); |
| 267 } | 277 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 "theking@gmail.com", "", "", "", "", true, | 423 "theking@gmail.com", "", "", "", "", true, |
| 414 has_credit_card_fields, false); | 424 has_credit_card_fields, false); |
| 415 } | 425 } |
| 416 | 426 |
| 417 void ExpectFilledCreditCardFormElvis(int page_id, | 427 void ExpectFilledCreditCardFormElvis(int page_id, |
| 418 const FormData& filled_form, | 428 const FormData& filled_form, |
| 419 int expected_page_id, | 429 int expected_page_id, |
| 420 bool has_address_fields) { | 430 bool has_address_fields) { |
| 421 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", | 431 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", |
| 422 "", "", "", "", "", "", "Elvis Presley", "4234567890123456", | 432 "", "", "", "", "", "", "Elvis Presley", "4234567890123456", |
| 423 "04", "2012", has_address_fields, true, false); | 433 "04", "2999", has_address_fields, true, false); |
| 424 } | 434 } |
| 425 | 435 |
| 426 void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id, | 436 void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id, |
| 427 const FormData& filled_form, | 437 const FormData& filled_form, |
| 428 int expected_page_id, | 438 int expected_page_id, |
| 429 bool has_address_fields, | 439 bool has_address_fields, |
| 430 const char* year, | 440 const char* year, |
| 431 const char* month) { | 441 const char* month) { |
| 432 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", | 442 ExpectFilledForm(page_id, filled_form, expected_page_id, "", "", "", "", "", |
| 433 "", "", "", "", "", "", "Miku Hatsune", "4234567890654321", | 443 "", "", "", "", "", "", "Miku Hatsune", "4234567890654321", |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 FormData form; | 1331 FormData form; |
| 1322 CreateTestCreditCardFormData(&form, true, false); | 1332 CreateTestCreditCardFormData(&form, true, false); |
| 1323 std::vector<FormData> forms(1, form); | 1333 std::vector<FormData> forms(1, form); |
| 1324 FormsSeen(forms); | 1334 FormsSeen(forms); |
| 1325 | 1335 |
| 1326 FormFieldData field = form.fields[1]; | 1336 FormFieldData field = form.fields[1]; |
| 1327 GetAutofillSuggestions(form, field); | 1337 GetAutofillSuggestions(form, field); |
| 1328 | 1338 |
| 1329 // Test that we sent the right values to the external delegate. | 1339 // Test that we sent the right values to the external delegate. |
| 1330 external_delegate_->CheckSuggestions( | 1340 external_delegate_->CheckSuggestions( |
| 1331 kDefaultPageID, | 1341 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1332 Suggestion( | 1342 "3456", |
| 1333 "Visa\xC2\xA0\xE2\x8B\xAF" | 1343 "04/99", kVisaCard, |
| 1334 "3456", | 1344 autofill_manager_->GetPackedCreditCardID(4)), |
| 1335 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1345 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1336 Suggestion( | 1346 "8765", |
| 1337 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1347 "10/98", kMasterCard, |
| 1338 "8765", | 1348 autofill_manager_->GetPackedCreditCardID(5))); |
| 1339 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | |
| 1340 } | 1349 } |
| 1341 | 1350 |
| 1342 // Test that we return all credit card profile suggestions when the triggering | 1351 // Test that we return all credit card profile suggestions when the triggering |
| 1343 // field has whitespace in it. | 1352 // field has whitespace in it. |
| 1344 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { | 1353 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { |
| 1345 // Set up our form data. | 1354 // Set up our form data. |
| 1346 FormData form; | 1355 FormData form; |
| 1347 CreateTestCreditCardFormData(&form, true, false); | 1356 CreateTestCreditCardFormData(&form, true, false); |
| 1348 std::vector<FormData> forms(1, form); | 1357 std::vector<FormData> forms(1, form); |
| 1349 FormsSeen(forms); | 1358 FormsSeen(forms); |
| 1350 | 1359 |
| 1351 FormFieldData field = form.fields[1]; | 1360 FormFieldData field = form.fields[1]; |
| 1352 field.value = ASCIIToUTF16(" "); | 1361 field.value = ASCIIToUTF16(" "); |
| 1353 GetAutofillSuggestions(form, field); | 1362 GetAutofillSuggestions(form, field); |
| 1354 | 1363 |
| 1355 // Test that we sent the right values to the external delegate. | 1364 // Test that we sent the right values to the external delegate. |
| 1356 external_delegate_->CheckSuggestions( | 1365 external_delegate_->CheckSuggestions( |
| 1357 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" | 1366 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1358 "3456", | 1367 "3456", |
| 1359 "04/12", kVisaCard, | 1368 "04/99", kVisaCard, |
| 1360 autofill_manager_->GetPackedCreditCardID(4)), | 1369 autofill_manager_->GetPackedCreditCardID(4)), |
| 1361 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | 1370 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1362 "8765", | 1371 "8765", |
| 1363 "10/14", kMasterCard, | 1372 "10/98", kMasterCard, |
| 1364 autofill_manager_->GetPackedCreditCardID(5))); | 1373 autofill_manager_->GetPackedCreditCardID(5))); |
| 1365 } | 1374 } |
| 1366 | 1375 |
| 1367 // Test that we return all credit card profile suggestions when the triggering | 1376 // Test that we return all credit card profile suggestions when the triggering |
| 1368 // field has stop characters in it, which should be removed. | 1377 // field has stop characters in it, which should be removed. |
| 1369 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { | 1378 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { |
| 1370 // Set up our form data. | 1379 // Set up our form data. |
| 1371 FormData form; | 1380 FormData form; |
| 1372 CreateTestCreditCardFormData(&form, true, false); | 1381 CreateTestCreditCardFormData(&form, true, false); |
| 1373 std::vector<FormData> forms(1, form); | 1382 std::vector<FormData> forms(1, form); |
| 1374 FormsSeen(forms); | 1383 FormsSeen(forms); |
| 1375 | 1384 |
| 1376 FormFieldData field = form.fields[1]; | 1385 FormFieldData field = form.fields[1]; |
| 1377 field.value = ASCIIToUTF16("____-____-____-____"); | 1386 field.value = ASCIIToUTF16("____-____-____-____"); |
| 1378 GetAutofillSuggestions(form, field); | 1387 GetAutofillSuggestions(form, field); |
| 1379 | 1388 |
| 1380 // Test that we sent the right values to the external delegate. | 1389 // Test that we sent the right values to the external delegate. |
| 1381 external_delegate_->CheckSuggestions( | 1390 external_delegate_->CheckSuggestions( |
| 1382 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" | 1391 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1383 "3456", | 1392 "3456", |
| 1384 "04/12", kVisaCard, | 1393 "04/99", kVisaCard, |
| 1385 autofill_manager_->GetPackedCreditCardID(4)), | 1394 autofill_manager_->GetPackedCreditCardID(4)), |
| 1386 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | 1395 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1387 "8765", | 1396 "8765", |
| 1388 "10/14", kMasterCard, | 1397 "10/98", kMasterCard, |
| 1389 autofill_manager_->GetPackedCreditCardID(5))); | 1398 autofill_manager_->GetPackedCreditCardID(5))); |
| 1390 } | 1399 } |
| 1391 | 1400 |
| 1392 // Test that we return all credit card profile suggestions when the triggering | 1401 // Test that we return all credit card profile suggestions when the triggering |
| 1393 // field has stop characters in it and some input. | 1402 // field has stop characters in it and some input. |
| 1394 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { | 1403 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1395 // Add a credit card with particular numbers that we will attempt to recall. | 1404 // Add a credit card with particular numbers that we will attempt to recall. |
| 1396 CreditCard* credit_card = new CreditCard; | 1405 CreditCard* credit_card = new CreditCard; |
| 1397 test::SetCreditCardInfo(credit_card, "John Smith", | 1406 test::SetCreditCardInfo(credit_card, "John Smith", |
| 1398 "5255667890123123", // Mastercard | 1407 "5255667890123123", // Mastercard |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1427 CreateTestCreditCardFormData(&form, true, false); | 1436 CreateTestCreditCardFormData(&form, true, false); |
| 1428 std::vector<FormData> forms(1, form); | 1437 std::vector<FormData> forms(1, form); |
| 1429 FormsSeen(forms); | 1438 FormsSeen(forms); |
| 1430 | 1439 |
| 1431 FormFieldData field; | 1440 FormFieldData field; |
| 1432 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 1441 test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); |
| 1433 GetAutofillSuggestions(form, field); | 1442 GetAutofillSuggestions(form, field); |
| 1434 | 1443 |
| 1435 // Test that we sent the right values to the external delegate. | 1444 // Test that we sent the right values to the external delegate. |
| 1436 external_delegate_->CheckSuggestions( | 1445 external_delegate_->CheckSuggestions( |
| 1437 kDefaultPageID, | 1446 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1438 Suggestion( | 1447 "3456", |
| 1439 "Visa\xC2\xA0\xE2\x8B\xAF" | 1448 "04/99", kVisaCard, |
| 1440 "3456", | 1449 autofill_manager_->GetPackedCreditCardID(4))); |
| 1441 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | |
| 1442 } | 1450 } |
| 1443 | 1451 |
| 1444 // Test that we return credit card profile suggestions when the selected form | 1452 // Test that we return credit card profile suggestions when the selected form |
| 1445 // field is not the credit card number field. | 1453 // field is not the credit card number field. |
| 1446 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { | 1454 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { |
| 1447 // Set up our form data. | 1455 // Set up our form data. |
| 1448 FormData form; | 1456 FormData form; |
| 1449 CreateTestCreditCardFormData(&form, true, false); | 1457 CreateTestCreditCardFormData(&form, true, false); |
| 1450 std::vector<FormData> forms(1, form); | 1458 std::vector<FormData> forms(1, form); |
| 1451 FormsSeen(forms); | 1459 FormsSeen(forms); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 } | 1508 } |
| 1501 | 1509 |
| 1502 // Test that we return all credit card suggestions in the case that two cards | 1510 // Test that we return all credit card suggestions in the case that two cards |
| 1503 // have the same obfuscated number. | 1511 // have the same obfuscated number. |
| 1504 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { | 1512 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { |
| 1505 // Add a credit card with the same obfuscated number as Elvis's. | 1513 // Add a credit card with the same obfuscated number as Elvis's. |
| 1506 // |credit_card| will be owned by the mock PersonalDataManager. | 1514 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1507 CreditCard* credit_card = new CreditCard; | 1515 CreditCard* credit_card = new CreditCard; |
| 1508 test::SetCreditCardInfo(credit_card, "Elvis Presley", | 1516 test::SetCreditCardInfo(credit_card, "Elvis Presley", |
| 1509 "5231567890123456", // Mastercard | 1517 "5231567890123456", // Mastercard |
| 1510 "05", "2012"); | 1518 "05", "2999"); |
| 1511 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1519 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1512 autofill_manager_->AddCreditCard(credit_card); | 1520 autofill_manager_->AddCreditCard(credit_card); |
| 1513 | 1521 |
| 1514 // Set up our form data. | 1522 // Set up our form data. |
| 1515 FormData form; | 1523 FormData form; |
| 1516 CreateTestCreditCardFormData(&form, true, false); | 1524 CreateTestCreditCardFormData(&form, true, false); |
| 1517 std::vector<FormData> forms(1, form); | 1525 std::vector<FormData> forms(1, form); |
| 1518 FormsSeen(forms); | 1526 FormsSeen(forms); |
| 1519 | 1527 |
| 1520 FormFieldData field = form.fields[1]; | 1528 FormFieldData field = form.fields[1]; |
| 1521 GetAutofillSuggestions(form, field); | 1529 GetAutofillSuggestions(form, field); |
| 1522 | 1530 |
| 1523 // Test that we sent the right values to the external delegate. | 1531 // Test that we sent the right values to the external delegate. |
| 1524 external_delegate_->CheckSuggestions( | 1532 external_delegate_->CheckSuggestions( |
| 1525 kDefaultPageID, | 1533 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1526 Suggestion( | 1534 "3456", |
| 1527 "Visa\xC2\xA0\xE2\x8B\xAF" | 1535 "04/99", kVisaCard, |
| 1528 "3456", | 1536 autofill_manager_->GetPackedCreditCardID(4)), |
| 1529 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1537 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1530 Suggestion( | 1538 "8765", |
| 1531 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1539 "10/98", kMasterCard, |
| 1532 "8765", | 1540 autofill_manager_->GetPackedCreditCardID(5)), |
| 1533 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5)), | 1541 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1534 Suggestion( | 1542 "3456", |
| 1535 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1543 "05/99", kMasterCard, |
| 1536 "3456", | 1544 autofill_manager_->GetPackedCreditCardID(7))); |
| 1537 "05/12", kMasterCard, autofill_manager_->GetPackedCreditCardID(7))); | |
| 1538 } | 1545 } |
| 1539 | 1546 |
| 1540 // Test that we return profile and credit card suggestions for combined forms. | 1547 // Test that we return profile and credit card suggestions for combined forms. |
| 1541 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1548 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 1542 // Set up our form data. | 1549 // Set up our form data. |
| 1543 FormData form; | 1550 FormData form; |
| 1544 test::CreateTestAddressFormData(&form); | 1551 test::CreateTestAddressFormData(&form); |
| 1545 CreateTestCreditCardFormData(&form, true, false); | 1552 CreateTestCreditCardFormData(&form, true, false); |
| 1546 std::vector<FormData> forms(1, form); | 1553 std::vector<FormData> forms(1, form); |
| 1547 FormsSeen(forms); | 1554 FormsSeen(forms); |
| 1548 | 1555 |
| 1549 FormFieldData field = form.fields[0]; | 1556 FormFieldData field = form.fields[0]; |
| 1550 GetAutofillSuggestions(form, field); | 1557 GetAutofillSuggestions(form, field); |
| 1551 | 1558 |
| 1552 // Test that we sent the right address suggestions to the external delegate. | 1559 // Test that we sent the right address suggestions to the external delegate. |
| 1553 external_delegate_->CheckSuggestions( | 1560 external_delegate_->CheckSuggestions( |
| 1554 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), | 1561 kDefaultPageID, Suggestion("Charles", "123 Apple St.", "", 1), |
| 1555 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); | 1562 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 2)); |
| 1556 | 1563 |
| 1557 const int kPageID2 = 2; | 1564 const int kPageID2 = 2; |
| 1558 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | 1565 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 1559 GetAutofillSuggestions(kPageID2, form, field); | 1566 GetAutofillSuggestions(kPageID2, form, field); |
| 1560 | 1567 |
| 1561 // Test that we sent the credit card suggestions to the external delegate. | 1568 // Test that we sent the credit card suggestions to the external delegate. |
| 1562 external_delegate_->CheckSuggestions( | 1569 external_delegate_->CheckSuggestions( |
| 1563 kPageID2, | 1570 kPageID2, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1564 Suggestion( | 1571 "3456", |
| 1565 "Visa\xC2\xA0\xE2\x8B\xAF" | 1572 "04/99", kVisaCard, |
| 1566 "3456", | 1573 autofill_manager_->GetPackedCreditCardID(4)), |
| 1567 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1574 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1568 Suggestion( | 1575 "8765", |
| 1569 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1576 "10/98", kMasterCard, |
| 1570 "8765", | 1577 autofill_manager_->GetPackedCreditCardID(5))); |
| 1571 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | |
| 1572 } | 1578 } |
| 1573 | 1579 |
| 1574 // Test that for non-https forms with both address and credit card fields, we | 1580 // Test that for non-https forms with both address and credit card fields, we |
| 1575 // only return address suggestions. Instead of credit card suggestions, we | 1581 // only return address suggestions. Instead of credit card suggestions, we |
| 1576 // should return a warning explaining that credit card profile suggestions are | 1582 // should return a warning explaining that credit card profile suggestions are |
| 1577 // unavailable when the form is not https. | 1583 // unavailable when the form is not https. |
| 1578 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1584 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 1579 // Set up our form data. | 1585 // Set up our form data. |
| 1580 FormData form; | 1586 FormData form; |
| 1581 test::CreateTestAddressFormData(&form); | 1587 test::CreateTestAddressFormData(&form); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 &response_page_id, &response_data); | 1942 &response_page_id, &response_data); |
| 1937 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1943 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, |
| 1938 kDefaultPageID, false, "", "04"); | 1944 kDefaultPageID, false, "", "04"); |
| 1939 } | 1945 } |
| 1940 | 1946 |
| 1941 // Test that we correctly fill a credit card form with month input type. | 1947 // Test that we correctly fill a credit card form with month input type. |
| 1942 // 3. year non-empty, month empty | 1948 // 3. year non-empty, month empty |
| 1943 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { | 1949 TEST_F(AutofillManagerTest, FillCreditCardFormYearNoMonth) { |
| 1944 // Same as the SetUp(), but generate 4 credit cards with year month | 1950 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1945 // combination. | 1951 // combination. |
| 1946 personal_data_.CreateTestCreditCardsYearAndMonth("2012", ""); | 1952 personal_data_.CreateTestCreditCardsYearAndMonth("2999", ""); |
| 1947 // Set up our form data. | 1953 // Set up our form data. |
| 1948 FormData form; | 1954 FormData form; |
| 1949 CreateTestCreditCardFormData(&form, true, true); | 1955 CreateTestCreditCardFormData(&form, true, true); |
| 1950 std::vector<FormData> forms(1, form); | 1956 std::vector<FormData> forms(1, form); |
| 1951 FormsSeen(forms); | 1957 FormsSeen(forms); |
| 1952 | 1958 |
| 1953 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1959 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1954 int response_page_id = 0; | 1960 int response_page_id = 0; |
| 1955 FormData response_data; | 1961 FormData response_data; |
| 1956 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1962 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1957 MakeFrontendID(guid, std::string()), | 1963 MakeFrontendID(guid, std::string()), |
| 1958 &response_page_id, &response_data); | 1964 &response_page_id, &response_data); |
| 1959 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1965 ExpectFilledCreditCardYearMonthWithYearMonth( |
| 1960 kDefaultPageID, false, "2012", ""); | 1966 response_page_id, response_data, kDefaultPageID, false, "2999", ""); |
| 1961 } | 1967 } |
| 1962 | 1968 |
| 1963 // Test that we correctly fill a credit card form with month input type. | 1969 // Test that we correctly fill a credit card form with month input type. |
| 1964 // 4. year non-empty, month empty | 1970 // 4. year non-empty, month empty |
| 1965 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { | 1971 TEST_F(AutofillManagerTest, FillCreditCardFormYearMonth) { |
| 1966 // Same as the SetUp(), but generate 4 credit cards with year month | 1972 // Same as the SetUp(), but generate 4 credit cards with year month |
| 1967 // combination. | 1973 // combination. |
| 1968 personal_data_.ClearCreditCards(); | 1974 personal_data_.ClearCreditCards(); |
| 1969 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); | 1975 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); |
| 1970 // Set up our form data. | 1976 // Set up our form data. |
| 1971 FormData form; | 1977 FormData form; |
| 1972 CreateTestCreditCardFormData(&form, true, true); | 1978 CreateTestCreditCardFormData(&form, true, true); |
| 1973 std::vector<FormData> forms(1, form); | 1979 std::vector<FormData> forms(1, form); |
| 1974 FormsSeen(forms); | 1980 FormsSeen(forms); |
| 1975 | 1981 |
| 1976 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 1982 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
| 1977 int response_page_id = 0; | 1983 int response_page_id = 0; |
| 1978 FormData response_data; | 1984 FormData response_data; |
| 1979 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 1985 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1980 MakeFrontendID(guid, std::string()), | 1986 MakeFrontendID(guid, std::string()), |
| 1981 &response_page_id, &response_data); | 1987 &response_page_id, &response_data); |
| 1982 ExpectFilledCreditCardYearMonthWithYearMonth(response_page_id, response_data, | 1988 ExpectFilledCreditCardYearMonthWithYearMonth( |
| 1983 kDefaultPageID, false, "2012", "04"); | 1989 response_page_id, response_data, kDefaultPageID, false, "2999", "04"); |
| 1984 } | 1990 } |
| 1985 | 1991 |
| 1986 // Test that we correctly fill a credit card form with first and last cardholder | 1992 // Test that we correctly fill a credit card form with first and last cardholder |
| 1987 // name. | 1993 // name. |
| 1988 TEST_F(AutofillManagerTest, FillCreditCardFormSplitName) { | 1994 TEST_F(AutofillManagerTest, FillCreditCardFormSplitName) { |
| 1989 // Set up our form data. | 1995 // Set up our form data. |
| 1990 FormData form; | 1996 FormData form; |
| 1991 form.name = ASCIIToUTF16("MyForm"); | 1997 form.name = ASCIIToUTF16("MyForm"); |
| 1992 form.origin = GURL("https://myform.com/form.html"); | 1998 form.origin = GURL("https://myform.com/form.html"); |
| 1993 form.action = GURL("https://myform.com/submit.html"); | 1999 form.action = GURL("https://myform.com/submit.html"); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 MakeFrontendID(guid, std::string()), | 2231 MakeFrontendID(guid, std::string()), |
| 2226 &response_page_id, &response_data); | 2232 &response_page_id, &response_data); |
| 2227 | 2233 |
| 2228 // The credit card name and number should be filled. | 2234 // The credit card name and number should be filled. |
| 2229 ExpectFilledField("Name on Card", "nameoncard", "Elvis Presley", "text", | 2235 ExpectFilledField("Name on Card", "nameoncard", "Elvis Presley", "text", |
| 2230 response_data.fields[0]); | 2236 response_data.fields[0]); |
| 2231 ExpectFilledField("Card Number", "cardnumber", "4234567890123456", "text", | 2237 ExpectFilledField("Card Number", "cardnumber", "4234567890123456", "text", |
| 2232 response_data.fields[1]); | 2238 response_data.fields[1]); |
| 2233 | 2239 |
| 2234 // The expiration month should be filled. | 2240 // The expiration month should be filled. |
| 2235 ExpectFilledField("Expiration Date", "ccmonth", "04/2012", "text", | 2241 ExpectFilledField("Expiration Date", "ccmonth", "04/2999", "text", |
| 2236 response_data.fields[2]); | 2242 response_data.fields[2]); |
| 2237 } | 2243 } |
| 2238 | 2244 |
| 2239 // Test that credit card fields are filled even if they have the autocomplete | 2245 // Test that credit card fields are filled even if they have the autocomplete |
| 2240 // attribute set to off. | 2246 // attribute set to off. |
| 2241 TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { | 2247 TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { |
| 2242 // Set up our form data. | 2248 // Set up our form data. |
| 2243 FormData form; | 2249 FormData form; |
| 2244 CreateTestCreditCardFormData(&form, true, false); | 2250 CreateTestCreditCardFormData(&form, true, false); |
| 2245 | 2251 |
| 2246 // Set the autocomplete=off on all fields. | 2252 // Set the autocomplete=off on all fields. |
| 2247 for (FormFieldData field : form.fields) | 2253 for (FormFieldData field : form.fields) |
| 2248 field.should_autocomplete = false; | 2254 field.should_autocomplete = false; |
| 2249 | 2255 |
| 2250 std::vector<FormData> forms(1, form); | 2256 std::vector<FormData> forms(1, form); |
| 2251 FormsSeen(forms); | 2257 FormsSeen(forms); |
| 2252 | 2258 |
| 2253 const char guid[] = "00000000-0000-0000-0000-000000000004"; | 2259 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 2254 int response_page_id = 0; | 2260 int response_page_id = 0; |
| 2255 FormData response_data; | 2261 FormData response_data; |
| 2256 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), | 2262 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2257 MakeFrontendID(guid, std::string()), | 2263 MakeFrontendID(guid, std::string()), |
| 2258 &response_page_id, &response_data); | 2264 &response_page_id, &response_data); |
| 2259 | 2265 |
| 2260 // All fields should be filled. | 2266 // All fields should be filled. |
| 2261 ExpectFilledCreditCardFormElvis(response_page_id, response_data, | 2267 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 2262 kDefaultPageID, false); | 2268 kDefaultPageID, false); |
| 2263 } | 2269 } |
| 2264 | 2270 |
| 2271 // Test that selecting an expired credit card fills everything except the |
| 2272 // expiration date. |
| 2273 TEST_F(AutofillManagerTest, FillCreditCardForm_ExpiredCard) { |
| 2274 personal_data_.CreateTestExpiredCreditCard(); |
| 2275 |
| 2276 // Set up the form data. |
| 2277 FormData form; |
| 2278 form.name = ASCIIToUTF16("MyForm"); |
| 2279 form.origin = GURL("https://myform.com/form.html"); |
| 2280 form.action = GURL("https://myform.com/submit.html"); |
| 2281 |
| 2282 // Create a credit card form. |
| 2283 FormFieldData field; |
| 2284 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 2285 field.autocomplete_attribute = "cc-name"; |
| 2286 form.fields.push_back(field); |
| 2287 std::vector<const char*> kCreditCardTypes = {"Visa", "Master Card", "AmEx", |
| 2288 "discover"}; |
| 2289 test::CreateTestSelectField("Card Type", "cardtype", "", kCreditCardTypes, |
| 2290 kCreditCardTypes, 4, &field); |
| 2291 field.autocomplete_attribute = "cc-type"; |
| 2292 form.fields.push_back(field); |
| 2293 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 2294 field.autocomplete_attribute = "cc-number"; |
| 2295 form.fields.push_back(field); |
| 2296 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field); |
| 2297 field.autocomplete_attribute = "cc-exp-month"; |
| 2298 form.fields.push_back(field); |
| 2299 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field); |
| 2300 field.autocomplete_attribute = "cc-exp-year"; |
| 2301 form.fields.push_back(field); |
| 2302 std::vector<FormData> forms(1, form); |
| 2303 FormsSeen(forms); |
| 2304 |
| 2305 const char guid[] = "00000000-0000-0000-0000-000000000009"; |
| 2306 int response_page_id = 0; |
| 2307 FormData response_data; |
| 2308 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2309 MakeFrontendID(guid, std::string()), |
| 2310 &response_page_id, &response_data); |
| 2311 |
| 2312 // The credit card name, type and number should be filled. |
| 2313 ExpectFilledField("Name on Card", "nameoncard", "Homer Simpson", "text", |
| 2314 response_data.fields[0]); |
| 2315 ExpectFilledField("Card Type", "cardtype", "Visa", "select-one", |
| 2316 response_data.fields[1]); |
| 2317 ExpectFilledField("Card Number", "cardnumber", "4234567890654321", "text", |
| 2318 response_data.fields[2]); |
| 2319 |
| 2320 // The expiration month and year should not be filled. |
| 2321 ExpectFilledField("Expiration Month", "ccmonth", "", "text", |
| 2322 response_data.fields[3]); |
| 2323 ExpectFilledField("Expiration Year", "ccyear", "", "text", |
| 2324 response_data.fields[4]); |
| 2325 } |
| 2326 |
| 2265 // Test that non-focusable field is ignored while inferring boundaries between | 2327 // Test that non-focusable field is ignored while inferring boundaries between |
| 2266 // sections: http://crbug.com/231160 | 2328 // sections: http://crbug.com/231160 |
| 2267 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { | 2329 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { |
| 2268 // Create a form with both focusable and non-focusable fields. | 2330 // Create a form with both focusable and non-focusable fields. |
| 2269 FormData form; | 2331 FormData form; |
| 2270 form.name = ASCIIToUTF16("MyForm"); | 2332 form.name = ASCIIToUTF16("MyForm"); |
| 2271 form.origin = GURL("https://myform.com/form.html"); | 2333 form.origin = GURL("https://myform.com/form.html"); |
| 2272 form.action = GURL("https://myform.com/submit.html"); | 2334 form.action = GURL("https://myform.com/submit.html"); |
| 2273 | 2335 |
| 2274 FormFieldData field; | 2336 FormFieldData field; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); | 2592 ExpectFilledField("", "firstname", "", "text", response_data.fields[1]); |
| 2531 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); | 2593 ExpectFilledField("", "lastname", "", "text", response_data.fields[2]); |
| 2532 ExpectFilledField("", "address", "", "text", response_data.fields[3]); | 2594 ExpectFilledField("", "address", "", "text", response_data.fields[3]); |
| 2533 ExpectFilledField("", "city", "", "text", response_data.fields[4]); | 2595 ExpectFilledField("", "city", "", "text", response_data.fields[4]); |
| 2534 ExpectFilledField("", "state", "", "text", response_data.fields[5]); | 2596 ExpectFilledField("", "state", "", "text", response_data.fields[5]); |
| 2535 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); | 2597 ExpectFilledField("", "zip", "", "text", response_data.fields[6]); |
| 2536 ExpectFilledField("", "ccname", "Elvis Presley", "text", | 2598 ExpectFilledField("", "ccname", "Elvis Presley", "text", |
| 2537 response_data.fields[7]); | 2599 response_data.fields[7]); |
| 2538 ExpectFilledField("", "ccnumber", "4234567890123456", "text", | 2600 ExpectFilledField("", "ccnumber", "4234567890123456", "text", |
| 2539 response_data.fields[8]); | 2601 response_data.fields[8]); |
| 2540 ExpectFilledField("", "ccexp", "04/2012", "text", response_data.fields[9]); | 2602 ExpectFilledField("", "ccexp", "04/2999", "text", response_data.fields[9]); |
| 2541 ExpectFilledField("", "email", "", "text", response_data.fields[10]); | 2603 ExpectFilledField("", "email", "", "text", response_data.fields[10]); |
| 2542 } | 2604 } |
| 2543 } | 2605 } |
| 2544 | 2606 |
| 2545 // Test that we correctly fill a form that has a single logical section with | 2607 // Test that we correctly fill a form that has a single logical section with |
| 2546 // multiple email address fields. | 2608 // multiple email address fields. |
| 2547 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { | 2609 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { |
| 2548 // Set up our form data. | 2610 // Set up our form data. |
| 2549 FormData form; | 2611 FormData form; |
| 2550 test::CreateTestAddressFormData(&form); | 2612 test::CreateTestAddressFormData(&form); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2620 } | 2682 } |
| 2621 | 2683 |
| 2622 const int kPageID3 = 3; | 2684 const int kPageID3 = 3; |
| 2623 response_page_id = 0; | 2685 response_page_id = 0; |
| 2624 FillAutofillFormDataAndSaveResults( | 2686 FillAutofillFormDataAndSaveResults( |
| 2625 kPageID3, form, form.fields[form.fields.size() - 2], | 2687 kPageID3, form, form.fields[form.fields.size() - 2], |
| 2626 MakeFrontendID(guid2, std::string()), &response_page_id, &response_data); | 2688 MakeFrontendID(guid2, std::string()), &response_page_id, &response_data); |
| 2627 { | 2689 { |
| 2628 SCOPED_TRACE("Credit card 2"); | 2690 SCOPED_TRACE("Credit card 2"); |
| 2629 ExpectFilledForm(response_page_id, response_data, kPageID3, "", "", "", "", | 2691 ExpectFilledForm(response_page_id, response_data, kPageID3, "", "", "", "", |
| 2630 "", "", "", "", "", "", "", "", "", "", "2012", true, true, | 2692 "", "", "", "", "", "", "", "", "", "", "2999", true, true, |
| 2631 false); | 2693 false); |
| 2632 } | 2694 } |
| 2633 } | 2695 } |
| 2634 | 2696 |
| 2635 // Test that we correctly fill a phone number split across multiple fields. | 2697 // Test that we correctly fill a phone number split across multiple fields. |
| 2636 TEST_F(AutofillManagerTest, FillPhoneNumber) { | 2698 TEST_F(AutofillManagerTest, FillPhoneNumber) { |
| 2637 // In one form, rely on the maxlength attribute to imply US phone number | 2699 // In one form, rely on the maxlength attribute to imply US phone number |
| 2638 // parts. In the other form, rely on the autocompletetype attribute. | 2700 // parts. In the other form, rely on the autocompletetype attribute. |
| 2639 FormData form_with_us_number_max_length; | 2701 FormData form_with_us_number_max_length; |
| 2640 form_with_us_number_max_length.name = ASCIIToUTF16("MyMaxlengthPhoneForm"); | 2702 form_with_us_number_max_length.name = ASCIIToUTF16("MyMaxlengthPhoneForm"); |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3221 MakeFrontendID(std::string(), guid), | 3283 MakeFrontendID(std::string(), guid), |
| 3222 &response_page_id, &response_data); | 3284 &response_page_id, &response_data); |
| 3223 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, | 3285 ExpectFilledAddressFormElvis(response_page_id, response_data, kDefaultPageID, |
| 3224 false); | 3286 false); |
| 3225 | 3287 |
| 3226 personal_data_.ClearAutofillProfiles(); | 3288 personal_data_.ClearAutofillProfiles(); |
| 3227 // The default credit card is a Elvis card. It must be removed because name | 3289 // The default credit card is a Elvis card. It must be removed because name |
| 3228 // fields would be detected. However at least one profile or card is needed to | 3290 // fields would be detected. However at least one profile or card is needed to |
| 3229 // start the upload process, which is why this other card is created. | 3291 // start the upload process, which is why this other card is created. |
| 3230 personal_data_.ClearCreditCards(); | 3292 personal_data_.ClearCreditCards(); |
| 3231 personal_data_.CreateTestCreditCardsYearAndMonth("2012", "04"); | 3293 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); |
| 3232 ASSERT_EQ(0u, personal_data_.GetProfiles().size()); | 3294 ASSERT_EQ(0u, personal_data_.GetProfiles().size()); |
| 3233 | 3295 |
| 3234 // Simulate form submission. The first submission should not count the data | 3296 // Simulate form submission. The first submission should not count the data |
| 3235 // towards possible types. Therefore we expect all UNKNOWN_TYPE entries. | 3297 // towards possible types. Therefore we expect all UNKNOWN_TYPE entries. |
| 3236 ServerFieldTypeSet type_set; | 3298 ServerFieldTypeSet type_set; |
| 3237 type_set.insert(UNKNOWN_TYPE); | 3299 type_set.insert(UNKNOWN_TYPE); |
| 3238 std::vector<ServerFieldTypeSet> unknown_types(expected_types.size(), | 3300 std::vector<ServerFieldTypeSet> unknown_types(expected_types.size(), |
| 3239 type_set); | 3301 type_set); |
| 3240 autofill_manager_->set_expected_submitted_field_types(unknown_types); | 3302 autofill_manager_->set_expected_submitted_field_types(unknown_types); |
| 3241 FormSubmitted(response_data); | 3303 FormSubmitted(response_data); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3380 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", | 3442 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", |
| 3381 "Apt. 10", "Paris", "Ile de France", "75008", "FR", | 3443 "Apt. 10", "Paris", "Ile de France", "75008", "FR", |
| 3382 "+33 2 49 19 70 70"); | 3444 "+33 2 49 19 70 70"); |
| 3383 profile.set_guid("00000000-0000-0000-0000-000000000001"); | 3445 profile.set_guid("00000000-0000-0000-0000-000000000001"); |
| 3384 profiles.push_back(profile); | 3446 profiles.push_back(profile); |
| 3385 | 3447 |
| 3386 // Set up the test credit cards. | 3448 // Set up the test credit cards. |
| 3387 std::vector<CreditCard> credit_cards; | 3449 std::vector<CreditCard> credit_cards; |
| 3388 CreditCard credit_card; | 3450 CreditCard credit_card; |
| 3389 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", | 3451 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", |
| 3390 "2012"); | 3452 "2999"); |
| 3391 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); | 3453 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); |
| 3392 credit_cards.push_back(credit_card); | 3454 credit_cards.push_back(credit_card); |
| 3393 | 3455 |
| 3394 typedef struct { | 3456 typedef struct { |
| 3395 std::string input_value; // The value to input in the field. | 3457 std::string input_value; // The value to input in the field. |
| 3396 ServerFieldType field_type; // The expected field type to be determined. | 3458 ServerFieldType field_type; // The expected field type to be determined. |
| 3397 } TestCase; | 3459 } TestCase; |
| 3398 | 3460 |
| 3399 TestCase test_cases[] = { | 3461 TestCase test_cases[] = { |
| 3400 // Profile fields matches. | 3462 // Profile fields matches. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3435 {"33", PHONE_HOME_COUNTRY_CODE}, | 3497 {"33", PHONE_HOME_COUNTRY_CODE}, |
| 3436 {"2", PHONE_HOME_CITY_CODE}, | 3498 {"2", PHONE_HOME_CITY_CODE}, |
| 3437 | 3499 |
| 3438 // Credit card fields matches. | 3500 // Credit card fields matches. |
| 3439 {"John Doe", CREDIT_CARD_NAME_FULL}, | 3501 {"John Doe", CREDIT_CARD_NAME_FULL}, |
| 3440 {"John", CREDIT_CARD_NAME_FIRST}, | 3502 {"John", CREDIT_CARD_NAME_FIRST}, |
| 3441 {"Doe", CREDIT_CARD_NAME_LAST}, | 3503 {"Doe", CREDIT_CARD_NAME_LAST}, |
| 3442 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER}, | 3504 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER}, |
| 3443 {"04", CREDIT_CARD_EXP_MONTH}, | 3505 {"04", CREDIT_CARD_EXP_MONTH}, |
| 3444 {"April", CREDIT_CARD_EXP_MONTH}, | 3506 {"April", CREDIT_CARD_EXP_MONTH}, |
| 3445 {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR}, | 3507 {"2999", CREDIT_CARD_EXP_4_DIGIT_YEAR}, |
| 3446 {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR}, | 3508 {"99", CREDIT_CARD_EXP_2_DIGIT_YEAR}, |
| 3447 {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, | 3509 {"04/2999", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, |
| 3448 | 3510 |
| 3449 // Make sure whitespaces and invalid characters are handled properly. | 3511 // Make sure whitespaces and invalid characters are handled properly. |
| 3450 {"", EMPTY_TYPE}, | 3512 {"", EMPTY_TYPE}, |
| 3451 {" ", EMPTY_TYPE}, | 3513 {" ", EMPTY_TYPE}, |
| 3452 {"***", UNKNOWN_TYPE}, | 3514 {"***", UNKNOWN_TYPE}, |
| 3453 {" Elvis", NAME_FIRST}, | 3515 {" Elvis", NAME_FIRST}, |
| 3454 {"Elvis ", NAME_FIRST}, | 3516 {"Elvis ", NAME_FIRST}, |
| 3455 | 3517 |
| 3456 // Make sure fields that differ by case match. | 3518 // Make sure fields that differ by case match. |
| 3457 {"elvis ", NAME_FIRST}, | 3519 {"elvis ", NAME_FIRST}, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3563 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", | 3625 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", |
| 3564 "", "Memphis", "Tennessee", "38116", "US", | 3626 "", "Memphis", "Tennessee", "38116", "US", |
| 3565 "(234) 567-8901"); | 3627 "(234) 567-8901"); |
| 3566 profile.set_guid("00000000-0000-0000-0000-000000000001"); | 3628 profile.set_guid("00000000-0000-0000-0000-000000000001"); |
| 3567 profiles.push_back(profile); | 3629 profiles.push_back(profile); |
| 3568 | 3630 |
| 3569 // Set up the test credit card. | 3631 // Set up the test credit card. |
| 3570 std::vector<CreditCard> credit_cards; | 3632 std::vector<CreditCard> credit_cards; |
| 3571 CreditCard credit_card; | 3633 CreditCard credit_card; |
| 3572 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", | 3634 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", |
| 3573 "04", "2012"); | 3635 "04", "2999"); |
| 3574 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); | 3636 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); |
| 3575 credit_cards.push_back(credit_card); | 3637 credit_cards.push_back(credit_card); |
| 3576 | 3638 |
| 3577 typedef struct { | 3639 typedef struct { |
| 3578 std::string input_value; | 3640 std::string input_value; |
| 3579 ServerFieldType predicted_type; | 3641 ServerFieldType predicted_type; |
| 3580 bool expect_disambiguation; | 3642 bool expect_disambiguation; |
| 3581 ServerFieldType expected_upload_type; | 3643 ServerFieldType expected_upload_type; |
| 3582 } TestFieldData; | 3644 } TestFieldData; |
| 3583 | 3645 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 test_cases[9].push_back({"Presley", CREDIT_CARD_NAME_LAST, true, NAME_LAST}); | 3721 test_cases[9].push_back({"Presley", CREDIT_CARD_NAME_LAST, true, NAME_LAST}); |
| 3660 test_cases[9].push_back( | 3722 test_cases[9].push_back( |
| 3661 {"Tennessee", ADDRESS_HOME_STATE, true, ADDRESS_HOME_STATE}); | 3723 {"Tennessee", ADDRESS_HOME_STATE, true, ADDRESS_HOME_STATE}); |
| 3662 | 3724 |
| 3663 // An ambiguous name field that is preceded and followed by credit card | 3725 // An ambiguous name field that is preceded and followed by credit card |
| 3664 // fields should be disambiguated as a credit card name. | 3726 // fields should be disambiguated as a credit card name. |
| 3665 test_cases[10].push_back( | 3727 test_cases[10].push_back( |
| 3666 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER, true, CREDIT_CARD_NUMBER}); | 3728 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER, true, CREDIT_CARD_NUMBER}); |
| 3667 test_cases[10].push_back({"Elvis", NAME_FIRST, true, CREDIT_CARD_NAME_FIRST}); | 3729 test_cases[10].push_back({"Elvis", NAME_FIRST, true, CREDIT_CARD_NAME_FIRST}); |
| 3668 test_cases[10].push_back({"Presley", NAME_LAST, true, CREDIT_CARD_NAME_LAST}); | 3730 test_cases[10].push_back({"Presley", NAME_LAST, true, CREDIT_CARD_NAME_LAST}); |
| 3669 test_cases[10].push_back({"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, | 3731 test_cases[10].push_back({"2999", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, |
| 3670 CREDIT_CARD_EXP_4_DIGIT_YEAR}); | 3732 CREDIT_CARD_EXP_4_DIGIT_YEAR}); |
| 3671 | 3733 |
| 3672 // An ambiguous name field that is preceded by a non credit card field and | 3734 // An ambiguous name field that is preceded by a non credit card field and |
| 3673 // followed by a credit card field should not be disambiguated. | 3735 // followed by a credit card field should not be disambiguated. |
| 3674 test_cases[11].push_back( | 3736 test_cases[11].push_back( |
| 3675 {"Memphis", ADDRESS_HOME_CITY, true, ADDRESS_HOME_CITY}); | 3737 {"Memphis", ADDRESS_HOME_CITY, true, ADDRESS_HOME_CITY}); |
| 3676 test_cases[11].push_back( | 3738 test_cases[11].push_back( |
| 3677 {"Elvis", NAME_FIRST, false, CREDIT_CARD_NAME_FIRST}); | 3739 {"Elvis", NAME_FIRST, false, CREDIT_CARD_NAME_FIRST}); |
| 3678 test_cases[11].push_back( | 3740 test_cases[11].push_back( |
| 3679 {"Presley", NAME_LAST, false, CREDIT_CARD_NAME_LAST}); | 3741 {"Presley", NAME_LAST, false, CREDIT_CARD_NAME_LAST}); |
| 3680 test_cases[11].push_back({"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, | 3742 test_cases[11].push_back({"2999", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, |
| 3681 CREDIT_CARD_EXP_4_DIGIT_YEAR}); | 3743 CREDIT_CARD_EXP_4_DIGIT_YEAR}); |
| 3682 | 3744 |
| 3683 // An ambiguous name field that is preceded by a credit card field and | 3745 // An ambiguous name field that is preceded by a credit card field and |
| 3684 // followed by a non credit card field should not be disambiguated. | 3746 // followed by a non credit card field should not be disambiguated. |
| 3685 test_cases[12].push_back({"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, | 3747 test_cases[12].push_back({"2999", CREDIT_CARD_EXP_4_DIGIT_YEAR, true, |
| 3686 CREDIT_CARD_EXP_4_DIGIT_YEAR}); | 3748 CREDIT_CARD_EXP_4_DIGIT_YEAR}); |
| 3687 test_cases[12].push_back( | 3749 test_cases[12].push_back( |
| 3688 {"Elvis", NAME_FIRST, false, CREDIT_CARD_NAME_FIRST}); | 3750 {"Elvis", NAME_FIRST, false, CREDIT_CARD_NAME_FIRST}); |
| 3689 test_cases[12].push_back( | 3751 test_cases[12].push_back( |
| 3690 {"Presley", NAME_LAST, false, CREDIT_CARD_NAME_LAST}); | 3752 {"Presley", NAME_LAST, false, CREDIT_CARD_NAME_LAST}); |
| 3691 test_cases[12].push_back( | 3753 test_cases[12].push_back( |
| 3692 {"Memphis", ADDRESS_HOME_CITY, true, ADDRESS_HOME_CITY}); | 3754 {"Memphis", ADDRESS_HOME_CITY, true, ADDRESS_HOME_CITY}); |
| 3693 | 3755 |
| 3694 for (const std::vector<TestFieldData>& test_fields : test_cases) { | 3756 for (const std::vector<TestFieldData>& test_fields : test_cases) { |
| 3695 FormData form; | 3757 FormData form; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4008 | 4070 |
| 4009 // Verify whether suggestions are populated correctly for one of the middle | 4071 // Verify whether suggestions are populated correctly for one of the middle |
| 4010 // credit card number fields when filled partially. | 4072 // credit card number fields when filled partially. |
| 4011 FormFieldData number_field = form.fields[3]; | 4073 FormFieldData number_field = form.fields[3]; |
| 4012 number_field.value = ASCIIToUTF16("901"); | 4074 number_field.value = ASCIIToUTF16("901"); |
| 4013 | 4075 |
| 4014 // Get the suggestions for already filled credit card |number_field|. | 4076 // Get the suggestions for already filled credit card |number_field|. |
| 4015 GetAutofillSuggestions(form, number_field); | 4077 GetAutofillSuggestions(form, number_field); |
| 4016 | 4078 |
| 4017 external_delegate_->CheckSuggestions( | 4079 external_delegate_->CheckSuggestions( |
| 4018 kDefaultPageID, | 4080 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 4019 Suggestion( | 4081 "3456", |
| 4020 "Visa\xC2\xA0\xE2\x8B\xAF" | 4082 "04/99", kVisaCard, |
| 4021 "3456", | 4083 autofill_manager_->GetPackedCreditCardID(4))); |
| 4022 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | |
| 4023 } | 4084 } |
| 4024 | 4085 |
| 4025 // Test that inputs detected to be CVC inputs are forced to | 4086 // Test that inputs detected to be CVC inputs are forced to |
| 4026 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. | 4087 // !should_autocomplete for AutocompleteHistoryManager::OnWillSubmitForm. |
| 4027 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { | 4088 TEST_F(AutofillManagerTest, DontSaveCvcInAutocompleteHistory) { |
| 4028 autofill_manager_->autocomplete_history_manager_.reset( | 4089 autofill_manager_->autocomplete_history_manager_.reset( |
| 4029 new MockAutocompleteHistoryManager(autofill_driver_.get(), | 4090 new MockAutocompleteHistoryManager(autofill_driver_.get(), |
| 4030 &autofill_client_)); | 4091 &autofill_client_)); |
| 4031 FormData form_seen_by_ahm; | 4092 FormData form_seen_by_ahm; |
| 4032 MockAutocompleteHistoryManager* mock_ahm = | 4093 MockAutocompleteHistoryManager* mock_ahm = |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4832 FormsSeen(mixed_forms); | 4893 FormsSeen(mixed_forms); |
| 4833 | 4894 |
| 4834 // Suggestions should always be displayed. | 4895 // Suggestions should always be displayed. |
| 4835 for (const FormFieldData& field : mixed_form.fields) { | 4896 for (const FormFieldData& field : mixed_form.fields) { |
| 4836 GetAutofillSuggestions(mixed_form, field); | 4897 GetAutofillSuggestions(mixed_form, field); |
| 4837 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4898 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 4838 } | 4899 } |
| 4839 } | 4900 } |
| 4840 | 4901 |
| 4841 } // namespace autofill | 4902 } // namespace autofill |
| OLD | NEW |