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

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 BUILD deps Created 3 years, 7 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 namespace {
28
29 class FakeAddressNormalizer : public AddressNormalizer {
30 public:
31 FakeAddressNormalizer() {}
32
33 void LoadRulesForRegion(const std::string& region_code) override {}
34
35 bool AreRulesLoadedForRegion(const std::string& region_code) override {
36 return true;
37 }
38
39 void StartAddressNormalization(
40 const autofill::AutofillProfile& profile,
41 const std::string& region_code,
42 int timeout_seconds,
43 AddressNormalizer::Delegate* requester) override {
44 requester->OnAddressNormalized(profile);
45 }
46
47 void OnAddressValidationRulesLoaded(const std::string& region_code,
48 bool success) override {}
49 };
50
51 class FakePaymentRequestDelegate : public PaymentRequestDelegate {
52 public:
53 FakePaymentRequestDelegate(
54 autofill::PersonalDataManager* personal_data_manager)
55 : personal_data_manager_(personal_data_manager),
56 locale_("en-US"),
57 last_committed_url_("https://shop.com") {}
58
59 void ShowDialog(PaymentRequest* request) override {}
60
61 void CloseDialog() override {}
62
63 void ShowErrorMessage() override {}
64
65 autofill::PersonalDataManager* GetPersonalDataManager() override {
66 return personal_data_manager_;
67 }
68
69 const std::string& GetApplicationLocale() const override { return locale_; }
70
71 bool IsIncognito() const override { return false; }
72
73 bool IsSslCertificateValid() override { return true; }
74
75 const GURL& GetLastCommittedURL() const override {
76 return last_committed_url_;
77 }
78
79 void DoFullCardRequest(
80 const autofill::CreditCard& credit_card,
81 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
82 result_delegate) override {
83 result_delegate->OnFullCardRequestSucceeded(credit_card,
84 base::ASCIIToUTF16("123"));
85 }
86
87 AddressNormalizer* GetAddressNormalizer() override {
88 return &address_normalizer_;
89 }
90
91 autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
92
93 private:
94 autofill::PersonalDataManager* personal_data_manager_;
95 std::string locale_;
96 const GURL last_committed_url_;
97 FakeAddressNormalizer address_normalizer_;
98 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
99 };
100
101 } // namespace
102
103 class PaymentResponseHelperTest : public testing::Test, 26 class PaymentResponseHelperTest : public testing::Test,
104 public PaymentResponseHelper::Delegate { 27 public PaymentResponseHelper::Delegate {
105 protected: 28 protected:
106 PaymentResponseHelperTest() 29 PaymentResponseHelperTest()
107 : payment_request_delegate_(&test_personal_data_manager_), 30 : test_payment_request_delegate_(&test_personal_data_manager_),
108 address_(autofill::test::GetFullProfile()), 31 address_(autofill::test::GetFullProfile()),
109 billing_addresses_({&address_}) { 32 billing_addresses_({&address_}) {
110 test_personal_data_manager_.AddTestingProfile(&address_); 33 test_personal_data_manager_.AddTestingProfile(&address_);
111 34
112 // Setup the autofill payment instrument. 35 // Setup the autofill payment instrument.
113 autofill::CreditCard visa_card = autofill::test::GetCreditCard(); 36 autofill::CreditCard visa_card = autofill::test::GetCreditCard();
114 visa_card.set_billing_address_id(address_.guid()); 37 visa_card.set_billing_address_id(address_.guid());
115 visa_card.set_use_count(5u); 38 visa_card.set_use_count(5u);
116 autofill_instrument_ = base::MakeUnique<AutofillPaymentInstrument>( 39 autofill_instrument_ = base::MakeUnique<AutofillPaymentInstrument>(
117 "visa", visa_card, billing_addresses_, "en-US", 40 "visa", visa_card, billing_addresses_, "en-US",
118 &payment_request_delegate_); 41 &test_payment_request_delegate_);
119 } 42 }
120 ~PaymentResponseHelperTest() override {} 43 ~PaymentResponseHelperTest() override {}
121 44
122 // PaymentRequestState::Delegate: 45 // PaymentRequestState::Delegate:
123 void OnPaymentResponseReady(mojom::PaymentResponsePtr response) override { 46 void OnPaymentResponseReady(mojom::PaymentResponsePtr response) override {
124 payment_response_ = std::move(response); 47 payment_response_ = std::move(response);
125 }; 48 };
126 49
127 // Convenience method to create a PaymentRequestSpec with specified |details| 50 // Convenience method to create a PaymentRequestSpec with specified |details|
128 // and |method_data|. 51 // and |method_data|.
(...skipping 30 matching lines...) Expand all
159 entry->supported_methods.push_back("visa"); 82 entry->supported_methods.push_back("visa");
160 method_data.push_back(std::move(entry)); 83 method_data.push_back(std::move(entry));
161 return method_data; 84 return method_data;
162 } 85 }
163 86
164 PaymentRequestSpec* spec() { return spec_.get(); } 87 PaymentRequestSpec* spec() { return spec_.get(); }
165 const mojom::PaymentResponsePtr& response() { return payment_response_; } 88 const mojom::PaymentResponsePtr& response() { return payment_response_; }
166 autofill::AutofillProfile* test_address() { return &address_; } 89 autofill::AutofillProfile* test_address() { return &address_; }
167 PaymentInstrument* test_instrument() { return autofill_instrument_.get(); } 90 PaymentInstrument* test_instrument() { return autofill_instrument_.get(); }
168 PaymentRequestDelegate* test_payment_request_delegate() { 91 PaymentRequestDelegate* test_payment_request_delegate() {
169 return &payment_request_delegate_; 92 return &test_payment_request_delegate_;
170 } 93 }
171 94
172 private: 95 private:
173 std::unique_ptr<PaymentRequestSpec> spec_; 96 std::unique_ptr<PaymentRequestSpec> spec_;
174 mojom::PaymentResponsePtr payment_response_; 97 mojom::PaymentResponsePtr payment_response_;
175 autofill::TestPersonalDataManager test_personal_data_manager_; 98 autofill::TestPersonalDataManager test_personal_data_manager_;
176 FakePaymentRequestDelegate payment_request_delegate_; 99 TestPaymentRequestDelegate test_payment_request_delegate_;
177 100
178 // Test data. 101 // Test data.
179 autofill::AutofillProfile address_; 102 autofill::AutofillProfile address_;
180 const std::vector<autofill::AutofillProfile*> billing_addresses_; 103 const std::vector<autofill::AutofillProfile*> billing_addresses_;
181 std::unique_ptr<AutofillPaymentInstrument> autofill_instrument_; 104 std::unique_ptr<AutofillPaymentInstrument> autofill_instrument_;
182 }; 105 };
183 106
184 // Test generating a PaymentResponse. 107 // Test generating a PaymentResponse.
185 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_SupportedMethod) { 108 TEST_F(PaymentResponseHelperTest, GeneratePaymentResponse_SupportedMethod) {
186 // 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
334 257
335 PaymentResponseHelper helper("en-US", spec(), test_instrument(), 258 PaymentResponseHelper helper("en-US", spec(), test_instrument(),
336 test_payment_request_delegate(), test_address(), 259 test_payment_request_delegate(), test_address(),
337 test_address(), this); 260 test_address(), this);
338 261
339 // Check that the phone was formatted. 262 // Check that the phone was formatted.
340 EXPECT_EQ("+15151231234", response()->payer_phone.value()); 263 EXPECT_EQ("+15151231234", response()->payer_phone.value());
341 } 264 }
342 265
343 } // namespace payments 266 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698