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

Side by Side Diff: components/autofill/browser/phone_field_unittest.cc

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 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
« no previous file with comments | « components/autofill/browser/phone_field.cc ('k') | components/autofill/browser/phone_number.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/browser/autofill_field.h"
9 #include "components/autofill/browser/autofill_scanner.h"
10 #include "components/autofill/browser/phone_field.h"
11 #include "components/autofill/core/common/form_field_data.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace autofill {
15
16 class PhoneFieldTest : public testing::Test {
17 public:
18 PhoneFieldTest() {}
19
20 protected:
21 ScopedVector<const AutofillField> list_;
22 scoped_ptr<PhoneField> field_;
23 FieldTypeMap field_type_map_;
24
25 // Downcast for tests.
26 static PhoneField* Parse(AutofillScanner* scanner) {
27 return static_cast<PhoneField*>(PhoneField::Parse(scanner));
28 }
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(PhoneFieldTest);
32 };
33
34 TEST_F(PhoneFieldTest, Empty) {
35 AutofillScanner scanner(list_.get());
36 field_.reset(Parse(&scanner));
37 ASSERT_EQ(static_cast<PhoneField*>(NULL), field_.get());
38 }
39
40 TEST_F(PhoneFieldTest, NonParse) {
41 list_.push_back(new AutofillField);
42 AutofillScanner scanner(list_.get());
43 field_.reset(Parse(&scanner));
44 ASSERT_EQ(static_cast<PhoneField*>(NULL), field_.get());
45 }
46
47 TEST_F(PhoneFieldTest, ParseOneLinePhone) {
48 FormFieldData field;
49 field.form_control_type = "text";
50
51 field.label = ASCIIToUTF16("Phone");
52 field.name = ASCIIToUTF16("phone");
53 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1")));
54
55 AutofillScanner scanner(list_.get());
56 field_.reset(Parse(&scanner));
57 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
58 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
59 ASSERT_TRUE(
60 field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
61 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
62 }
63
64 TEST_F(PhoneFieldTest, ParseTwoLinePhone) {
65 FormFieldData field;
66 field.form_control_type = "text";
67
68 field.label = ASCIIToUTF16("Area Code");
69 field.name = ASCIIToUTF16("area code");
70 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1")));
71
72 field.label = ASCIIToUTF16("Phone");
73 field.name = ASCIIToUTF16("phone");
74 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2")));
75
76 AutofillScanner scanner(list_.get());
77 field_.reset(Parse(&scanner));
78 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
79 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
80 ASSERT_TRUE(
81 field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
82 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
83 ASSERT_TRUE(
84 field_type_map_.find(ASCIIToUTF16("phone2")) != field_type_map_.end());
85 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone2")]);
86 }
87
88 TEST_F(PhoneFieldTest, ThreePartPhoneNumber) {
89 // Phone in format <field> - <field> - <field> could be either
90 // <area code> - <prefix> - <suffix>, or
91 // <country code> - <area code> - <phone>. The only distinguishing feature is
92 // size: <prefix> is no bigger than 3 characters, and <suffix> is no bigger
93 // than 4.
94 FormFieldData field;
95 field.form_control_type = "text";
96
97 field.label = ASCIIToUTF16("Phone:");
98 field.name = ASCIIToUTF16("dayphone1");
99 field.max_length = 0;
100 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1")));
101
102 field.label = ASCIIToUTF16("-");
103 field.name = ASCIIToUTF16("dayphone2");
104 field.max_length = 3;
105 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2")));
106
107 field.label = ASCIIToUTF16("-");
108 field.name = ASCIIToUTF16("dayphone3");
109 field.max_length = 4;
110 list_.push_back(new AutofillField(field, ASCIIToUTF16("suffix3")));
111
112 field.label = ASCIIToUTF16("ext.:");
113 field.name = ASCIIToUTF16("dayphone4");
114 field.max_length = 0;
115 list_.push_back(new AutofillField(field, ASCIIToUTF16("ext4")));
116
117 AutofillScanner scanner(list_.get());
118 field_.reset(Parse(&scanner));
119 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
120 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
121 ASSERT_TRUE(
122 field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
123 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
124 ASSERT_TRUE(
125 field_type_map_.find(ASCIIToUTF16("prefix2")) != field_type_map_.end());
126 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("prefix2")]);
127 ASSERT_TRUE(
128 field_type_map_.find(ASCIIToUTF16("suffix3")) != field_type_map_.end());
129 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("suffix3")]);
130 EXPECT_TRUE(
131 field_type_map_.find(ASCIIToUTF16("ext4")) == field_type_map_.end());
132 }
133
134 // This scenario of explicitly labeled "prefix" and "suffix" phone numbers
135 // encountered in http://crbug.com/40694 with page
136 // https://www.wrapables.com/jsp/Signup.jsp.
137 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix) {
138 FormFieldData field;
139 field.form_control_type = "text";
140
141 field.label = ASCIIToUTF16("Phone:");
142 field.name = ASCIIToUTF16("area");
143 list_.push_back(new AutofillField(field, ASCIIToUTF16("areacode1")));
144
145 field.label = string16();
146 field.name = ASCIIToUTF16("prefix");
147 list_.push_back(new AutofillField(field, ASCIIToUTF16("prefix2")));
148
149 field.label = string16();
150 field.name = ASCIIToUTF16("suffix");
151 list_.push_back(new AutofillField(field, ASCIIToUTF16("suffix3")));
152
153 AutofillScanner scanner(list_.get());
154 field_.reset(Parse(&scanner));
155 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
156 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
157 ASSERT_TRUE(
158 field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
159 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
160 ASSERT_TRUE(
161 field_type_map_.find(ASCIIToUTF16("prefix2")) != field_type_map_.end());
162 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("prefix2")]);
163 ASSERT_TRUE(
164 field_type_map_.find(ASCIIToUTF16("suffix3")) != field_type_map_.end());
165 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("suffix3")]);
166 }
167
168 TEST_F(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2) {
169 FormFieldData field;
170 field.form_control_type = "text";
171
172 field.label = ASCIIToUTF16("(");
173 field.name = ASCIIToUTF16("phone1");
174 field.max_length = 3;
175 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone1")));
176
177 field.label = ASCIIToUTF16(")");
178 field.name = ASCIIToUTF16("phone2");
179 field.max_length = 3;
180 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone2")));
181
182 field.label = string16();
183 field.name = ASCIIToUTF16("phone3");
184 field.max_length = 4;
185 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone3")));
186
187 AutofillScanner scanner(list_.get());
188 field_.reset(Parse(&scanner));
189 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
190 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
191 ASSERT_TRUE(
192 field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
193 EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("phone1")]);
194 ASSERT_TRUE(
195 field_type_map_.find(ASCIIToUTF16("phone2")) != field_type_map_.end());
196 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone2")]);
197 ASSERT_TRUE(
198 field_type_map_.find(ASCIIToUTF16("phone3")) != field_type_map_.end());
199 EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone3")]);
200 }
201
202 TEST_F(PhoneFieldTest, CountryAndCityAndPhoneNumber) {
203 // Phone in format <country code>:3 - <city and number>:10
204 // The |maxlength| is considered, otherwise it's too broad.
205 FormFieldData field;
206 field.form_control_type = "text";
207
208 field.label = ASCIIToUTF16("Phone Number");
209 field.name = ASCIIToUTF16("CountryCode");
210 field.max_length = 3;
211 list_.push_back(new AutofillField(field, ASCIIToUTF16("country")));
212
213 field.label = ASCIIToUTF16("Phone Number");
214 field.name = ASCIIToUTF16("PhoneNumber");
215 field.max_length = 10;
216 list_.push_back(new AutofillField(field, ASCIIToUTF16("phone")));
217
218 AutofillScanner scanner(list_.get());
219 field_.reset(Parse(&scanner));
220 ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
221 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
222 ASSERT_TRUE(
223 field_type_map_.find(ASCIIToUTF16("country")) != field_type_map_.end());
224 EXPECT_EQ(PHONE_HOME_COUNTRY_CODE, field_type_map_[ASCIIToUTF16("country")]);
225 ASSERT_TRUE(
226 field_type_map_.find(ASCIIToUTF16("phone")) != field_type_map_.end());
227 EXPECT_EQ(PHONE_HOME_CITY_AND_NUMBER, field_type_map_[ASCIIToUTF16("phone")]);
228 }
229
230 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/phone_field.cc ('k') | components/autofill/browser/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698