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

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

Issue 2808633002: [Payments] Move PaymentResponse logic to PaymentResponseHelper. (Closed)
Patch Set: Addressed Mathp's 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 EXPECT_FALSE(state()->is_ready_to_pay()); 291 EXPECT_FALSE(state()->is_ready_to_pay());
292 292
293 state()->SetSelectedContactProfile(test_address()); 293 state()->SetSelectedContactProfile(test_address());
294 EXPECT_EQ(2, num_on_selected_information_changed_called()); 294 EXPECT_EQ(2, num_on_selected_information_changed_called());
295 295
296 // Ready to pay! 296 // Ready to pay!
297 EXPECT_TRUE(state()->is_ready_to_pay()); 297 EXPECT_TRUE(state()->is_ready_to_pay());
298 } 298 }
299 299
300 // TODO(crbug.com/710160): Move the PaymentResponse tests to
301 // payment_response_helper_unittest.cc.
300 // Test generating a PaymentResponse. 302 // Test generating a PaymentResponse.
301 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_SupportedMethod) { 303 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_SupportedMethod) {
302 // Default options (no shipping, no contact info). 304 // Default options (no shipping, no contact info).
303 RecreateStateWithOptions(mojom::PaymentOptions::New()); 305 RecreateStateWithOptions(mojom::PaymentOptions::New());
304 state()->SetSelectedInstrument(state()->available_instruments()[0].get()); 306 state()->SetSelectedInstrument(state()->available_instruments()[0].get());
305 EXPECT_EQ(1, num_on_selected_information_changed_called()); 307 EXPECT_EQ(1, num_on_selected_information_changed_called());
306 EXPECT_TRUE(state()->is_ready_to_pay()); 308 EXPECT_TRUE(state()->is_ready_to_pay());
307 309
308 // TODO(mathp): Currently synchronous, when async will need a RunLoop. 310 // TODO(mathp): Currently synchronous, when async will need a RunLoop.
309 // "visa" is specified directly in the supportedMethods so it is returned 311 // "visa" is specified directly in the supportedMethods so it is returned
(...skipping 11 matching lines...) Expand all
321 "\"recipient\":\"John H. Doe\"," 323 "\"recipient\":\"John H. Doe\","
322 "\"region\":\"CA\"}," 324 "\"region\":\"CA\"},"
323 "\"cardNumber\":\"4111111111111111\"," 325 "\"cardNumber\":\"4111111111111111\","
324 "\"cardSecurityCode\":\"123\"," 326 "\"cardSecurityCode\":\"123\","
325 "\"cardholderName\":\"Test User\"," 327 "\"cardholderName\":\"Test User\","
326 "\"expiryMonth\":\"11\"," 328 "\"expiryMonth\":\"11\","
327 "\"expiryYear\":\"2017\"}", 329 "\"expiryYear\":\"2017\"}",
328 response()->stringified_details); 330 response()->stringified_details);
329 } 331 }
330 332
333 // TODO(crbug.com/710160): Move the PaymentResponse tests to
334 // payment_response_helper_unittest.cc.
331 // Test generating a PaymentResponse when the method is specified through 335 // Test generating a PaymentResponse when the method is specified through
332 // "basic-card". 336 // "basic-card".
333 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_BasicCard) { 337 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_BasicCard) {
334 // The method data supports visa through basic-card. 338 // The method data supports visa through basic-card.
335 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); 339 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New();
336 entry->supported_methods.push_back("basic-card"); 340 entry->supported_methods.push_back("basic-card");
337 entry->supported_networks.push_back(mojom::BasicCardNetwork::VISA); 341 entry->supported_networks.push_back(mojom::BasicCardNetwork::VISA);
338 std::vector<mojom::PaymentMethodDataPtr> method_data; 342 std::vector<mojom::PaymentMethodDataPtr> method_data;
339 method_data.push_back(std::move(entry)); 343 method_data.push_back(std::move(entry));
340 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), 344 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(),
(...skipping 17 matching lines...) Expand all
358 "\"recipient\":\"John H. Doe\"," 362 "\"recipient\":\"John H. Doe\","
359 "\"region\":\"CA\"}," 363 "\"region\":\"CA\"},"
360 "\"cardNumber\":\"4111111111111111\"," 364 "\"cardNumber\":\"4111111111111111\","
361 "\"cardSecurityCode\":\"123\"," 365 "\"cardSecurityCode\":\"123\","
362 "\"cardholderName\":\"Test User\"," 366 "\"cardholderName\":\"Test User\","
363 "\"expiryMonth\":\"11\"," 367 "\"expiryMonth\":\"11\","
364 "\"expiryYear\":\"2017\"}", 368 "\"expiryYear\":\"2017\"}",
365 response()->stringified_details); 369 response()->stringified_details);
366 } 370 }
367 371
372 // TODO(crbug.com/710160): Move the PaymentResponse tests to
373 // payment_response_helper_unittest.cc.
368 // Tests the the generated PaymentResponse has the correct values for the 374 // Tests the the generated PaymentResponse has the correct values for the
369 // shipping address. 375 // shipping address.
370 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ShippingAddress) { 376 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ShippingAddress) {
371 // Setup so that a shipping address is requested. 377 // Setup so that a shipping address is requested.
372 std::vector<mojom::PaymentShippingOptionPtr> shipping_options; 378 std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
373 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New(); 379 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New();
374 option->id = "option:1"; 380 option->id = "option:1";
375 option->selected = true; 381 option->selected = true;
376 shipping_options.push_back(std::move(option)); 382 shipping_options.push_back(std::move(option));
377 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New(); 383 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
(...skipping 14 matching lines...) Expand all
392 EXPECT_EQ("Elysium", response()->shipping_address->city); 398 EXPECT_EQ("Elysium", response()->shipping_address->city);
393 EXPECT_EQ("", response()->shipping_address->dependent_locality); 399 EXPECT_EQ("", response()->shipping_address->dependent_locality);
394 EXPECT_EQ("91111", response()->shipping_address->postal_code); 400 EXPECT_EQ("91111", response()->shipping_address->postal_code);
395 EXPECT_EQ("", response()->shipping_address->sorting_code); 401 EXPECT_EQ("", response()->shipping_address->sorting_code);
396 EXPECT_EQ("", response()->shipping_address->language_code); 402 EXPECT_EQ("", response()->shipping_address->language_code);
397 EXPECT_EQ("Underworld", response()->shipping_address->organization); 403 EXPECT_EQ("Underworld", response()->shipping_address->organization);
398 EXPECT_EQ("John H. Doe", response()->shipping_address->recipient); 404 EXPECT_EQ("John H. Doe", response()->shipping_address->recipient);
399 EXPECT_EQ("16502111111", response()->shipping_address->phone); 405 EXPECT_EQ("16502111111", response()->shipping_address->phone);
400 } 406 }
401 407
408 // TODO(crbug.com/710160): Move the PaymentResponse tests to
409 // payment_response_helper_unittest.cc.
402 // Tests the the generated PaymentResponse has the correct values for the 410 // Tests the the generated PaymentResponse has the correct values for the
403 // contact details when all values are requested. 411 // contact details when all values are requested.
404 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_All) { 412 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_All) {
405 // Request all contact detail values. 413 // Request all contact detail values.
406 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); 414 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
407 options->request_payer_name = true; 415 options->request_payer_name = true;
408 options->request_payer_phone = true; 416 options->request_payer_phone = true;
409 options->request_payer_email = true; 417 options->request_payer_email = true;
410 RecreateStateWithOptions(std::move(options)); 418 RecreateStateWithOptions(std::move(options));
411 419
412 EXPECT_TRUE(state()->is_ready_to_pay()); 420 EXPECT_TRUE(state()->is_ready_to_pay());
413 state()->GeneratePaymentResponse(); 421 state()->GeneratePaymentResponse();
414 422
415 // Check that all the expected values were set. 423 // Check that all the expected values were set.
416 EXPECT_EQ("John H. Doe", response()->payer_name.value()); 424 EXPECT_EQ("John H. Doe", response()->payer_name.value());
417 EXPECT_EQ("16502111111", response()->payer_phone.value()); 425 EXPECT_EQ("16502111111", response()->payer_phone.value());
418 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value()); 426 EXPECT_EQ("johndoe@hades.com", response()->payer_email.value());
419 } 427 }
420 428
429 // TODO(crbug.com/710160): Move the PaymentResponse tests to
430 // payment_response_helper_unittest.cc.
421 // Tests the the generated PaymentResponse has the correct values for the 431 // Tests the the generated PaymentResponse has the correct values for the
422 // contact details when all values are requested. 432 // contact details when all values are requested.
423 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_Some) { 433 TEST_F(PaymentRequestStateTest, GeneratePaymentResponse_ContactDetails_Some) {
424 // Request one contact detail value. 434 // Request one contact detail value.
425 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); 435 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
426 options->request_payer_name = true; 436 options->request_payer_name = true;
427 RecreateStateWithOptions(std::move(options)); 437 RecreateStateWithOptions(std::move(options));
428 438
429 EXPECT_TRUE(state()->is_ready_to_pay()); 439 EXPECT_TRUE(state()->is_ready_to_pay());
430 state()->GeneratePaymentResponse(); 440 state()->GeneratePaymentResponse();
431 441
432 // Check that the name was set, but not the other values. 442 // Check that the name was set, but not the other values.
433 EXPECT_EQ("John H. Doe", response()->payer_name.value()); 443 EXPECT_EQ("John H. Doe", response()->payer_name.value());
434 EXPECT_FALSE(response()->payer_phone.has_value()); 444 EXPECT_FALSE(response()->payer_phone.has_value());
435 EXPECT_FALSE(response()->payer_email.has_value()); 445 EXPECT_FALSE(response()->payer_email.has_value());
436 } 446 }
437 447
438 } // namespace payments 448 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698