Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 442403002: Adjust displayed phone number for prefix/suffix case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove duplicate code. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, GetProfileSuggestionsForPrefixSuffixPhone) {
Ilya Sherman 2014/09/03 00:55:49 nit: "PrefixSuffixPhone" -> "PhonePrefixOrSuffix"
ziran.sun 2014/09/04 13:10:25 Done.
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* label;
Ilya Sherman 2014/09/03 00:55:49 nit: Can this be "const char* const"? Ditto for t
ziran.sun 2014/09/04 13:10:25 Done.
1488 const char* name;
1489 size_t max_length;
1490 const char* 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")};
Ilya Sherman 2014/09/03 00:55:49 Why are the labels "1", rather than the values tha
ziran.sun 2014/09/04 13:10:25 From my understanding, distinguishing label does n
Ilya Sherman 2014/09/11 05:32:14 Yes, you're right. Sorry for my confusion.
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 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 test::CreateTestAddressFormData(&form); 2891 test::CreateTestAddressFormData(&form);
2817 std::vector<FormData> forms(1, form); 2892 std::vector<FormData> forms(1, form);
2818 FormsSeen(forms); 2893 FormsSeen(forms);
2819 const FormFieldData& field = form.fields[0]; 2894 const FormFieldData& field = form.fields[0];
2820 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 2895 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2821 2896
2822 EXPECT_TRUE(external_delegate_->on_query_seen()); 2897 EXPECT_TRUE(external_delegate_->on_query_seen());
2823 } 2898 }
2824 2899
2825 } // namespace autofill 2900 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698