Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: ios/chrome/browser/ui/payments/billing_address_selection_mediator_unittest.mm

Issue 2970233002: [Payment Request] Adds a JourneyLogger instance to the PaymentRequest (Closed)
Patch Set: Addressed comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/billing_address_selection_mediator.h" 5 #import "ios/chrome/browser/ui/payments/billing_address_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 "components/payments/core/payments_profile_comparator.h" 13 #include "components/payments/core/payments_profile_comparator.h"
14 #include "ios/chrome/browser/application_context.h" 14 #include "ios/chrome/browser/application_context.h"
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
15 #include "ios/chrome/browser/payments/payment_request_test_util.h" 16 #include "ios/chrome/browser/payments/payment_request_test_util.h"
16 #import "ios/chrome/browser/payments/payment_request_util.h" 17 #import "ios/chrome/browser/payments/payment_request_util.h"
17 #include "ios/chrome/browser/payments/test_payment_request.h" 18 #include "ios/chrome/browser/payments/test_payment_request.h"
18 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" 19 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h"
20 #import "ios/web/public/test/fakes/test_web_state.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
21 #include "third_party/ocmock/gtest_support.h" 23 #include "third_party/ocmock/gtest_support.h"
22 24
23 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support." 26 #error "This file requires ARC support."
25 #endif 27 #endif
26 28
27 namespace { 29 namespace {
28 using ::payment_request_util::GetNameLabelFromAutofillProfile; 30 using ::payment_request_util::GetNameLabelFromAutofillProfile;
29 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; 31 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile;
30 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile; 32 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
31 using ::payment_request_util::GetAddressNotificationLabelFromAutofillProfile; 33 using ::payment_request_util::GetAddressNotificationLabelFromAutofillProfile;
32 } // namespace 34 } // namespace
33 35
34 class FakePaymentsProfileComparator 36 class FakePaymentsProfileComparator
35 : public payments::PaymentsProfileComparator { 37 : public payments::PaymentsProfileComparator {
36 public: 38 public:
37 FakePaymentsProfileComparator(const std::string& app_locale, 39 FakePaymentsProfileComparator(const std::string& app_locale,
38 const payments::PaymentOptionsProvider& options) 40 const payments::PaymentOptionsProvider& options)
39 : PaymentsProfileComparator(app_locale, options) {} 41 : PaymentsProfileComparator(app_locale, options) {}
40 }; 42 };
41 43
42 class PaymentRequestBillingAddressSelectionMediatorTest : public PlatformTest { 44 class PaymentRequestBillingAddressSelectionMediatorTest : public PlatformTest {
43 protected: 45 protected:
44 PaymentRequestBillingAddressSelectionMediatorTest() 46 PaymentRequestBillingAddressSelectionMediatorTest()
45 : autofill_profile_1_(autofill::test::GetFullProfile()), 47 : autofill_profile_1_(autofill::test::GetFullProfile()),
46 autofill_profile_2_(autofill::test::GetFullProfile2()), 48 autofill_profile_2_(autofill::test::GetFullProfile2()),
47 autofill_profile_3_(autofill::test::GetIncompleteProfile1()), 49 autofill_profile_3_(autofill::test::GetIncompleteProfile1()),
48 autofill_profile_4_(autofill::test::GetIncompleteProfile2()) { 50 autofill_profile_4_(autofill::test::GetIncompleteProfile2()),
51 chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {
49 // Add testing profiles to autofill::TestPersonalDataManager. 52 // Add testing profiles to autofill::TestPersonalDataManager.
50 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); 53 personal_data_manager_.AddTestingProfile(&autofill_profile_1_);
51 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); 54 personal_data_manager_.AddTestingProfile(&autofill_profile_2_);
52 personal_data_manager_.AddTestingProfile(&autofill_profile_3_); 55 personal_data_manager_.AddTestingProfile(&autofill_profile_3_);
53 personal_data_manager_.AddTestingProfile(&autofill_profile_4_); 56 personal_data_manager_.AddTestingProfile(&autofill_profile_4_);
57
54 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( 58 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>(
55 payment_request_test_util::CreateTestWebPaymentRequest(), 59 payment_request_test_util::CreateTestWebPaymentRequest(),
56 &personal_data_manager_); 60 chrome_browser_state_.get(), &web_state_, &personal_data_manager_);
57 profile_comparator_ = base::MakeUnique<FakePaymentsProfileComparator>( 61 profile_comparator_ = base::MakeUnique<FakePaymentsProfileComparator>(
58 GetApplicationContext()->GetApplicationLocale(), 62 GetApplicationContext()->GetApplicationLocale(),
59 *payment_request_.get()); 63 *payment_request_.get());
60 payment_request_->SetProfileComparator(profile_comparator_.get()); 64 payment_request_->SetProfileComparator(profile_comparator_.get());
61 } 65 }
62 66
63 void SetUp() override { 67 void SetUp() override {
64 mediator_ = [[BillingAddressSelectionMediator alloc] 68 mediator_ = [[BillingAddressSelectionMediator alloc]
65 initWithPaymentRequest:payment_request_.get() 69 initWithPaymentRequest:payment_request_.get()
66 selectedBillingProfile:payment_request_->billing_profiles()[1]]; 70 selectedBillingProfile:payment_request_->billing_profiles()[1]];
67 } 71 }
68 72
69 BillingAddressSelectionMediator* GetMediator() { return mediator_; } 73 BillingAddressSelectionMediator* GetMediator() { return mediator_; }
70 74
71 base::test::ScopedTaskEnvironment scoped_task_evironment_; 75 base::test::ScopedTaskEnvironment scoped_task_evironment_;
72 76
73 BillingAddressSelectionMediator* mediator_; 77 BillingAddressSelectionMediator* mediator_;
74 78
75 autofill::AutofillProfile autofill_profile_1_; 79 autofill::AutofillProfile autofill_profile_1_;
76 autofill::AutofillProfile autofill_profile_2_; 80 autofill::AutofillProfile autofill_profile_2_;
77 autofill::AutofillProfile autofill_profile_3_; 81 autofill::AutofillProfile autofill_profile_3_;
78 autofill::AutofillProfile autofill_profile_4_; 82 autofill::AutofillProfile autofill_profile_4_;
83 web::TestWebState web_state_;
79 autofill::TestPersonalDataManager personal_data_manager_; 84 autofill::TestPersonalDataManager personal_data_manager_;
85 std::unique_ptr<FakePaymentsProfileComparator> profile_comparator_;
86 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
80 std::unique_ptr<payments::TestPaymentRequest> payment_request_; 87 std::unique_ptr<payments::TestPaymentRequest> payment_request_;
81 std::unique_ptr<FakePaymentsProfileComparator> profile_comparator_;
82 }; 88 };
83 89
84 // Tests that the expected selectable items are created and that the index of 90 // Tests that the expected selectable items are created and that the index of
85 // the selected item is properly set. 91 // the selected item is properly set.
86 TEST_F(PaymentRequestBillingAddressSelectionMediatorTest, TestSelectableItems) { 92 TEST_F(PaymentRequestBillingAddressSelectionMediatorTest, TestSelectableItems) {
87 NSArray<CollectionViewItem*>* selectable_items = 93 NSArray<CollectionViewItem*>* selectable_items =
88 [GetMediator() selectableItems]; 94 [GetMediator() selectableItems];
89 95
90 ASSERT_EQ(4U, selectable_items.count); 96 ASSERT_EQ(4U, selectable_items.count);
91 97
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 selectedBillingProfile:nil]; 177 selectedBillingProfile:nil];
172 178
173 NSArray<CollectionViewItem*>* selectable_items = 179 NSArray<CollectionViewItem*>* selectable_items =
174 [GetMediator() selectableItems]; 180 [GetMediator() selectableItems];
175 181
176 ASSERT_EQ(4U, selectable_items.count); 182 ASSERT_EQ(4U, selectable_items.count);
177 183
178 // The selected item index must be invalid. 184 // The selected item index must be invalid.
179 EXPECT_EQ(NSUIntegerMax, GetMediator().selectedItemIndex); 185 EXPECT_EQ(NSUIntegerMax, GetMediator().selectedItemIndex);
180 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698