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

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

Issue 322453003: autocomplete: support address-line3, address-level{1,2,3} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update autofill_metrics.cc Created 6 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
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 <string> 5 #include <string>
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/address.h" 9 #include "components/autofill/core/browser/address.h"
10 #include "components/autofill/core/browser/autofill_type.h" 10 #include "components/autofill/core/browser/autofill_type.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 // Verifies that Address::GetInfo() correctly combines address lines. 154 // Verifies that Address::GetInfo() correctly combines address lines.
155 TEST(AddressTest, GetStreetAddress) { 155 TEST(AddressTest, GetStreetAddress) {
156 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); 156 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS);
157 157
158 // Address has no address lines. 158 // Address has no address lines.
159 Address address; 159 Address address;
160 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 160 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
161 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 161 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
162 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
162 EXPECT_EQ(base::string16(), address.GetInfo(type, "en-US")); 163 EXPECT_EQ(base::string16(), address.GetInfo(type, "en-US"));
163 164
164 // Address has only line 1. 165 // Address has only line 1.
165 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 166 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
166 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 167 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
167 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 168 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
169 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
168 EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), address.GetInfo(type, "en-US")); 170 EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), address.GetInfo(type, "en-US"));
169 171
170 // Address has only line 2. 172 // Address has only line 2.
171 address.SetRawInfo(ADDRESS_HOME_LINE1, base::string16()); 173 address.SetRawInfo(ADDRESS_HOME_LINE1, base::string16());
172 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt 42.")); 174 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt 42."));
173 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 175 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
174 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 176 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
177 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
175 EXPECT_EQ(ASCIIToUTF16("\nApt 42."), address.GetInfo(type, "en-US")); 178 EXPECT_EQ(ASCIIToUTF16("\nApt 42."), address.GetInfo(type, "en-US"));
176 179
177 // Address has lines 1 and 2. 180 // Address has lines 1 and 2.
178 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 181 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
179 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 182 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
180 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 183 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
181 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 184 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
185 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
182 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n" 186 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
183 "Apt. 42"), 187 "Apt. 42"),
184 address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); 188 address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
185 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n" 189 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
186 "Apt. 42"), 190 "Apt. 42"),
187 address.GetInfo(type, "en-US")); 191 address.GetInfo(type, "en-US"));
192
193 // A wild third line appears.
194 address.SetRawInfo(ADDRESS_HOME_LINE3, ASCIIToUTF16("Living room couch"));
195 EXPECT_EQ(ASCIIToUTF16("Living room couch"),
196 address.GetRawInfo(ADDRESS_HOME_LINE3));
197 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
198 "Apt. 42\n"
199 "Living room couch"),
200 address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
201
202 // The second line vanishes.
203 address.SetRawInfo(ADDRESS_HOME_LINE2, base::string16());
204 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
205 EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
206 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
207 EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
208 "\n"
209 "Living room couch"),
210 address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
211
Ilya Sherman 2014/06/12 22:37:54 nit: Spurious newline.
Evan Stade 2014/06/13 01:49:43 baleted
188 } 212 }
189 213
190 // Verifies that overwriting an address with N lines with one that has fewer 214 // Verifies that overwriting an address with N lines with one that has fewer
191 // than N lines does not result in an address with blank lines at the end. 215 // than N lines does not result in an address with blank lines at the end.
192 TEST(AddressTest, GetStreetAddressAfterOverwritingLongAddressWithShorterOne) { 216 TEST(AddressTest, GetStreetAddressAfterOverwritingLongAddressWithShorterOne) {
193 // Start with an address that has two lines. 217 // Start with an address that has two lines.
194 Address address; 218 Address address;
195 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 219 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
196 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 220 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
197 221
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Verifies that Address::SetInfo() rejects setting data for 265 // Verifies that Address::SetInfo() rejects setting data for
242 // ADDRESS_HOME_STREET_ADDRESS without newlines, as there is no good general way 266 // ADDRESS_HOME_STREET_ADDRESS without newlines, as there is no good general way
243 // to parse that data into the consituent address lines. Addresses without 267 // to parse that data into the consituent address lines. Addresses without
244 // newlines should be set properly. 268 // newlines should be set properly.
245 TEST(AddressTest, SetStreetAddress) { 269 TEST(AddressTest, SetStreetAddress) {
246 const base::string16 empty_street_address; 270 const base::string16 empty_street_address;
247 const base::string16 one_line_street_address = 271 const base::string16 one_line_street_address =
248 ASCIIToUTF16("456 New St., Apt. 17"); 272 ASCIIToUTF16("456 New St., Apt. 17");
249 const base::string16 multi_line_street_address = 273 const base::string16 multi_line_street_address =
250 ASCIIToUTF16("789 Fancy Pkwy.\n" 274 ASCIIToUTF16("789 Fancy Pkwy.\n"
251 "Unit 3.14"); 275 "Unit 3.14\n"
276 "Box 9");
252 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); 277 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS);
253 278
254 // Start with a non-empty address. 279 // Start with a non-empty address.
255 Address address; 280 Address address;
256 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 281 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
257 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 282 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
283 address.SetRawInfo(ADDRESS_HOME_LINE3, ASCIIToUTF16("and a half"));
258 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 284 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
259 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 285 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
286 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
260 287
261 // Attempting to set a one-line address should fail, as the single line might 288 // Attempting to set a one-line address should fail, as the single line might
262 // actually represent multiple logical lines, combined into one due to the 289 // actually represent multiple logical lines, combined into one due to the
263 // user having to work around constraints imposed by the website. 290 // user having to work around constraints imposed by the website.
264 EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US")); 291 EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US"));
265 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 292 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
266 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 293 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
294 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3));
267 295
268 // Attempting to set a multi-line address should succeed. 296 // Attempting to set a multi-line address should succeed.
269 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US")); 297 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US"));
270 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."), 298 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."),
271 address.GetRawInfo(ADDRESS_HOME_LINE1)); 299 address.GetRawInfo(ADDRESS_HOME_LINE1));
272 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2)); 300 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2));
301 EXPECT_EQ(ASCIIToUTF16("Box 9"), address.GetRawInfo(ADDRESS_HOME_LINE3));
273 302
274 // Attempting to set an empty address should also succeed, and clear out the 303 // Attempting to set an empty address should also succeed, and clear out the
275 // previously stored data. 304 // previously stored data.
276 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 305 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
277 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 306 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
307 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
278 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US")); 308 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US"));
279 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 309 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
280 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 310 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
311 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3));
281 } 312 }
282 313
283 // Verifies that Address::SetInfio() rejects setting data for 314 // Verifies that Address::SetInfio() rejects setting data for
284 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines. 315 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines.
285 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) { 316 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) {
286 // Start with a non-empty address. 317 // Start with a non-empty address.
287 Address address; 318 Address address;
288 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 319 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
289 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 320 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
290 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 321 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ASCIIToUTF16("Address line 1" 374 ASCIIToUTF16("Address line 1"
344 "Address line 2" 375 "Address line 2"
345 "\n"), 376 "\n"),
346 "en-US")); 377 "en-US"));
347 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 378 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
348 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 379 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
349 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); 380 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
350 } 381 }
351 382
352 } // namespace autofill 383 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698