| 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> |
| 8 |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/scoped_task_environment.h" | 10 #include "base/test/scoped_task_environment.h" |
| 9 #include "components/autofill/core/browser/autofill_test_utils.h" | 11 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 10 #include "components/autofill/core/browser/autofill_type.h" | 12 #include "components/autofill/core/browser/autofill_type.h" |
| 11 #include "components/autofill/core/browser/field_types.h" | 13 #include "components/autofill/core/browser/field_types.h" |
| 12 #include "components/autofill/core/browser/test_personal_data_manager.h" | 14 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 13 #include "components/payments/core/autofill_payment_instrument.h" | 15 #include "components/payments/core/autofill_payment_instrument.h" |
| 14 #include "components/payments/core/currency_formatter.h" | 16 #include "components/payments/core/currency_formatter.h" |
| 15 #include "components/payments/core/payment_method_data.h" | 17 #include "components/payments/core/payment_method_data.h" |
| 16 #include "ios/chrome/browser/application_context.h" | 18 #include "ios/chrome/browser/application_context.h" |
| 19 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 17 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 20 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 18 #include "ios/chrome/browser/payments/test_payment_request.h" | 21 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 19 #include "ios/web/public/payments/payment_request.h" | 22 #include "ios/web/public/payments/payment_request.h" |
| 23 #import "ios/web/public/test/fakes/test_web_state.h" |
| 20 #include "testing/gmock/include/gmock/gmock-matchers.h" | 24 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 27 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." | 29 #error "This file requires ARC support." |
| 26 #endif | 30 #endif |
| 27 | 31 |
| 28 namespace { | 32 namespace { |
| 29 | 33 |
| 30 class MockTestPersonalDataManager : public autofill::TestPersonalDataManager { | 34 class MockTestPersonalDataManager : public autofill::TestPersonalDataManager { |
| 31 public: | 35 public: |
| 32 MockTestPersonalDataManager() : TestPersonalDataManager() {} | 36 MockTestPersonalDataManager() : TestPersonalDataManager() {} |
| 33 MOCK_METHOD1(RecordUseOf, void(const autofill::AutofillDataModel&)); | 37 MOCK_METHOD1(RecordUseOf, void(const autofill::AutofillDataModel&)); |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 MATCHER_P(GuidMatches, guid, "") { | 40 MATCHER_P(GuidMatches, guid, "") { |
| 37 return arg.guid() == guid; | 41 return arg.guid() == guid; |
| 38 } | 42 } |
| 39 | 43 |
| 40 } // namespace | 44 } // namespace |
| 41 | 45 |
| 42 namespace payments { | 46 namespace payments { |
| 43 | 47 |
| 44 class PaymentRequestTest : public testing::Test { | 48 class PaymentRequestTest : public testing::Test { |
| 45 protected: | 49 protected: |
| 50 PaymentRequestTest() |
| 51 : chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {} |
| 52 |
| 46 // Returns PaymentDetails with one shipping option that's selected. | 53 // Returns PaymentDetails with one shipping option that's selected. |
| 47 web::PaymentDetails CreateDetailsWithShippingOption() { | 54 web::PaymentDetails CreateDetailsWithShippingOption() { |
| 48 web::PaymentDetails details; | 55 web::PaymentDetails details; |
| 49 std::vector<web::PaymentShippingOption> shipping_options; | 56 std::vector<web::PaymentShippingOption> shipping_options; |
| 50 web::PaymentShippingOption option1; | 57 web::PaymentShippingOption option1; |
| 51 option1.id = base::UTF8ToUTF16("option:1"); | 58 option1.id = base::UTF8ToUTF16("option:1"); |
| 52 option1.selected = true; | 59 option1.selected = true; |
| 53 shipping_options.push_back(std::move(option1)); | 60 shipping_options.push_back(std::move(option1)); |
| 54 details.shipping_options = std::move(shipping_options); | 61 details.shipping_options = std::move(shipping_options); |
| 55 | 62 |
| 56 return details; | 63 return details; |
| 57 } | 64 } |
| 58 | 65 |
| 59 web::PaymentOptions CreatePaymentOptions(bool request_payer_name, | 66 web::PaymentOptions CreatePaymentOptions(bool request_payer_name, |
| 60 bool request_payer_phone, | 67 bool request_payer_phone, |
| 61 bool request_payer_email, | 68 bool request_payer_email, |
| 62 bool request_shipping) { | 69 bool request_shipping) { |
| 63 web::PaymentOptions options; | 70 web::PaymentOptions options; |
| 64 options.request_payer_name = request_payer_name; | 71 options.request_payer_name = request_payer_name; |
| 65 options.request_payer_phone = request_payer_phone; | 72 options.request_payer_phone = request_payer_phone; |
| 66 options.request_payer_email = request_payer_email; | 73 options.request_payer_email = request_payer_email; |
| 67 options.request_shipping = request_shipping; | 74 options.request_shipping = request_shipping; |
| 68 return options; | 75 return options; |
| 69 } | 76 } |
| 70 | 77 |
| 71 base::test::ScopedTaskEnvironment scoped_task_environment_; | 78 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 79 |
| 80 web::TestWebState web_state_; |
| 81 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 72 }; | 82 }; |
| 73 | 83 |
| 74 // Tests that the payments::CurrencyFormatter is constructed with the correct | 84 // Tests that the payments::CurrencyFormatter is constructed with the correct |
| 75 // currency code and currency system. | 85 // currency code and currency system. |
| 76 TEST_F(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) { | 86 TEST_F(PaymentRequestTest, CreatesCurrencyFormatterCorrectly) { |
| 77 ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale()); | 87 ASSERT_EQ("en", GetApplicationContext()->GetApplicationLocale()); |
| 78 | 88 |
| 79 web::PaymentRequest web_payment_request; | 89 web::PaymentRequest web_payment_request; |
| 80 autofill::TestPersonalDataManager personal_data_manager; | 90 autofill::TestPersonalDataManager personal_data_manager; |
| 81 | 91 |
| 82 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); | 92 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); |
| 83 TestPaymentRequest payment_request1(web_payment_request, | 93 TestPaymentRequest payment_request1(web_payment_request, |
| 94 chrome_browser_state_.get(), &web_state_, |
| 84 &personal_data_manager); | 95 &personal_data_manager); |
| 85 CurrencyFormatter* currency_formatter = | 96 CurrencyFormatter* currency_formatter = |
| 86 payment_request1.GetOrCreateCurrencyFormatter(); | 97 payment_request1.GetOrCreateCurrencyFormatter(); |
| 87 EXPECT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00")); | 98 EXPECT_EQ(base::UTF8ToUTF16("$55.00"), currency_formatter->Format("55.00")); |
| 88 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); | 99 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); |
| 89 | 100 |
| 90 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("JPY"); | 101 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("JPY"); |
| 91 TestPaymentRequest payment_request2(web_payment_request, | 102 TestPaymentRequest payment_request2(web_payment_request, |
| 103 chrome_browser_state_.get(), &web_state_, |
| 92 &personal_data_manager); | 104 &personal_data_manager); |
| 93 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter(); | 105 currency_formatter = payment_request2.GetOrCreateCurrencyFormatter(); |
| 94 EXPECT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00")); | 106 EXPECT_EQ(base::UTF8ToUTF16("¥55"), currency_formatter->Format("55.00")); |
| 95 EXPECT_EQ("JPY", currency_formatter->formatted_currency_code()); | 107 EXPECT_EQ("JPY", currency_formatter->formatted_currency_code()); |
| 96 | 108 |
| 97 web_payment_request.details.total.amount.currency_system = | 109 web_payment_request.details.total.amount.currency_system = |
| 98 base::ASCIIToUTF16("NOT_ISO4217"); | 110 base::ASCIIToUTF16("NOT_ISO4217"); |
| 99 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); | 111 web_payment_request.details.total.amount.currency = base::ASCIIToUTF16("USD"); |
| 100 TestPaymentRequest payment_request3(web_payment_request, | 112 TestPaymentRequest payment_request3(web_payment_request, |
| 113 chrome_browser_state_.get(), &web_state_, |
| 101 &personal_data_manager); | 114 &personal_data_manager); |
| 102 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); | 115 currency_formatter = payment_request3.GetOrCreateCurrencyFormatter(); |
| 103 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); | 116 EXPECT_EQ(base::UTF8ToUTF16("55.00"), currency_formatter->Format("55.00")); |
| 104 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); | 117 EXPECT_EQ("USD", currency_formatter->formatted_currency_code()); |
| 105 } | 118 } |
| 106 | 119 |
| 107 // Tests that the accepted card networks are identified correctly. | 120 // Tests that the accepted card networks are identified correctly. |
| 108 TEST_F(PaymentRequestTest, AcceptedPaymentNetworks) { | 121 TEST_F(PaymentRequestTest, AcceptedPaymentNetworks) { |
| 109 web::PaymentRequest web_payment_request; | 122 web::PaymentRequest web_payment_request; |
| 110 autofill::TestPersonalDataManager personal_data_manager; | 123 autofill::TestPersonalDataManager personal_data_manager; |
| 111 | 124 |
| 112 PaymentMethodData method_datum1; | 125 PaymentMethodData method_datum1; |
| 113 method_datum1.supported_methods.push_back("visa"); | 126 method_datum1.supported_methods.push_back("visa"); |
| 114 web_payment_request.method_data.push_back(method_datum1); | 127 web_payment_request.method_data.push_back(method_datum1); |
| 115 PaymentMethodData method_datum2; | 128 PaymentMethodData method_datum2; |
| 116 method_datum2.supported_methods.push_back("mastercard"); | 129 method_datum2.supported_methods.push_back("mastercard"); |
| 117 web_payment_request.method_data.push_back(method_datum2); | 130 web_payment_request.method_data.push_back(method_datum2); |
| 118 | 131 |
| 119 TestPaymentRequest payment_request(web_payment_request, | 132 TestPaymentRequest payment_request(web_payment_request, |
| 133 chrome_browser_state_.get(), &web_state_, |
| 120 &personal_data_manager); | 134 &personal_data_manager); |
| 121 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | 135 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); |
| 122 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 136 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
| 123 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | 137 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); |
| 124 } | 138 } |
| 125 | 139 |
| 126 // Test that parsing supported methods (with invalid values and duplicates) | 140 // Test that parsing supported methods (with invalid values and duplicates) |
| 127 // works as expected. | 141 // works as expected. |
| 128 TEST_F(PaymentRequestTest, SupportedMethods) { | 142 TEST_F(PaymentRequestTest, SupportedMethods) { |
| 129 web::PaymentRequest web_payment_request; | 143 web::PaymentRequest web_payment_request; |
| 130 autofill::TestPersonalDataManager personal_data_manager; | 144 autofill::TestPersonalDataManager personal_data_manager; |
| 131 | 145 |
| 132 PaymentMethodData method_datum1; | 146 PaymentMethodData method_datum1; |
| 133 method_datum1.supported_methods.push_back("visa"); | 147 method_datum1.supported_methods.push_back("visa"); |
| 134 method_datum1.supported_methods.push_back("mastercard"); | 148 method_datum1.supported_methods.push_back("mastercard"); |
| 135 method_datum1.supported_methods.push_back("invalid"); | 149 method_datum1.supported_methods.push_back("invalid"); |
| 136 method_datum1.supported_methods.push_back(""); | 150 method_datum1.supported_methods.push_back(""); |
| 137 method_datum1.supported_methods.push_back("visa"); | 151 method_datum1.supported_methods.push_back("visa"); |
| 138 web_payment_request.method_data.push_back(method_datum1); | 152 web_payment_request.method_data.push_back(method_datum1); |
| 139 | 153 |
| 140 TestPaymentRequest payment_request(web_payment_request, | 154 TestPaymentRequest payment_request(web_payment_request, |
| 155 chrome_browser_state_.get(), &web_state_, |
| 141 &personal_data_manager); | 156 &personal_data_manager); |
| 142 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | 157 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); |
| 143 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 158 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
| 144 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | 159 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); |
| 145 } | 160 } |
| 146 | 161 |
| 147 // Test that parsing supported methods in different method data entries (with | 162 // Test that parsing supported methods in different method data entries (with |
| 148 // invalid values and duplicates) works as expected. | 163 // invalid values and duplicates) works as expected. |
| 149 TEST_F(PaymentRequestTest, SupportedMethods_MultipleEntries) { | 164 TEST_F(PaymentRequestTest, SupportedMethods_MultipleEntries) { |
| 150 web::PaymentRequest web_payment_request; | 165 web::PaymentRequest web_payment_request; |
| 151 autofill::TestPersonalDataManager personal_data_manager; | 166 autofill::TestPersonalDataManager personal_data_manager; |
| 152 | 167 |
| 153 PaymentMethodData method_datum1; | 168 PaymentMethodData method_datum1; |
| 154 method_datum1.supported_methods.push_back("visa"); | 169 method_datum1.supported_methods.push_back("visa"); |
| 155 web_payment_request.method_data.push_back(method_datum1); | 170 web_payment_request.method_data.push_back(method_datum1); |
| 156 PaymentMethodData method_datum2; | 171 PaymentMethodData method_datum2; |
| 157 method_datum2.supported_methods.push_back("mastercard"); | 172 method_datum2.supported_methods.push_back("mastercard"); |
| 158 web_payment_request.method_data.push_back(method_datum2); | 173 web_payment_request.method_data.push_back(method_datum2); |
| 159 PaymentMethodData method_datum3; | 174 PaymentMethodData method_datum3; |
| 160 method_datum3.supported_methods.push_back(""); | 175 method_datum3.supported_methods.push_back(""); |
| 161 web_payment_request.method_data.push_back(method_datum3); | 176 web_payment_request.method_data.push_back(method_datum3); |
| 162 PaymentMethodData method_datum4; | 177 PaymentMethodData method_datum4; |
| 163 method_datum4.supported_methods.push_back("visa"); | 178 method_datum4.supported_methods.push_back("visa"); |
| 164 web_payment_request.method_data.push_back(method_datum4); | 179 web_payment_request.method_data.push_back(method_datum4); |
| 165 | 180 |
| 166 TestPaymentRequest payment_request(web_payment_request, | 181 TestPaymentRequest payment_request(web_payment_request, |
| 182 chrome_browser_state_.get(), &web_state_, |
| 167 &personal_data_manager); | 183 &personal_data_manager); |
| 168 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | 184 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); |
| 169 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 185 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
| 170 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | 186 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); |
| 171 } | 187 } |
| 172 | 188 |
| 173 // Test that only specifying basic-card means that all are supported. | 189 // Test that only specifying basic-card means that all are supported. |
| 174 TEST_F(PaymentRequestTest, SupportedMethods_OnlyBasicCard) { | 190 TEST_F(PaymentRequestTest, SupportedMethods_OnlyBasicCard) { |
| 175 web::PaymentRequest web_payment_request; | 191 web::PaymentRequest web_payment_request; |
| 176 autofill::TestPersonalDataManager personal_data_manager; | 192 autofill::TestPersonalDataManager personal_data_manager; |
| 177 | 193 |
| 178 PaymentMethodData method_datum1; | 194 PaymentMethodData method_datum1; |
| 179 method_datum1.supported_methods.push_back("basic-card"); | 195 method_datum1.supported_methods.push_back("basic-card"); |
| 180 web_payment_request.method_data.push_back(method_datum1); | 196 web_payment_request.method_data.push_back(method_datum1); |
| 181 | 197 |
| 182 TestPaymentRequest payment_request(web_payment_request, | 198 TestPaymentRequest payment_request(web_payment_request, |
| 199 chrome_browser_state_.get(), &web_state_, |
| 183 &personal_data_manager); | 200 &personal_data_manager); |
| 184 | 201 |
| 185 // All of the basic card networks are supported. | 202 // All of the basic card networks are supported. |
| 186 ASSERT_EQ(8U, payment_request.supported_card_networks().size()); | 203 ASSERT_EQ(8U, payment_request.supported_card_networks().size()); |
| 187 EXPECT_EQ("amex", payment_request.supported_card_networks()[0]); | 204 EXPECT_EQ("amex", payment_request.supported_card_networks()[0]); |
| 188 EXPECT_EQ("diners", payment_request.supported_card_networks()[1]); | 205 EXPECT_EQ("diners", payment_request.supported_card_networks()[1]); |
| 189 EXPECT_EQ("discover", payment_request.supported_card_networks()[2]); | 206 EXPECT_EQ("discover", payment_request.supported_card_networks()[2]); |
| 190 EXPECT_EQ("jcb", payment_request.supported_card_networks()[3]); | 207 EXPECT_EQ("jcb", payment_request.supported_card_networks()[3]); |
| 191 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); | 208 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); |
| 192 EXPECT_EQ("mir", payment_request.supported_card_networks()[5]); | 209 EXPECT_EQ("mir", payment_request.supported_card_networks()[5]); |
| 193 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[6]); | 210 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[6]); |
| 194 EXPECT_EQ("visa", payment_request.supported_card_networks()[7]); | 211 EXPECT_EQ("visa", payment_request.supported_card_networks()[7]); |
| 195 } | 212 } |
| 196 | 213 |
| 197 // Test that specifying a method AND basic-card means that all are supported, | 214 // Test that specifying a method AND basic-card means that all are supported, |
| 198 // but with the method as first. | 215 // but with the method as first. |
| 199 TEST_F(PaymentRequestTest, SupportedMethods_BasicCard_WithSpecificMethod) { | 216 TEST_F(PaymentRequestTest, SupportedMethods_BasicCard_WithSpecificMethod) { |
| 200 web::PaymentRequest web_payment_request; | 217 web::PaymentRequest web_payment_request; |
| 201 autofill::TestPersonalDataManager personal_data_manager; | 218 autofill::TestPersonalDataManager personal_data_manager; |
| 202 | 219 |
| 203 PaymentMethodData method_datum1; | 220 PaymentMethodData method_datum1; |
| 204 method_datum1.supported_methods.push_back("jcb"); | 221 method_datum1.supported_methods.push_back("jcb"); |
| 205 method_datum1.supported_methods.push_back("basic-card"); | 222 method_datum1.supported_methods.push_back("basic-card"); |
| 206 web_payment_request.method_data.push_back(method_datum1); | 223 web_payment_request.method_data.push_back(method_datum1); |
| 207 | 224 |
| 208 TestPaymentRequest payment_request(web_payment_request, | 225 TestPaymentRequest payment_request(web_payment_request, |
| 226 chrome_browser_state_.get(), &web_state_, |
| 209 &personal_data_manager); | 227 &personal_data_manager); |
| 210 | 228 |
| 211 // All of the basic card networks are supported, but JCB is first because it | 229 // All of the basic card networks are supported, but JCB is first because it |
| 212 // was specified first. | 230 // was specified first. |
| 213 EXPECT_EQ(8u, payment_request.supported_card_networks().size()); | 231 EXPECT_EQ(8u, payment_request.supported_card_networks().size()); |
| 214 EXPECT_EQ("jcb", payment_request.supported_card_networks()[0]); | 232 EXPECT_EQ("jcb", payment_request.supported_card_networks()[0]); |
| 215 EXPECT_EQ("amex", payment_request.supported_card_networks()[1]); | 233 EXPECT_EQ("amex", payment_request.supported_card_networks()[1]); |
| 216 EXPECT_EQ("diners", payment_request.supported_card_networks()[2]); | 234 EXPECT_EQ("diners", payment_request.supported_card_networks()[2]); |
| 217 EXPECT_EQ("discover", payment_request.supported_card_networks()[3]); | 235 EXPECT_EQ("discover", payment_request.supported_card_networks()[3]); |
| 218 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); | 236 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 232 method_datum1.supported_methods.push_back("visa"); | 250 method_datum1.supported_methods.push_back("visa"); |
| 233 web_payment_request.method_data.push_back(method_datum1); | 251 web_payment_request.method_data.push_back(method_datum1); |
| 234 PaymentMethodData method_datum2; | 252 PaymentMethodData method_datum2; |
| 235 method_datum2.supported_methods.push_back("basic-card"); | 253 method_datum2.supported_methods.push_back("basic-card"); |
| 236 method_datum2.supported_networks.push_back("visa"); | 254 method_datum2.supported_networks.push_back("visa"); |
| 237 method_datum2.supported_networks.push_back("mastercard"); | 255 method_datum2.supported_networks.push_back("mastercard"); |
| 238 method_datum2.supported_networks.push_back("unionpay"); | 256 method_datum2.supported_networks.push_back("unionpay"); |
| 239 web_payment_request.method_data.push_back(method_datum2); | 257 web_payment_request.method_data.push_back(method_datum2); |
| 240 | 258 |
| 241 TestPaymentRequest payment_request(web_payment_request, | 259 TestPaymentRequest payment_request(web_payment_request, |
| 260 chrome_browser_state_.get(), &web_state_, |
| 242 &personal_data_manager); | 261 &personal_data_manager); |
| 243 | 262 |
| 244 EXPECT_EQ(3u, payment_request.supported_card_networks().size()); | 263 EXPECT_EQ(3u, payment_request.supported_card_networks().size()); |
| 245 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[0]); | 264 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[0]); |
| 246 EXPECT_EQ("visa", payment_request.supported_card_networks()[1]); | 265 EXPECT_EQ("visa", payment_request.supported_card_networks()[1]); |
| 247 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[2]); | 266 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[2]); |
| 248 } | 267 } |
| 249 | 268 |
| 250 // Test that specifying basic-card with supported networks after specifying | 269 // Test that specifying basic-card with supported networks after specifying |
| 251 // some methods | 270 // some methods |
| 252 TEST_F(PaymentRequestTest, SupportedMethods_BasicCard_WithSupportedNetworks) { | 271 TEST_F(PaymentRequestTest, SupportedMethods_BasicCard_WithSupportedNetworks) { |
| 253 web::PaymentRequest web_payment_request; | 272 web::PaymentRequest web_payment_request; |
| 254 autofill::TestPersonalDataManager personal_data_manager; | 273 autofill::TestPersonalDataManager personal_data_manager; |
| 255 | 274 |
| 256 PaymentMethodData method_datum1; | 275 PaymentMethodData method_datum1; |
| 257 method_datum1.supported_methods.push_back("basic-card"); | 276 method_datum1.supported_methods.push_back("basic-card"); |
| 258 method_datum1.supported_networks.push_back("visa"); | 277 method_datum1.supported_networks.push_back("visa"); |
| 259 method_datum1.supported_networks.push_back("unionpay"); | 278 method_datum1.supported_networks.push_back("unionpay"); |
| 260 web_payment_request.method_data.push_back(method_datum1); | 279 web_payment_request.method_data.push_back(method_datum1); |
| 261 | 280 |
| 262 TestPaymentRequest payment_request(web_payment_request, | 281 TestPaymentRequest payment_request(web_payment_request, |
| 282 chrome_browser_state_.get(), &web_state_, |
| 263 &personal_data_manager); | 283 &personal_data_manager); |
| 264 | 284 |
| 265 // Only the specified networks are supported. | 285 // Only the specified networks are supported. |
| 266 EXPECT_EQ(2u, payment_request.supported_card_networks().size()); | 286 EXPECT_EQ(2u, payment_request.supported_card_networks().size()); |
| 267 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 287 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
| 268 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[1]); | 288 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[1]); |
| 269 } | 289 } |
| 270 | 290 |
| 271 // Tests that an autofill payment instrumnt e.g., credit cards can be added | 291 // Tests that an autofill payment instrumnt e.g., credit cards can be added |
| 272 // to the list of available payment methods. | 292 // to the list of available payment methods. |
| 273 TEST_F(PaymentRequestTest, AddAutofillPaymentInstrument) { | 293 TEST_F(PaymentRequestTest, AddAutofillPaymentInstrument) { |
| 274 web::PaymentRequest web_payment_request; | 294 web::PaymentRequest web_payment_request; |
| 275 PaymentMethodData method_datum; | 295 PaymentMethodData method_datum; |
| 276 method_datum.supported_methods.push_back("basic-card"); | 296 method_datum.supported_methods.push_back("basic-card"); |
| 277 method_datum.supported_networks.push_back("visa"); | 297 method_datum.supported_networks.push_back("visa"); |
| 278 method_datum.supported_networks.push_back("amex"); | 298 method_datum.supported_networks.push_back("amex"); |
| 279 web_payment_request.method_data.push_back(method_datum); | 299 web_payment_request.method_data.push_back(method_datum); |
| 280 | 300 |
| 281 autofill::TestPersonalDataManager personal_data_manager; | 301 autofill::TestPersonalDataManager personal_data_manager; |
| 282 | 302 |
| 283 autofill::CreditCard credit_card_1 = autofill::test::GetCreditCard(); | 303 autofill::CreditCard credit_card_1 = autofill::test::GetCreditCard(); |
| 284 personal_data_manager.AddTestingCreditCard(&credit_card_1); | 304 personal_data_manager.AddTestingCreditCard(&credit_card_1); |
| 285 | 305 |
| 286 TestPaymentRequest payment_request(web_payment_request, | 306 TestPaymentRequest payment_request(web_payment_request, |
| 307 chrome_browser_state_.get(), &web_state_, |
| 287 &personal_data_manager); | 308 &personal_data_manager); |
| 288 EXPECT_EQ(1U, payment_request.payment_methods().size()); | 309 EXPECT_EQ(1U, payment_request.payment_methods().size()); |
| 289 | 310 |
| 290 autofill::CreditCard credit_card_2 = autofill::test::GetCreditCard2(); | 311 autofill::CreditCard credit_card_2 = autofill::test::GetCreditCard2(); |
| 291 AutofillPaymentInstrument* added_credit_card = | 312 AutofillPaymentInstrument* added_credit_card = |
| 292 payment_request.AddAutofillPaymentInstrument(credit_card_2); | 313 payment_request.AddAutofillPaymentInstrument(credit_card_2); |
| 293 | 314 |
| 294 EXPECT_EQ(2U, payment_request.payment_methods().size()); | 315 EXPECT_EQ(2U, payment_request.payment_methods().size()); |
| 295 EXPECT_EQ(credit_card_2, *added_credit_card->credit_card()); | 316 EXPECT_EQ(credit_card_2, *added_credit_card->credit_card()); |
| 296 } | 317 } |
| 297 | 318 |
| 298 // Tests that a profile can be added to the list of available profiles. | 319 // Tests that a profile can be added to the list of available profiles. |
| 299 TEST_F(PaymentRequestTest, AddAutofillProfile) { | 320 TEST_F(PaymentRequestTest, AddAutofillProfile) { |
| 300 web::PaymentRequest web_payment_request; | 321 web::PaymentRequest web_payment_request; |
| 301 web_payment_request.options = CreatePaymentOptions( | 322 web_payment_request.options = CreatePaymentOptions( |
| 302 /*request_payer_name=*/true, /*request_payer_phone=*/true, | 323 /*request_payer_name=*/true, /*request_payer_phone=*/true, |
| 303 /*request_payer_email=*/true, /*request_shipping=*/true); | 324 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 304 | 325 |
| 305 autofill::TestPersonalDataManager personal_data_manager; | 326 autofill::TestPersonalDataManager personal_data_manager; |
| 306 | 327 |
| 307 autofill::AutofillProfile profile_1 = autofill::test::GetFullProfile(); | 328 autofill::AutofillProfile profile_1 = autofill::test::GetFullProfile(); |
| 308 personal_data_manager.AddTestingProfile(&profile_1); | 329 personal_data_manager.AddTestingProfile(&profile_1); |
| 309 | 330 |
| 310 TestPaymentRequest payment_request(web_payment_request, | 331 TestPaymentRequest payment_request(web_payment_request, |
| 332 chrome_browser_state_.get(), &web_state_, |
| 311 &personal_data_manager); | 333 &personal_data_manager); |
| 312 EXPECT_EQ(1U, payment_request.shipping_profiles().size()); | 334 EXPECT_EQ(1U, payment_request.shipping_profiles().size()); |
| 313 EXPECT_EQ(1U, payment_request.contact_profiles().size()); | 335 EXPECT_EQ(1U, payment_request.contact_profiles().size()); |
| 314 | 336 |
| 315 autofill::AutofillProfile profile_2 = autofill::test::GetFullProfile2(); | 337 autofill::AutofillProfile profile_2 = autofill::test::GetFullProfile2(); |
| 316 autofill::AutofillProfile* added_profile = | 338 autofill::AutofillProfile* added_profile = |
| 317 payment_request.AddAutofillProfile(profile_2); | 339 payment_request.AddAutofillProfile(profile_2); |
| 318 | 340 |
| 319 EXPECT_EQ(2U, payment_request.shipping_profiles().size()); | 341 EXPECT_EQ(2U, payment_request.shipping_profiles().size()); |
| 320 EXPECT_EQ(2U, payment_request.contact_profiles().size()); | 342 EXPECT_EQ(2U, payment_request.contact_profiles().size()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 337 option2.selected = true; | 359 option2.selected = true; |
| 338 shipping_options.push_back(std::move(option2)); | 360 shipping_options.push_back(std::move(option2)); |
| 339 web::PaymentShippingOption option3; | 361 web::PaymentShippingOption option3; |
| 340 option3.id = base::UTF8ToUTF16("option:3"); | 362 option3.id = base::UTF8ToUTF16("option:3"); |
| 341 option3.selected = true; | 363 option3.selected = true; |
| 342 shipping_options.push_back(std::move(option3)); | 364 shipping_options.push_back(std::move(option3)); |
| 343 details.shipping_options = std::move(shipping_options); | 365 details.shipping_options = std::move(shipping_options); |
| 344 web_payment_request.details = std::move(details); | 366 web_payment_request.details = std::move(details); |
| 345 | 367 |
| 346 TestPaymentRequest payment_request(web_payment_request, | 368 TestPaymentRequest payment_request(web_payment_request, |
| 369 chrome_browser_state_.get(), &web_state_, |
| 347 &personal_data_manager); | 370 &personal_data_manager); |
| 348 // The last one marked "selected" should be selected. | 371 // The last one marked "selected" should be selected. |
| 349 EXPECT_EQ(base::UTF8ToUTF16("option:3"), | 372 EXPECT_EQ(base::UTF8ToUTF16("option:3"), |
| 350 payment_request.selected_shipping_option()->id); | 373 payment_request.selected_shipping_option()->id); |
| 351 | 374 |
| 352 // Simulate an update that no longer has any shipping options. There is no | 375 // Simulate an update that no longer has any shipping options. There is no |
| 353 // longer a selected shipping option. | 376 // longer a selected shipping option. |
| 354 web::PaymentDetails new_details; | 377 web::PaymentDetails new_details; |
| 355 payment_request.UpdatePaymentDetails(std::move(new_details)); | 378 payment_request.UpdatePaymentDetails(std::move(new_details)); |
| 356 EXPECT_EQ(nullptr, payment_request.selected_shipping_option()); | 379 EXPECT_EQ(nullptr, payment_request.selected_shipping_option()); |
| 357 } | 380 } |
| 358 | 381 |
| 359 // Test that loading profiles when none are available works as expected. | 382 // Test that loading profiles when none are available works as expected. |
| 360 TEST_F(PaymentRequestTest, SelectedProfiles_NoProfiles) { | 383 TEST_F(PaymentRequestTest, SelectedProfiles_NoProfiles) { |
| 361 autofill::TestPersonalDataManager personal_data_manager; | 384 autofill::TestPersonalDataManager personal_data_manager; |
| 362 web::PaymentRequest web_payment_request; | 385 web::PaymentRequest web_payment_request; |
| 363 web_payment_request.details = CreateDetailsWithShippingOption(); | 386 web_payment_request.details = CreateDetailsWithShippingOption(); |
| 364 web_payment_request.options = CreatePaymentOptions( | 387 web_payment_request.options = CreatePaymentOptions( |
| 365 /*request_payer_name=*/true, /*request_payer_phone=*/true, | 388 /*request_payer_name=*/true, /*request_payer_phone=*/true, |
| 366 /*request_payer_email=*/true, /*request_shipping=*/true); | 389 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 367 | 390 |
| 368 // No profiles are selected because none are available! | 391 // No profiles are selected because none are available! |
| 369 TestPaymentRequest payment_request(web_payment_request, | 392 TestPaymentRequest payment_request(web_payment_request, |
| 393 chrome_browser_state_.get(), &web_state_, |
| 370 &personal_data_manager); | 394 &personal_data_manager); |
| 371 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); | 395 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); |
| 372 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); | 396 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); |
| 373 } | 397 } |
| 374 | 398 |
| 375 // Test that loading complete shipping and contact profiles works as expected. | 399 // Test that loading complete shipping and contact profiles works as expected. |
| 376 TEST_F(PaymentRequestTest, SelectedProfiles_Complete) { | 400 TEST_F(PaymentRequestTest, SelectedProfiles_Complete) { |
| 377 autofill::TestPersonalDataManager personal_data_manager; | 401 autofill::TestPersonalDataManager personal_data_manager; |
| 378 autofill::AutofillProfile address = autofill::test::GetFullProfile(); | 402 autofill::AutofillProfile address = autofill::test::GetFullProfile(); |
| 379 address.set_use_count(5U); | 403 address.set_use_count(5U); |
| 380 personal_data_manager.AddTestingProfile(&address); | 404 personal_data_manager.AddTestingProfile(&address); |
| 381 autofill::AutofillProfile address2 = autofill::test::GetFullProfile2(); | 405 autofill::AutofillProfile address2 = autofill::test::GetFullProfile2(); |
| 382 address2.set_use_count(15U); | 406 address2.set_use_count(15U); |
| 383 personal_data_manager.AddTestingProfile(&address2); | 407 personal_data_manager.AddTestingProfile(&address2); |
| 384 | 408 |
| 385 web::PaymentRequest web_payment_request; | 409 web::PaymentRequest web_payment_request; |
| 386 web_payment_request.details = CreateDetailsWithShippingOption(); | 410 web_payment_request.details = CreateDetailsWithShippingOption(); |
| 387 web_payment_request.options = CreatePaymentOptions( | 411 web_payment_request.options = CreatePaymentOptions( |
| 388 /*request_payer_name=*/true, /*request_payer_phone=*/true, | 412 /*request_payer_name=*/true, /*request_payer_phone=*/true, |
| 389 /*request_payer_email=*/true, /*request_shipping=*/true); | 413 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 390 | 414 |
| 391 // address2 is selected because it has the most use count (Frecency model). | 415 // address2 is selected because it has the most use count (Frecency model). |
| 392 TestPaymentRequest payment_request(web_payment_request, | 416 TestPaymentRequest payment_request(web_payment_request, |
| 417 chrome_browser_state_.get(), &web_state_, |
| 393 &personal_data_manager); | 418 &personal_data_manager); |
| 394 EXPECT_EQ(address2.guid(), | 419 EXPECT_EQ(address2.guid(), |
| 395 payment_request.selected_shipping_profile()->guid()); | 420 payment_request.selected_shipping_profile()->guid()); |
| 396 EXPECT_EQ(address2.guid(), | 421 EXPECT_EQ(address2.guid(), |
| 397 payment_request.selected_contact_profile()->guid()); | 422 payment_request.selected_contact_profile()->guid()); |
| 398 } | 423 } |
| 399 | 424 |
| 400 // Test that loading complete shipping and contact profiles, when there are no | 425 // Test that loading complete shipping and contact profiles, when there are no |
| 401 // shipping options available, works as expected. | 426 // shipping options available, works as expected. |
| 402 TEST_F(PaymentRequestTest, SelectedProfiles_Complete_NoShippingOption) { | 427 TEST_F(PaymentRequestTest, SelectedProfiles_Complete_NoShippingOption) { |
| 403 autofill::TestPersonalDataManager personal_data_manager; | 428 autofill::TestPersonalDataManager personal_data_manager; |
| 404 autofill::AutofillProfile address = autofill::test::GetFullProfile(); | 429 autofill::AutofillProfile address = autofill::test::GetFullProfile(); |
| 405 address.set_use_count(5U); | 430 address.set_use_count(5U); |
| 406 personal_data_manager.AddTestingProfile(&address); | 431 personal_data_manager.AddTestingProfile(&address); |
| 407 | 432 |
| 408 web::PaymentRequest web_payment_request; | 433 web::PaymentRequest web_payment_request; |
| 409 // No shipping options. | 434 // No shipping options. |
| 410 web_payment_request.details = web::PaymentDetails(); | 435 web_payment_request.details = web::PaymentDetails(); |
| 411 web_payment_request.options = CreatePaymentOptions( | 436 web_payment_request.options = CreatePaymentOptions( |
| 412 /*request_payer_name=*/true, /*request_payer_phone=*/true, | 437 /*request_payer_name=*/true, /*request_payer_phone=*/true, |
| 413 /*request_payer_email=*/true, /*request_shipping=*/true); | 438 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 414 | 439 |
| 415 // No shipping profile is selected because the merchant has not selected a | 440 // No shipping profile is selected because the merchant has not selected a |
| 416 // shipping option. However there is a suitable contact profile. | 441 // shipping option. However there is a suitable contact profile. |
| 417 TestPaymentRequest payment_request(web_payment_request, | 442 TestPaymentRequest payment_request(web_payment_request, |
| 443 chrome_browser_state_.get(), &web_state_, |
| 418 &personal_data_manager); | 444 &personal_data_manager); |
| 419 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); | 445 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); |
| 420 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); | 446 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); |
| 421 } | 447 } |
| 422 | 448 |
| 423 // Test that loading incomplete shipping and contact profiles works as expected. | 449 // Test that loading incomplete shipping and contact profiles works as expected. |
| 424 TEST_F(PaymentRequestTest, SelectedProfiles_Incomplete) { | 450 TEST_F(PaymentRequestTest, SelectedProfiles_Incomplete) { |
| 425 autofill::TestPersonalDataManager personal_data_manager; | 451 autofill::TestPersonalDataManager personal_data_manager; |
| 426 // Add a profile with no phone (incomplete). | 452 // Add a profile with no phone (incomplete). |
| 427 autofill::AutofillProfile address1 = autofill::test::GetFullProfile(); | 453 autofill::AutofillProfile address1 = autofill::test::GetFullProfile(); |
| 428 address1.SetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), | 454 address1.SetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), |
| 429 base::string16(), "en-US"); | 455 base::string16(), "en-US"); |
| 430 address1.set_use_count(5U); | 456 address1.set_use_count(5U); |
| 431 personal_data_manager.AddTestingProfile(&address1); | 457 personal_data_manager.AddTestingProfile(&address1); |
| 432 // Add a complete profile, with fewer use counts. | 458 // Add a complete profile, with fewer use counts. |
| 433 autofill::AutofillProfile address2 = autofill::test::GetFullProfile2(); | 459 autofill::AutofillProfile address2 = autofill::test::GetFullProfile2(); |
| 434 address2.set_use_count(3U); | 460 address2.set_use_count(3U); |
| 435 personal_data_manager.AddTestingProfile(&address2); | 461 personal_data_manager.AddTestingProfile(&address2); |
| 436 | 462 |
| 437 web::PaymentRequest web_payment_request; | 463 web::PaymentRequest web_payment_request; |
| 438 web_payment_request.details = CreateDetailsWithShippingOption(); | 464 web_payment_request.details = CreateDetailsWithShippingOption(); |
| 439 web_payment_request.options = CreatePaymentOptions( | 465 web_payment_request.options = CreatePaymentOptions( |
| 440 /*request_payer_name=*/true, /*request_payer_phone=*/true, | 466 /*request_payer_name=*/true, /*request_payer_phone=*/true, |
| 441 /*request_payer_email=*/true, /*request_shipping=*/true); | 467 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 442 | 468 |
| 443 // Even though address1 has more use counts, address2 is selected because it | 469 // Even though address1 has more use counts, address2 is selected because it |
| 444 // is complete. | 470 // is complete. |
| 445 TestPaymentRequest payment_request(web_payment_request, | 471 TestPaymentRequest payment_request(web_payment_request, |
| 472 chrome_browser_state_.get(), &web_state_, |
| 446 &personal_data_manager); | 473 &personal_data_manager); |
| 447 EXPECT_EQ(address2.guid(), | 474 EXPECT_EQ(address2.guid(), |
| 448 payment_request.selected_shipping_profile()->guid()); | 475 payment_request.selected_shipping_profile()->guid()); |
| 449 EXPECT_EQ(address2.guid(), | 476 EXPECT_EQ(address2.guid(), |
| 450 payment_request.selected_contact_profile()->guid()); | 477 payment_request.selected_contact_profile()->guid()); |
| 451 } | 478 } |
| 452 | 479 |
| 453 // Test that loading incomplete contact profiles works as expected when the | 480 // Test that loading incomplete contact profiles works as expected when the |
| 454 // merchant is not interested in the missing field. Test that the most complete | 481 // merchant is not interested in the missing field. Test that the most complete |
| 455 // shipping profile is selected. | 482 // shipping profile is selected. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 472 // The merchant doesn't care about the phone number. | 499 // The merchant doesn't care about the phone number. |
| 473 web_payment_request.options = CreatePaymentOptions( | 500 web_payment_request.options = CreatePaymentOptions( |
| 474 /*request_payer_name=*/true, /*request_payer_phone=*/false, | 501 /*request_payer_name=*/true, /*request_payer_phone=*/false, |
| 475 /*request_payer_email=*/true, /*request_shipping=*/true); | 502 /*request_payer_email=*/true, /*request_shipping=*/true); |
| 476 | 503 |
| 477 // address1 has more use counts, and even though it has no phone number, it's | 504 // address1 has more use counts, and even though it has no phone number, it's |
| 478 // still selected as the contact profile because merchant doesn't require | 505 // still selected as the contact profile because merchant doesn't require |
| 479 // phone. address2 is selected as the shipping profile because it's the most | 506 // phone. address2 is selected as the shipping profile because it's the most |
| 480 // complete for shipping. | 507 // complete for shipping. |
| 481 TestPaymentRequest payment_request(web_payment_request, | 508 TestPaymentRequest payment_request(web_payment_request, |
| 509 chrome_browser_state_.get(), &web_state_, |
| 482 &personal_data_manager); | 510 &personal_data_manager); |
| 483 EXPECT_EQ(address2.guid(), | 511 EXPECT_EQ(address2.guid(), |
| 484 payment_request.selected_shipping_profile()->guid()); | 512 payment_request.selected_shipping_profile()->guid()); |
| 485 EXPECT_EQ(address1.guid(), | 513 EXPECT_EQ(address1.guid(), |
| 486 payment_request.selected_contact_profile()->guid()); | 514 payment_request.selected_contact_profile()->guid()); |
| 487 } | 515 } |
| 488 | 516 |
| 489 // Test that loading payment methods when none are available works as expected. | 517 // Test that loading payment methods when none are available works as expected. |
| 490 TEST_F(PaymentRequestTest, SelectedPaymentMethod_NoPaymentMethods) { | 518 TEST_F(PaymentRequestTest, SelectedPaymentMethod_NoPaymentMethods) { |
| 491 autofill::TestPersonalDataManager personal_data_manager; | 519 autofill::TestPersonalDataManager personal_data_manager; |
| 492 web::PaymentRequest web_payment_request = | 520 web::PaymentRequest web_payment_request = |
| 493 payment_request_test_util::CreateTestWebPaymentRequest(); | 521 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 494 | 522 |
| 495 // No payment methods are selected because none are available! | 523 // No payment methods are selected because none are available! |
| 496 TestPaymentRequest payment_request(web_payment_request, | 524 TestPaymentRequest payment_request(web_payment_request, |
| 525 chrome_browser_state_.get(), &web_state_, |
| 497 &personal_data_manager); | 526 &personal_data_manager); |
| 498 EXPECT_EQ(nullptr, payment_request.selected_payment_method()); | 527 EXPECT_EQ(nullptr, payment_request.selected_payment_method()); |
| 499 } | 528 } |
| 500 | 529 |
| 501 // Test that loading expired credit cards works as expected. | 530 // Test that loading expired credit cards works as expected. |
| 502 TEST_F(PaymentRequestTest, SelectedPaymentMethod_ExpiredCard) { | 531 TEST_F(PaymentRequestTest, SelectedPaymentMethod_ExpiredCard) { |
| 503 autofill::TestPersonalDataManager personal_data_manager; | 532 autofill::TestPersonalDataManager personal_data_manager; |
| 504 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); | 533 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); |
| 505 personal_data_manager.AddTestingProfile(&billing_address); | 534 personal_data_manager.AddTestingProfile(&billing_address); |
| 506 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 535 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 507 personal_data_manager.AddTestingCreditCard(&credit_card); | 536 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 508 credit_card.SetExpirationYear(2016); // Expired. | 537 credit_card.SetExpirationYear(2016); // Expired. |
| 509 credit_card.set_billing_address_id(billing_address.guid()); | 538 credit_card.set_billing_address_id(billing_address.guid()); |
| 510 | 539 |
| 511 web::PaymentRequest web_payment_request = | 540 web::PaymentRequest web_payment_request = |
| 512 payment_request_test_util::CreateTestWebPaymentRequest(); | 541 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 513 | 542 |
| 514 // credit_card is selected because expired cards are valid for payment. | 543 // credit_card is selected because expired cards are valid for payment. |
| 515 TestPaymentRequest payment_request(web_payment_request, | 544 TestPaymentRequest payment_request(web_payment_request, |
| 545 chrome_browser_state_.get(), &web_state_, |
| 516 &personal_data_manager); | 546 &personal_data_manager); |
| 517 EXPECT_EQ(payment_request.selected_payment_method()->type(), | 547 EXPECT_EQ(payment_request.selected_payment_method()->type(), |
| 518 PaymentInstrument::Type::AUTOFILL); | 548 PaymentInstrument::Type::AUTOFILL); |
| 519 AutofillPaymentInstrument* payment_instrument = | 549 AutofillPaymentInstrument* payment_instrument = |
| 520 static_cast<AutofillPaymentInstrument*>( | 550 static_cast<AutofillPaymentInstrument*>( |
| 521 payment_request.selected_payment_method()); | 551 payment_request.selected_payment_method()); |
| 522 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 552 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 523 } | 553 } |
| 524 | 554 |
| 525 // Test that loading complete payment methods works as expected. | 555 // Test that loading complete payment methods works as expected. |
| 526 TEST_F(PaymentRequestTest, SelectedPaymentMethod_Complete) { | 556 TEST_F(PaymentRequestTest, SelectedPaymentMethod_Complete) { |
| 527 autofill::TestPersonalDataManager personal_data_manager; | 557 autofill::TestPersonalDataManager personal_data_manager; |
| 528 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); | 558 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); |
| 529 personal_data_manager.AddTestingProfile(&billing_address); | 559 personal_data_manager.AddTestingProfile(&billing_address); |
| 530 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 560 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 531 credit_card.set_use_count(5U); | 561 credit_card.set_use_count(5U); |
| 532 personal_data_manager.AddTestingCreditCard(&credit_card); | 562 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 533 credit_card.set_billing_address_id(billing_address.guid()); | 563 credit_card.set_billing_address_id(billing_address.guid()); |
| 534 autofill::CreditCard credit_card2 = autofill::test::GetCreditCard2(); | 564 autofill::CreditCard credit_card2 = autofill::test::GetCreditCard2(); |
| 535 credit_card2.set_use_count(15U); | 565 credit_card2.set_use_count(15U); |
| 536 personal_data_manager.AddTestingCreditCard(&credit_card2); | 566 personal_data_manager.AddTestingCreditCard(&credit_card2); |
| 537 credit_card2.set_billing_address_id(billing_address.guid()); | 567 credit_card2.set_billing_address_id(billing_address.guid()); |
| 538 | 568 |
| 539 web::PaymentRequest web_payment_request = | 569 web::PaymentRequest web_payment_request = |
| 540 payment_request_test_util::CreateTestWebPaymentRequest(); | 570 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 541 | 571 |
| 542 // credit_card2 is selected because it has the most use count (Frecency | 572 // credit_card2 is selected because it has the most use count (Frecency |
| 543 // model). | 573 // model). |
| 544 TestPaymentRequest payment_request(web_payment_request, | 574 TestPaymentRequest payment_request(web_payment_request, |
| 575 chrome_browser_state_.get(), &web_state_, |
| 545 &personal_data_manager); | 576 &personal_data_manager); |
| 546 AutofillPaymentInstrument* payment_instrument = | 577 AutofillPaymentInstrument* payment_instrument = |
| 547 static_cast<AutofillPaymentInstrument*>( | 578 static_cast<AutofillPaymentInstrument*>( |
| 548 payment_request.selected_payment_method()); | 579 payment_request.selected_payment_method()); |
| 549 EXPECT_EQ(credit_card2.guid(), payment_instrument->credit_card()->guid()); | 580 EXPECT_EQ(credit_card2.guid(), payment_instrument->credit_card()->guid()); |
| 550 } | 581 } |
| 551 | 582 |
| 552 // Test that loading incomplete payment methods works as expected. | 583 // Test that loading incomplete payment methods works as expected. |
| 553 TEST_F(PaymentRequestTest, SelectedPaymentMethod_Incomplete) { | 584 TEST_F(PaymentRequestTest, SelectedPaymentMethod_Incomplete) { |
| 554 autofill::TestPersonalDataManager personal_data_manager; | 585 autofill::TestPersonalDataManager personal_data_manager; |
| 555 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); | 586 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile(); |
| 556 personal_data_manager.AddTestingProfile(&billing_address); | 587 personal_data_manager.AddTestingProfile(&billing_address); |
| 557 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 588 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 558 credit_card.set_use_count(5U); | 589 credit_card.set_use_count(5U); |
| 559 personal_data_manager.AddTestingCreditCard(&credit_card); | 590 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 560 credit_card.set_billing_address_id(billing_address.guid()); | 591 credit_card.set_billing_address_id(billing_address.guid()); |
| 561 autofill::CreditCard credit_card2 = autofill::test::GetCreditCard2(); | 592 autofill::CreditCard credit_card2 = autofill::test::GetCreditCard2(); |
| 562 credit_card2.set_use_count(15U); | 593 credit_card2.set_use_count(15U); |
| 563 personal_data_manager.AddTestingCreditCard(&credit_card2); | 594 personal_data_manager.AddTestingCreditCard(&credit_card2); |
| 564 | 595 |
| 565 web::PaymentRequest web_payment_request = | 596 web::PaymentRequest web_payment_request = |
| 566 payment_request_test_util::CreateTestWebPaymentRequest(); | 597 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 567 | 598 |
| 568 // Even though credit_card2 has more use counts, credit_card is selected | 599 // Even though credit_card2 has more use counts, credit_card is selected |
| 569 // because it is complete. | 600 // because it is complete. |
| 570 TestPaymentRequest payment_request(web_payment_request, | 601 TestPaymentRequest payment_request(web_payment_request, |
| 602 chrome_browser_state_.get(), &web_state_, |
| 571 &personal_data_manager); | 603 &personal_data_manager); |
| 572 AutofillPaymentInstrument* payment_instrument = | 604 AutofillPaymentInstrument* payment_instrument = |
| 573 static_cast<AutofillPaymentInstrument*>( | 605 static_cast<AutofillPaymentInstrument*>( |
| 574 payment_request.selected_payment_method()); | 606 payment_request.selected_payment_method()); |
| 575 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 607 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 576 } | 608 } |
| 577 | 609 |
| 578 // Test that the use counts of the data models are updated as expected when | 610 // Test that the use counts of the data models are updated as expected when |
| 579 // different autofill profiles are used as the shipping address and the contact | 611 // different autofill profiles are used as the shipping address and the contact |
| 580 // info. | 612 // info. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 591 contact_info.set_use_count(5U); | 623 contact_info.set_use_count(5U); |
| 592 personal_data_manager.AddTestingProfile(&contact_info); | 624 personal_data_manager.AddTestingProfile(&contact_info); |
| 593 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 625 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 594 personal_data_manager.AddTestingCreditCard(&credit_card); | 626 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 595 credit_card.set_billing_address_id(address.guid()); | 627 credit_card.set_billing_address_id(address.guid()); |
| 596 | 628 |
| 597 web::PaymentRequest web_payment_request = | 629 web::PaymentRequest web_payment_request = |
| 598 payment_request_test_util::CreateTestWebPaymentRequest(); | 630 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 599 | 631 |
| 600 TestPaymentRequest payment_request(web_payment_request, | 632 TestPaymentRequest payment_request(web_payment_request, |
| 633 chrome_browser_state_.get(), &web_state_, |
| 601 &personal_data_manager); | 634 &personal_data_manager); |
| 602 AutofillPaymentInstrument* payment_instrument = | 635 AutofillPaymentInstrument* payment_instrument = |
| 603 static_cast<AutofillPaymentInstrument*>( | 636 static_cast<AutofillPaymentInstrument*>( |
| 604 payment_request.selected_payment_method()); | 637 payment_request.selected_payment_method()); |
| 605 EXPECT_EQ(address.guid(), | 638 EXPECT_EQ(address.guid(), |
| 606 payment_request.selected_shipping_profile()->guid()); | 639 payment_request.selected_shipping_profile()->guid()); |
| 607 EXPECT_EQ(contact_info.guid(), | 640 EXPECT_EQ(contact_info.guid(), |
| 608 payment_request.selected_contact_profile()->guid()); | 641 payment_request.selected_contact_profile()->guid()); |
| 609 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 642 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 610 | 643 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 627 autofill::AutofillProfile address = autofill::test::GetFullProfile(); | 660 autofill::AutofillProfile address = autofill::test::GetFullProfile(); |
| 628 personal_data_manager.AddTestingProfile(&address); | 661 personal_data_manager.AddTestingProfile(&address); |
| 629 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 662 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 630 personal_data_manager.AddTestingCreditCard(&credit_card); | 663 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 631 credit_card.set_billing_address_id(address.guid()); | 664 credit_card.set_billing_address_id(address.guid()); |
| 632 | 665 |
| 633 web::PaymentRequest web_payment_request = | 666 web::PaymentRequest web_payment_request = |
| 634 payment_request_test_util::CreateTestWebPaymentRequest(); | 667 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 635 | 668 |
| 636 TestPaymentRequest payment_request(web_payment_request, | 669 TestPaymentRequest payment_request(web_payment_request, |
| 670 chrome_browser_state_.get(), &web_state_, |
| 637 &personal_data_manager); | 671 &personal_data_manager); |
| 638 AutofillPaymentInstrument* payment_instrument = | 672 AutofillPaymentInstrument* payment_instrument = |
| 639 static_cast<AutofillPaymentInstrument*>( | 673 static_cast<AutofillPaymentInstrument*>( |
| 640 payment_request.selected_payment_method()); | 674 payment_request.selected_payment_method()); |
| 641 EXPECT_EQ(address.guid(), | 675 EXPECT_EQ(address.guid(), |
| 642 payment_request.selected_shipping_profile()->guid()); | 676 payment_request.selected_shipping_profile()->guid()); |
| 643 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); | 677 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); |
| 644 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 678 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 645 | 679 |
| 646 // Even though |address| is used for contact info, shipping address, and | 680 // Even though |address| is used for contact info, shipping address, and |
| (...skipping 17 matching lines...) Expand all Loading... |
| 664 personal_data_manager.AddTestingCreditCard(&credit_card); | 698 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 665 credit_card.set_billing_address_id(address.guid()); | 699 credit_card.set_billing_address_id(address.guid()); |
| 666 | 700 |
| 667 web::PaymentRequest web_payment_request = | 701 web::PaymentRequest web_payment_request = |
| 668 payment_request_test_util::CreateTestWebPaymentRequest(); | 702 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 669 web_payment_request.options.request_payer_name = false; | 703 web_payment_request.options.request_payer_name = false; |
| 670 web_payment_request.options.request_payer_email = false; | 704 web_payment_request.options.request_payer_email = false; |
| 671 web_payment_request.options.request_payer_phone = false; | 705 web_payment_request.options.request_payer_phone = false; |
| 672 | 706 |
| 673 TestPaymentRequest payment_request(web_payment_request, | 707 TestPaymentRequest payment_request(web_payment_request, |
| 708 chrome_browser_state_.get(), &web_state_, |
| 674 &personal_data_manager); | 709 &personal_data_manager); |
| 675 AutofillPaymentInstrument* payment_instrument = | 710 AutofillPaymentInstrument* payment_instrument = |
| 676 static_cast<AutofillPaymentInstrument*>( | 711 static_cast<AutofillPaymentInstrument*>( |
| 677 payment_request.selected_payment_method()); | 712 payment_request.selected_payment_method()); |
| 678 EXPECT_EQ(address.guid(), | 713 EXPECT_EQ(address.guid(), |
| 679 payment_request.selected_shipping_profile()->guid()); | 714 payment_request.selected_shipping_profile()->guid()); |
| 680 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); | 715 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); |
| 681 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 716 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 682 | 717 |
| 683 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) | 718 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 697 personal_data_manager.AddTestingProfile(&address); | 732 personal_data_manager.AddTestingProfile(&address); |
| 698 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 733 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
| 699 personal_data_manager.AddTestingCreditCard(&credit_card); | 734 personal_data_manager.AddTestingCreditCard(&credit_card); |
| 700 credit_card.set_billing_address_id(address.guid()); | 735 credit_card.set_billing_address_id(address.guid()); |
| 701 | 736 |
| 702 web::PaymentRequest web_payment_request = | 737 web::PaymentRequest web_payment_request = |
| 703 payment_request_test_util::CreateTestWebPaymentRequest(); | 738 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 704 web_payment_request.options.request_shipping = false; | 739 web_payment_request.options.request_shipping = false; |
| 705 | 740 |
| 706 TestPaymentRequest payment_request(web_payment_request, | 741 TestPaymentRequest payment_request(web_payment_request, |
| 742 chrome_browser_state_.get(), &web_state_, |
| 707 &personal_data_manager); | 743 &personal_data_manager); |
| 708 AutofillPaymentInstrument* payment_instrument = | 744 AutofillPaymentInstrument* payment_instrument = |
| 709 static_cast<AutofillPaymentInstrument*>( | 745 static_cast<AutofillPaymentInstrument*>( |
| 710 payment_request.selected_payment_method()); | 746 payment_request.selected_payment_method()); |
| 711 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); | 747 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); |
| 712 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); | 748 EXPECT_EQ(address.guid(), payment_request.selected_contact_profile()->guid()); |
| 713 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 749 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 714 | 750 |
| 715 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) | 751 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) |
| 716 .Times(1); | 752 .Times(1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 732 credit_card.set_billing_address_id(address.guid()); | 768 credit_card.set_billing_address_id(address.guid()); |
| 733 | 769 |
| 734 web::PaymentRequest web_payment_request = | 770 web::PaymentRequest web_payment_request = |
| 735 payment_request_test_util::CreateTestWebPaymentRequest(); | 771 payment_request_test_util::CreateTestWebPaymentRequest(); |
| 736 web_payment_request.options.request_shipping = false; | 772 web_payment_request.options.request_shipping = false; |
| 737 web_payment_request.options.request_payer_name = false; | 773 web_payment_request.options.request_payer_name = false; |
| 738 web_payment_request.options.request_payer_email = false; | 774 web_payment_request.options.request_payer_email = false; |
| 739 web_payment_request.options.request_payer_phone = false; | 775 web_payment_request.options.request_payer_phone = false; |
| 740 | 776 |
| 741 TestPaymentRequest payment_request(web_payment_request, | 777 TestPaymentRequest payment_request(web_payment_request, |
| 778 chrome_browser_state_.get(), &web_state_, |
| 742 &personal_data_manager); | 779 &personal_data_manager); |
| 743 AutofillPaymentInstrument* payment_instrument = | 780 AutofillPaymentInstrument* payment_instrument = |
| 744 static_cast<AutofillPaymentInstrument*>( | 781 static_cast<AutofillPaymentInstrument*>( |
| 745 payment_request.selected_payment_method()); | 782 payment_request.selected_payment_method()); |
| 746 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); | 783 EXPECT_EQ(nullptr, payment_request.selected_shipping_profile()); |
| 747 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); | 784 EXPECT_EQ(nullptr, payment_request.selected_contact_profile()); |
| 748 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); | 785 EXPECT_EQ(credit_card.guid(), payment_instrument->credit_card()->guid()); |
| 749 | 786 |
| 750 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) | 787 EXPECT_CALL(personal_data_manager, RecordUseOf(GuidMatches(address.guid()))) |
| 751 .Times(0); | 788 .Times(0); |
| 752 EXPECT_CALL(personal_data_manager, | 789 EXPECT_CALL(personal_data_manager, |
| 753 RecordUseOf(GuidMatches(credit_card.guid()))) | 790 RecordUseOf(GuidMatches(credit_card.guid()))) |
| 754 .Times(1); | 791 .Times(1); |
| 755 | 792 |
| 756 payment_request.RecordUseStats(); | 793 payment_request.RecordUseStats(); |
| 757 } | 794 } |
| 758 | 795 |
| 759 } // namespace payments | 796 } // namespace payments |
| OLD | NEW |