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

Side by Side Diff: components/payments/content/payment_request_state_unittest.cc

Issue 2779813003: [Payments] Add Ship. Addr. & Contact Info in Payment Response on Desktop. (Closed)
Patch Set: Addressed comments Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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
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 // Setup so that a shipping address is requested.
347 std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
348 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New();
349 option->id = "option:1";
350 option->selected = true;
351 shipping_options.push_back(std::move(option));
352 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
353 details->shipping_options = std::move(shipping_options);
354 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
355 options->request_shipping = true;
356 RecreateStateWithOptionsAndDetails(std::move(options), std::move(details),
357 GetMethodDataForVisa());
358
359 EXPECT_TRUE(state()->is_ready_to_pay());
360 state()->GeneratePaymentResponse();
361
362 // Check that all the expected values were set.
363 EXPECT_EQ("US", response()->shipping_address->country);
364 EXPECT_EQ("666 Erebus St.", response()->shipping_address->address_line[0]);
365 EXPECT_EQ("Apt 8", response()->shipping_address->address_line[1]);
366 EXPECT_EQ("CA", response()->shipping_address->region);
367 EXPECT_EQ("Elysium", response()->shipping_address->city);
368 EXPECT_EQ("", response()->shipping_address->dependent_locality);
369 EXPECT_EQ("91111", response()->shipping_address->postal_code);
370 EXPECT_EQ("", response()->shipping_address->sorting_code);
371 EXPECT_EQ("", response()->shipping_address->language_code);
372 EXPECT_EQ("Underworld", response()->shipping_address->organization);
373 EXPECT_EQ("John H. Doe", response()->shipping_address->recipient);
374 EXPECT_EQ("16502111111", response()->shipping_address->phone);
375 }
376
377 // Tests the the generated PaymentResponse has the correct values for the
378 // contact details when all values are requested.
379 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_All) {
380 // Request all contact detail values.
381 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
382 options->request_payer_name = true;
383 options->request_payer_phone = true;
384 options->request_payer_email = true;
385 RecreateStateWithOptions(std::move(options));
386
387 EXPECT_TRUE(state()->is_ready_to_pay());
388 state()->GeneratePaymentResponse();
389
390 // Check that all the expected values were set.
391 EXPECT_EQ("John H. Doe", response()->payer_name.value());
392 EXPECT_EQ("16502111111", response()->payer_phone.value());
393 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value());
394 }
395
396 // Tests the the generated PaymentResponse has the correct values for the
397 // contact details when all values are requested.
398 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_Some) {
399 // Request one contact detail value.
400 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
401 options->request_payer_name = true;
402 RecreateStateWithOptions(std::move(options));
403
404 EXPECT_TRUE(state()->is_ready_to_pay());
405 state()->GeneratePaymentResponse();
406
407 // Check that the name was set, but not the other values.
408 EXPECT_EQ("John H. Doe", response()->payer_name.value());
409 EXPECT_FALSE(response()->payer_phone.has_value());
410 EXPECT_FALSE(response()->payer_email.has_value());
411 }
412
343 } // namespace payments 413 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_state.cc ('k') | components/payments/content/payment_response_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698