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

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

Issue 2836353002: [Payments] Normalize shipping address change on Desktop (Closed)
Patch Set: Fixed Deps 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
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_response_helper.h" 5 #include "components/payments/content/payment_response_helper.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/credit_card.h" 16 #include "components/autofill/core/browser/credit_card.h"
17 #include "components/autofill/core/browser/test_personal_data_manager.h" 17 #include "components/autofill/core/browser/test_personal_data_manager.h"
18 #include "components/payments/content/payment_request_spec.h" 18 #include "components/payments/content/payment_request_spec.h"
19 #include "components/payments/core/address_normalizer.h"
20 #include "components/payments/core/autofill_payment_instrument.h" 19 #include "components/payments/core/autofill_payment_instrument.h"
21 #include "components/payments/core/payment_request_delegate.h" 20 #include "components/payments/core/test_payment_request_delegate.h"
22 #include "components/payments/mojom/payment_request.mojom.h" 21 #include "components/payments/mojom/payment_request.mojom.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 23
25 namespace payments { 24 namespace payments {
26 25
27 class FakeAddressNormalizer : public AddressNormalizer {
28 public:
29 FakeAddressNormalizer() {}
30
31 void LoadRulesForRegion(const std::string& region_code) override {}
32
33 bool AreRulesLoadedForRegion(const std::string& region_code) override {
34 return true;
35 }
36
37 void StartAddressNormalization(
38 const autofill::AutofillProfile& profile,
39 const std::string& region_code,
40 int timeout_seconds,
41 AddressNormalizer::Delegate* requester) override {
42 requester->OnAddressNormalized(profile);
43 }
44
45 void OnAddressValidationRulesLoaded(const std::string& region_code,
46 bool success) override {}
47 };
48
49 class FakePaymentRequestDelegate : public PaymentRequestDelegate {
50 public:
51 FakePaymentRequestDelegate(
52 autofill::PersonalDataManager* personal_data_manager)
53 : personal_data_manager_(personal_data_manager),
54 locale_("en-US"),
55 last_committed_url_("https://shop.com") {}
56 void ShowDialog(PaymentRequest* request) override {}
57
58 void CloseDialog() override {}
59
60 void ShowErrorMessage() override {}
61
62 autofill::PersonalDataManager* GetPersonalDataManager() override {
63 return personal_data_manager_;
64 }
65
66 const std::string& GetApplicationLocale() const override { return locale_; }
67
68 bool IsIncognito() const override { return false; }
69
70 bool IsSslCertificateValid() override { return true; }
71
72 const GURL& GetLastCommittedURL() const override {
73 return last_committed_url_;
74 }
75
76 void DoFullCardRequest(
77 const autofill::CreditCard& credit_card,
78 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
79 result_delegate) override {
80 result_delegate->OnFullCardRequestSucceeded(credit_card,
81 base::ASCIIToUTF16("123"));
82 }
83
84 AddressNormalizer* GetAddressNormalizer() override {
85 return &address_normalizer_;
86 }
87
88 autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
89
90 private:
91 autofill::PersonalDataManager* personal_data_manager_;
92 std::string locale_;
93 const GURL last_committed_url_;
94 FakeAddressNormalizer address_normalizer_;
95 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
96 };
97
98 class PaymentResponseHelperTest : public testing::Test, 26 class PaymentResponseHelperTest : public testing::Test,
99 public PaymentResponseHelper::Delegate { 27 public PaymentResponseHelper::Delegate {
100 protected: 28 protected:
101 PaymentResponseHelperTest() 29 PaymentResponseHelperTest()
102 : payment_request_delegate_(&test_personal_data_manager_), 30 : test_payment_request_delegate_(&test_personal_data_manager_),
103 address_(autofill::test::GetFullProfile()), 31 address_(autofill::test::GetFullProfile()),
104 billing_addresses_({&address_}) { 32 billing_addresses_({&address_}) {
105 test_personal_data_manager_.AddTestingProfile(&address_); 33 test_personal_data_manager_.AddTestingProfile(&address_);
106 34
107 // Setup the autofill payment instrument. 35 // Setup the autofill payment instrument.
108 autofill::CreditCard visa_card = autofill::test::GetCreditCard(); 36 autofill::CreditCard visa_card = autofill::test::GetCreditCard();
109 visa_card.set_billing_address_id(address_.guid()); 37 visa_card.set_billing_address_id(address_.guid());
110 visa_card.set_use_count(5u); 38 visa_card.set_use_count(5u);
111 autofill_instrument_ = base::MakeUnique<AutofillPaymentInstrument>( 39 autofill_instrument_ = base::MakeUnique<AutofillPaymentInstrument>(
112 "visa", visa_card, billing_addresses_, "en-US", 40 "visa", visa_card, billing_addresses_, "en-US",
113 &payment_request_delegate_); 41 &test_payment_request_delegate_);
114 } 42 }
115 ~PaymentResponseHelperTest() override {} 43 ~PaymentResponseHelperTest() override {}
116 44
117 // PaymentRequestState::Delegate: 45 // PaymentRequestState::Delegate:
118 void OnPaymentResponseReady(mojom::PaymentResponsePtr response) override { 46 void OnPaymentResponseReady(mojom::PaymentResponsePtr response) override {
119 payment_response_ = std::move(response); 47 payment_response_ = std::move(response);
120 }; 48 };
121 49
122 // Convenience method to create a PaymentRequestSpec with specified |details| 50 // Convenience method to create a PaymentRequestSpec with specified |details|
123 // and |method_data|. 51 // and |method_data|.
(...skipping 30 matching lines...) Expand all
154 entry->supported_methods.push_back("visa"); 82 entry->supported_methods.push_back("visa");
155 method_data.push_back(std::move(entry)); 83 method_data.push_back(std::move(entry));
156 return method_data; 84 return method_data;
157 } 85 }
158 86
159 PaymentRequestSpec* spec() { return spec_.get(); } 87 PaymentRequestSpec* spec() { return spec_.get(); }
160 const mojom::PaymentResponsePtr& response() { return payment_response_; } 88 const mojom::PaymentResponsePtr& response() { return payment_response_; }
161 autofill::AutofillProfile* test_address() { return &address_; } 89 autofill::AutofillProfile* test_address() { return &address_; }
162 PaymentInstrument* test_instrument() { return autofill_instrument_.get(); } 90 PaymentInstrument* test_instrument() { return autofill_instrument_.get(); }
163 PaymentRequestDelegate* test_payment_request_delegate() { 91 PaymentRequestDelegate* test_payment_request_delegate() {
164 return &payment_request_delegate_; 92 return &test_payment_request_delegate_;
165 } 93 }
166 94
167 private: 95 private:
168 std::unique_ptr<PaymentRequestSpec> spec_; 96 std::unique_ptr<PaymentRequestSpec> spec_;
169 mojom::PaymentResponsePtr payment_response_; 97 mojom::PaymentResponsePtr payment_response_;
170 autofill::TestPersonalDataManager test_personal_data_manager_; 98 autofill::TestPersonalDataManager test_personal_data_manager_;
171 FakePaymentRequestDelegate payment_request_delegate_; 99 TestPaymentRequestDelegate test_payment_request_delegate_;
172 100
173 // Test data. 101 // Test data.
174 autofill::AutofillProfile address_; 102 autofill::AutofillProfile address_;
175 const std::vector<autofill::AutofillProfile*> billing_addresses_; 103 const std::vector<autofill::AutofillProfile*> billing_addresses_;
176 std::unique_ptr<AutofillPaymentInstrument> autofill_instrument_; 104 std::unique_ptr<AutofillPaymentInstrument> autofill_instrument_;
177 }; 105 };
178 106
179 // Test generating a PaymentResponse. 107 // Test generating a PaymentResponse.
180 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_SupportedMethod) { 108 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_SupportedMethod) {
181 // Default options (no shipping, no contact info). 109 // Default options (no shipping, no contact info).
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 257
330 PaymentResponseHelper helper("en-US", spec(), test_instrument(), 258 PaymentResponseHelper helper("en-US", spec(), test_instrument(),
331 test_payment_request_delegate(), test_address(), 259 test_payment_request_delegate(), test_address(),
332 test_address(), this); 260 test_address(), this);
333 261
334 // Check that the phone was formatted. 262 // Check that the phone was formatted.
335 EXPECT_EQ("+15151231234", response()->payer_phone.value()); 263 EXPECT_EQ("+15151231234", response()->payer_phone.value());
336 } 264 }
337 265
338 } // namespace payments 266 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698