Chromium Code Reviews| 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()) { |
| 36 // Add testing profiles to autofill::TestPersonalDataManager. | 38 // Add testing profiles to autofill::TestPersonalDataManager. |
| 37 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); | 39 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); |
| 38 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); | 40 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); |
| 41 | |
| 42 TestChromeBrowserState::Builder test_cbs_builder; | |
| 43 chrome_browser_state_ = test_cbs_builder.Build(); | |
| 44 | |
| 39 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( | 45 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( |
| 40 payment_request_test_util::CreateTestWebPaymentRequest(), | 46 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 41 &personal_data_manager_); | 47 chrome_browser_state_.get(), &web_state_, &personal_data_manager_); |
| 42 // Override the selected contact profile. | 48 // Override the selected contact profile. |
| 43 payment_request_->set_selected_contact_profile( | 49 payment_request_->set_selected_contact_profile( |
| 44 payment_request_->contact_profiles()[1]); | 50 payment_request_->contact_profiles()[1]); |
| 45 } | 51 } |
| 46 | 52 |
| 47 void SetUp() override { | 53 void SetUp() override { |
| 48 mediator_ = [[ContactInfoSelectionMediator alloc] | 54 mediator_ = [[ContactInfoSelectionMediator alloc] |
| 49 initWithPaymentRequest:payment_request_.get()]; | 55 initWithPaymentRequest:payment_request_.get()]; |
| 50 } | 56 } |
| 51 | 57 |
| 52 ContactInfoSelectionMediator* GetMediator() { return mediator_; } | 58 ContactInfoSelectionMediator* GetMediator() { return mediator_; } |
| 53 | 59 |
| 54 base::test::ScopedTaskEnvironment scoped_task_evironment_; | 60 base::test::ScopedTaskEnvironment scoped_task_evironment_; |
| 55 | 61 |
| 56 ContactInfoSelectionMediator* mediator_; | 62 ContactInfoSelectionMediator* mediator_; |
| 57 | 63 |
| 58 autofill::AutofillProfile autofill_profile_1_; | 64 autofill::AutofillProfile autofill_profile_1_; |
| 59 autofill::AutofillProfile autofill_profile_2_; | 65 autofill::AutofillProfile autofill_profile_2_; |
| 66 web::TestWebState web_state_; | |
| 60 autofill::TestPersonalDataManager personal_data_manager_; | 67 autofill::TestPersonalDataManager personal_data_manager_; |
| 61 std::unique_ptr<payments::TestPaymentRequest> payment_request_; | 68 std::unique_ptr<payments::TestPaymentRequest> payment_request_; |
| 69 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | |
|
please use gerrit instead
2017/07/06 14:52:25
Ditto
Moe
2017/07/07 02:24:54
Done.
| |
| 62 }; | 70 }; |
| 63 | 71 |
| 64 // Tests that the expected selectable items are created and that the index of | 72 // Tests that the expected selectable items are created and that the index of |
| 65 // the selected item is properly set. | 73 // the selected item is properly set. |
| 66 TEST_F(PaymentRequestContactInfoSelectionMediatorTest, TestSelectableItems) { | 74 TEST_F(PaymentRequestContactInfoSelectionMediatorTest, TestSelectableItems) { |
| 67 NSArray<CollectionViewItem*>* selectable_items = | 75 NSArray<CollectionViewItem*>* selectable_items = |
| 68 [GetMediator() selectableItems]; | 76 [GetMediator() selectableItems]; |
| 69 | 77 |
| 70 // There must be two selectable items. | 78 // There must be two selectable items. |
| 71 ASSERT_EQ(2U, selectable_items.count); | 79 ASSERT_EQ(2U, selectable_items.count); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 176 |
| 169 item = [selectable_items objectAtIndex:0]; | 177 item = [selectable_items objectAtIndex:0]; |
| 170 DCHECK([item isKindOfClass:[AutofillProfileItem class]]); | 178 DCHECK([item isKindOfClass:[AutofillProfileItem class]]); |
| 171 profile_item = base::mac::ObjCCastStrict<AutofillProfileItem>(item); | 179 profile_item = base::mac::ObjCCastStrict<AutofillProfileItem>(item); |
| 172 EXPECT_NE(nil, profile_item.name); | 180 EXPECT_NE(nil, profile_item.name); |
| 173 EXPECT_NE(nil, profile_item.email); | 181 EXPECT_NE(nil, profile_item.email); |
| 174 EXPECT_EQ(nil, profile_item.phoneNumber); | 182 EXPECT_EQ(nil, profile_item.phoneNumber); |
| 175 EXPECT_EQ(nil, profile_item.address); | 183 EXPECT_EQ(nil, profile_item.address); |
| 176 EXPECT_EQ(nil, profile_item.notification); | 184 EXPECT_EQ(nil, profile_item.notification); |
| 177 } | 185 } |
| OLD | NEW |