| 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/content/payment_response_helper.h" | 5 #include "components/payments/content/payment_response_helper.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 options->request_payer_name = true; | 238 options->request_payer_name = true; |
| 239 options->request_payer_phone = true; | 239 options->request_payer_phone = true; |
| 240 options->request_payer_email = true; | 240 options->request_payer_email = true; |
| 241 RecreateSpecWithOptions(std::move(options)); | 241 RecreateSpecWithOptions(std::move(options)); |
| 242 | 242 |
| 243 PaymentResponseHelper helper("en-US", spec(), test_instrument(), | 243 PaymentResponseHelper helper("en-US", spec(), test_instrument(), |
| 244 test_address(), test_address(), this); | 244 test_address(), test_address(), this); |
| 245 | 245 |
| 246 // Check that all the expected values were set. | 246 // Check that all the expected values were set. |
| 247 EXPECT_EQ("John H. Doe", response()->payer_name.value()); | 247 EXPECT_EQ("John H. Doe", response()->payer_name.value()); |
| 248 EXPECT_EQ("16502111111", response()->payer_phone.value()); | 248 EXPECT_EQ("+16502111111", response()->payer_phone.value()); |
| 249 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value()); | 249 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 // Tests the the generated PaymentResponse has the correct values for the | 252 // Tests the the generated PaymentResponse has the correct values for the |
| 253 // contact details when all values are requested. | 253 // contact details when all values are requested. |
| 254 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_ContactDetails_Some) { | 254 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_ContactDetails_Some) { |
| 255 // Request one contact detail value. | 255 // Request one contact detail value. |
| 256 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); | 256 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); |
| 257 options->request_payer_name = true; | 257 options->request_payer_name = true; |
| 258 RecreateSpecWithOptions(std::move(options)); | 258 RecreateSpecWithOptions(std::move(options)); |
| 259 | 259 |
| 260 PaymentResponseHelper helper("en-US", spec(), test_instrument(), | 260 PaymentResponseHelper helper("en-US", spec(), test_instrument(), |
| 261 test_address(), test_address(), this); | 261 test_address(), test_address(), this); |
| 262 | 262 |
| 263 // Check that the name was set, but not the other values. | 263 // Check that the name was set, but not the other values. |
| 264 EXPECT_EQ("John H. Doe", response()->payer_name.value()); | 264 EXPECT_EQ("John H. Doe", response()->payer_name.value()); |
| 265 EXPECT_FALSE(response()->payer_phone.has_value()); | 265 EXPECT_FALSE(response()->payer_phone.has_value()); |
| 266 EXPECT_FALSE(response()->payer_email.has_value()); | 266 EXPECT_FALSE(response()->payer_email.has_value()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Tests the the generated PaymentResponse has the correct values for the |
| 270 // contact details when all values are requested. |
| 271 TEST_F(PaymentResponseHelperTest, |
| 272 GeneratePaymentResponse_ContactPhoneIsFormatted) { |
| 273 // Request one contact detail value. |
| 274 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); |
| 275 options->request_payer_phone = true; |
| 276 test_address()->SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, |
| 277 base::UTF8ToUTF16("(515) 123-1234")); |
| 278 RecreateSpecWithOptions(std::move(options)); |
| 279 |
| 280 PaymentResponseHelper helper("en-US", spec(), test_instrument(), |
| 281 test_address(), test_address(), this); |
| 282 |
| 283 // Check that the phone was formatted. |
| 284 EXPECT_EQ("+15151231234", response()->payer_phone.value()); |
| 285 } |
| 286 |
| 269 } // namespace payments | 287 } // namespace payments |
| OLD | NEW |