| 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/autofill_payment_instrument.h" | 19 #include "components/payments/core/autofill_payment_instrument.h" |
| 20 #include "components/payments/core/payment_request_delegate.h" | 20 #include "components/payments/core/payment_request_delegate.h" |
| 21 #include "components/payments/mojom/payment_request.mojom.h" | 21 #include "components/payments/mojom/payment_request.mojom.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace payments { | 24 namespace payments { |
| 25 | 25 |
| 26 class FakePaymentRequestDelegate : public PaymentRequestDelegate { | 26 class FakePaymentRequestDelegate : public PaymentRequestDelegate { |
| 27 public: | 27 public: |
| 28 FakePaymentRequestDelegate( | 28 FakePaymentRequestDelegate( |
| 29 autofill::PersonalDataManager* personal_data_manager) | 29 autofill::PersonalDataManager* personal_data_manager) |
| 30 : personal_data_manager_(personal_data_manager), locale_("en-US") {} | 30 : personal_data_manager_(personal_data_manager), |
| 31 locale_("en-US"), |
| 32 last_committed_url_("https://shop.com") {} |
| 31 void ShowDialog(PaymentRequest* request) override {} | 33 void ShowDialog(PaymentRequest* request) override {} |
| 32 | 34 |
| 33 void CloseDialog() override {} | 35 void CloseDialog() override {} |
| 34 | 36 |
| 35 void ShowErrorMessage() override {} | 37 void ShowErrorMessage() override {} |
| 36 | 38 |
| 37 autofill::PersonalDataManager* GetPersonalDataManager() override { | 39 autofill::PersonalDataManager* GetPersonalDataManager() override { |
| 38 return personal_data_manager_; | 40 return personal_data_manager_; |
| 39 } | 41 } |
| 40 | 42 |
| 41 const std::string& GetApplicationLocale() const override { return locale_; } | 43 const std::string& GetApplicationLocale() const override { return locale_; } |
| 42 | 44 |
| 43 bool IsIncognito() const override { return false; } | 45 bool IsIncognito() const override { return false; } |
| 44 | 46 |
| 47 bool IsSslCertificateValid() override { return true; } |
| 48 |
| 49 const GURL& GetLastCommittedURL() const override { |
| 50 return last_committed_url_; |
| 51 } |
| 52 |
| 45 void DoFullCardRequest( | 53 void DoFullCardRequest( |
| 46 const autofill::CreditCard& credit_card, | 54 const autofill::CreditCard& credit_card, |
| 47 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> | 55 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> |
| 48 result_delegate) override { | 56 result_delegate) override { |
| 49 result_delegate->OnFullCardRequestSucceeded(credit_card, | 57 result_delegate->OnFullCardRequestSucceeded(credit_card, |
| 50 base::ASCIIToUTF16("123")); | 58 base::ASCIIToUTF16("123")); |
| 51 } | 59 } |
| 52 | 60 |
| 53 std::unique_ptr<const ::i18n::addressinput::Source> GetAddressInputSource() | 61 std::unique_ptr<const ::i18n::addressinput::Source> GetAddressInputSource() |
| 54 override { | 62 override { |
| 55 return nullptr; | 63 return nullptr; |
| 56 } | 64 } |
| 57 | 65 |
| 58 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() | 66 std::unique_ptr<::i18n::addressinput::Storage> GetAddressInputStorage() |
| 59 override { | 67 override { |
| 60 return nullptr; | 68 return nullptr; |
| 61 } | 69 } |
| 62 | 70 |
| 63 private: | 71 private: |
| 64 autofill::PersonalDataManager* personal_data_manager_; | 72 autofill::PersonalDataManager* personal_data_manager_; |
| 65 std::string locale_; | 73 std::string locale_; |
| 74 const GURL last_committed_url_; |
| 66 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate); | 75 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate); |
| 67 }; | 76 }; |
| 68 | 77 |
| 69 class PaymentResponseHelperTest : public testing::Test, | 78 class PaymentResponseHelperTest : public testing::Test, |
| 70 public PaymentResponseHelper::Delegate { | 79 public PaymentResponseHelper::Delegate { |
| 71 protected: | 80 protected: |
| 72 PaymentResponseHelperTest() | 81 PaymentResponseHelperTest() |
| 73 : payment_request_delegate_(&test_personal_data_manager_), | 82 : payment_request_delegate_(&test_personal_data_manager_), |
| 74 address_(autofill::test::GetFullProfile()), | 83 address_(autofill::test::GetFullProfile()), |
| 75 billing_addresses_({&address_}) { | 84 billing_addresses_({&address_}) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 RecreateSpecWithOptions(std::move(options)); | 300 RecreateSpecWithOptions(std::move(options)); |
| 292 | 301 |
| 293 PaymentResponseHelper helper("en-US", spec(), test_instrument(), | 302 PaymentResponseHelper helper("en-US", spec(), test_instrument(), |
| 294 test_address(), test_address(), this); | 303 test_address(), test_address(), this); |
| 295 | 304 |
| 296 // Check that the phone was formatted. | 305 // Check that the phone was formatted. |
| 297 EXPECT_EQ("+15151231234", response()->payer_phone.value()); | 306 EXPECT_EQ("+15151231234", response()->payer_phone.value()); |
| 298 } | 307 } |
| 299 | 308 |
| 300 } // namespace payments | 309 } // namespace payments |
| OLD | NEW |