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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/scoped_task_environment.h" | 10 #include "base/test/scoped_task_environment.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 base::test::ScopedTaskEnvironment scoped_task_environment_; | 78 base::test::ScopedTaskEnvironment scoped_task_environment_; |
79 | 79 |
80 web::TestWebState web_state_; | 80 web::TestWebState web_state_; |
81 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 81 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
82 }; | 82 }; |
83 | 83 |
84 // Tests that the payments::CurrencyFormatter is constructed with the correct | 84 // Tests that the payments::CurrencyFormatter is constructed with the correct |
85 // currency code and currency system. | 85 // currency code and currency system. |
86 TEST_F(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) { | 86 TEST_F(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) { |
87 ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale()); | |
88 | 87 |
89 web::PaymentRequest web_payment_request; | 88 web::PaymentRequest web_payment_request; |
90 autofill::TestPersonalDataManager personal_data_manager; | 89 autofill::TestPersonalDataManager personal_data_manager; |
91 | 90 |
92 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); | 91 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); |
93 TestPaymentRequest payment_request1(web_payment_request, | 92 TestPaymentRequest payment_request1(web_payment_request, |
94 chrome_browser_state_.get(), &web_state_, | 93 chrome_browser_state_.get(), &web_state_, |
95 &personal_data_manager); | 94 &personal_data_manager); |
| 95 ASSERT_EQ("en", payment_request1.GetApplicationLocale()); |
96 CurrencyFormatter* currency_formatter = | 96 CurrencyFormatter* currency_formatter = |
97 payment_request1.GetOrCreateCurrencyFormatter(); | 97 payment_request1.GetOrCreateCurrencyFormatter(); |
98 EXPECT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00")); | 98 EXPECT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00")); |
99 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); | 99 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); |
100 | 100 |
101 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("JPY"); | 101 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("JPY"); |
102 TestPaymentRequest payment_request2(web_payment_request, | 102 TestPaymentRequest payment_request2(web_payment_request, |
103 chrome_browser_state_.get(), &web_state_, | 103 chrome_browser_state_.get(), &web_state_, |
104 &personal_data_manager); | 104 &personal_data_manager); |
| 105 ASSERT_EQ("en", payment_request2.GetApplicationLocale()); |
105 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter(); | 106 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter(); |
106 EXPECT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00")); | 107 EXPECT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00")); |
107 EXPECT_EQ("JPY", currency_formatter->formatted_currency_code()); | 108 EXPECT_EQ("JPY", currency_formatter->formatted_currency_code()); |
108 | 109 |
109 web_payment_request.details.total.amount.currency_system = | 110 web_payment_request.details.total.amount.currency_system = |
110 base::ASCIIToUTF16("NOT_ISO4217"); | 111 base::ASCIIToUTF16("NOT_ISO4217"); |
111 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); | 112 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); |
112 TestPaymentRequest payment_request3(web_payment_request, | 113 TestPaymentRequest payment_request3(web_payment_request, |
113 chrome_browser_state_.get(), &web_state_, | 114 chrome_browser_state_.get(), &web_state_, |
114 &personal_data_manager); | 115 &personal_data_manager); |
| 116 ASSERT_EQ("en", payment_request3.GetApplicationLocale()); |
115 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); | 117 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); |
116 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); | 118 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); |
117 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); | 119 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); |
118 } | 120 } |
119 | 121 |
120 // Tests that the accepted card networks are identified correctly. | 122 // Tests that the accepted card networks are identified correctly. |
121 TEST_F(PaymentRequestTest, AcceptedPaymentNetworks) { | 123 TEST_F(PaymentRequestTest, AcceptedPaymentNetworks) { |
122 web::PaymentRequest web_payment_request; | 124 web::PaymentRequest web_payment_request; |
123 autofill::TestPersonalDataManager personal_data_manager; | 125 autofill::TestPersonalDataManager personal_data_manager; |
124 | 126 |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) | 789 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) |
788 .Times(0); | 790 .Times(0); |
789 EXPECT_CALL(personal_data_manager, | 791 EXPECT_CALL(personal_data_manager, |
790 RecordUseOf(GuidMatches(credit_card.guid()))) | 792 RecordUseOf(GuidMatches(credit_card.guid()))) |
791 .Times(1); | 793 .Times(1); |
792 | 794 |
793 payment_request.RecordUseStats(); | 795 payment_request.RecordUseStats(); |
794 } | 796 } |
795 | 797 |
796 } // namespace payments | 798 } // namespace payments |
OLD | NEW |