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