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

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

Issue 2741343011: [Payments] Move PersonalDataManager and locale to PaymentRequestState (Closed)
Patch Set: Initial 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 | « 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 "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/autofill_test_utils.h" 11 #include "components/autofill/core/browser/autofill_test_utils.h"
12 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/test_personal_data_manager.h" 13 #include "components/autofill/core/browser/test_personal_data_manager.h"
14 #include "components/payments/content/payment_request.mojom.h" 14 #include "components/payments/content/payment_request.mojom.h"
15 #include "components/payments/content/payment_request_spec.h" 15 #include "components/payments/content/payment_request_spec.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace payments { 18 namespace payments {
19 19
20 class PaymentRequestStateTest : public testing::Test, 20 class PaymentRequestStateTest : public testing::Test,
21 public PaymentRequestState::Observer, 21 public PaymentRequestState::Observer,
22 public PaymentRequestState::Delegate { 22 public PaymentRequestState::Delegate {
23 protected: 23 protected:
24 PaymentRequestStateTest() 24 PaymentRequestStateTest()
25 : num_on_selected_information_changed_called_(0), 25 : num_on_selected_information_changed_called_(0),
26 locale_("en-US"),
27 address_(autofill::test::GetFullProfile()), 26 address_(autofill::test::GetFullProfile()),
28 credit_card_(autofill::test::GetCreditCard()) { 27 credit_card_(autofill::test::GetCreditCard()) {
29 test_personal_data_manager_.AddTestingProfile(&address_); 28 test_personal_data_manager_.AddTestingProfile(&address_);
30 credit_card_.set_billing_address_id(address_.guid()); 29 credit_card_.set_billing_address_id(address_.guid());
31 test_personal_data_manager_.AddTestingCreditCard(&credit_card_); 30 test_personal_data_manager_.AddTestingCreditCard(&credit_card_);
32 } 31 }
33 ~PaymentRequestStateTest() override {} 32 ~PaymentRequestStateTest() override {}
34 33
35 // PaymentRequestState::Observer: 34 // PaymentRequestState::Observer:
36 void OnSelectedInformationChanged() override { 35 void OnSelectedInformationChanged() override {
37 num_on_selected_information_changed_called_++; 36 num_on_selected_information_changed_called_++;
38 } 37 }
39 38
40 // PaymentRequestState::Delegate: 39 // PaymentRequestState::Delegate:
41 const std::string& GetApplicationLocale() override { return locale_; };
42 autofill::PersonalDataManager* GetPersonalDataManager() override {
43 return &test_personal_data_manager_;
44 }
45 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override { 40 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override {
46 payment_response_ = std::move(response); 41 payment_response_ = std::move(response);
47 }; 42 };
48 43
49 void RecreateStateWithOptionsAndDetails( 44 void RecreateStateWithOptionsAndDetails(
50 mojom::PaymentOptionsPtr options, 45 mojom::PaymentOptionsPtr options,
51 mojom::PaymentDetailsPtr details, 46 mojom::PaymentDetailsPtr details,
52 std::vector<mojom::PaymentMethodDataPtr> method_data) { 47 std::vector<mojom::PaymentMethodDataPtr> method_data) {
53 // The spec will be based on the |options| and |details| passed in. 48 // The spec will be based on the |options| and |details| passed in.
54 spec_ = base::MakeUnique<PaymentRequestSpec>( 49 spec_ = base::MakeUnique<PaymentRequestSpec>(
55 std::move(options), std::move(details), std::move(method_data), 50 std::move(options), std::move(details), std::move(method_data), nullptr,
56 nullptr); 51 "en-US");
57 state_ = base::MakeUnique<PaymentRequestState>(spec_.get(), this); 52 state_ = base::MakeUnique<PaymentRequestState>(
53 spec_.get(), this, "en-US", &test_personal_data_manager_);
58 state_->AddObserver(this); 54 state_->AddObserver(this);
59 } 55 }
60 56
61 // Convenience method to create a PaymentRequestState with default details 57 // Convenience method to create a PaymentRequestState with default details
62 // (one shipping option) and method data (only supports visa). 58 // (one shipping option) and method data (only supports visa).
63 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) { 59 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) {
64 // Create dummy PaymentDetails with a single shipping option. 60 // Create dummy PaymentDetails with a single shipping option.
65 std::vector<mojom::PaymentShippingOptionPtr> shipping_options; 61 std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
66 mojom::PaymentShippingOptionPtr option = 62 mojom::PaymentShippingOptionPtr option =
67 mojom::PaymentShippingOption::New(); 63 mojom::PaymentShippingOption::New();
(...skipping 21 matching lines...) Expand all
89 return num_on_selected_information_changed_called_; 85 return num_on_selected_information_changed_called_;
90 } 86 }
91 87
92 autofill::AutofillProfile* test_address() { return &address_; } 88 autofill::AutofillProfile* test_address() { return &address_; }
93 autofill::CreditCard* test_credit_card() { return &credit_card_; } 89 autofill::CreditCard* test_credit_card() { return &credit_card_; }
94 90
95 private: 91 private:
96 std::unique_ptr<PaymentRequestState> state_; 92 std::unique_ptr<PaymentRequestState> state_;
97 std::unique_ptr<PaymentRequestSpec> spec_; 93 std::unique_ptr<PaymentRequestSpec> spec_;
98 int num_on_selected_information_changed_called_; 94 int num_on_selected_information_changed_called_;
99 std::string locale_;
100 mojom::PaymentResponsePtr payment_response_; 95 mojom::PaymentResponsePtr payment_response_;
101 autofill::TestPersonalDataManager test_personal_data_manager_; 96 autofill::TestPersonalDataManager test_personal_data_manager_;
102 97
103 // Test data. 98 // Test data.
104 autofill::AutofillProfile address_; 99 autofill::AutofillProfile address_;
105 autofill::CreditCard credit_card_; 100 autofill::CreditCard credit_card_;
106 }; 101 };
107 102
108 // Test that the last shipping option is selected. 103 // Test that the last shipping option is selected.
109 TEST_F(PaymentRequestStateTest, ShippingOptionsSelection) { 104 TEST_F(PaymentRequestStateTest, ShippingOptionsSelection) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 "\"region\":\"CA\"}," 204 "\"region\":\"CA\"},"
210 "\"cardNumber\":\"4111111111111111\"," 205 "\"cardNumber\":\"4111111111111111\","
211 "\"cardSecurityCode\":\"123\"," 206 "\"cardSecurityCode\":\"123\","
212 "\"cardholderName\":\"Test User\"," 207 "\"cardholderName\":\"Test User\","
213 "\"expiryMonth\":\"11\"," 208 "\"expiryMonth\":\"11\","
214 "\"expiryYear\":\"2017\"}", 209 "\"expiryYear\":\"2017\"}",
215 response()->stringified_details); 210 response()->stringified_details);
216 } 211 }
217 212
218 } // namespace payments 213 } // 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