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 = "fr"; |
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); |
130 } | 133 } |
131 | 134 |
132 TEST_F(AddressValidatorTest, SubKeysNotExist) { | 135 TEST_F(AddressValidatorTest, SubKeysNotExist) { |
133 const std::string country_code = "OZ"; | 136 const std::string country_code = "OZ"; |
| 137 const std::string language = "en"; |
134 | 138 |
135 set_expected_status(AddressValidator::RULES_UNAVAILABLE); | 139 set_expected_status(AddressValidator::RULES_UNAVAILABLE); |
136 | 140 |
137 validator_->LoadRules(country_code); | 141 validator_->LoadRules(country_code); |
138 std::vector<std::string> sub_keys = | 142 std::vector<std::pair<std::string, std::string>> sub_keys = |
139 validator_->GetRegionSubKeys(country_code); | 143 validator_->GetRegionSubKeys(country_code, language); |
140 ASSERT_TRUE(sub_keys.empty()); | 144 ASSERT_TRUE(sub_keys.empty()); |
141 } | 145 } |
142 | 146 |
143 TEST_F(AddressValidatorTest, RegionHasRules) { | 147 TEST_F(AddressValidatorTest, RegionHasRules) { |
144 const std::vector<std::string>& region_codes = GetRegionCodes(); | 148 const std::vector<std::string>& region_codes = GetRegionCodes(); |
145 AddressData address; | 149 AddressData address; |
146 for (size_t i = 0; i < region_codes.size(); ++i) { | 150 for (size_t i = 0; i < region_codes.size(); ++i) { |
147 SCOPED_TRACE("For region: " + region_codes[i]); | 151 SCOPED_TRACE("For region: " + region_codes[i]); |
148 validator_->LoadRules(region_codes[i]); | 152 validator_->LoadRules(region_codes[i]); |
149 address.region_code = region_codes[i]; | 153 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); | 923 source_->set_failures_number(99); |
920 validator_->LoadRules("CH"); | 924 validator_->LoadRules("CH"); |
921 validator_->LoadRules("GB"); | 925 validator_->LoadRules("GB"); |
922 base::RunLoop().RunUntilIdle(); | 926 base::RunLoop().RunUntilIdle(); |
923 | 927 |
924 EXPECT_FALSE(load_rules_success_); | 928 EXPECT_FALSE(load_rules_success_); |
925 EXPECT_EQ(16, source_->attempts_number()); | 929 EXPECT_EQ(16, source_->attempts_number()); |
926 } | 930 } |
927 | 931 |
928 } // namespace autofill | 932 } // namespace autofill |
OLD | NEW |