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

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

Issue 1639563002: [Autofill] Fill from the last digits when filling a phone number with a maximum length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 10 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
« no previous file with comments | « components/autofill/core/browser/autofill_field_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 { 2546 {
2547 SCOPED_TRACE("Credit card 2"); 2547 SCOPED_TRACE("Credit card 2");
2548 ExpectFilledForm(response_page_id, response_data, kPageID3, "", "", "", "", 2548 ExpectFilledForm(response_page_id, response_data, kPageID3, "", "", "", "",
2549 "", "", "", "", "", "", "", "", "", "", "2012", true, true, 2549 "", "", "", "", "", "", "", "", "", "", "2012", true, true,
2550 false); 2550 false);
2551 } 2551 }
2552 } 2552 }
2553 2553
2554 // Test that we correctly fill a phone number split across multiple fields. 2554 // Test that we correctly fill a phone number split across multiple fields.
2555 TEST_F(AutofillManagerTest, FillPhoneNumber) { 2555 TEST_F(AutofillManagerTest, FillPhoneNumber) {
2556 // In one form, rely on the maxlength attribute to imply phone number parts. 2556 // In one form, rely on the maxlength attribute to imply US phone number
2557 // In the other form, rely on the autocompletetype attribute. 2557 // parts. In the other form, rely on the autocompletetype attribute.
2558 FormData form_with_maxlength; 2558 FormData form_with_us_number_max_length;
2559 form_with_maxlength.name = ASCIIToUTF16("MyMaxlengthPhoneForm"); 2559 form_with_us_number_max_length.name = ASCIIToUTF16("MyMaxlengthPhoneForm");
2560 form_with_maxlength.origin = GURL("http://myform.com/phone_form.html"); 2560 form_with_us_number_max_length.origin =
2561 form_with_maxlength.action = GURL("http://myform.com/phone_submit.html"); 2561 GURL("http://myform.com/phone_form.html");
2562 FormData form_with_autocompletetype = form_with_maxlength; 2562 form_with_us_number_max_length.action =
2563 GURL("http://myform.com/phone_submit.html");
2564 FormData form_with_autocompletetype = form_with_us_number_max_length;
2563 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm"); 2565 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm");
2564 2566
2565 struct { 2567 struct {
2566 const char* label; 2568 const char* label;
2567 const char* name; 2569 const char* name;
2568 size_t max_length; 2570 size_t max_length;
2569 const char* autocomplete_attribute; 2571 const char* autocomplete_attribute;
2570 } test_fields[] = { 2572 } test_fields[] = {
2571 { "country code", "country_code", 1, "tel-country-code" }, 2573 { "country code", "country_code", 1, "tel-country-code" },
2572 { "area code", "area_code", 3, "tel-area-code" }, 2574 { "area code", "area_code", 3, "tel-area-code" },
2573 { "phone", "phone_prefix", 3, "tel-local-prefix" }, 2575 { "phone", "phone_prefix", 3, "tel-local-prefix" },
2574 { "-", "phone_suffix", 4, "tel-local-suffix" }, 2576 { "-", "phone_suffix", 4, "tel-local-suffix" },
2575 { "Phone Extension", "ext", 3, "tel-extension" } 2577 { "Phone Extension", "ext", 3, "tel-extension" }
2576 }; 2578 };
2577 2579
2578 FormFieldData field; 2580 FormFieldData field;
2579 const size_t default_max_length = field.max_length; 2581 const size_t default_max_length = field.max_length;
2580 for (size_t i = 0; i < arraysize(test_fields); ++i) { 2582 for (size_t i = 0; i < arraysize(test_fields); ++i) {
2581 test::CreateTestFormField( 2583 test::CreateTestFormField(
2582 test_fields[i].label, test_fields[i].name, "", "text", &field); 2584 test_fields[i].label, test_fields[i].name, "", "text", &field);
2583 field.max_length = test_fields[i].max_length; 2585 field.max_length = test_fields[i].max_length;
2584 field.autocomplete_attribute = std::string(); 2586 field.autocomplete_attribute = std::string();
2585 form_with_maxlength.fields.push_back(field); 2587 form_with_us_number_max_length.fields.push_back(field);
2586 2588
2587 field.max_length = default_max_length; 2589 field.max_length = default_max_length;
2588 field.autocomplete_attribute = test_fields[i].autocomplete_attribute; 2590 field.autocomplete_attribute = test_fields[i].autocomplete_attribute;
2589 form_with_autocompletetype.fields.push_back(field); 2591 form_with_autocompletetype.fields.push_back(field);
2590 } 2592 }
2591 2593
2592 std::vector<FormData> forms; 2594 std::vector<FormData> forms;
2593 forms.push_back(form_with_maxlength); 2595 forms.push_back(form_with_us_number_max_length);
2594 forms.push_back(form_with_autocompletetype); 2596 forms.push_back(form_with_autocompletetype);
2595 FormsSeen(forms); 2597 FormsSeen(forms);
2596 2598
2597 // We should be able to fill prefix and suffix fields for US numbers. 2599 // We should be able to fill prefix and suffix fields for US numbers.
2598 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( 2600 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID(
2599 "00000000-0000-0000-0000-000000000002"); 2601 "00000000-0000-0000-0000-000000000002");
2600 ASSERT_TRUE(work_profile != NULL); 2602 ASSERT_TRUE(work_profile != NULL);
2601 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 2603 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2602 ASCIIToUTF16("16505554567")); 2604 ASCIIToUTF16("16505554567"));
2603 2605
2604 std::string guid(work_profile->guid()); 2606 std::string guid(work_profile->guid());
2605 int page_id = 1; 2607 int page_id = 1;
2606 int response_page_id = 0; 2608 int response_page_id = 0;
2607 FormData response_data1; 2609 FormData response_data1;
2608 FillAutofillFormDataAndSaveResults( 2610 FillAutofillFormDataAndSaveResults(
2609 page_id, form_with_maxlength, *form_with_maxlength.fields.begin(), 2611 page_id, form_with_us_number_max_length,
2612 *form_with_us_number_max_length.fields.begin(),
2610 MakeFrontendID(std::string(), guid), &response_page_id, &response_data1); 2613 MakeFrontendID(std::string(), guid), &response_page_id, &response_data1);
2611 EXPECT_EQ(1, response_page_id); 2614 EXPECT_EQ(1, response_page_id);
2612 2615
2613 ASSERT_EQ(5U, response_data1.fields.size()); 2616 ASSERT_EQ(5U, response_data1.fields.size());
2614 EXPECT_EQ(ASCIIToUTF16("1"), response_data1.fields[0].value); 2617 EXPECT_EQ(ASCIIToUTF16("1"), response_data1.fields[0].value);
2615 EXPECT_EQ(ASCIIToUTF16("650"), response_data1.fields[1].value); 2618 EXPECT_EQ(ASCIIToUTF16("650"), response_data1.fields[1].value);
2616 EXPECT_EQ(ASCIIToUTF16("555"), response_data1.fields[2].value); 2619 EXPECT_EQ(ASCIIToUTF16("555"), response_data1.fields[2].value);
2617 EXPECT_EQ(ASCIIToUTF16("4567"), response_data1.fields[3].value); 2620 EXPECT_EQ(ASCIIToUTF16("4567"), response_data1.fields[3].value);
2618 EXPECT_EQ(base::string16(), response_data1.fields[4].value); 2621 EXPECT_EQ(base::string16(), response_data1.fields[4].value);
2619 2622
2620 page_id = 2; 2623 page_id = 2;
2621 response_page_id = 0; 2624 response_page_id = 0;
2622 FormData response_data2; 2625 FormData response_data2;
2623 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, 2626 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype,
2624 *form_with_autocompletetype.fields.begin(), 2627 *form_with_autocompletetype.fields.begin(),
2625 MakeFrontendID(std::string(), guid), 2628 MakeFrontendID(std::string(), guid),
2626 &response_page_id, &response_data2); 2629 &response_page_id, &response_data2);
2627 EXPECT_EQ(2, response_page_id); 2630 EXPECT_EQ(2, response_page_id);
2628 2631
2629 ASSERT_EQ(5U, response_data2.fields.size()); 2632 ASSERT_EQ(5U, response_data2.fields.size());
2630 EXPECT_EQ(ASCIIToUTF16("1"), response_data2.fields[0].value); 2633 EXPECT_EQ(ASCIIToUTF16("1"), response_data2.fields[0].value);
2631 EXPECT_EQ(ASCIIToUTF16("650"), response_data2.fields[1].value); 2634 EXPECT_EQ(ASCIIToUTF16("650"), response_data2.fields[1].value);
2632 EXPECT_EQ(ASCIIToUTF16("555"), response_data2.fields[2].value); 2635 EXPECT_EQ(ASCIIToUTF16("555"), response_data2.fields[2].value);
2633 EXPECT_EQ(ASCIIToUTF16("4567"), response_data2.fields[3].value); 2636 EXPECT_EQ(ASCIIToUTF16("4567"), response_data2.fields[3].value);
2634 EXPECT_EQ(base::string16(), response_data2.fields[4].value); 2637 EXPECT_EQ(base::string16(), response_data2.fields[4].value);
2635 2638
2636 // We should not be able to fill prefix and suffix fields for international 2639 // We should not be able to fill international numbers correctly in a form
2637 // numbers. 2640 // containing fields with US max_length. However, the field should fill with
2641 // the number of digits equal to the max length specified, starting from the
2642 // right.
2638 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); 2643 work_profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB"));
2639 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 2644 work_profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2640 ASCIIToUTF16("447700954321")); 2645 ASCIIToUTF16("447700954321"));
2641 page_id = 3; 2646 page_id = 3;
2642 response_page_id = 0; 2647 response_page_id = 0;
2643 FormData response_data3; 2648 FormData response_data3;
2644 FillAutofillFormDataAndSaveResults( 2649 FillAutofillFormDataAndSaveResults(
2645 page_id, form_with_maxlength, *form_with_maxlength.fields.begin(), 2650 page_id, form_with_us_number_max_length,
2651 *form_with_us_number_max_length.fields.begin(),
2646 MakeFrontendID(std::string(), guid), &response_page_id, &response_data3); 2652 MakeFrontendID(std::string(), guid), &response_page_id, &response_data3);
2647 EXPECT_EQ(3, response_page_id); 2653 EXPECT_EQ(3, response_page_id);
2648 2654
2649 ASSERT_EQ(5U, response_data3.fields.size()); 2655 ASSERT_EQ(5U, response_data3.fields.size());
2650 EXPECT_EQ(ASCIIToUTF16("44"), response_data3.fields[0].value); 2656 EXPECT_EQ(ASCIIToUTF16("4"), response_data3.fields[0].value);
2651 EXPECT_EQ(ASCIIToUTF16("7700"), response_data3.fields[1].value); 2657 EXPECT_EQ(ASCIIToUTF16("700"), response_data3.fields[1].value);
2652 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[2].value); 2658 EXPECT_EQ(ASCIIToUTF16("321"), response_data3.fields[2].value);
2653 EXPECT_EQ(ASCIIToUTF16("954321"), response_data3.fields[3].value); 2659 EXPECT_EQ(ASCIIToUTF16("4321"), response_data3.fields[3].value);
2654 EXPECT_EQ(base::string16(), response_data3.fields[4].value); 2660 EXPECT_EQ(base::string16(), response_data3.fields[4].value);
2655 2661
2656 page_id = 4; 2662 page_id = 4;
2657 response_page_id = 0; 2663 response_page_id = 0;
2658 FormData response_data4; 2664 FormData response_data4;
2659 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype, 2665 FillAutofillFormDataAndSaveResults(page_id, form_with_autocompletetype,
2660 *form_with_autocompletetype.fields.begin(), 2666 *form_with_autocompletetype.fields.begin(),
2661 MakeFrontendID(std::string(), guid), 2667 MakeFrontendID(std::string(), guid),
2662 &response_page_id, &response_data4); 2668 &response_page_id, &response_data4);
2663 EXPECT_EQ(4, response_page_id); 2669 EXPECT_EQ(4, response_page_id);
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
4291 FormsSeen(mixed_forms); 4297 FormsSeen(mixed_forms);
4292 4298
4293 // Suggestions should always be displayed. 4299 // Suggestions should always be displayed.
4294 for (const FormFieldData& field : mixed_form.fields) { 4300 for (const FormFieldData& field : mixed_form.fields) {
4295 GetAutofillSuggestions(mixed_form, field); 4301 GetAutofillSuggestions(mixed_form, field);
4296 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 4302 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4297 } 4303 }
4298 } 4304 }
4299 4305
4300 } // namespace autofill 4306 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_field_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698