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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 class AddressValidatorTest : public testing::Test, LoadRulesListener { | 55 class AddressValidatorTest : public testing::Test, LoadRulesListener { |
56 protected: | 56 protected: |
57 AddressValidatorTest() | 57 AddressValidatorTest() |
58 : validator_(new AddressValidator( | 58 : validator_(new AddressValidator( |
59 std::unique_ptr<Source>(new TestdataSource(true)), | 59 std::unique_ptr<Source>(new TestdataSource(true)), |
60 std::unique_ptr<Storage>(new NullStorage), | 60 std::unique_ptr<Storage>(new NullStorage), |
61 this)) { | 61 this)) { |
62 validator_->LoadRules("US"); | 62 validator_->LoadRules("US"); |
63 } | 63 } |
64 | 64 |
65 void set_expected_status(AddressValidator::Status expected_status) { | |
66 expected_status_ = expected_status; | |
67 } | |
68 | |
65 virtual ~AddressValidatorTest() {} | 69 virtual ~AddressValidatorTest() {} |
66 | 70 |
67 const std::unique_ptr<AddressValidator> validator_; | 71 const std::unique_ptr<AddressValidator> validator_; |
68 | 72 |
69 private: | 73 private: |
70 // LoadRulesListener implementation. | 74 // LoadRulesListener implementation. |
71 void OnAddressValidationRulesLoaded(const std::string& country_code, | 75 void OnAddressValidationRulesLoaded(const std::string& country_code, |
72 bool success) override { | 76 bool success) override { |
73 AddressData address_data; | 77 AddressData address_data; |
74 address_data.region_code = country_code; | 78 address_data.region_code = country_code; |
75 FieldProblemMap dummy; | 79 FieldProblemMap dummy; |
76 AddressValidator::Status status = | 80 AddressValidator::Status status = |
77 validator_->ValidateAddress(address_data, NULL, &dummy); | 81 validator_->ValidateAddress(address_data, NULL, &dummy); |
78 ASSERT_EQ(success, status == AddressValidator::SUCCESS); | 82 ASSERT_EQ(success, status == expected_status_); |
Mathieu
2017/06/29 19:11:25
I think the expected value usually comes first in
Parastoo
2017/06/29 21:13:24
Done.
| |
79 } | 83 } |
80 | 84 |
85 AddressValidator::Status expected_status_ = AddressValidator::SUCCESS; | |
86 | |
81 DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest); | 87 DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest); |
82 }; | 88 }; |
83 | 89 |
84 // Use this test fixture if you're going to use a region with a large set of | 90 // Use this test fixture if you're going to use a region with a large set of |
85 // validation rules. All rules should be loaded in SetUpTestCase(). | 91 // validation rules. All rules should be loaded in SetUpTestCase(). |
86 class LargeAddressValidatorTest : public testing::Test { | 92 class LargeAddressValidatorTest : public testing::Test { |
87 protected: | 93 protected: |
88 LargeAddressValidatorTest() {} | 94 LargeAddressValidatorTest() {} |
89 virtual ~LargeAddressValidatorTest() {} | 95 virtual ~LargeAddressValidatorTest() {} |
90 | 96 |
(...skipping 24 matching lines...) Expand all Loading... | |
115 const std::string country_code = "US"; | 121 const std::string country_code = "US"; |
116 const std::string first_state = "AL"; | 122 const std::string first_state = "AL"; |
117 | 123 |
118 validator_->LoadRules(country_code); | 124 validator_->LoadRules(country_code); |
119 std::vector<std::string> sub_keys = | 125 std::vector<std::string> sub_keys = |
120 validator_->GetRegionSubKeys(country_code); | 126 validator_->GetRegionSubKeys(country_code); |
121 ASSERT_FALSE(sub_keys.empty()); | 127 ASSERT_FALSE(sub_keys.empty()); |
122 ASSERT_EQ(sub_keys[0], first_state); | 128 ASSERT_EQ(sub_keys[0], first_state); |
123 } | 129 } |
124 | 130 |
125 TEST_F(AddressValidatorTest, SubKeysNotLoaded) { | 131 TEST_F(AddressValidatorTest, SubKeysNotExists) { |
Mathieu
2017/06/29 19:11:25
How about SubKeys_NonExistent
Parastoo
2017/06/29 21:13:24
Done.
| |
126 const std::string country_code = "ZZ"; | 132 const std::string country_code = "OZ"; |
133 | |
134 set_expected_status(AddressValidator::RULES_UNAVAILABLE); | |
127 | 135 |
128 validator_->LoadRules(country_code); | 136 validator_->LoadRules(country_code); |
129 std::vector<std::string> sub_keys = | 137 std::vector<std::string> sub_keys = |
130 validator_->GetRegionSubKeys(country_code); | 138 validator_->GetRegionSubKeys(country_code); |
131 ASSERT_TRUE(sub_keys.empty()); | 139 ASSERT_TRUE(sub_keys.empty()); |
132 } | 140 } |
133 | 141 |
134 TEST_F(AddressValidatorTest, RegionHasRules) { | 142 TEST_F(AddressValidatorTest, RegionHasRules) { |
135 const std::vector<std::string>& region_codes = GetRegionCodes(); | 143 const std::vector<std::string>& region_codes = GetRegionCodes(); |
136 AddressData address; | 144 AddressData address; |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
910 source_->set_failures_number(99); | 918 source_->set_failures_number(99); |
911 validator_->LoadRules("CH"); | 919 validator_->LoadRules("CH"); |
912 validator_->LoadRules("GB"); | 920 validator_->LoadRules("GB"); |
913 base::RunLoop().RunUntilIdle(); | 921 base::RunLoop().RunUntilIdle(); |
914 | 922 |
915 EXPECT_FALSE(load_rules_success_); | 923 EXPECT_FALSE(load_rules_success_); |
916 EXPECT_EQ(16, source_->attempts_number()); | 924 EXPECT_EQ(16, source_->attempts_number()); |
917 } | 925 } |
918 | 926 |
919 } // namespace autofill | 927 } // namespace autofill |
OLD | NEW |