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

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: fix test expectations 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));
188 } 211 }
189 212
190 // Verifies that overwriting an address with N lines with one that has fewer 213 // 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. 214 // than N lines does not result in an address with blank lines at the end.
192 TEST(AddressTest, GetStreetAddressAfterOverwritingLongAddressWithShorterOne) { 215 TEST(AddressTest, GetStreetAddressAfterOverwritingLongAddressWithShorterOne) {
193 // Start with an address that has two lines. 216 // Start with an address that has two lines.
194 Address address; 217 Address address;
195 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 218 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
196 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 219 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
197 220
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Verifies that Address::SetInfo() rejects setting data for 264 // Verifies that Address::SetInfo() rejects setting data for
242 // ADDRESS_HOME_STREET_ADDRESS without newlines, as there is no good general way 265 // 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 266 // to parse that data into the consituent address lines. Addresses without
244 // newlines should be set properly. 267 // newlines should be set properly.
245 TEST(AddressTest, SetStreetAddress) { 268 TEST(AddressTest, SetStreetAddress) {
246 const base::string16 empty_street_address; 269 const base::string16 empty_street_address;
247 const base::string16 one_line_street_address = 270 const base::string16 one_line_street_address =
248 ASCIIToUTF16("456 New St., Apt. 17"); 271 ASCIIToUTF16("456 New St., Apt. 17");
249 const base::string16 multi_line_street_address = 272 const base::string16 multi_line_street_address =
250 ASCIIToUTF16("789 Fancy Pkwy.\n" 273 ASCIIToUTF16("789 Fancy Pkwy.\n"
251 "Unit 3.14"); 274 "Unit 3.14\n"
275 "Box 9");
252 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); 276 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS);
253 277
254 // Start with a non-empty address. 278 // Start with a non-empty address.
255 Address address; 279 Address address;
256 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 280 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
257 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 281 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
282 address.SetRawInfo(ADDRESS_HOME_LINE3, ASCIIToUTF16("and a half"));
258 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 283 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
259 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 284 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
285 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
260 286
261 // Attempting to set a one-line address should fail, as the single line might 287 // 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 288 // actually represent multiple logical lines, combined into one due to the
263 // user having to work around constraints imposed by the website. 289 // user having to work around constraints imposed by the website.
264 EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US")); 290 EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US"));
265 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 291 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
266 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 292 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
293 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3));
267 294
268 // Attempting to set a multi-line address should succeed. 295 // Attempting to set a multi-line address should succeed.
269 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US")); 296 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US"));
270 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."), 297 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."),
271 address.GetRawInfo(ADDRESS_HOME_LINE1)); 298 address.GetRawInfo(ADDRESS_HOME_LINE1));
272 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2)); 299 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2));
300 EXPECT_EQ(ASCIIToUTF16("Box 9"), address.GetRawInfo(ADDRESS_HOME_LINE3));
273 301
274 // Attempting to set an empty address should also succeed, and clear out the 302 // Attempting to set an empty address should also succeed, and clear out the
275 // previously stored data. 303 // previously stored data.
276 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 304 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
277 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); 305 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
306 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty());
278 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US")); 307 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US"));
279 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 308 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
280 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 309 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
310 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3));
281 } 311 }
282 312
283 // Verifies that Address::SetInfio() rejects setting data for 313 // Verifies that Address::SetInfio() rejects setting data for
284 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines. 314 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines.
285 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) { 315 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) {
286 // Start with a non-empty address. 316 // Start with a non-empty address.
287 Address address; 317 Address address;
288 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); 318 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
289 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); 319 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
290 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); 320 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" 373 ASCIIToUTF16("Address line 1"
344 "Address line 2" 374 "Address line 2"
345 "\n"), 375 "\n"),
346 "en-US")); 376 "en-US"));
347 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); 377 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
348 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); 378 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
349 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); 379 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
350 } 380 }
351 381
352 } // namespace autofill 382 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/address.cc ('k') | components/autofill/core/browser/autofill_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698