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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/core/address_normalizer_unittest.cc
diff --git a/components/payments/core/address_normalizer_unittest.cc b/components/payments/core/address_normalizer_unittest.cc
index ee934bbb4f351e7f31584ef998e4cb309016c76f..12355b005feb53fedaf6a71062a540039f727d1a 100644
--- a/components/payments/core/address_normalizer_unittest.cc
+++ b/components/payments/core/address_normalizer_unittest.cc
@@ -33,22 +33,26 @@ class NormalizationDelegate : public AddressNormalizer::Delegate {
~NormalizationDelegate() override {}
- void OnAddressNormalized(
- const autofill::AutofillProfile& normalized_profile) override {
+ void OnAddressNormalized(const autofill::AutofillProfile& profile) override {
normalized_called_ = true;
+ profile_ = profile;
}
void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override {
not_normalized_called_ = true;
+ profile_ = profile;
}
bool normalized_called() { return normalized_called_; }
bool not_normalized_called() { return not_normalized_called_; }
+ AutofillProfile profile() { return profile_; }
+
private:
bool normalized_called_;
bool not_normalized_called_;
+ AutofillProfile profile_;
DISALLOW_COPY_AND_ASSIGN(NormalizationDelegate);
};
@@ -190,4 +194,52 @@ TEST_F(AddressNormalizerTest, StartNormalization_RulesNotLoaded_WillLoad) {
EXPECT_FALSE(delegate.not_normalized_called());
}
+// Tests that the phone number is formatted when the address is normalized.
+TEST_F(AddressNormalizerTest, FormatPhone_AddressNormalized) {
+ NormalizationDelegate delegate;
+ AutofillProfile profile;
+ profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
+ base::UTF8ToUTF16("5151231234"));
+
+ // Load the rules.
+ normalizer_->LoadRulesForRegion("US");
+ EXPECT_TRUE(normalizer_->AreRulesLoadedForRegion("US"));
+
+ // Start the normalization.
+ normalizer_->StartAddressNormalization(profile, "US", 0, &delegate);
+
+ // Make sure the address was normalized.
+ EXPECT_TRUE(delegate.normalized_called());
+
+ // Expect that the phone number was formatted.
+ EXPECT_EQ("+15151231234", base::UTF16ToUTF8(delegate.profile().GetRawInfo(
+ autofill::PHONE_HOME_WHOLE_NUMBER)));
+}
+
+// Tests that the phone number is formatted even when the address is not
+// normalized.
+TEST_F(AddressNormalizerTest, FormatPhone_AddressNotNormalized) {
+ NormalizationDelegate delegate;
+ AutofillProfile profile;
+ profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
+ base::UTF8ToUTF16("5151231234"));
+
+ // Make sure the rules will not be loaded in the StartAddressNormalization
+ // call.
+ normalizer_->ShouldLoadRules(false);
+
+ // Start the normalization.
+ normalizer_->StartAddressNormalization(profile, "US", 0, &delegate);
+
+ // Let the timeout execute.
+ base::RunLoop().RunUntilIdle();
+
+ // Make sure the address was not normalized.
+ EXPECT_TRUE(delegate.not_normalized_called());
+
+ // Expect that the phone number was formatted.
+ EXPECT_EQ("+15151231234", base::UTF16ToUTF8(delegate.profile().GetRawInfo(
+ autofill::PHONE_HOME_WHOLE_NUMBER)));
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698