| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  142   } |  142   } | 
|  143  |  143  | 
|  144   // Make sure that garbage values don't match when the country code is empty. |  144   // Make sure that garbage values don't match when the country code is empty. | 
|  145   address.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16()); |  145   address.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16()); | 
|  146   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |  146   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 
|  147   ServerFieldTypeSet matching_types; |  147   ServerFieldTypeSet matching_types; | 
|  148   address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); |  148   address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); | 
|  149   EXPECT_EQ(0U, matching_types.size()); |  149   EXPECT_EQ(0U, matching_types.size()); | 
|  150 } |  150 } | 
|  151  |  151  | 
|  152 // Verifies that Address::GetInfo() can correctly return a concatenated full |  152 // Verifies that Address::GetInfo() correctly combines address lines. | 
|  153 // street address. |  | 
|  154 TEST(AddressTest, GetStreetAddress) { |  153 TEST(AddressTest, GetStreetAddress) { | 
 |  154   const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); | 
 |  155  | 
|  155   // Address has no address lines. |  156   // Address has no address lines. | 
|  156   Address address; |  157   Address address; | 
|  157   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |  158   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 
|  158   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |  159   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 
|  159  |  | 
|  160   AutofillType type = AutofillType(HTML_TYPE_STREET_ADDRESS, HTML_MODE_NONE); |  | 
|  161   EXPECT_EQ(base::string16(), address.GetInfo(type, "en-US")); |  160   EXPECT_EQ(base::string16(), address.GetInfo(type, "en-US")); | 
|  162  |  161  | 
|  163   // Address has only line 1. |  162   // Address has only line 1. | 
|  164   address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); |  163   address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); | 
|  165   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |  164   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 
|  166   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |  165   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 
|  167  |  166   EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), address.GetInfo(type, "en-US")); | 
|  168   EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), |  | 
|  169             address.GetInfo(type, "en-US")); |  | 
|  170  |  167  | 
|  171   // Address has lines 1 and 2. |  168   // Address has lines 1 and 2. | 
|  172   address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); |  169   address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); | 
|  173   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |  170   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 
|  174   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |  171   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 
|  175  |  172   EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n" | 
 |  173                          "Apt. 42"), | 
 |  174             address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); | 
|  176   EXPECT_EQ(ASCIIToUTF16("123 Example Ave., Apt. 42"), |  175   EXPECT_EQ(ASCIIToUTF16("123 Example Ave., Apt. 42"), | 
|  177             address.GetInfo(type, "en-US")); |  176             address.GetInfo(type, "en-US")); | 
|  178 } |  177 } | 
|  179  |  178  | 
 |  179 // Verifies that Address::SetRawInfo() is able to split address lines correctly. | 
 |  180 TEST(AddressTest, SetRawStreetAddress) { | 
 |  181   const base::string16 empty_street_address; | 
 |  182   const base::string16 short_street_address = ASCIIToUTF16("456 Nowhere Ln."); | 
 |  183   const base::string16 long_street_address = | 
 |  184       ASCIIToUTF16("123 Example Ave.\n" | 
 |  185                    "Apt. 42\n" | 
 |  186                    "(The one with the blue door)"); | 
 |  187  | 
 |  188   Address address; | 
 |  189   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  190   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  191  | 
 |  192   // Address lines beyond the first two are simply dropped. | 
 |  193   address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address); | 
 |  194   EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), | 
 |  195             address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  196   EXPECT_EQ(ASCIIToUTF16("Apt. 42"), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  197  | 
 |  198   // A short address should clear out unused address lines. | 
 |  199   address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, short_street_address); | 
 |  200   EXPECT_EQ(ASCIIToUTF16("456 Nowhere Ln."), | 
 |  201             address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  202   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  203  | 
 |  204   // An empty address should clear out all address lines. | 
 |  205   address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address); | 
 |  206   address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, empty_street_address); | 
 |  207   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  208   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  209 } | 
 |  210  | 
|  180 // Verifies that Address::SetInfo() rejects setting data for |  211 // Verifies that Address::SetInfo() rejects setting data for | 
|  181 // HTML_TYPE_STREET_ADDRESS, as there is no good general way to parse that data |  212 // ADDRESS_HOME_STREET_ADDRESS without newlines, as there is no good general way | 
|  182 // into the consituent address lines. |  213 // to parse that data into the consituent address lines. Addresses without | 
 |  214 // newlines should be set properly. | 
|  183 TEST(AddressTest, SetStreetAddress) { |  215 TEST(AddressTest, SetStreetAddress) { | 
|  184   // Address has no address lines. |  216   const base::string16 empty_street_address; | 
 |  217   const base::string16 one_line_street_address = | 
 |  218       ASCIIToUTF16("456 New St., Apt. 17"); | 
 |  219   const base::string16 multi_line_street_address = | 
 |  220       ASCIIToUTF16("789 Fancy Pkwy.\n" | 
 |  221                    "Unit 3.14"); | 
 |  222   const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS); | 
 |  223  | 
 |  224   // Start with a non-empty address. | 
|  185   Address address; |  225   Address address; | 
|  186   address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); |  226   address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave.")); | 
|  187   address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); |  227   address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42")); | 
|  188   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |  228   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 
|  189   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |  229   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 
|  190  |  230  | 
|  191   AutofillType type = AutofillType(HTML_TYPE_STREET_ADDRESS, HTML_MODE_NONE); |  231   // Attempting to set a one-line address should fail, as the single line might | 
|  192   base::string16 street_address = ASCIIToUTF16("456 New St., Apt. 17"); |  232   // actually represent multiple logical lines, combined into one due to the | 
|  193   EXPECT_FALSE(address.SetInfo(type, street_address, "en-US")); |  233   // user having to work around constraints imposed by the website. | 
|  194   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); |  234   EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US")); | 
|  195   EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); |  235   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  236   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  237  | 
 |  238   // Attempting to set a multi-line address should succeed. | 
 |  239   EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US")); | 
 |  240   EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."), | 
 |  241             address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  242   EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
 |  243  | 
 |  244   // Attempting to set an empty address should also succeed, and clear out the | 
 |  245   // previously stored data. | 
 |  246   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty()); | 
 |  247   EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty()); | 
 |  248   EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US")); | 
 |  249   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1)); | 
 |  250   EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2)); | 
|  196 } |  251 } | 
|  197  |  252  | 
|  198 }  // namespace autofill |  253 }  // namespace autofill | 
| OLD | NEW |