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

Side by Side Diff: ios/chrome/browser/payments/payment_request_unittest.mm

Issue 2750363002: [Payment Request] supported card networks + adding a credit card. (Closed)
Patch Set: Addressed comments Created 3 years, 9 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
« no previous file with comments | « ios/chrome/browser/payments/payment_request.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/test_personal_data_manager.h" 8 #include "components/autofill/core/browser/test_personal_data_manager.h"
9 #include "components/payments/core/currency_formatter.h" 9 #include "components/payments/core/currency_formatter.h"
10 #include "ios/chrome/browser/application_context.h" 10 #include "ios/chrome/browser/application_context.h"
11 #include "ios/chrome/browser/payments/payment_request_test_util.h"
11 #include "ios/web/public/payments/payment_request.h" 12 #include "ios/web/public/payments/payment_request.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 16 #error "This file requires ARC support."
16 #endif 17 #endif
17 18
18 // Tests that the payments::CurrencyFormatter is constructed with the correct 19 // Tests that the payments::CurrencyFormatter is constructed with the correct
19 // currency code and currency system. 20 // currency code and currency system.
20 TEST(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) { 21 TEST(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) {
21 ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale()); 22 ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale());
22 23
24 web::PaymentRequest web_payment_request;
23 autofill::TestPersonalDataManager personal_data_manager; 25 autofill::TestPersonalDataManager personal_data_manager;
24 26
25 std::unique_ptr<web::PaymentRequest> web_payment_request = 27 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD");
26 base::MakeUnique<web::PaymentRequest>(); 28 PaymentRequest payment_request1(
27 web_payment_request->details.total.amount.currency = 29 base::MakeUnique<web::PaymentRequest>(web_payment_request),
28 base::ASCIIToUTF16("USD"); 30 &personal_data_manager);
29 PaymentRequest payment_request1(std::move(web_payment_request),
30 &personal_data_manager);
31 payments::CurrencyFormatter* currency_formatter = 31 payments::CurrencyFormatter* currency_formatter =
32 payment_request1.GetOrCreateCurrencyFormatter(); 32 payment_request1.GetOrCreateCurrencyFormatter();
33 ASSERT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00")); 33 EXPECT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00"));
34 ASSERT_EQ("USD", currency_formatter->formatted_currency_code()); 34 EXPECT_EQ("USD", currency_formatter->formatted_currency_code());
35 35
36 web_payment_request = base::MakeUnique<web::PaymentRequest>(); 36 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("JPY");
37 web_payment_request->details.total.amount.currency = 37 PaymentRequest payment_request2(
38 base::ASCIIToUTF16("JPY"); 38 base::MakeUnique<web::PaymentRequest>(web_payment_request),
39 PaymentRequest payment_request2(std::move(web_payment_request), 39 &personal_data_manager);
40 &personal_data_manager);
41 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter(); 40 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter();
42 ASSERT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00")); 41 EXPECT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00"));
43 ASSERT_EQ("JPY", currency_formatter->formatted_currency_code()); 42 EXPECT_EQ("JPY", currency_formatter->formatted_currency_code());
44 43
45 web_payment_request = base::MakeUnique<web::PaymentRequest>(); 44 web_payment_request.details.total.amount.currency_system =
46 web_payment_request->details.total.amount.currency_system =
47 base::ASCIIToUTF16("NOT_ISO4217"); 45 base::ASCIIToUTF16("NOT_ISO4217");
48 web_payment_request->details.total.amount.currency = 46 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD");
49 base::ASCIIToUTF16("USD"); 47 PaymentRequest payment_request3(
50 PaymentRequest payment_request3(std::move(web_payment_request), 48 base::MakeUnique<web::PaymentRequest>(web_payment_request),
51 &personal_data_manager); 49 &personal_data_manager);
52 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); 50 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter();
53 ASSERT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); 51 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00"));
54 ASSERT_EQ("USD", currency_formatter->formatted_currency_code()); 52 EXPECT_EQ("USD", currency_formatter->formatted_currency_code());
55 } 53 }
54
55 // Tests that the accepted card networks are identified correctly.
56 TEST(PaymentRequestTest, AcceptedPaymentNetworks) {
57 web::PaymentRequest web_payment_request;
58 autofill::TestPersonalDataManager personal_data_manager;
59
60 web::PaymentMethodData method_datum1;
61 method_datum1.supported_methods.push_back(base::ASCIIToUTF16("visa"));
62 web_payment_request.method_data.push_back(method_datum1);
63 web::PaymentMethodData method_datum2;
64 method_datum2.supported_methods.push_back(base::ASCIIToUTF16("mastercard"));
65 web_payment_request.method_data.push_back(method_datum2);
66
67 PaymentRequest payment_request(
68 base::MakeUnique<web::PaymentRequest>(web_payment_request),
69 &personal_data_manager);
70 ASSERT_EQ(2U, payment_request.supported_card_networks().size());
71 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]);
72 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]);
73 }
74
75 // Tests that credit cards can be added to the list of cached credit cards.
76 TEST(PaymentRequestTest, AddCreditCard) {
77 web::PaymentRequest web_payment_request;
78 autofill::TestPersonalDataManager personal_data_manager;
79
80 PaymentRequest payment_request(
81 base::MakeUnique<web::PaymentRequest>(web_payment_request),
82 &personal_data_manager);
83 EXPECT_EQ(0U, payment_request.credit_cards().size());
84
85 std::unique_ptr<autofill::CreditCard> credit_card =
86 payment_request_test_util::CreateTestCreditCard();
87 const autofill::CreditCard* added_credit_card = credit_card.get();
88 payment_request.AddCreditCard(std::move(credit_card));
89 ASSERT_EQ(1U, payment_request.credit_cards().size());
90 EXPECT_EQ(added_credit_card, payment_request.credit_cards()[0]);
91 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/payment_request.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698