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

Side by Side Diff: chrome/browser/autofill/phone_number_unittest.cc

Issue 7892048: Autofill: Remove fax number completely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autofill_profile.h" 6 #include "chrome/browser/autofill/autofill_profile.h"
7 #include "chrome/browser/autofill/field_types.h" 7 #include "chrome/browser/autofill/field_types.h"
8 #include "chrome/browser/autofill/phone_number.h" 8 #include "chrome/browser/autofill/phone_number.h"
9 #include "chrome/browser/autofill/phone_number_i18n.h" 9 #include "chrome/browser/autofill/phone_number_i18n.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 TEST(PhoneNumberTest, Matcher) { 12 TEST(PhoneNumberTest, Matcher) {
13 AutofillProfile profile; 13 AutofillProfile profile;
14 profile.SetCountryCode("US"); 14 profile.SetCountryCode("US");
15 // Set phone number so country_code == 1, city_code = 650, number = 2345678. 15 // Set phone number so country_code == 1, city_code = 650, number = 2345678.
16 string16 phone(ASCIIToUTF16("1 [650] 234-5678")); 16 string16 phone(ASCIIToUTF16("1 [650] 234-5678"));
17 PhoneNumber phone_number(AutofillType::PHONE_HOME, &profile); 17 PhoneNumber phone_number(&profile);
18 phone_number.SetInfo(PHONE_HOME_WHOLE_NUMBER, phone); 18 phone_number.SetInfo(PHONE_HOME_WHOLE_NUMBER, phone);
19 phone_number.NormalizePhone(); 19 phone_number.NormalizePhone();
20 20
21 FieldTypeSet matching_types; 21 FieldTypeSet matching_types;
22 phone_number.GetMatchingTypes(ASCIIToUTF16(""), &matching_types); 22 phone_number.GetMatchingTypes(ASCIIToUTF16(""), &matching_types);
23 EXPECT_EQ(1U, matching_types.size()); 23 EXPECT_EQ(1U, matching_types.size());
24 EXPECT_TRUE(matching_types.find(EMPTY_TYPE) != matching_types.end()); 24 EXPECT_TRUE(matching_types.find(EMPTY_TYPE) != matching_types.end());
25 matching_types.clear(); 25 matching_types.clear();
26 phone_number.GetMatchingTypes(ASCIIToUTF16("1"), &matching_types); 26 phone_number.GetMatchingTypes(ASCIIToUTF16("1"), &matching_types);
27 EXPECT_EQ(1U, matching_types.size()); 27 EXPECT_EQ(1U, matching_types.size());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 matching_types.clear(); 68 matching_types.clear();
69 phone_number.GetMatchingTypes(ASCIIToUTF16("6502345678"), &matching_types); 69 phone_number.GetMatchingTypes(ASCIIToUTF16("6502345678"), &matching_types);
70 EXPECT_EQ(1U, matching_types.size()); 70 EXPECT_EQ(1U, matching_types.size());
71 EXPECT_TRUE(matching_types.find(PHONE_HOME_CITY_AND_NUMBER) != 71 EXPECT_TRUE(matching_types.find(PHONE_HOME_CITY_AND_NUMBER) !=
72 matching_types.end()); 72 matching_types.end());
73 matching_types.clear(); 73 matching_types.clear();
74 phone_number.GetMatchingTypes(ASCIIToUTF16("(650)2345678"), &matching_types); 74 phone_number.GetMatchingTypes(ASCIIToUTF16("(650)2345678"), &matching_types);
75 EXPECT_EQ(1U, matching_types.size()); 75 EXPECT_EQ(1U, matching_types.size());
76 EXPECT_TRUE(matching_types.find(PHONE_HOME_CITY_AND_NUMBER) != 76 EXPECT_TRUE(matching_types.find(PHONE_HOME_CITY_AND_NUMBER) !=
77 matching_types.end()); 77 matching_types.end());
78
79 string16 fax(ASCIIToUTF16("+1(650)650-5678"));
80 PhoneNumber fax_number(&profile);
81 fax_number.SetInfo(PHONE_FAX_WHOLE_NUMBER, fax);
82
83 matching_types.clear();
84 fax_number.GetMatchingTypes(ASCIIToUTF16("16506505678"), &matching_types);
85 EXPECT_EQ(1U, matching_types.size());
86 EXPECT_TRUE(matching_types.find(PHONE_FAX_WHOLE_NUMBER) !=
87 matching_types.end());
88
89 matching_types.clear();
90 fax_number.GetMatchingTypes(ASCIIToUTF16("650"), &matching_types);
91 EXPECT_EQ(2U, matching_types.size());
92 EXPECT_TRUE(matching_types.find(PHONE_FAX_CITY_CODE) !=
93 matching_types.end());
94 EXPECT_TRUE(matching_types.find(PHONE_FAX_NUMBER) !=
95 matching_types.end());
96 } 78 }
97 79
98 TEST(PhoneNumberTest, PhoneCombineHelper) { 80 TEST(PhoneNumberTest, PhoneCombineHelper) {
99 PhoneNumber::PhoneCombineHelper number1(AutofillType::PHONE_HOME); 81 PhoneNumber::PhoneCombineHelper number1;
100 EXPECT_FALSE(number1.SetInfo(ADDRESS_BILLING_CITY, 82 EXPECT_FALSE(number1.SetInfo(ADDRESS_BILLING_CITY,
101 ASCIIToUTF16("1"))); 83 ASCIIToUTF16("1")));
102 EXPECT_FALSE(number1.SetInfo(PHONE_FAX_COUNTRY_CODE,
103 ASCIIToUTF16("1")));
104 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_COUNTRY_CODE, 84 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_COUNTRY_CODE,
105 ASCIIToUTF16("1"))); 85 ASCIIToUTF16("1")));
106 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_CITY_CODE, 86 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_CITY_CODE,
107 ASCIIToUTF16("650"))); 87 ASCIIToUTF16("650")));
108 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_NUMBER, 88 EXPECT_TRUE(number1.SetInfo(PHONE_HOME_NUMBER,
109 ASCIIToUTF16("2345678"))); 89 ASCIIToUTF16("2345678")));
110 string16 parsed_phone; 90 string16 parsed_phone;
111 EXPECT_TRUE(number1.ParseNumber("US", &parsed_phone)); 91 EXPECT_TRUE(number1.ParseNumber("US", &parsed_phone));
112 // International format as it has a country code. 92 // International format as it has a country code.
113 EXPECT_EQ(ASCIIToUTF16("+1 650-234-5678"), parsed_phone); 93 EXPECT_EQ(ASCIIToUTF16("+1 650-234-5678"), parsed_phone);
114 94
115 PhoneNumber::PhoneCombineHelper number2(AutofillType::PHONE_FAX); 95 PhoneNumber::PhoneCombineHelper number3;
116 EXPECT_FALSE(number2.SetInfo(PHONE_HOME_COUNTRY_CODE,
117 ASCIIToUTF16("1")));
118 EXPECT_TRUE(number2.SetInfo(PHONE_FAX_COUNTRY_CODE,
119 ASCIIToUTF16("1")));
120 EXPECT_TRUE(number2.SetInfo(PHONE_FAX_CITY_CODE,
121 ASCIIToUTF16("650")));
122 EXPECT_TRUE(number2.SetInfo(PHONE_FAX_NUMBER,
123 ASCIIToUTF16("2345679")));
124 EXPECT_TRUE(number2.ParseNumber("US", &parsed_phone));
125 // International format as it has a country code.
126 EXPECT_EQ(ASCIIToUTF16("+1 650-234-5679"), parsed_phone);
127
128 PhoneNumber::PhoneCombineHelper number3(AutofillType::PHONE_HOME);
129 EXPECT_TRUE(number3.SetInfo(PHONE_HOME_CITY_CODE, 96 EXPECT_TRUE(number3.SetInfo(PHONE_HOME_CITY_CODE,
130 ASCIIToUTF16("650"))); 97 ASCIIToUTF16("650")));
131 EXPECT_TRUE(number3.SetInfo(PHONE_HOME_NUMBER, 98 EXPECT_TRUE(number3.SetInfo(PHONE_HOME_NUMBER,
132 ASCIIToUTF16("2345680"))); 99 ASCIIToUTF16("2345680")));
133 EXPECT_TRUE(number3.ParseNumber("US", &parsed_phone)); 100 EXPECT_TRUE(number3.ParseNumber("US", &parsed_phone));
134 // National format as it does not have a country code. 101 // National format as it does not have a country code.
135 EXPECT_EQ(ASCIIToUTF16("(650) 234-5680"), parsed_phone); 102 EXPECT_EQ(ASCIIToUTF16("(650) 234-5680"), parsed_phone);
136 103
137 PhoneNumber::PhoneCombineHelper number4(AutofillType::PHONE_HOME); 104 PhoneNumber::PhoneCombineHelper number4;
138 EXPECT_TRUE(number4.SetInfo(PHONE_HOME_CITY_CODE, 105 EXPECT_TRUE(number4.SetInfo(PHONE_HOME_CITY_CODE,
139 ASCIIToUTF16("123"))); // Incorrect city code. 106 ASCIIToUTF16("123"))); // Incorrect city code.
140 EXPECT_TRUE(number4.SetInfo(PHONE_HOME_NUMBER, 107 EXPECT_TRUE(number4.SetInfo(PHONE_HOME_NUMBER,
141 ASCIIToUTF16("2345680"))); 108 ASCIIToUTF16("2345680")));
142 EXPECT_FALSE(number4.ParseNumber("US", &parsed_phone)); 109 EXPECT_FALSE(number4.ParseNumber("US", &parsed_phone));
143 EXPECT_EQ(string16(), parsed_phone); 110 EXPECT_EQ(string16(), parsed_phone);
144 111
145 PhoneNumber::PhoneCombineHelper number5(AutofillType::PHONE_HOME); 112 PhoneNumber::PhoneCombineHelper number5;
146 EXPECT_TRUE(number5.SetInfo(PHONE_HOME_CITY_AND_NUMBER, 113 EXPECT_TRUE(number5.SetInfo(PHONE_HOME_CITY_AND_NUMBER,
147 ASCIIToUTF16("6502345681"))); 114 ASCIIToUTF16("6502345681")));
148 EXPECT_TRUE(number5.ParseNumber("US", &parsed_phone)); 115 EXPECT_TRUE(number5.ParseNumber("US", &parsed_phone));
149 EXPECT_EQ(ASCIIToUTF16("(650) 234-5681"), parsed_phone); 116 EXPECT_EQ(ASCIIToUTF16("(650) 234-5681"), parsed_phone);
150 117
151 PhoneNumber::PhoneCombineHelper number6(AutofillType::PHONE_HOME); 118 PhoneNumber::PhoneCombineHelper number6;
152 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_CITY_CODE, 119 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_CITY_CODE,
153 ASCIIToUTF16("650"))); 120 ASCIIToUTF16("650")));
154 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_NUMBER, 121 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_NUMBER,
155 ASCIIToUTF16("234"))); 122 ASCIIToUTF16("234")));
156 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_NUMBER, 123 EXPECT_TRUE(number6.SetInfo(PHONE_HOME_NUMBER,
157 ASCIIToUTF16("5682"))); 124 ASCIIToUTF16("5682")));
158 EXPECT_TRUE(number6.ParseNumber("US", &parsed_phone)); 125 EXPECT_TRUE(number6.ParseNumber("US", &parsed_phone));
159 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone); 126 EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone);
160 } 127 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | chrome/browser/automation/testing_automation_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698