Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/payment_request_data_util.h" | 5 #include "components/payments/core/payment_request_data_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/macros.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
| 13 #include "components/autofill/core/browser/autofill_test_utils.h" | 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/credit_card.h" | 15 #include "components/autofill/core/browser/credit_card.h" |
| 15 #include "components/payments/core/basic_card_response.h" | 16 #include "components/payments/core/basic_card_response.h" |
| 16 #include "components/payments/core/payment_address.h" | 17 #include "components/payments/core/payment_address.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace payments { | 20 namespace payments { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Tests that the phone numbers are correctly formatted to display to the user. | 86 // Tests that the phone numbers are correctly formatted to display to the user. |
| 86 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) { | 87 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) { |
| 87 EXPECT_EQ("+1 515-123-1234", | 88 EXPECT_EQ("+1 515-123-1234", |
| 88 payments::data_util::FormatPhoneForDisplay("5151231234", "US")); | 89 payments::data_util::FormatPhoneForDisplay("5151231234", "US")); |
| 89 EXPECT_EQ("+33 1 42 68 53 00", | 90 EXPECT_EQ("+33 1 42 68 53 00", |
| 90 payments::data_util::FormatPhoneForDisplay("142685300", "FR")); | 91 payments::data_util::FormatPhoneForDisplay("142685300", "FR")); |
| 91 } | 92 } |
| 92 | 93 |
| 94 // Test for the GetFormattedPhoneNumberForDisplay method. | |
| 95 struct PhoneNumberFormatCase { | |
| 96 PhoneNumberFormatCase(const char* phone, | |
| 97 const char* country, | |
| 98 const char* locale, | |
| 99 const char* expected_format) | |
| 100 : phone(phone), | |
| 101 country(country), | |
| 102 locale(locale), | |
| 103 expected_format(expected_format) {} | |
| 104 | |
| 105 const char* phone; | |
| 106 const char* country; | |
| 107 const char* locale; | |
|
Mathieu
2017/05/29 16:34:00
are you using this?
sebsg
2017/05/29 19:48:39
Done.
| |
| 108 const char* expected_format; | |
| 109 }; | |
| 110 | |
| 111 class GetFormattedPhoneNumberForDisplayTest | |
| 112 : public testing::TestWithParam<PhoneNumberFormatCase> {}; | |
| 113 | |
| 114 TEST_P(GetFormattedPhoneNumberForDisplayTest, | |
| 115 GetFormattedPhoneNumberForDisplay) { | |
| 116 autofill::AutofillProfile profile; | |
| 117 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, | |
| 118 base::UTF8ToUTF16(GetParam().phone)); | |
| 119 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, | |
| 120 base::UTF8ToUTF16(GetParam().country)); | |
| 121 EXPECT_EQ(GetParam().expected_format, | |
| 122 base::UTF16ToUTF8( | |
| 123 GetFormattedPhoneNumberForDisplay(profile, GetParam().locale))); | |
| 124 } | |
| 125 | |
| 126 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.
| |
| 127 GetFormattedPhoneNumberForDisplay, | |
| 128 GetFormattedPhoneNumberForDisplayTest, | |
| 129 testing::Values( | |
| 130 ///////////////////// | |
| 131 // 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.
| |
| 132 ///////////////////// | |
| 133 // Formatted phone numbers. | |
| 134 PhoneNumberFormatCase("+1 415-555-5555", "CA", "", "+1 415-555-5555"), | |
| 135 PhoneNumberFormatCase("1 415-555-5555", "CA", "", "+1 415-555-5555"), | |
| 136 PhoneNumberFormatCase("415-555-5555", "CA", "", "+1 415-555-5555"), | |
| 137 // Raw phone numbers. | |
| 138 PhoneNumberFormatCase("+14155555555", "CA", "", "+1 415-555-5555"), | |
| 139 PhoneNumberFormatCase("14155555555", "CA", "", "+1 415-555-5555"), | |
| 140 PhoneNumberFormatCase("4155555555", "CA", "", "+1 415-555-5555"), | |
| 141 | |
| 142 ///////////////////// | |
| 143 // US phone in AU. | |
| 144 ///////////////////// | |
| 145 // A US phone with the country code is correctly formatted as an US | |
| 146 // number. | |
| 147 PhoneNumberFormatCase("+1 415-555-5555", "AU", "", "+1 415-555-5555"), | |
| 148 PhoneNumberFormatCase("1 415-555-5555", "AU", "", "+1 415-555-5555"), | |
| 149 // Without a country code, the phone is formatted for the profile's | |
| 150 // country, even if it's invalid. | |
| 151 PhoneNumberFormatCase("415-555-5555", "AU", "", "+61 4155555555"), | |
| 152 | |
| 153 ///////////////////// | |
| 154 // AU phone in AU. | |
| 155 ///////////////////// | |
| 156 // Formatted phone numbers. | |
| 157 PhoneNumberFormatCase("+61 2 9374 4000", "AU", "", "+61 2 9374 4000"), | |
| 158 PhoneNumberFormatCase("61 2 9374 4000", "AU", "", "+61 2 9374 4000"), | |
| 159 PhoneNumberFormatCase("02 9374 4000", "AU", "", "+61 2 9374 4000"), | |
| 160 PhoneNumberFormatCase("2 9374 4000", "AU", "", "+61 2 9374 4000"), | |
| 161 // Raw phone numbers. | |
| 162 PhoneNumberFormatCase("+61293744000", "AU", "", "+61 2 9374 4000"), | |
| 163 PhoneNumberFormatCase("61293744000", "AU", "", "+61 2 9374 4000"), | |
| 164 PhoneNumberFormatCase("0293744000", "AU", "", "+61 2 9374 4000"), | |
| 165 PhoneNumberFormatCase("293744000", "AU", "", "+61 2 9374 4000"), | |
| 166 | |
| 167 ///////////////////// | |
| 168 // AU phone in US. | |
| 169 ///////////////////// | |
| 170 // An AU phone with the country code is correctly formatted as an AU | |
| 171 // number. | |
| 172 PhoneNumberFormatCase("+61 2 9374 4000", "US", "", "+61 2 9374 4000"), | |
| 173 PhoneNumberFormatCase("61 2 9374 4000", "US", "", "+61 2 9374 4000"), | |
| 174 // Without a country code, the phone is formatted for the profile's | |
| 175 // country. | |
| 176 // This local AU number fits the length of a US number, so it's | |
| 177 // formatted for US. | |
| 178 PhoneNumberFormatCase("02 9374 4000", "US", "", "+1 029-374-4000"), | |
| 179 // This local AU number is formatted as an US number, even if it's | |
| 180 // invlaid. | |
| 181 PhoneNumberFormatCase("2 9374 4000", "US", "", "+1 293744000"))); | |
| 182 | |
| 93 } // namespace data_util | 183 } // namespace data_util |
| 94 } // namespace payments | 184 } // namespace payments |
| OLD | NEW |