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_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" | 19 #include "components/payments/core/address_normalizer.h" |
20 #include "components/payments/core/autofill_payment_instrument.h" | 20 #include "components/payments/core/autofill_payment_instrument.h" |
21 #include "components/payments/core/payment_request_delegate.h" | 21 #include "components/payments/core/payment_request_delegate.h" |
22 #include "components/payments/mojom/payment_request.mojom.h" | 22 #include "components/payments/mojom/payment_request.mojom.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace payments { | 25 namespace payments { |
26 | 26 |
| 27 namespace { |
| 28 |
27 class FakeAddressNormalizer : public AddressNormalizer { | 29 class FakeAddressNormalizer : public AddressNormalizer { |
28 public: | 30 public: |
29 FakeAddressNormalizer() {} | 31 FakeAddressNormalizer() {} |
30 | 32 |
31 void LoadRulesForRegion(const std::string& region_code) override {} | 33 void LoadRulesForRegion(const std::string& region_code) override {} |
32 | 34 |
33 bool AreRulesLoadedForRegion(const std::string& region_code) override { | 35 bool AreRulesLoadedForRegion(const std::string& region_code) override { |
34 return true; | 36 return true; |
35 } | 37 } |
36 | 38 |
37 void StartAddressNormalization( | 39 void StartAddressNormalization( |
38 const autofill::AutofillProfile& profile, | 40 const autofill::AutofillProfile& profile, |
39 const std::string& region_code, | 41 const std::string& region_code, |
40 int timeout_seconds, | 42 int timeout_seconds, |
41 AddressNormalizer::Delegate* requester) override { | 43 AddressNormalizer::Delegate* requester) override { |
42 requester->OnAddressNormalized(profile); | 44 requester->OnAddressNormalized(profile); |
43 } | 45 } |
44 | 46 |
45 void OnAddressValidationRulesLoaded(const std::string& region_code, | 47 void OnAddressValidationRulesLoaded(const std::string& region_code, |
46 bool success) override {} | 48 bool success) override {} |
47 }; | 49 }; |
48 | 50 |
49 class FakePaymentRequestDelegate : public PaymentRequestDelegate { | 51 class FakePaymentRequestDelegate : public PaymentRequestDelegate { |
50 public: | 52 public: |
51 FakePaymentRequestDelegate( | 53 FakePaymentRequestDelegate( |
52 autofill::PersonalDataManager* personal_data_manager) | 54 autofill::PersonalDataManager* personal_data_manager) |
53 : personal_data_manager_(personal_data_manager), | 55 : personal_data_manager_(personal_data_manager), |
54 locale_("en-US"), | 56 locale_("en-US"), |
55 last_committed_url_("https://shop.com") {} | 57 last_committed_url_("https://shop.com") {} |
| 58 |
56 void ShowDialog(PaymentRequest* request) override {} | 59 void ShowDialog(PaymentRequest* request) override {} |
57 | 60 |
58 void CloseDialog() override {} | 61 void CloseDialog() override {} |
59 | 62 |
60 void ShowErrorMessage() override {} | 63 void ShowErrorMessage() override {} |
61 | 64 |
62 autofill::PersonalDataManager* GetPersonalDataManager() override { | 65 autofill::PersonalDataManager* GetPersonalDataManager() override { |
63 return personal_data_manager_; | 66 return personal_data_manager_; |
64 } | 67 } |
65 | 68 |
(...skipping 22 matching lines...) Expand all Loading... |
88 autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; } | 91 autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; } |
89 | 92 |
90 private: | 93 private: |
91 autofill::PersonalDataManager* personal_data_manager_; | 94 autofill::PersonalDataManager* personal_data_manager_; |
92 std::string locale_; | 95 std::string locale_; |
93 const GURL last_committed_url_; | 96 const GURL last_committed_url_; |
94 FakeAddressNormalizer address_normalizer_; | 97 FakeAddressNormalizer address_normalizer_; |
95 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate); | 98 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate); |
96 }; | 99 }; |
97 | 100 |
| 101 } // namespace |
| 102 |
98 class PaymentResponseHelperTest : public testing::Test, | 103 class PaymentResponseHelperTest : public testing::Test, |
99 public PaymentResponseHelper::Delegate { | 104 public PaymentResponseHelper::Delegate { |
100 protected: | 105 protected: |
101 PaymentResponseHelperTest() | 106 PaymentResponseHelperTest() |
102 : payment_request_delegate_(&test_personal_data_manager_), | 107 : payment_request_delegate_(&test_personal_data_manager_), |
103 address_(autofill::test::GetFullProfile()), | 108 address_(autofill::test::GetFullProfile()), |
104 billing_addresses_({&address_}) { | 109 billing_addresses_({&address_}) { |
105 test_personal_data_manager_.AddTestingProfile(&address_); | 110 test_personal_data_manager_.AddTestingProfile(&address_); |
106 | 111 |
107 // Setup the autofill payment instrument. | 112 // Setup the autofill payment instrument. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 334 |
330 PaymentResponseHelper helper("en-US", spec(), test_instrument(), | 335 PaymentResponseHelper helper("en-US", spec(), test_instrument(), |
331 test_payment_request_delegate(), test_address(), | 336 test_payment_request_delegate(), test_address(), |
332 test_address(), this); | 337 test_address(), this); |
333 | 338 |
334 // Check that the phone was formatted. | 339 // Check that the phone was formatted. |
335 EXPECT_EQ("+15151231234", response()->payer_phone.value()); | 340 EXPECT_EQ("+15151231234", response()->payer_phone.value()); |
336 } | 341 } |
337 | 342 |
338 } // namespace payments | 343 } // namespace payments |
OLD | NEW |