| 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/address.h" | 10 #include "components/autofill/core/browser/address.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 DISALLOW_COPY_AND_ASSIGN(AddressTest); | 29 DISALLOW_COPY_AND_ASSIGN(AddressTest); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Test that country codes are properly decoded as country names. | 32 // Test that country codes are properly decoded as country names. |
| 33 TEST_F(AddressTest, GetCountry) { | 33 TEST_F(AddressTest, GetCountry) { |
| 34 Address address; | 34 Address address; |
| 35 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 35 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 36 | 36 |
| 37 // Make sure that nothing breaks when the country code is missing. | 37 // Make sure that nothing breaks when the country code is missing. |
| 38 base::string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 38 base::string16 country = |
| 39 address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 39 EXPECT_EQ(base::string16(), country); | 40 EXPECT_EQ(base::string16(), country); |
| 40 | 41 |
| 41 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"), "en-US"); | 42 address.SetInfo( |
| 42 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 43 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("US"), "en-US"); |
| 44 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 43 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 45 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 44 | 46 |
| 45 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 47 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
| 46 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 48 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 47 EXPECT_EQ(ASCIIToUTF16("Canada"), country); | 49 EXPECT_EQ(ASCIIToUTF16("Canada"), country); |
| 48 } | 50 } |
| 49 | 51 |
| 50 // Test that we properly detect country codes appropriate for each country. | 52 // Test that we properly detect country codes appropriate for each country. |
| 51 TEST_F(AddressTest, SetCountry) { | 53 TEST_F(AddressTest, SetCountry) { |
| 52 Address address; | 54 Address address; |
| 53 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 55 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 54 | 56 |
| 55 // Test basic conversion. | 57 // Test basic conversion. |
| 56 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"), "en-US"); | 58 address.SetInfo( |
| 57 base::string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 59 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("United States"), |
| 60 "en-US"); |
| 61 base::string16 country = |
| 62 address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 58 EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 63 EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 59 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 64 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 60 | 65 |
| 61 // Test basic synonym detection. | 66 // Test basic synonym detection. |
| 62 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA"), "en-US"); | 67 address.SetInfo( |
| 63 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 68 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA"), "en-US"); |
| 69 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 64 EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 70 EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 65 EXPECT_EQ(ASCIIToUTF16("United States"), country); | 71 EXPECT_EQ(ASCIIToUTF16("United States"), country); |
| 66 | 72 |
| 67 // Test case-insensitivity. | 73 // Test case-insensitivity. |
| 68 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA"), "en-US"); | 74 address.SetInfo( |
| 69 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 75 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("canADA"), "en-US"); |
| 76 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 70 EXPECT_EQ(ASCIIToUTF16("CA"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 77 EXPECT_EQ(ASCIIToUTF16("CA"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 71 EXPECT_EQ(ASCIIToUTF16("Canada"), country); | 78 EXPECT_EQ(ASCIIToUTF16("Canada"), country); |
| 72 | 79 |
| 73 // Test country code detection. | 80 // Test country code detection. |
| 74 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP"), "en-US"); | 81 address.SetInfo( |
| 75 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 82 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("JP"), "en-US"); |
| 83 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 76 EXPECT_EQ(ASCIIToUTF16("JP"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 84 EXPECT_EQ(ASCIIToUTF16("JP"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 77 EXPECT_EQ(ASCIIToUTF16("Japan"), country); | 85 EXPECT_EQ(ASCIIToUTF16("Japan"), country); |
| 78 | 86 |
| 79 // Test that we ignore unknown countries. | 87 // Test that we ignore unknown countries. |
| 80 address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown"), "en-US"); | 88 address.SetInfo( |
| 81 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); | 89 AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("Unknown"), "en-US"); |
| 90 country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US"); |
| 82 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 91 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 83 EXPECT_EQ(base::string16(), country); | 92 EXPECT_EQ(base::string16(), country); |
| 84 } | 93 } |
| 85 | 94 |
| 86 // Test that we properly match typed values to stored country data. | 95 // Test that we properly match typed values to stored country data. |
| 87 TEST_F(AddressTest, IsCountry) { | 96 TEST_F(AddressTest, IsCountry) { |
| 88 Address address; | 97 Address address; |
| 89 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); | 98 address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
| 90 | 99 |
| 91 const char* const kValidMatches[] = { | 100 const char* const kValidMatches[] = { |
| 92 "United States", | 101 "United States", |
| 93 "USA", | 102 "USA", |
| 94 "US", | 103 "US", |
| 95 "United states", | 104 "United states", |
| 96 "us" | 105 "us" |
| 97 }; | 106 }; |
| 98 for (size_t i = 0; i < arraysize(kValidMatches); ++i) { | 107 for (size_t i = 0; i < arraysize(kValidMatches); ++i) { |
| 99 SCOPED_TRACE(kValidMatches[i]); | 108 SCOPED_TRACE(kValidMatches[i]); |
| 100 FieldTypeSet matching_types; | 109 ServerFieldTypeSet matching_types; |
| 101 address.GetMatchingTypes(ASCIIToUTF16(kValidMatches[i]), "US", | 110 address.GetMatchingTypes(ASCIIToUTF16(kValidMatches[i]), "US", |
| 102 &matching_types); | 111 &matching_types); |
| 103 ASSERT_EQ(1U, matching_types.size()); | 112 ASSERT_EQ(1U, matching_types.size()); |
| 104 EXPECT_EQ(ADDRESS_HOME_COUNTRY, *matching_types.begin()); | 113 EXPECT_EQ(ADDRESS_HOME_COUNTRY, *matching_types.begin()); |
| 105 } | 114 } |
| 106 | 115 |
| 107 const char* const kInvalidMatches[] = { | 116 const char* const kInvalidMatches[] = { |
| 108 "United", | 117 "United", |
| 109 "Garbage" | 118 "Garbage" |
| 110 }; | 119 }; |
| 111 for (size_t i = 0; i < arraysize(kInvalidMatches); ++i) { | 120 for (size_t i = 0; i < arraysize(kInvalidMatches); ++i) { |
| 112 FieldTypeSet matching_types; | 121 ServerFieldTypeSet matching_types; |
| 113 address.GetMatchingTypes(ASCIIToUTF16(kInvalidMatches[i]), "US", | 122 address.GetMatchingTypes(ASCIIToUTF16(kInvalidMatches[i]), "US", |
| 114 &matching_types); | 123 &matching_types); |
| 115 EXPECT_EQ(0U, matching_types.size()); | 124 EXPECT_EQ(0U, matching_types.size()); |
| 116 } | 125 } |
| 117 | 126 |
| 118 // Make sure that garbage values don't match when the country code is empty. | 127 // Make sure that garbage values don't match when the country code is empty. |
| 119 address.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16()); | 128 address.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16()); |
| 120 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 129 EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 121 FieldTypeSet matching_types; | 130 ServerFieldTypeSet matching_types; |
| 122 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); | 131 address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); |
| 123 EXPECT_EQ(0U, matching_types.size()); | 132 EXPECT_EQ(0U, matching_types.size()); |
| 124 } | 133 } |
| 125 | 134 |
| 126 } // namespace autofill | 135 } // namespace autofill |
| OLD | NEW |