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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 // Disable Autofill. | 1305 // Disable Autofill. |
1306 autofill_manager_->set_autofill_enabled(false); | 1306 autofill_manager_->set_autofill_enabled(false); |
1307 | 1307 |
1308 const FormFieldData& field = form.fields[0]; | 1308 const FormFieldData& field = form.fields[0]; |
1309 GetAutofillSuggestions(form, field); | 1309 GetAutofillSuggestions(form, field); |
1310 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1310 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
1311 } | 1311 } |
1312 | 1312 |
1313 // Test that we return all credit card profile suggestions when all form fields | 1313 // Test that we return all credit card profile suggestions when all form fields |
1314 // are empty. | 1314 // are empty. |
1315 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 1315 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_EmptyValue) { |
1316 // Set up our form data. | 1316 // Set up our form data. |
1317 FormData form; | 1317 FormData form; |
1318 CreateTestCreditCardFormData(&form, true, false); | 1318 CreateTestCreditCardFormData(&form, true, false); |
1319 std::vector<FormData> forms(1, form); | 1319 std::vector<FormData> forms(1, form); |
1320 FormsSeen(forms); | 1320 FormsSeen(forms); |
1321 | 1321 |
1322 FormFieldData field = form.fields[1]; | 1322 FormFieldData field = form.fields[1]; |
1323 GetAutofillSuggestions(form, field); | 1323 GetAutofillSuggestions(form, field); |
1324 | 1324 |
1325 // Test that we sent the right values to the external delegate. | 1325 // Test that we sent the right values to the external delegate. |
1326 external_delegate_->CheckSuggestions( | 1326 external_delegate_->CheckSuggestions( |
1327 kDefaultPageID, | 1327 kDefaultPageID, |
1328 Suggestion( | 1328 Suggestion( |
1329 "Visa\xC2\xA0\xE2\x8B\xAF" | 1329 "Visa\xC2\xA0\xE2\x8B\xAF" |
1330 "3456", | 1330 "3456", |
1331 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), | 1331 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4)), |
1332 Suggestion( | 1332 Suggestion( |
1333 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 1333 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
1334 "8765", | 1334 "8765", |
1335 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1335 "10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); |
1336 } | 1336 } |
1337 | 1337 |
| 1338 // Test that we return all credit card profile suggestions when the triggering |
| 1339 // field has whitespace in it. |
| 1340 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) { |
| 1341 // Set up our form data. |
| 1342 FormData form; |
| 1343 CreateTestCreditCardFormData(&form, true, false); |
| 1344 std::vector<FormData> forms(1, form); |
| 1345 FormsSeen(forms); |
| 1346 |
| 1347 FormFieldData field = form.fields[1]; |
| 1348 field.value = ASCIIToUTF16(" "); |
| 1349 GetAutofillSuggestions(form, field); |
| 1350 |
| 1351 // Test that we sent the right values to the external delegate. |
| 1352 external_delegate_->CheckSuggestions( |
| 1353 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1354 "3456", |
| 1355 "04/12", kVisaCard, |
| 1356 autofill_manager_->GetPackedCreditCardID(4)), |
| 1357 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1358 "8765", |
| 1359 "10/14", kMasterCard, |
| 1360 autofill_manager_->GetPackedCreditCardID(5))); |
| 1361 } |
| 1362 |
| 1363 // Test that we return all credit card profile suggestions when the triggering |
| 1364 // field has stop characters in it, which should be removed. |
| 1365 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) { |
| 1366 // Set up our form data. |
| 1367 FormData form; |
| 1368 CreateTestCreditCardFormData(&form, true, false); |
| 1369 std::vector<FormData> forms(1, form); |
| 1370 FormsSeen(forms); |
| 1371 |
| 1372 FormFieldData field = form.fields[1]; |
| 1373 field.value = ASCIIToUTF16("____-____-____-____"); |
| 1374 GetAutofillSuggestions(form, field); |
| 1375 |
| 1376 // Test that we sent the right values to the external delegate. |
| 1377 external_delegate_->CheckSuggestions( |
| 1378 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" |
| 1379 "3456", |
| 1380 "04/12", kVisaCard, |
| 1381 autofill_manager_->GetPackedCreditCardID(4)), |
| 1382 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1383 "8765", |
| 1384 "10/14", kMasterCard, |
| 1385 autofill_manager_->GetPackedCreditCardID(5))); |
| 1386 } |
| 1387 |
| 1388 // Test that we return all credit card profile suggestions when the triggering |
| 1389 // field has stop characters in it and some input. |
| 1390 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1391 // Add a credit card with particular numbers that we will attempt to recall. |
| 1392 CreditCard* credit_card = new CreditCard; |
| 1393 test::SetCreditCardInfo(credit_card, "John Smith", |
| 1394 "5255667890123123", // Mastercard |
| 1395 "08", "2017"); |
| 1396 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1397 autofill_manager_->AddCreditCard(credit_card); |
| 1398 |
| 1399 // Set up our form data. |
| 1400 FormData form; |
| 1401 CreateTestCreditCardFormData(&form, true, false); |
| 1402 std::vector<FormData> forms(1, form); |
| 1403 FormsSeen(forms); |
| 1404 |
| 1405 FormFieldData field = form.fields[1]; |
| 1406 |
| 1407 field.value = ASCIIToUTF16("5255-66__-____-____"); |
| 1408 GetAutofillSuggestions(form, field); |
| 1409 |
| 1410 // Test that we sent the right value to the external delegate. |
| 1411 external_delegate_->CheckSuggestions( |
| 1412 kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 1413 "3123", |
| 1414 "08/17", kMasterCard, |
| 1415 autofill_manager_->GetPackedCreditCardID(7))); |
| 1416 } |
| 1417 |
1338 // Test that we return only matching credit card profile suggestions when the | 1418 // Test that we return only matching credit card profile suggestions when the |
1339 // selected form field has been partially filled out. | 1419 // selected form field has been partially filled out. |
1340 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 1420 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { |
1341 // Set up our form data. | 1421 // Set up our form data. |
1342 FormData form; | 1422 FormData form; |
1343 CreateTestCreditCardFormData(&form, true, false); | 1423 CreateTestCreditCardFormData(&form, true, false); |
1344 std::vector<FormData> forms(1, form); | 1424 std::vector<FormData> forms(1, form); |
1345 FormsSeen(forms); | 1425 FormsSeen(forms); |
1346 | 1426 |
1347 FormFieldData field; | 1427 FormFieldData field; |
(...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4211 FormsSeen(mixed_forms); | 4291 FormsSeen(mixed_forms); |
4212 | 4292 |
4213 // Suggestions should always be displayed. | 4293 // Suggestions should always be displayed. |
4214 for (const FormFieldData& field : mixed_form.fields) { | 4294 for (const FormFieldData& field : mixed_form.fields) { |
4215 GetAutofillSuggestions(mixed_form, field); | 4295 GetAutofillSuggestions(mixed_form, field); |
4216 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4296 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
4217 } | 4297 } |
4218 } | 4298 } |
4219 | 4299 |
4220 } // namespace autofill | 4300 } // namespace autofill |
OLD | NEW |