OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "third_party/libaddressinput/chromium/chrome_address_validator.h" | 5 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 static AddressValidator* validator_; | 113 static AddressValidator* validator_; |
114 | 114 |
115 private: | 115 private: |
116 DISALLOW_COPY_AND_ASSIGN(LargeAddressValidatorTest); | 116 DISALLOW_COPY_AND_ASSIGN(LargeAddressValidatorTest); |
117 }; | 117 }; |
118 | 118 |
119 AddressValidator* LargeAddressValidatorTest::validator_ = NULL; | 119 AddressValidator* LargeAddressValidatorTest::validator_ = NULL; |
120 | 120 |
121 TEST_F(AddressValidatorTest, SubKeysLoaded) { | 121 TEST_F(AddressValidatorTest, SubKeysLoaded) { |
122 const std::string country_code = "US"; | 122 const std::string country_code = "US"; |
123 const std::string first_state = "AL"; | 123 const std::string state_code = "AL"; |
| 124 const std::string state_name = "Alabama"; |
| 125 const std::string language = "en"; |
124 | 126 |
125 validator_->LoadRules(country_code); | 127 validator_->LoadRules(country_code); |
126 std::vector<std::string> sub_keys = | 128 std::vector<std::pair<std::string, std::string>> sub_keys = |
127 validator_->GetRegionSubKeys(country_code); | 129 validator_->GetRegionSubKeys(country_code, language); |
128 ASSERT_FALSE(sub_keys.empty()); | 130 ASSERT_FALSE(sub_keys.empty()); |
129 ASSERT_EQ(sub_keys[0], first_state); | 131 ASSERT_EQ(state_code, sub_keys[0].first); |
| 132 ASSERT_EQ(state_name, sub_keys[0].second); |
| 133 } |
| 134 |
| 135 TEST_F(AddressValidatorTest, SubKeysLoaded_DefaultLanguage) { |
| 136 const std::string country_code = "CA"; |
| 137 const std::string province_code = "BC"; |
| 138 const std::string province_name = "British Columbia"; |
| 139 const std::string language = "en"; |
| 140 |
| 141 validator_->LoadRules(country_code); |
| 142 std::vector<std::pair<std::string, std::string>> sub_keys = |
| 143 validator_->GetRegionSubKeys(country_code, language); |
| 144 ASSERT_FALSE(sub_keys.empty()); |
| 145 ASSERT_EQ(province_code, sub_keys[1].first); |
| 146 ASSERT_EQ(province_name, sub_keys[1].second); |
| 147 } |
| 148 |
| 149 TEST_F(AddressValidatorTest, SubKeysLoaded_NonDefaultLanguage) { |
| 150 const std::string country_code = "CA"; |
| 151 const std::string province_code = "BC"; |
| 152 const std::string province_name = "Colombie-Britannique"; |
| 153 const std::string language = "fr"; |
| 154 |
| 155 validator_->LoadRules(country_code); |
| 156 std::vector<std::pair<std::string, std::string>> sub_keys = |
| 157 validator_->GetRegionSubKeys(country_code, language); |
| 158 ASSERT_FALSE(sub_keys.empty()); |
| 159 ASSERT_EQ(province_code, sub_keys[1].first); |
| 160 ASSERT_EQ(province_name, sub_keys[1].second); |
| 161 } |
| 162 |
| 163 TEST_F(AddressValidatorTest, SubKeysLoaded_LanguageNotAvailable) { |
| 164 const std::string country_code = "CA"; |
| 165 const std::string province_code = "BC"; |
| 166 const std::string province_name = "British Columbia"; |
| 167 const std::string language = "es"; |
| 168 |
| 169 validator_->LoadRules(country_code); |
| 170 std::vector<std::pair<std::string, std::string>> sub_keys = |
| 171 validator_->GetRegionSubKeys(country_code, language); |
| 172 ASSERT_FALSE(sub_keys.empty()); |
| 173 ASSERT_EQ(province_code, sub_keys[1].first); |
| 174 ASSERT_EQ(province_name, sub_keys[1].second); |
| 175 } |
| 176 |
| 177 TEST_F(AddressValidatorTest, SubKeysLoaded_NamesNotAvailable) { |
| 178 const std::string country_code = "ES"; |
| 179 const std::string province_code = "A Coruña"; |
| 180 const std::string province_name = "A Coruña"; |
| 181 const std::string language = "es"; |
| 182 |
| 183 validator_->LoadRules(country_code); |
| 184 std::vector<std::pair<std::string, std::string>> sub_keys = |
| 185 validator_->GetRegionSubKeys(country_code, language); |
| 186 ASSERT_FALSE(sub_keys.empty()); |
| 187 ASSERT_EQ(province_code, sub_keys[0].first); |
| 188 ASSERT_EQ(province_name, sub_keys[0].second); |
130 } | 189 } |
131 | 190 |
132 TEST_F(AddressValidatorTest, SubKeysNotExist) { | 191 TEST_F(AddressValidatorTest, SubKeysNotExist) { |
133 const std::string country_code = "OZ"; | 192 const std::string country_code = "OZ"; |
| 193 const std::string language = "en"; |
134 | 194 |
135 set_expected_status(AddressValidator::RULES_UNAVAILABLE); | 195 set_expected_status(AddressValidator::RULES_UNAVAILABLE); |
136 | 196 |
137 validator_->LoadRules(country_code); | 197 validator_->LoadRules(country_code); |
138 std::vector<std::string> sub_keys = | 198 std::vector<std::pair<std::string, std::string>> sub_keys = |
139 validator_->GetRegionSubKeys(country_code); | 199 validator_->GetRegionSubKeys(country_code, language); |
140 ASSERT_TRUE(sub_keys.empty()); | 200 ASSERT_TRUE(sub_keys.empty()); |
141 } | 201 } |
142 | 202 |
143 TEST_F(AddressValidatorTest, RegionHasRules) { | 203 TEST_F(AddressValidatorTest, RegionHasRules) { |
144 const std::vector<std::string>& region_codes = GetRegionCodes(); | 204 const std::vector<std::string>& region_codes = GetRegionCodes(); |
145 AddressData address; | 205 AddressData address; |
146 for (size_t i = 0; i < region_codes.size(); ++i) { | 206 for (size_t i = 0; i < region_codes.size(); ++i) { |
147 SCOPED_TRACE("For region: " + region_codes[i]); | 207 SCOPED_TRACE("For region: " + region_codes[i]); |
148 validator_->LoadRules(region_codes[i]); | 208 validator_->LoadRules(region_codes[i]); |
149 address.region_code = region_codes[i]; | 209 address.region_code = region_codes[i]; |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 source_->set_failures_number(99); | 979 source_->set_failures_number(99); |
920 validator_->LoadRules("CH"); | 980 validator_->LoadRules("CH"); |
921 validator_->LoadRules("GB"); | 981 validator_->LoadRules("GB"); |
922 base::RunLoop().RunUntilIdle(); | 982 base::RunLoop().RunUntilIdle(); |
923 | 983 |
924 EXPECT_FALSE(load_rules_success_); | 984 EXPECT_FALSE(load_rules_success_); |
925 EXPECT_EQ(16, source_->attempts_number()); | 985 EXPECT_EQ(16, source_->attempts_number()); |
926 } | 986 } |
927 | 987 |
928 } // namespace autofill | 988 } // namespace autofill |
OLD | NEW |