| 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 "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 "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 int num_on_selected_information_changed_called_; | 98 int num_on_selected_information_changed_called_; |
| 99 mojom::PaymentResponsePtr payment_response_; | 99 mojom::PaymentResponsePtr payment_response_; |
| 100 autofill::TestPersonalDataManager test_personal_data_manager_; | 100 autofill::TestPersonalDataManager test_personal_data_manager_; |
| 101 | 101 |
| 102 // Test data. | 102 // Test data. |
| 103 autofill::AutofillProfile address_; | 103 autofill::AutofillProfile address_; |
| 104 autofill::CreditCard credit_card_visa_; | 104 autofill::CreditCard credit_card_visa_; |
| 105 autofill::CreditCard credit_card_amex_; | 105 autofill::CreditCard credit_card_amex_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 TEST_F(PaymentRequestStateTest, CanMakePayment) { |
| 109 // Default options. |
| 110 RecreateStateWithOptions(mojom::PaymentOptions::New()); |
| 111 |
| 112 // CanMakePayment returns true because the method data requires Visa, and the |
| 113 // user has a Visa card on file. |
| 114 EXPECT_TRUE(state()->CanMakePayment()); |
| 115 } |
| 116 |
| 117 TEST_F(PaymentRequestStateTest, CanMakePayment_CannotMakePayment) { |
| 118 // The method data requires MasterCard. |
| 119 std::vector<mojom::PaymentMethodDataPtr> method_data; |
| 120 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); |
| 121 entry->supported_methods.push_back("mastercard"); |
| 122 method_data.push_back(std::move(entry)); |
| 123 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), |
| 124 mojom::PaymentDetails::New(), |
| 125 std::move(method_data)); |
| 126 |
| 127 // CanMakePayment returns false because the method data requires MasterCard, |
| 128 // and the user doesn't have such an instrument. |
| 129 EXPECT_FALSE(state()->CanMakePayment()); |
| 130 } |
| 131 |
| 132 TEST_F(PaymentRequestStateTest, CanMakePayment_OnlyBasicCard) { |
| 133 // The method data supports everything in basic-card. |
| 134 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); |
| 135 entry->supported_methods.push_back("basic-card"); |
| 136 std::vector<mojom::PaymentMethodDataPtr> method_data; |
| 137 method_data.push_back(std::move(entry)); |
| 138 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), |
| 139 mojom::PaymentDetails::New(), |
| 140 std::move(method_data)); |
| 141 |
| 142 // CanMakePayment returns true because the method data supports everything, |
| 143 // and the user has at least one instrument. |
| 144 EXPECT_TRUE(state()->CanMakePayment()); |
| 145 } |
| 146 |
| 147 TEST_F(PaymentRequestStateTest, CanMakePayment_BasicCard_SpecificAvailable) { |
| 148 // The method data supports everything in basic-card. |
| 149 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); |
| 150 entry->supported_methods.push_back("basic-card"); |
| 151 entry->supported_networks.push_back(mojom::BasicCardNetwork::VISA); |
| 152 std::vector<mojom::PaymentMethodDataPtr> method_data; |
| 153 method_data.push_back(std::move(entry)); |
| 154 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), |
| 155 mojom::PaymentDetails::New(), |
| 156 std::move(method_data)); |
| 157 |
| 158 // CanMakePayment returns true because the method data supports visa, and the |
| 159 // user has a Visa instrument. |
| 160 EXPECT_TRUE(state()->CanMakePayment()); |
| 161 } |
| 162 |
| 163 TEST_F(PaymentRequestStateTest, CanMakePayment_BasicCard_SpecificUnavailable) { |
| 164 // The method data supports everything in basic-card. |
| 165 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); |
| 166 entry->supported_methods.push_back("basic-card"); |
| 167 entry->supported_networks.push_back(mojom::BasicCardNetwork::MASTERCARD); |
| 168 std::vector<mojom::PaymentMethodDataPtr> method_data; |
| 169 method_data.push_back(std::move(entry)); |
| 170 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), |
| 171 mojom::PaymentDetails::New(), |
| 172 std::move(method_data)); |
| 173 |
| 174 // CanMakePayment returns false because the method data supports mastercard, |
| 175 // and the user doesn't have such an instrument. |
| 176 EXPECT_FALSE(state()->CanMakePayment()); |
| 177 } |
| 178 |
| 108 // Test that the last shipping option is selected. | 179 // Test that the last shipping option is selected. |
| 109 TEST_F(PaymentRequestStateTest, ShippingOptionsSelection) { | 180 TEST_F(PaymentRequestStateTest, ShippingOptionsSelection) { |
| 110 std::vector<mojom::PaymentShippingOptionPtr> shipping_options; | 181 std::vector<mojom::PaymentShippingOptionPtr> shipping_options; |
| 111 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New(); | 182 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New(); |
| 112 option->id = "option:1"; | 183 option->id = "option:1"; |
| 113 option->selected = false; | 184 option->selected = false; |
| 114 shipping_options.push_back(std::move(option)); | 185 shipping_options.push_back(std::move(option)); |
| 115 mojom::PaymentShippingOptionPtr option2 = mojom::PaymentShippingOption::New(); | 186 mojom::PaymentShippingOptionPtr option2 = mojom::PaymentShippingOption::New(); |
| 116 option2->id = "option:2"; | 187 option2->id = "option:2"; |
| 117 option2->selected = true; | 188 option2->selected = true; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 "\"region\":\"CA\"}," | 270 "\"region\":\"CA\"}," |
| 200 "\"cardNumber\":\"4111111111111111\"," | 271 "\"cardNumber\":\"4111111111111111\"," |
| 201 "\"cardSecurityCode\":\"123\"," | 272 "\"cardSecurityCode\":\"123\"," |
| 202 "\"cardholderName\":\"Test User\"," | 273 "\"cardholderName\":\"Test User\"," |
| 203 "\"expiryMonth\":\"11\"," | 274 "\"expiryMonth\":\"11\"," |
| 204 "\"expiryYear\":\"2017\"}", | 275 "\"expiryYear\":\"2017\"}", |
| 205 response()->stringified_details); | 276 response()->stringified_details); |
| 206 } | 277 } |
| 207 | 278 |
| 208 } // namespace payments | 279 } // namespace payments |
| OLD | NEW |