Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: components/payments/core/address_normalizer_unittest.cc

Issue 2808983003: [Payments] Format shipping and billing phone number in normalizer. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/core/address_normalizer.h" 5 #include "components/payments/core/address_normalizer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 using ::i18n::addressinput::TestdataSource; 26 using ::i18n::addressinput::TestdataSource;
27 27
28 // The requester of normalization for this test. 28 // The requester of normalization for this test.
29 class NormalizationDelegate : public AddressNormalizer::Delegate { 29 class NormalizationDelegate : public AddressNormalizer::Delegate {
30 public: 30 public:
31 NormalizationDelegate() 31 NormalizationDelegate()
32 : normalized_called_(false), not_normalized_called_(false) {} 32 : normalized_called_(false), not_normalized_called_(false) {}
33 33
34 ~NormalizationDelegate() override {} 34 ~NormalizationDelegate() override {}
35 35
36 void OnAddressNormalized( 36 void OnAddressNormalized(const autofill::AutofillProfile& profile) override {
37 const autofill::AutofillProfile& normalized_profile) override {
38 normalized_called_ = true; 37 normalized_called_ = true;
38 profile_ = profile;
39 } 39 }
40 40
41 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override { 41 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override {
42 not_normalized_called_ = true; 42 not_normalized_called_ = true;
43 profile_ = profile;
43 } 44 }
44 45
45 bool normalized_called() { return normalized_called_; } 46 bool normalized_called() { return normalized_called_; }
46 47
47 bool not_normalized_called() { return not_normalized_called_; } 48 bool not_normalized_called() { return not_normalized_called_; }
48 49
50 AutofillProfile profile() { return profile_; }
51
49 private: 52 private:
50 bool normalized_called_; 53 bool normalized_called_;
51 bool not_normalized_called_; 54 bool not_normalized_called_;
55 AutofillProfile profile_;
52 56
53 DISALLOW_COPY_AND_ASSIGN(NormalizationDelegate); 57 DISALLOW_COPY_AND_ASSIGN(NormalizationDelegate);
54 }; 58 };
55 59
56 // Used to load region rules for this test. 60 // Used to load region rules for this test.
57 class ChromiumTestdataSource : public TestdataSource { 61 class ChromiumTestdataSource : public TestdataSource {
58 public: 62 public:
59 ChromiumTestdataSource() : TestdataSource(true) {} 63 ChromiumTestdataSource() : TestdataSource(true) {}
60 64
61 ~ChromiumTestdataSource() override {} 65 ~ChromiumTestdataSource() override {}
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 187
184 // Even if the rules are not loaded before the call to 188 // Even if the rules are not loaded before the call to
185 // StartAddressNormalization, they should get loaded in the call. Since our 189 // StartAddressNormalization, they should get loaded in the call. Since our
186 // test source is synchronous, the normalization will happen synchronously 190 // test source is synchronous, the normalization will happen synchronously
187 // too. 191 // too.
188 EXPECT_TRUE(normalizer_->AreRulesLoadedForRegion("US")); 192 EXPECT_TRUE(normalizer_->AreRulesLoadedForRegion("US"));
189 EXPECT_TRUE(delegate.normalized_called()); 193 EXPECT_TRUE(delegate.normalized_called());
190 EXPECT_FALSE(delegate.not_normalized_called()); 194 EXPECT_FALSE(delegate.not_normalized_called());
191 } 195 }
192 196
197 // Tests that the phone number is formatted when the address is normalized.
198 TEST_F(AddressNormalizerTest, FormatPhone_AddressNormalized) {
199 NormalizationDelegate delegate;
200 AutofillProfile profile;
201 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
202 base::UTF8ToUTF16("5151231234"));
203
204 // Load the rules.
205 normalizer_->LoadRulesForRegion("US");
206 EXPECT_TRUE(normalizer_->AreRulesLoadedForRegion("US"));
207
208 // Start the normalization.
209 normalizer_->StartAddressNormalization(profile, "US", 0, &delegate);
210
211 // Make sure the address was normalized.
212 EXPECT_TRUE(delegate.normalized_called());
213
214 // Expect that the phone number was formatted.
215 EXPECT_EQ("+15151231234", base::UTF16ToUTF8(delegate.profile().GetRawInfo(
216 autofill::PHONE_HOME_WHOLE_NUMBER)));
217 }
218
219 // Tests that the phone number is formatted even when the address is not
220 // normalized.
221 TEST_F(AddressNormalizerTest, FormatPhone_AddressNotNormalized) {
222 NormalizationDelegate delegate;
223 AutofillProfile profile;
224 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
225 base::UTF8ToUTF16("5151231234"));
226
227 // Make sure the rules will not be loaded in the StartAddressNormalization
228 // call.
229 normalizer_->ShouldLoadRules(false);
230
231 // Start the normalization.
232 normalizer_->StartAddressNormalization(profile, "US", 0, &delegate);
233
234 // Let the timeout execute.
235 base::RunLoop().RunUntilIdle();
236
237 // Make sure the address was not normalized.
238 EXPECT_TRUE(delegate.not_normalized_called());
239
240 // Expect that the phone number was formatted.
241 EXPECT_EQ("+15151231234", base::UTF16ToUTF8(delegate.profile().GetRawInfo(
242 autofill::PHONE_HOME_WHOLE_NUMBER)));
243 }
244
193 } // namespace payments 245 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698