| 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 "ios/chrome/browser/payments/payment_request.h" | 5 #include "ios/chrome/browser/payments/payment_request.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/browser/autofill_test_utils.h" | 8 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 9 #include "components/autofill/core/browser/test_personal_data_manager.h" | 9 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 10 #include "components/payments/core/currency_formatter.h" | 10 #include "components/payments/core/currency_formatter.h" |
| 11 #include "components/payments/core/payment_method_data.h" |
| 11 #include "ios/chrome/browser/application_context.h" | 12 #include "ios/chrome/browser/application_context.h" |
| 12 #include "ios/web/public/payments/payment_request.h" | 13 #include "ios/web/public/payments/payment_request.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 // Tests that the payments::CurrencyFormatter is constructed with the correct | 20 // Tests that the payments::CurrencyFormatter is constructed with the correct |
| 20 // currency code and currency system. | 21 // currency code and currency system. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); | 45 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); |
| 45 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); | 46 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); |
| 46 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); | 47 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); |
| 47 } | 48 } |
| 48 | 49 |
| 49 // Tests that the accepted card networks are identified correctly. | 50 // Tests that the accepted card networks are identified correctly. |
| 50 TEST(PaymentRequestTest, AcceptedPaymentNetworks) { | 51 TEST(PaymentRequestTest, AcceptedPaymentNetworks) { |
| 51 web::PaymentRequest web_payment_request; | 52 web::PaymentRequest web_payment_request; |
| 52 autofill::TestPersonalDataManager personal_data_manager; | 53 autofill::TestPersonalDataManager personal_data_manager; |
| 53 | 54 |
| 54 web::PaymentMethodData method_datum1; | 55 payments::PaymentMethodData method_datum1; |
| 55 method_datum1.supported_methods.push_back(base::ASCIIToUTF16("visa")); | 56 method_datum1.supported_methods.push_back(base::ASCIIToUTF16("visa")); |
| 56 web_payment_request.method_data.push_back(method_datum1); | 57 web_payment_request.method_data.push_back(method_datum1); |
| 57 web::PaymentMethodData method_datum2; | 58 payments::PaymentMethodData method_datum2; |
| 58 method_datum2.supported_methods.push_back(base::ASCIIToUTF16("mastercard")); | 59 method_datum2.supported_methods.push_back(base::ASCIIToUTF16("mastercard")); |
| 59 web_payment_request.method_data.push_back(method_datum2); | 60 web_payment_request.method_data.push_back(method_datum2); |
| 60 | 61 |
| 61 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | 62 PaymentRequest payment_request(web_payment_request, &personal_data_manager); |
| 62 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | 63 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); |
| 63 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 64 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
| 64 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | 65 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Tests that credit cards can be added to the list of cached credit cards. | 68 // Tests that credit cards can be added to the list of cached credit cards. |
| 68 TEST(PaymentRequestTest, AddCreditCard) { | 69 TEST(PaymentRequestTest, AddCreditCard) { |
| 69 web::PaymentRequest web_payment_request; | 70 web::PaymentRequest web_payment_request; |
| 70 autofill::TestPersonalDataManager personal_data_manager; | 71 autofill::TestPersonalDataManager personal_data_manager; |
| 71 | 72 |
| 72 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | 73 PaymentRequest payment_request(web_payment_request, &personal_data_manager); |
| 73 EXPECT_EQ(0U, payment_request.credit_cards().size()); | 74 EXPECT_EQ(0U, payment_request.credit_cards().size()); |
| 74 | 75 |
| 75 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 76 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 76 payment_request.AddCreditCard(credit_card); | 77 payment_request.AddCreditCard(credit_card); |
| 77 ASSERT_EQ(1U, payment_request.credit_cards().size()); | 78 ASSERT_EQ(1U, payment_request.credit_cards().size()); |
| 78 EXPECT_EQ(credit_card, *payment_request.credit_cards()[0]); | 79 EXPECT_EQ(credit_card, *payment_request.credit_cards()[0]); |
| 79 } | 80 } |
| OLD | NEW |