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_request_state.h" | 5 #include "components/payments/content/payment_request_state.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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 "\"recipient\":\"John H. Doe\"," | 333 "\"recipient\":\"John H. Doe\"," |
334 "\"region\":\"CA\"}," | 334 "\"region\":\"CA\"}," |
335 "\"cardNumber\":\"4111111111111111\"," | 335 "\"cardNumber\":\"4111111111111111\"," |
336 "\"cardSecurityCode\":\"123\"," | 336 "\"cardSecurityCode\":\"123\"," |
337 "\"cardholderName\":\"Test User\"," | 337 "\"cardholderName\":\"Test User\"," |
338 "\"expiryMonth\":\"11\"," | 338 "\"expiryMonth\":\"11\"," |
339 "\"expiryYear\":\"2017\"}", | 339 "\"expiryYear\":\"2017\"}", |
340 response()->stringified_details); | 340 response()->stringified_details); |
341 } | 341 } |
342 | 342 |
| 343 // Tests the the generated PaymentResponse has the correct values for the |
| 344 // shipping address. |
| 345 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ShippingAddress) { |
| 346 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); |
| 347 options->request_shipping = true; |
| 348 RecreateStateWithOptions(std::move(options)); |
| 349 |
| 350 EXPECT_TRUE(state()->is_ready_to_pay()); |
| 351 state()->GeneratePaymentResponse(); |
| 352 |
| 353 // Check that all the expected values were set. |
| 354 EXPECT_EQ("US", response()->shipping_address->country); |
| 355 EXPECT_EQ("666 Erebus St.", response()->shipping_address->address_line[0]); |
| 356 EXPECT_EQ("Apt 8", response()->shipping_address->address_line[1]); |
| 357 EXPECT_EQ("CA", response()->shipping_address->region); |
| 358 EXPECT_EQ("Elysium", response()->shipping_address->city); |
| 359 EXPECT_EQ("", response()->shipping_address->dependent_locality); |
| 360 EXPECT_EQ("91111", response()->shipping_address->postal_code); |
| 361 EXPECT_EQ("", response()->shipping_address->sorting_code); |
| 362 EXPECT_EQ("", response()->shipping_address->language_code); |
| 363 EXPECT_EQ("Underworld", response()->shipping_address->organization); |
| 364 EXPECT_EQ("John H. Doe", response()->shipping_address->recipient); |
| 365 EXPECT_EQ("16502111111", response()->shipping_address->phone); |
| 366 } |
| 367 |
| 368 // Tests the the generated PaymentResponse has the correct values for the |
| 369 // contact details when all values are requested. |
| 370 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_All) { |
| 371 // Request all contact detail values. |
| 372 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); |
| 373 options->request_payer_name = true; |
| 374 options->request_payer_phone = true; |
| 375 options->request_payer_email = true; |
| 376 RecreateStateWithOptions(std::move(options)); |
| 377 |
| 378 EXPECT_TRUE(state()->is_ready_to_pay()); |
| 379 state()->GeneratePaymentResponse(); |
| 380 |
| 381 // Check that all the expected values were set. |
| 382 EXPECT_EQ("John H. Doe", response()->payer_name.value()); |
| 383 EXPECT_EQ("16502111111", response()->payer_phone.value()); |
| 384 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value()); |
| 385 } |
| 386 |
| 387 // Tests the the generated PaymentResponse has the correct values for the |
| 388 // contact details when all values are requested. |
| 389 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_Some) { |
| 390 // Request one contact detail value. |
| 391 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); |
| 392 options->request_payer_name = true; |
| 393 RecreateStateWithOptions(std::move(options)); |
| 394 |
| 395 EXPECT_TRUE(state()->is_ready_to_pay()); |
| 396 state()->GeneratePaymentResponse(); |
| 397 |
| 398 // Check that the name was set, but not the other values. |
| 399 EXPECT_EQ("John H. Doe", response()->payer_name.value()); |
| 400 EXPECT_FALSE(response()->payer_phone.has_value()); |
| 401 EXPECT_FALSE(response()->payer_email.has_value()); |
| 402 } |
| 403 |
343 } // namespace payments | 404 } // namespace payments |
OLD | NEW |