| 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/contact_info_selection_mediator.h" | 5 #import "ios/chrome/browser/ui/payments/contact_info_selection_mediator.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/test/scoped_task_environment.h" | 9 #include "base/test/scoped_task_environment.h" |
| 10 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 11 #include "components/autofill/core/browser/autofill_test_utils.h" | 11 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 12 #include "components/autofill/core/browser/test_personal_data_manager.h" | 12 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 13 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 14 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 14 #import "ios/chrome/browser/payments/payment_request_util.h" | 15 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 15 #include "ios/chrome/browser/payments/test_payment_request.h" | 16 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 16 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" | 17 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" |
| 18 #import "ios/web/public/test/fakes/test_web_state.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 19 #include "third_party/ocmock/gtest_support.h" | 21 #include "third_party/ocmock/gtest_support.h" |
| 20 | 22 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." | 24 #error "This file requires ARC support." |
| 23 #endif | 25 #endif |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 using ::payment_request_util::GetNameLabelFromAutofillProfile; | 28 using ::payment_request_util::GetNameLabelFromAutofillProfile; |
| 27 using ::payment_request_util::GetEmailLabelFromAutofillProfile; | 29 using ::payment_request_util::GetEmailLabelFromAutofillProfile; |
| 28 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile; | 30 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile; |
| 29 } // namespace | 31 } // namespace |
| 30 | 32 |
| 31 class PaymentRequestContactInfoSelectionMediatorTest : public PlatformTest { | 33 class PaymentRequestContactInfoSelectionMediatorTest : public PlatformTest { |
| 32 protected: | 34 protected: |
| 33 PaymentRequestContactInfoSelectionMediatorTest() | 35 PaymentRequestContactInfoSelectionMediatorTest() |
| 34 : autofill_profile_1_(autofill::test::GetFullProfile()), | 36 : autofill_profile_1_(autofill::test::GetFullProfile()), |
| 35 autofill_profile_2_(autofill::test::GetFullProfile2()) { | 37 autofill_profile_2_(autofill::test::GetFullProfile2()), |
| 38 chrome_browser_state_(TestChromeBrowserState::Builder().Build()) { |
| 36 // Add testing profiles to autofill::TestPersonalDataManager. | 39 // Add testing profiles to autofill::TestPersonalDataManager. |
| 37 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); | 40 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); |
| 38 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); | 41 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); |
| 42 |
| 39 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( | 43 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( |
| 40 payment_request_test_util::CreateTestWebPaymentRequest(), | 44 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 41 &personal_data_manager_); | 45 chrome_browser_state_.get(), &web_state_, &personal_data_manager_); |
| 42 // Override the selected contact profile. | 46 // Override the selected contact profile. |
| 43 payment_request_->set_selected_contact_profile( | 47 payment_request_->set_selected_contact_profile( |
| 44 payment_request_->contact_profiles()[1]); | 48 payment_request_->contact_profiles()[1]); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void SetUp() override { | 51 void SetUp() override { |
| 48 mediator_ = [[ContactInfoSelectionMediator alloc] | 52 mediator_ = [[ContactInfoSelectionMediator alloc] |
| 49 initWithPaymentRequest:payment_request_.get()]; | 53 initWithPaymentRequest:payment_request_.get()]; |
| 50 } | 54 } |
| 51 | 55 |
| 52 ContactInfoSelectionMediator* GetMediator() { return mediator_; } | 56 ContactInfoSelectionMediator* GetMediator() { return mediator_; } |
| 53 | 57 |
| 54 base::test::ScopedTaskEnvironment scoped_task_evironment_; | 58 base::test::ScopedTaskEnvironment scoped_task_evironment_; |
| 55 | 59 |
| 56 ContactInfoSelectionMediator* mediator_; | 60 ContactInfoSelectionMediator* mediator_; |
| 57 | 61 |
| 58 autofill::AutofillProfile autofill_profile_1_; | 62 autofill::AutofillProfile autofill_profile_1_; |
| 59 autofill::AutofillProfile autofill_profile_2_; | 63 autofill::AutofillProfile autofill_profile_2_; |
| 64 web::TestWebState web_state_; |
| 60 autofill::TestPersonalDataManager personal_data_manager_; | 65 autofill::TestPersonalDataManager personal_data_manager_; |
| 66 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 61 std::unique_ptr<payments::TestPaymentRequest> payment_request_; | 67 std::unique_ptr<payments::TestPaymentRequest> payment_request_; |
| 62 }; | 68 }; |
| 63 | 69 |
| 64 // Tests that the expected selectable items are created and that the index of | 70 // Tests that the expected selectable items are created and that the index of |
| 65 // the selected item is properly set. | 71 // the selected item is properly set. |
| 66 TEST_F(PaymentRequestContactInfoSelectionMediatorTest, TestSelectableItems) { | 72 TEST_F(PaymentRequestContactInfoSelectionMediatorTest, TestSelectableItems) { |
| 67 NSArray<CollectionViewItem*>* selectable_items = | 73 NSArray<CollectionViewItem*>* selectable_items = |
| 68 [GetMediator() selectableItems]; | 74 [GetMediator() selectableItems]; |
| 69 | 75 |
| 70 // There must be two selectable items. | 76 // There must be two selectable items. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 174 |
| 169 item = [selectable_items objectAtIndex:0]; | 175 item = [selectable_items objectAtIndex:0]; |
| 170 DCHECK([item isKindOfClass:[AutofillProfileItem class]]); | 176 DCHECK([item isKindOfClass:[AutofillProfileItem class]]); |
| 171 profile_item = base::mac::ObjCCastStrict<AutofillProfileItem>(item); | 177 profile_item = base::mac::ObjCCastStrict<AutofillProfileItem>(item); |
| 172 EXPECT_NE(nil, profile_item.name); | 178 EXPECT_NE(nil, profile_item.name); |
| 173 EXPECT_NE(nil, profile_item.email); | 179 EXPECT_NE(nil, profile_item.email); |
| 174 EXPECT_EQ(nil, profile_item.phoneNumber); | 180 EXPECT_EQ(nil, profile_item.phoneNumber); |
| 175 EXPECT_EQ(nil, profile_item.address); | 181 EXPECT_EQ(nil, profile_item.address); |
| 176 EXPECT_EQ(nil, profile_item.notification); | 182 EXPECT_EQ(nil, profile_item.notification); |
| 177 } | 183 } |
| OLD | NEW |