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

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

Issue 2905283002: [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
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..3bc83c7dffdb35d0d335cb7f09c3b6e1089cbd82 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,94 @@ 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* locale,
+ const char* expected_format)
+ : phone(phone),
+ country(country),
+ locale(locale),
+ expected_format(expected_format) {}
+
+ const char* phone;
+ const char* country;
+ const char* locale;
Mathieu 2017/05/29 16:34:00 are you using this?
sebsg 2017/05/29 19:48:39 Done.
+ const char* expected_format;
+};
+
+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(
Mathieu 2017/05/29 16:34:00 let's have a US phone in MX and MX phone in US blo
sebsg 2017/05/29 19:48:39 Done.
+ GetFormattedPhoneNumberForDisplay,
+ GetFormattedPhoneNumberForDisplayTest,
+ testing::Values(
+ /////////////////////
+ // US phone in US.
Mathieu 2017/05/29 16:34:00 US phone in CA? Let's also have a US phone in US
sebsg 2017/05/29 19:48:39 Done.
+ /////////////////////
+ // 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"),
+
+ /////////////////////
+ // 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")));
+
} // namespace data_util
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698