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 <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 using ::i18n::addressinput::INVALID_FORMAT; | 47 using ::i18n::addressinput::INVALID_FORMAT; |
48 using ::i18n::addressinput::MISMATCHING_VALUE; | 48 using ::i18n::addressinput::MISMATCHING_VALUE; |
49 using ::i18n::addressinput::MISSING_REQUIRED_FIELD; | 49 using ::i18n::addressinput::MISSING_REQUIRED_FIELD; |
50 using ::i18n::addressinput::UNEXPECTED_FIELD; | 50 using ::i18n::addressinput::UNEXPECTED_FIELD; |
51 using ::i18n::addressinput::UNKNOWN_VALUE; | 51 using ::i18n::addressinput::UNKNOWN_VALUE; |
52 using ::i18n::addressinput::USES_P_O_BOX; | 52 using ::i18n::addressinput::USES_P_O_BOX; |
53 | 53 |
54 class AddressValidatorTest : public testing::Test, LoadRulesListener { | 54 class AddressValidatorTest : public testing::Test, LoadRulesListener { |
55 protected: | 55 protected: |
56 AddressValidatorTest() | 56 AddressValidatorTest() |
57 : validator_( | 57 : validator_(new AddressValidator( |
58 new AddressValidator(scoped_ptr<Source>(new TestdataSource(true)), | 58 std::unique_ptr<Source>(new TestdataSource(true)), |
59 scoped_ptr<Storage>(new NullStorage), | 59 std::unique_ptr<Storage>(new NullStorage), |
60 this)) { | 60 this)) { |
61 validator_->LoadRules("US"); | 61 validator_->LoadRules("US"); |
62 } | 62 } |
63 | 63 |
64 virtual ~AddressValidatorTest() {} | 64 virtual ~AddressValidatorTest() {} |
65 | 65 |
66 const scoped_ptr<AddressValidator> validator_; | 66 const std::unique_ptr<AddressValidator> validator_; |
67 | 67 |
68 private: | 68 private: |
69 // LoadRulesListener implementation. | 69 // LoadRulesListener implementation. |
70 virtual void OnAddressValidationRulesLoaded(const std::string& country_code, | 70 virtual void OnAddressValidationRulesLoaded(const std::string& country_code, |
71 bool success) override { | 71 bool success) override { |
72 AddressData address_data; | 72 AddressData address_data; |
73 address_data.region_code = country_code; | 73 address_data.region_code = country_code; |
74 FieldProblemMap dummy; | 74 FieldProblemMap dummy; |
75 AddressValidator::Status status = | 75 AddressValidator::Status status = |
76 validator_->ValidateAddress(address_data, NULL, &dummy); | 76 validator_->ValidateAddress(address_data, NULL, &dummy); |
77 ASSERT_EQ(success, status == AddressValidator::SUCCESS); | 77 ASSERT_EQ(success, status == AddressValidator::SUCCESS); |
78 } | 78 } |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest); | 80 DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest); |
81 }; | 81 }; |
82 | 82 |
83 // Use this test fixture if you're going to use a region with a large set of | 83 // Use this test fixture if you're going to use a region with a large set of |
84 // validation rules. All rules should be loaded in SetUpTestCase(). | 84 // validation rules. All rules should be loaded in SetUpTestCase(). |
85 class LargeAddressValidatorTest : public testing::Test { | 85 class LargeAddressValidatorTest : public testing::Test { |
86 protected: | 86 protected: |
87 LargeAddressValidatorTest() {} | 87 LargeAddressValidatorTest() {} |
88 virtual ~LargeAddressValidatorTest() {} | 88 virtual ~LargeAddressValidatorTest() {} |
89 | 89 |
90 static void SetUpTestCase() { | 90 static void SetUpTestCase() { |
91 validator_ = | 91 validator_ = |
92 new AddressValidator(scoped_ptr<Source>(new TestdataSource(true)), | 92 new AddressValidator(std::unique_ptr<Source>(new TestdataSource(true)), |
93 scoped_ptr<Storage>(new NullStorage), | 93 std::unique_ptr<Storage>(new NullStorage), NULL); |
94 NULL); | |
95 validator_->LoadRules("CN"); | 94 validator_->LoadRules("CN"); |
96 validator_->LoadRules("KR"); | 95 validator_->LoadRules("KR"); |
97 validator_->LoadRules("TW"); | 96 validator_->LoadRules("TW"); |
98 } | 97 } |
99 | 98 |
100 static void TearDownTestcase() { | 99 static void TearDownTestcase() { |
101 delete validator_; | 100 delete validator_; |
102 validator_ = NULL; | 101 validator_ = NULL; |
103 } | 102 } |
104 | 103 |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 732 } |
734 | 733 |
735 // Use this test fixture for configuring the number of failed attempts to load | 734 // Use this test fixture for configuring the number of failed attempts to load |
736 // rules. | 735 // rules. |
737 class FailingAddressValidatorTest : public testing::Test, LoadRulesListener { | 736 class FailingAddressValidatorTest : public testing::Test, LoadRulesListener { |
738 protected: | 737 protected: |
739 // A validator that retries loading rules without delay. | 738 // A validator that retries loading rules without delay. |
740 class TestAddressValidator : public AddressValidator { | 739 class TestAddressValidator : public AddressValidator { |
741 public: | 740 public: |
742 // Takes ownership of |source| and |storage|. | 741 // Takes ownership of |source| and |storage|. |
743 TestAddressValidator(scoped_ptr<::i18n::addressinput::Source> source, | 742 TestAddressValidator(std::unique_ptr<::i18n::addressinput::Source> source, |
744 scoped_ptr<::i18n::addressinput::Storage> storage, | 743 std::unique_ptr<::i18n::addressinput::Storage> storage, |
745 LoadRulesListener* load_rules_listener) | 744 LoadRulesListener* load_rules_listener) |
746 : AddressValidator(std::move(source), | 745 : AddressValidator(std::move(source), |
747 std::move(storage), | 746 std::move(storage), |
748 load_rules_listener) {} | 747 load_rules_listener) {} |
749 | 748 |
750 virtual ~TestAddressValidator() {} | 749 virtual ~TestAddressValidator() {} |
751 | 750 |
752 protected: | 751 protected: |
753 virtual base::TimeDelta GetBaseRetryPeriod() const override { | 752 virtual base::TimeDelta GetBaseRetryPeriod() const override { |
754 return base::TimeDelta::FromSeconds(0); | 753 return base::TimeDelta::FromSeconds(0); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 794 |
796 // The source to use for successful downloads. | 795 // The source to use for successful downloads. |
797 TestdataSource actual_source_; | 796 TestdataSource actual_source_; |
798 | 797 |
799 DISALLOW_COPY_AND_ASSIGN(FailingSource); | 798 DISALLOW_COPY_AND_ASSIGN(FailingSource); |
800 }; | 799 }; |
801 | 800 |
802 FailingAddressValidatorTest() | 801 FailingAddressValidatorTest() |
803 : source_(new FailingSource), | 802 : source_(new FailingSource), |
804 validator_( | 803 validator_( |
805 new TestAddressValidator(scoped_ptr<Source>(source_), | 804 new TestAddressValidator(std::unique_ptr<Source>(source_), |
806 scoped_ptr<Storage>(new NullStorage), | 805 std::unique_ptr<Storage>(new NullStorage), |
807 this)), | 806 this)), |
808 load_rules_success_(false) {} | 807 load_rules_success_(false) {} |
809 | 808 |
810 virtual ~FailingAddressValidatorTest() {} | 809 virtual ~FailingAddressValidatorTest() {} |
811 | 810 |
812 FailingSource* source_; // Owned by |validator_|. | 811 FailingSource* source_; // Owned by |validator_|. |
813 scoped_ptr<AddressValidator> validator_; | 812 std::unique_ptr<AddressValidator> validator_; |
814 bool load_rules_success_; | 813 bool load_rules_success_; |
815 | 814 |
816 private: | 815 private: |
817 // LoadRulesListener implementation. | 816 // LoadRulesListener implementation. |
818 virtual void OnAddressValidationRulesLoaded(const std::string&, | 817 virtual void OnAddressValidationRulesLoaded(const std::string&, |
819 bool success) override { | 818 bool success) override { |
820 load_rules_success_ = success; | 819 load_rules_success_ = success; |
821 } | 820 } |
822 | 821 |
823 base::MessageLoop ui_; | 822 base::MessageLoop ui_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 source_->set_failures_number(99); | 882 source_->set_failures_number(99); |
884 validator_->LoadRules("CH"); | 883 validator_->LoadRules("CH"); |
885 validator_->LoadRules("GB"); | 884 validator_->LoadRules("GB"); |
886 base::RunLoop().RunUntilIdle(); | 885 base::RunLoop().RunUntilIdle(); |
887 | 886 |
888 EXPECT_FALSE(load_rules_success_); | 887 EXPECT_FALSE(load_rules_success_); |
889 EXPECT_EQ(16, source_->attempts_number()); | 888 EXPECT_EQ(16, source_->attempts_number()); |
890 } | 889 } |
891 | 890 |
892 } // namespace autofill | 891 } // namespace autofill |
OLD | NEW |