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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 ASCIIToUTF16("Natty Bumppo"), | 1468 ASCIIToUTF16("Natty Bumppo"), |
1469 }; | 1469 }; |
1470 base::string16 expected_icons[] = { base::string16(), base::string16(), | 1470 base::string16 expected_icons[] = { base::string16(), base::string16(), |
1471 base::string16()}; | 1471 base::string16()}; |
1472 int expected_unique_ids[] = {1, 2, 3}; | 1472 int expected_unique_ids[] = {1, 2, 3}; |
1473 external_delegate_->CheckSuggestions( | 1473 external_delegate_->CheckSuggestions( |
1474 kDefaultPageID, arraysize(expected_values), expected_values, | 1474 kDefaultPageID, arraysize(expected_values), expected_values, |
1475 expected_labels, expected_icons, expected_unique_ids); | 1475 expected_labels, expected_icons, expected_unique_ids); |
1476 } | 1476 } |
1477 | 1477 |
| 1478 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { |
| 1479 // Set up our form data. |
| 1480 FormData form; |
| 1481 form.name = ASCIIToUTF16("MyForm"); |
| 1482 form.origin = GURL("http://myform.com/form.html"); |
| 1483 form.action = GURL("http://myform.com/submit.html"); |
| 1484 form.user_submitted = true; |
| 1485 |
| 1486 struct { |
| 1487 const char* const label; |
| 1488 const char* const name; |
| 1489 size_t max_length; |
| 1490 const char* const autocomplete_attribute; |
| 1491 } test_fields[] = {{"country code", "country_code", 1, "tel-country-code"}, |
| 1492 {"area code", "area_code", 3, "tel-area-code"}, |
| 1493 {"phone", "phone_prefix", 3, "tel-local-prefix"}, |
| 1494 {"-", "phone_suffix", 4, "tel-local-suffix"}, |
| 1495 {"Phone Extension", "ext", 5, "tel-extension"}}; |
| 1496 |
| 1497 FormFieldData field; |
| 1498 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_fields); ++i) { |
| 1499 test::CreateTestFormField( |
| 1500 test_fields[i].label, test_fields[i].name, "", "text", &field); |
| 1501 field.max_length = test_fields[i].max_length; |
| 1502 field.autocomplete_attribute = std::string(); |
| 1503 form.fields.push_back(field); |
| 1504 } |
| 1505 |
| 1506 std::vector<FormData> forms(1, form); |
| 1507 FormsSeen(forms); |
| 1508 |
| 1509 AutofillProfile* profile = new AutofillProfile; |
| 1510 profile->set_guid("00000000-0000-0000-0000-000000000104"); |
| 1511 std::vector<base::string16> multi_values(2); |
| 1512 multi_values[0] = ASCIIToUTF16("1800FLOWERS"); |
| 1513 multi_values[1] = ASCIIToUTF16("14158889999"); |
| 1514 |
| 1515 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); |
| 1516 personal_data_.ClearAutofillProfiles(); |
| 1517 autofill_manager_->AddProfile(profile); |
| 1518 |
| 1519 const FormFieldData& phone_prefix = form.fields[2]; |
| 1520 GetAutofillSuggestions(form, phone_prefix); |
| 1521 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1522 // Test that we sent the right prefix values to the external delegate. |
| 1523 base::string16 expected_prefix_values[] = {ASCIIToUTF16("356"), |
| 1524 ASCIIToUTF16("888")}; |
| 1525 base::string16 expected_prefix_labels[] = {ASCIIToUTF16("1"), |
| 1526 ASCIIToUTF16("1")}; |
| 1527 base::string16 expected_prefix_icons[] = {base::string16(), base::string16()}; |
| 1528 int expected_unique_ids[] = {1, 2}; |
| 1529 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 1530 arraysize(expected_prefix_values), |
| 1531 expected_prefix_values, |
| 1532 expected_prefix_labels, |
| 1533 expected_prefix_icons, |
| 1534 expected_unique_ids); |
| 1535 |
| 1536 const FormFieldData& phone_suffix = form.fields[3]; |
| 1537 GetAutofillSuggestions(form, phone_suffix); |
| 1538 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1539 // Test that we sent the right suffix values to the external delegate. |
| 1540 base::string16 expected_suffix_values[] = {ASCIIToUTF16("9377"), |
| 1541 ASCIIToUTF16("9999")}; |
| 1542 base::string16 expected_suffix_labels[] = {ASCIIToUTF16("1"), |
| 1543 ASCIIToUTF16("1")}; |
| 1544 base::string16 expected_suffix_icons[] = {base::string16(), base::string16()}; |
| 1545 external_delegate_->CheckSuggestions(kDefaultPageID, |
| 1546 arraysize(expected_suffix_values), |
| 1547 expected_suffix_values, |
| 1548 expected_suffix_labels, |
| 1549 expected_suffix_icons, |
| 1550 expected_unique_ids); |
| 1551 } |
| 1552 |
1478 // Test that we correctly fill an address form. | 1553 // Test that we correctly fill an address form. |
1479 TEST_F(AutofillManagerTest, FillAddressForm) { | 1554 TEST_F(AutofillManagerTest, FillAddressForm) { |
1480 // Set up our form data. | 1555 // Set up our form data. |
1481 FormData form; | 1556 FormData form; |
1482 test::CreateTestAddressFormData(&form); | 1557 test::CreateTestAddressFormData(&form); |
1483 std::vector<FormData> forms(1, form); | 1558 std::vector<FormData> forms(1, form); |
1484 FormsSeen(forms); | 1559 FormsSeen(forms); |
1485 | 1560 |
1486 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1561 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
1487 GUIDPair empty(std::string(), 0); | 1562 GUIDPair empty(std::string(), 0); |
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2834 test::CreateTestAddressFormData(&form); | 2909 test::CreateTestAddressFormData(&form); |
2835 std::vector<FormData> forms(1, form); | 2910 std::vector<FormData> forms(1, form); |
2836 FormsSeen(forms); | 2911 FormsSeen(forms); |
2837 const FormFieldData& field = form.fields[0]; | 2912 const FormFieldData& field = form.fields[0]; |
2838 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2913 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2839 | 2914 |
2840 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2915 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2841 } | 2916 } |
2842 | 2917 |
2843 } // namespace autofill | 2918 } // namespace autofill |
OLD | NEW |