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

Side by Side Diff: components/payments/content/payment_request_state_unittest.cc

Issue 2789093002: [Payments] Desktop: implement shipping address/option change (Closed)
Patch Set: compile fix Created 3 years, 8 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 | « components/payments/content/payment_request_state.cc ('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 "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 "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // PaymentRequestState::Observer: 46 // PaymentRequestState::Observer:
47 void OnSelectedInformationChanged() override { 47 void OnSelectedInformationChanged() override {
48 num_on_selected_information_changed_called_++; 48 num_on_selected_information_changed_called_++;
49 } 49 }
50 50
51 // PaymentRequestState::Delegate: 51 // PaymentRequestState::Delegate:
52 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override { 52 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override {
53 payment_response_ = std::move(response); 53 payment_response_ = std::move(response);
54 }; 54 };
55 void OnShippingOptionIdSelected(std::string shipping_option_id) override {}
56 void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override {}
55 57
56 void RecreateStateWithOptionsAndDetails( 58 void RecreateStateWithOptionsAndDetails(
57 mojom::PaymentOptionsPtr options, 59 mojom::PaymentOptionsPtr options,
58 mojom::PaymentDetailsPtr details, 60 mojom::PaymentDetailsPtr details,
59 std::vector<mojom::PaymentMethodDataPtr> method_data) { 61 std::vector<mojom::PaymentMethodDataPtr> method_data) {
60 // The spec will be based on the |options| and |details| passed in. 62 // The spec will be based on the |options| and |details| passed in.
61 spec_ = base::MakeUnique<PaymentRequestSpec>( 63 spec_ = base::MakeUnique<PaymentRequestSpec>(
62 std::move(options), std::move(details), std::move(method_data), nullptr, 64 std::move(options), std::move(details), std::move(method_data), nullptr,
63 "en-US"); 65 "en-US");
64 state_ = base::MakeUnique<PaymentRequestState>( 66 state_ = base::MakeUnique<PaymentRequestState>(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 method_data.push_back(std::move(entry)); 196 method_data.push_back(std::move(entry));
195 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(), 197 RecreateStateWithOptionsAndDetails(mojom::PaymentOptions::New(),
196 mojom::PaymentDetails::New(), 198 mojom::PaymentDetails::New(),
197 std::move(method_data)); 199 std::move(method_data));
198 200
199 // CanMakePayment returns false because the method data supports mastercard, 201 // CanMakePayment returns false because the method data supports mastercard,
200 // and the user doesn't have such an instrument. 202 // and the user doesn't have such an instrument.
201 EXPECT_FALSE(state()->CanMakePayment()); 203 EXPECT_FALSE(state()->CanMakePayment());
202 } 204 }
203 205
204 // Test that the last shipping option is selected.
205 TEST_F(PaymentRequestStateTest, ShippingOptionsSelection) {
206 std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
207 mojom::PaymentShippingOptionPtr option = mojom::PaymentShippingOption::New();
208 option->id = "option:1";
209 option->selected = false;
210 shipping_options.push_back(std::move(option));
211 mojom::PaymentShippingOptionPtr option2 = mojom::PaymentShippingOption::New();
212 option2->id = "option:2";
213 option2->selected = true;
214 shipping_options.push_back(std::move(option2));
215 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
216 details->shipping_options = std::move(shipping_options);
217
218 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
219 options->request_shipping = true;
220 RecreateStateWithOptionsAndDetails(std::move(options), std::move(details),
221 GetMethodDataForVisa());
222
223 EXPECT_EQ("option:2", state()->selected_shipping_option()->id);
224 }
225
226 TEST_F(PaymentRequestStateTest, ReadyToPay_DefaultSelections) { 206 TEST_F(PaymentRequestStateTest, ReadyToPay_DefaultSelections) {
227 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); 207 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
228 options->request_shipping = true; 208 options->request_shipping = true;
229 options->request_payer_name = true; 209 options->request_payer_name = true;
230 options->request_payer_phone = true; 210 options->request_payer_phone = true;
231 options->request_payer_email = true; 211 options->request_payer_email = true;
232 RecreateStateWithOptions(std::move(options)); 212 RecreateStateWithOptions(std::move(options));
233 213
214 // Because there are shipping options, no address is selected by default.
215 // Therefore we are not ready to pay.
216 EXPECT_FALSE(state()->is_ready_to_pay());
217
218 state()->SetSelectedShippingProfile(test_address());
219 EXPECT_EQ(1, num_on_selected_information_changed_called());
220
234 EXPECT_TRUE(state()->is_ready_to_pay()); 221 EXPECT_TRUE(state()->is_ready_to_pay());
235 } 222 }
236 223
237 // Testing that only supported intruments are shown. In this test the merchant 224 // Testing that only supported intruments are shown. In this test the merchant
238 // only supports Visa. 225 // only supports Visa.
239 TEST_F(PaymentRequestStateTest, UnsupportedCardAreNotAvailable) { 226 TEST_F(PaymentRequestStateTest, UnsupportedCardAreNotAvailable) {
240 // Default options. 227 // Default options.
241 RecreateStateWithOptions(mojom::PaymentOptions::New()); 228 RecreateStateWithOptions(mojom::PaymentOptions::New());
242 229
243 // Ready to pay because the default instrument is selected and supported. 230 // Ready to pay because the default instrument is selected and supported.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 EXPECT_TRUE(state()->is_ready_to_pay()); 391 EXPECT_TRUE(state()->is_ready_to_pay());
405 state()->GeneratePaymentResponse(); 392 state()->GeneratePaymentResponse();
406 393
407 // Check that the name was set, but not the other values. 394 // Check that the name was set, but not the other values.
408 EXPECT_EQ("John H. Doe", response()->payer_name.value()); 395 EXPECT_EQ("John H. Doe", response()->payer_name.value());
409 EXPECT_FALSE(response()->payer_phone.has_value()); 396 EXPECT_FALSE(response()->payer_phone.has_value());
410 EXPECT_FALSE(response()->payer_email.has_value()); 397 EXPECT_FALSE(response()->payer_email.has_value());
411 } 398 }
412 399
413 } // namespace payments 400 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698