diff options
author | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 20:24:21 +0000 |
---|---|---|
committer | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 20:24:21 +0000 |
commit | 6703e57d549a6ca6ffedb6311b007b0af736f244 (patch) | |
tree | 7cfd0695d2221da636da432c29b2d33f731adabc /third_party | |
parent | 442a2176288b8846450d9f0257b27363df3c10cf (diff) | |
download | chromium_src-6703e57d549a6ca6ffedb6311b007b0af736f244.zip chromium_src-6703e57d549a6ca6ffedb6311b007b0af736f244.tar.gz chromium_src-6703e57d549a6ca6ffedb6311b007b0af736f244.tar.bz2 |
rAc: validate a section's inputs when its validation rules load.
R=estade@chromium.org, groby@chromium.org
BUG=317839
Review URL: https://codereview.chromium.org/129773005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/libaddressinput/chromium/cpp/src/address_validator.cc | 16 | ||||
-rw-r--r-- | third_party/libaddressinput/chromium/cpp/test/address_validator_test.cc | 8 |
2 files changed, 18 insertions, 6 deletions
diff --git a/third_party/libaddressinput/chromium/cpp/src/address_validator.cc b/third_party/libaddressinput/chromium/cpp/src/address_validator.cc index 33453fb..fe36bd8 100644 --- a/third_party/libaddressinput/chromium/cpp/src/address_validator.cc +++ b/third_party/libaddressinput/chromium/cpp/src/address_validator.cc @@ -116,11 +116,13 @@ class AddressValidatorImpl : public AddressValidator { // We can still validate the required fields even if the full ruleset isn't // ready. if (ruleset_it == rules_.end()) { - Rule rule; - rule.CopyFrom(Rule::GetDefault()); - if (rule.ParseSerializedRule( - RegionDataConstants::GetRegionData(address.country_code))) { - EnforceRequiredFields(rule, address, filter, problems); + if (problems != NULL) { + Rule rule; + rule.CopyFrom(Rule::GetDefault()); + if (rule.ParseSerializedRule( + RegionDataConstants::GetRegionData(address.country_code))) { + EnforceRequiredFields(rule, address, filter, problems); + } } return loading_rules_.find(address.country_code) != loading_rules_.end() @@ -128,6 +130,9 @@ class AddressValidatorImpl : public AddressValidator { : RULES_UNAVAILABLE; } + if (problems == NULL) + return SUCCESS; + const Ruleset* ruleset = ruleset_it->second; assert(ruleset != NULL); const Rule& country_rule = @@ -225,6 +230,7 @@ class AddressValidatorImpl : public AddressValidator { const AddressData& address, const AddressProblemFilter& filter, AddressProblems* problems) const { + assert(problems != NULL); for (std::vector<AddressField>::const_iterator field_it = country_rule.GetRequired().begin(); field_it != country_rule.GetRequired().end(); diff --git a/third_party/libaddressinput/chromium/cpp/test/address_validator_test.cc b/third_party/libaddressinput/chromium/cpp/test/address_validator_test.cc index 40beab7..0007312 100644 --- a/third_party/libaddressinput/chromium/cpp/test/address_validator_test.cc +++ b/third_party/libaddressinput/chromium/cpp/test/address_validator_test.cc @@ -50,7 +50,13 @@ class AddressValidatorTest : public testing::Test, public LoadRulesDelegate { private: // LoadRulesDelegate implementation. virtual void OnAddressValidationRulesLoaded(const std::string& country_code, - bool success) {} + bool success) { + AddressData address_data; + address_data.country_code = country_code; + AddressValidator::Status status = + validator_->ValidateAddress(address_data, AddressProblemFilter(), NULL); + EXPECT_EQ(success, status == AddressValidator::SUCCESS); + } }; TEST_F(AddressValidatorTest, EmptyAddressNoFatalFailure) { |