Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 address.GetRawInfo(ADDRESS_HOME_LINE1)); | 254 address.GetRawInfo(ADDRESS_HOME_LINE1)); |
| 255 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 255 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 256 | 256 |
| 257 // An empty address should clear out all address lines. | 257 // An empty address should clear out all address lines. |
| 258 address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address); | 258 address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address); |
| 259 address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, empty_street_address); | 259 address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, empty_street_address); |
| 260 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 260 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); |
| 261 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 261 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Verifies that Address::SetInfo() rejects setting data for | 264 // Street addresses should be set properly. |
| 265 // ADDRESS_HOME_STREET_ADDRESS without newlines, as there is no good general way | |
| 266 // to parse that data into the consituent address lines. Addresses without | |
| 267 // newlines should be set properly. | |
| 268 TEST(AddressTest, SetStreetAddress) { | 265 TEST(AddressTest, SetStreetAddress) { |
| 269 const base::string16 empty_street_address; | 266 const base::string16 empty_street_address; |
| 270 const base::string16 one_line_street_address = | |
| 271 ASCIIToUTF16("456 New St., Apt. 17"); | |
| 272 const base::string16 multi_line_street_address = | 267 const base::string16 multi_line_street_address = |
| 273 ASCIIToUTF16("789 Fancy Pkwy.\n" | 268 ASCIIToUTF16("789 Fancy Pkwy.\n" |
| 274 "Unit 3.14\n" | 269 "Unit 3.14\n" |
| 275 "Box 9"); | 270 "Box 9"); |
| 271 const base::string16 single_line_street_address = | |
| 272 ASCIIToUTF16("123 Main, Apt 7"); | |
| 276 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); | 273 const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); |
| 277 | 274 |
| 278 // Start with a non-empty address. | 275 // Start with a non-empty address. |
| 279 Address address; | 276 Address address; |
| 280 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); | 277 address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); |
| 281 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); | 278 address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); |
| 282 address.SetRawInfo(ADDRESS_HOME_LINE3, ASCIIToUTF16("and a half")); | 279 address.SetRawInfo(ADDRESS_HOME_LINE3, ASCIIToUTF16("and a half")); |
| 283 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 280 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |
| 284 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 281 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |
| 285 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty()); | 282 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty()); |
| 286 | 283 |
| 287 // Attempting to set a one-line address should fail, as the single line might | |
| 288 // actually represent multiple logical lines, combined into one due to the | |
| 289 // user having to work around constraints imposed by the website. | |
| 290 EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US")); | |
| 291 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | |
| 292 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | |
| 293 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3)); | |
| 294 | |
| 295 // Attempting to set a multi-line address should succeed. | 284 // Attempting to set a multi-line address should succeed. |
| 296 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US")); | 285 EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US")); |
| 297 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."), | 286 EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."), |
| 298 address.GetRawInfo(ADDRESS_HOME_LINE1)); | 287 address.GetRawInfo(ADDRESS_HOME_LINE1)); |
| 299 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 288 EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 300 EXPECT_EQ(ASCIIToUTF16("Box 9"), address.GetRawInfo(ADDRESS_HOME_LINE3)); | 289 EXPECT_EQ(ASCIIToUTF16("Box 9"), address.GetRawInfo(ADDRESS_HOME_LINE3)); |
| 301 | 290 |
| 291 // Setting a single line street address should clear out subsequent lines. | |
| 292 EXPECT_TRUE(address.SetInfo(type, single_line_street_address, "en-US")); | |
| 293 EXPECT_EQ(single_line_street_address, address.GetRawInfo(ADDRESS_HOME_LINE1)); | |
| 294 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | |
| 295 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3)); | |
| 296 | |
| 302 // Attempting to set an empty address should also succeed, and clear out the | 297 // Attempting to set an empty address should also succeed, and clear out the |
| 303 // previously stored data. | 298 // previously stored data. |
| 304 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 299 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |
|
Ilya Sherman
2014/07/01 02:55:17
IMO it's good to start with all lines non-empty, a
Evan Stade
2014/07/01 23:18:52
fair enough, fixed
| |
| 305 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | |
| 306 EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE3).empty()); | |
| 307 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US")); | 300 EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US")); |
| 308 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 301 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); |
| 309 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 302 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 310 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3)); | 303 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE3)); |
| 311 } | 304 } |
| 312 | 305 |
| 313 // Verifies that Address::SetInfio() rejects setting data for | 306 // Verifies that Address::SetInfio() rejects setting data for |
| 314 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines. | 307 // ADDRESS_HOME_STREET_ADDRESS if the data has any interior blank lines. |
| 315 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) { | 308 TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) { |
| 316 // Start with a non-empty address. | 309 // Start with a non-empty address. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 ASCIIToUTF16("Address line 1" | 366 ASCIIToUTF16("Address line 1" |
| 374 "Address line 2" | 367 "Address line 2" |
| 375 "\n"), | 368 "\n"), |
| 376 "en-US")); | 369 "en-US")); |
| 377 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 370 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); |
| 378 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 371 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); |
| 379 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); | 372 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); |
| 380 } | 373 } |
| 381 | 374 |
| 382 } // namespace autofill | 375 } // namespace autofill |
| OLD | NEW |