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

Unified Diff: components/payments/core/payment_request_data_util_unittest.cc

Issue 2910423003: [Payments] Allow international phone from different country in shipping editor. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « components/payments/core/payment_request_data_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/core/payment_request_data_util_unittest.cc
diff --git a/components/payments/core/payment_request_data_util_unittest.cc b/components/payments/core/payment_request_data_util_unittest.cc
index df86baee726f2c7375185aaab918271e2b126687..3181a47d28275cad12cf395471a844d74c96b219 100644
--- a/components/payments/core/payment_request_data_util_unittest.cc
+++ b/components/payments/core/payment_request_data_util_unittest.cc
@@ -7,6 +7,7 @@
#include <memory>
#include "base/json/json_writer.h"
+#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/autofill/core/browser/autofill_profile.h"
@@ -90,5 +91,171 @@ TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) {
payments::data_util::FormatPhoneForDisplay("142685300", "FR"));
}
+// Test for the GetFormattedPhoneNumberForDisplay method.
+struct PhoneNumberFormatCase {
+ PhoneNumberFormatCase(const char* phone,
+ const char* country,
+ const char* expected_format,
+ const char* locale = "")
+ : phone(phone),
+ country(country),
+ expected_format(expected_format),
+ locale(locale) {}
+
+ const char* phone;
+ const char* country;
+ const char* expected_format;
+ const char* locale;
+};
+
+class GetFormattedPhoneNumberForDisplayTest
+ : public testing::TestWithParam<PhoneNumberFormatCase> {};
+
+TEST_P(GetFormattedPhoneNumberForDisplayTest,
+ GetFormattedPhoneNumberForDisplay) {
+ autofill::AutofillProfile profile;
+ profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
+ base::UTF8ToUTF16(GetParam().phone));
+ profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY,
+ base::UTF8ToUTF16(GetParam().country));
+ EXPECT_EQ(GetParam().expected_format,
+ base::UTF16ToUTF8(
+ GetFormattedPhoneNumberForDisplay(profile, GetParam().locale)));
+}
+
+INSTANTIATE_TEST_CASE_P(
+ GetFormattedPhoneNumberForDisplay,
+ GetFormattedPhoneNumberForDisplayTest,
+ testing::Values(
+ //////////////////////////
+ // US phone in US.
+ //////////////////////////
+ // Formatted phone numbers.
+ PhoneNumberFormatCase("+1 415-555-5555", "US", "+1 415-555-5555"),
+ PhoneNumberFormatCase("1 415-555-5555", "US", "+1 415-555-5555"),
+ PhoneNumberFormatCase("415-555-5555", "US", "+1 415-555-5555"),
+ // Raw phone numbers.
+ PhoneNumberFormatCase("+14155555555", "US", "+1 415-555-5555"),
+ PhoneNumberFormatCase("14155555555", "US", "+1 415-555-5555"),
+ PhoneNumberFormatCase("4155555555", "US", "+1 415-555-5555"),
+
+ //////////////////////////
+ // US phone in CA.
+ //////////////////////////
+ // Formatted phone numbers.
+ PhoneNumberFormatCase("+1 415-555-5555", "CA", "+1 415-555-5555"),
+ PhoneNumberFormatCase("1 415-555-5555", "CA", "+1 415-555-5555"),
+ PhoneNumberFormatCase("415-555-5555", "CA", "+1 415-555-5555"),
+ // Raw phone numbers.
+ PhoneNumberFormatCase("+14155555555", "CA", "+1 415-555-5555"),
+ PhoneNumberFormatCase("14155555555", "CA", "+1 415-555-5555"),
+ PhoneNumberFormatCase("4155555555", "CA", "+1 415-555-5555"),
+
+ //////////////////////////
+ // US phone in AU.
+ //////////////////////////
+ // A US phone with the country code is correctly formatted as an US
+ // number.
+ PhoneNumberFormatCase("+1 415-555-5555", "AU", "+1 415-555-5555"),
+ PhoneNumberFormatCase("1 415-555-5555", "AU", "+1 415-555-5555"),
+ // Without a country code, the phone is formatted for the profile's
+ // country, even if it's invalid.
+ PhoneNumberFormatCase("415-555-5555", "AU", "+61 4155555555"),
+
+ //////////////////////////
+ // US phone in MX.
+ //////////////////////////
+ // A US phone with the country code is correctly formatted as an US
+ // number.
+ PhoneNumberFormatCase("+1 415-555-5555", "MX", "+1 415-555-5555"),
+ // "+52 1 415 555 5555" is a valid number for Mexico,
+ PhoneNumberFormatCase("1 415-555-5555", "MX", "+52 1 415 555 5555"),
+ // Without a country code, the phone is formatted for the profile's
+ // country.
+ PhoneNumberFormatCase("415-555-5555", "MX", "+52 415 555 5555"),
+
+ //////////////////////////
+ // AU phone in AU.
+ //////////////////////////
+ // Formatted phone numbers.
+ PhoneNumberFormatCase("+61 2 9374 4000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("61 2 9374 4000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("02 9374 4000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("2 9374 4000", "AU", "+61 2 9374 4000"),
+ // Raw phone numbers.
+ PhoneNumberFormatCase("+61293744000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("61293744000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("0293744000", "AU", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("293744000", "AU", "+61 2 9374 4000"),
+
+ //////////////////////////
+ // AU phone in US.
+ //////////////////////////
+ // An AU phone with the country code is correctly formatted as an AU
+ // number.
+ PhoneNumberFormatCase("+61 2 9374 4000", "US", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("61 2 9374 4000", "US", "+61 2 9374 4000"),
+ // Without a country code, the phone is formatted for the profile's
+ // country.
+ // This local AU number fits the length of a US number, so it's
+ // formatted for US.
+ PhoneNumberFormatCase("02 9374 4000", "US", "+1 029-374-4000"),
+ // This local AU number is formatted as an US number, even if it's
+ // invlaid.
+ PhoneNumberFormatCase("2 9374 4000", "US", "+1 293744000"),
+
+ //////////////////////////
+ // MX phone in MX.
+ //////////////////////////
+ // Formatted phone numbers.
+ PhoneNumberFormatCase("+52 55 5342 8400", "MX", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("52 55 5342 8400", "MX", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("55 5342 8400", "MX", "+52 55 5342 8400"),
+ // Raw phone numbers.
+ PhoneNumberFormatCase("+525553428400", "MX", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("525553428400", "MX", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("5553428400", "MX", "+52 55 5342 8400"),
+
+ //////////////////////////
+ // MX phone in US.
+ //////////////////////////
+ // A MX phone with the country code is correctly formatted as a MX
+ // number.
+ PhoneNumberFormatCase("+52 55 5342 8400", "US", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("52 55 5342 8400", "US", "+52 55 5342 8400"),
+ // This local MX number fits the length of a US number, so it's
+ // formatted for US.
+ PhoneNumberFormatCase("55 5342 8400", "US", "+1 555-342-8400")));
+
+INSTANTIATE_TEST_CASE_P(
+ GetFormattedPhoneNumberForDisplay_EdgeCases,
+ GetFormattedPhoneNumberForDisplayTest,
+ testing::Values(
+ //////////////////////////
+ // No country.
+ //////////////////////////
+ // Fallback to locale if no country is set.
+ PhoneNumberFormatCase("52 55 5342 8400",
+ "",
+ "+52 55 5342 8400",
+ "es_MX"),
+ PhoneNumberFormatCase("55 5342 8400", "", "+52 55 5342 8400", "es_MX"),
+ PhoneNumberFormatCase("55 5342 8400", "", "+1 555-342-8400", "en_US"),
+ PhoneNumberFormatCase("61 2 9374 4000", "", "+61 2 9374 4000", "en_AU"),
+ PhoneNumberFormatCase("02 9374 4000", "", "+61 2 9374 4000", "en_AU"),
+
+ //////////////////////////
+ // No country or locale.
+ //////////////////////////
+ // Format according to the country code.
+ PhoneNumberFormatCase("61 2 9374 4000", "", "+61 2 9374 4000"),
+ PhoneNumberFormatCase("52 55 5342 8400", "", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("1 415 555 5555", "", "+1 415-555-5555"),
+ // If no country code is found, formats for US.
+ PhoneNumberFormatCase("02 9374 4000", "", "+1 029-374-4000"),
+ PhoneNumberFormatCase("2 9374 4000", "", "+1 293744000"),
+ PhoneNumberFormatCase("55 5342 8400", "", "+1 555-342-8400"),
+ PhoneNumberFormatCase("52 55 5342 8400", "", "+52 55 5342 8400"),
+ PhoneNumberFormatCase("415-555-5555", "", "+1 415-555-5555")));
} // namespace data_util
} // namespace payments
« no previous file with comments | « components/payments/core/payment_request_data_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698