| 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 #import "ios/chrome/browser/ui/payments/payment_request_mediator.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_mediator.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 using ::payment_request_util::GetShippingAddressLabelFromAutofillProfile; | 46 using ::payment_request_util::GetShippingAddressLabelFromAutofillProfile; |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 class PaymentRequestMediatorTest : public PlatformTest { | 49 class PaymentRequestMediatorTest : public PlatformTest { |
| 50 protected: | 50 protected: |
| 51 PaymentRequestMediatorTest() | 51 PaymentRequestMediatorTest() |
| 52 : autofill_profile_(autofill::test::GetFullProfile()), | 52 : autofill_profile_(autofill::test::GetFullProfile()), |
| 53 credit_card_(autofill::test::GetCreditCard()) { | 53 credit_card_(autofill::test::GetCreditCard()) { |
| 54 // Add testing profile and credit card to autofill::TestPersonalDataManager. | 54 // Add testing profile and credit card to autofill::TestPersonalDataManager. |
| 55 personal_data_manager_.AddTestingProfile(&autofill_profile_); | 55 personal_data_manager_.AddTestingProfile(&autofill_profile_); |
| 56 credit_card_.set_billing_address_id(autofill_profile_.guid()); |
| 56 personal_data_manager_.AddTestingCreditCard(&credit_card_); | 57 personal_data_manager_.AddTestingCreditCard(&credit_card_); |
| 57 | 58 |
| 58 payment_request_ = base::MakeUnique<TestPaymentRequest>( | 59 payment_request_ = base::MakeUnique<TestPaymentRequest>( |
| 59 payment_request_test_util::CreateTestWebPaymentRequest(), | 60 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 60 &personal_data_manager_); | 61 &personal_data_manager_); |
| 61 | 62 |
| 62 TestChromeBrowserState::Builder test_cbs_builder; | 63 TestChromeBrowserState::Builder test_cbs_builder; |
| 63 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(), | 64 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(), |
| 64 &ios::BuildFakeSigninManager); | 65 &ios::BuildFakeSigninManager); |
| 65 chrome_browser_state_ = test_cbs_builder.Build(); | 66 chrome_browser_state_ = test_cbs_builder.Build(); |
| 66 mediator_ = [[PaymentRequestMediator alloc] | 67 mediator_ = [[PaymentRequestMediator alloc] |
| 67 initWithBrowserState:chrome_browser_state_.get() | 68 initWithBrowserState:chrome_browser_state_.get() |
| 68 paymentRequest:payment_request_.get()]; | 69 paymentRequest:payment_request_.get()]; |
| 69 } | 70 } |
| 70 | 71 |
| 71 PaymentRequestMediator* GetPaymentRequestMediator() { return mediator_; } | 72 PaymentRequestMediator* GetPaymentRequestMediator() { return mediator_; } |
| 72 | 73 |
| 73 web::TestWebThreadBundle thread_bundle_; | 74 web::TestWebThreadBundle thread_bundle_; |
| 74 | 75 |
| 75 autofill::AutofillProfile autofill_profile_; | 76 autofill::AutofillProfile autofill_profile_; |
| 76 autofill::CreditCard credit_card_; | 77 autofill::CreditCard credit_card_; |
| 77 autofill::TestPersonalDataManager personal_data_manager_; | 78 autofill::TestPersonalDataManager personal_data_manager_; |
| 78 std::unique_ptr<TestPaymentRequest> payment_request_; | 79 std::unique_ptr<TestPaymentRequest> payment_request_; |
| 79 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 80 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 80 PaymentRequestMediator* mediator_; | 81 PaymentRequestMediator* mediator_; |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 // Tests whether payment can be completed when expected. | 84 // Tests whether payment can be completed when expected. |
| 84 TEST_F(PaymentRequestMediatorTest, TestCanPay) { | 85 TEST_F(PaymentRequestMediatorTest, TestCanPay) { |
| 86 EXPECT_TRUE(payment_request_->selected_credit_card()); |
| 87 EXPECT_TRUE(payment_request_->selected_shipping_profile()); |
| 88 EXPECT_TRUE(payment_request_->selected_shipping_option()); |
| 89 EXPECT_TRUE(payment_request_->selected_contact_profile()); |
| 90 EXPECT_TRUE([GetPaymentRequestMediator() canPay]); |
| 91 |
| 85 // Payment cannot be completed if there is no selected credit card. | 92 // Payment cannot be completed if there is no selected credit card. |
| 86 EXPECT_TRUE([GetPaymentRequestMediator() canPay]); | |
| 87 autofill::CreditCard* selected_credit_card = | 93 autofill::CreditCard* selected_credit_card = |
| 88 payment_request_->selected_credit_card(); | 94 payment_request_->selected_credit_card(); |
| 89 payment_request_->set_selected_credit_card(nullptr); | 95 payment_request_->set_selected_credit_card(nullptr); |
| 90 EXPECT_FALSE([GetPaymentRequestMediator() canPay]); | 96 EXPECT_FALSE([GetPaymentRequestMediator() canPay]); |
| 91 | 97 |
| 92 // Restore the selected credit card. | 98 // Restore the selected credit card. |
| 93 payment_request_->set_selected_credit_card(selected_credit_card); | 99 payment_request_->set_selected_credit_card(selected_credit_card); |
| 94 EXPECT_TRUE([GetPaymentRequestMediator() canPay]); | 100 EXPECT_TRUE([GetPaymentRequestMediator() canPay]); |
| 95 | 101 |
| 96 // Payment cannot be completed if there is no selected shipping profile, | 102 // Payment cannot be completed if there is no selected shipping profile, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // Fake a signed in user. | 443 // Fake a signed in user. |
| 438 signin_manager->SetAuthenticatedAccountInfo("12345", "username@example.com"); | 444 signin_manager->SetAuthenticatedAccountInfo("12345", "username@example.com"); |
| 439 | 445 |
| 440 item = [GetPaymentRequestMediator() footerItem]; | 446 item = [GetPaymentRequestMediator() footerItem]; |
| 441 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item); | 447 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item); |
| 442 EXPECT_TRUE([footer_item.text | 448 EXPECT_TRUE([footer_item.text |
| 443 isEqualToString:l10n_util::GetNSStringF( | 449 isEqualToString:l10n_util::GetNSStringF( |
| 444 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN, | 450 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN, |
| 445 base::ASCIIToUTF16("username@example.com"))]); | 451 base::ASCIIToUTF16("username@example.com"))]); |
| 446 } | 452 } |
| OLD | NEW |