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

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: Initial 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;
(...skipping 15 matching lines...) Expand all
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()) {
49 // Add testing profiles to autofill::TestPersonalDataManager. 51 // Add testing profiles to autofill::TestPersonalDataManager.
50 personal_data_manager_.AddTestingProfile(&autofill_profile_1_); 52 personal_data_manager_.AddTestingProfile(&autofill_profile_1_);
51 personal_data_manager_.AddTestingProfile(&autofill_profile_2_); 53 personal_data_manager_.AddTestingProfile(&autofill_profile_2_);
52 personal_data_manager_.AddTestingProfile(&autofill_profile_3_); 54 personal_data_manager_.AddTestingProfile(&autofill_profile_3_);
53 personal_data_manager_.AddTestingProfile(&autofill_profile_4_); 55 personal_data_manager_.AddTestingProfile(&autofill_profile_4_);
56
57 TestChromeBrowserState::Builder test_cbs_builder;
58 chrome_browser_state_ = test_cbs_builder.Build();
59
54 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( 60 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>(
55 payment_request_test_util::CreateTestWebPaymentRequest(), 61 payment_request_test_util::CreateTestWebPaymentRequest(),
56 &personal_data_manager_); 62 chrome_browser_state_.get(), &web_state_, &personal_data_manager_);
57 profile_comparator_ = base::MakeUnique<FakePaymentsProfileComparator>( 63 profile_comparator_ = base::MakeUnique<FakePaymentsProfileComparator>(
58 GetApplicationContext()->GetApplicationLocale(), 64 GetApplicationContext()->GetApplicationLocale(),
59 *payment_request_.get()); 65 *payment_request_.get());
60 payment_request_->SetProfileComparator(profile_comparator_.get()); 66 payment_request_->SetProfileComparator(profile_comparator_.get());
61 } 67 }
62 68
63 void SetUp() override { 69 void SetUp() override {
64 mediator_ = [[BillingAddressSelectionMediator alloc] 70 mediator_ = [[BillingAddressSelectionMediator alloc]
65 initWithPaymentRequest:payment_request_.get() 71 initWithPaymentRequest:payment_request_.get()
66 selectedBillingProfile:payment_request_->billing_profiles()[1]]; 72 selectedBillingProfile:payment_request_->billing_profiles()[1]];
67 } 73 }
68 74
69 BillingAddressSelectionMediator* GetMediator() { return mediator_; } 75 BillingAddressSelectionMediator* GetMediator() { return mediator_; }
70 76
71 base::test::ScopedTaskEnvironment scoped_task_evironment_; 77 base::test::ScopedTaskEnvironment scoped_task_evironment_;
72 78
73 BillingAddressSelectionMediator* mediator_; 79 BillingAddressSelectionMediator* mediator_;
74 80
75 autofill::AutofillProfile autofill_profile_1_; 81 autofill::AutofillProfile autofill_profile_1_;
76 autofill::AutofillProfile autofill_profile_2_; 82 autofill::AutofillProfile autofill_profile_2_;
77 autofill::AutofillProfile autofill_profile_3_; 83 autofill::AutofillProfile autofill_profile_3_;
78 autofill::AutofillProfile autofill_profile_4_; 84 autofill::AutofillProfile autofill_profile_4_;
85 web::TestWebState web_state_;
79 autofill::TestPersonalDataManager personal_data_manager_; 86 autofill::TestPersonalDataManager personal_data_manager_;
80 std::unique_ptr<payments::TestPaymentRequest> payment_request_; 87 std::unique_ptr<payments::TestPaymentRequest> payment_request_;
81 std::unique_ptr<FakePaymentsProfileComparator> profile_comparator_; 88 std::unique_ptr<FakePaymentsProfileComparator> profile_comparator_;
89 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
82 }; 90 };
83 91
84 // Tests that the expected selectable items are created and that the index of 92 // Tests that the expected selectable items are created and that the index of
85 // the selected item is properly set. 93 // the selected item is properly set.
86 TEST_F(PaymentRequestBillingAddressSelectionMediatorTest, TestSelectableItems) { 94 TEST_F(PaymentRequestBillingAddressSelectionMediatorTest, TestSelectableItems) {
87 NSArray<CollectionViewItem*>* selectable_items = 95 NSArray<CollectionViewItem*>* selectable_items =
88 [GetMediator() selectableItems]; 96 [GetMediator() selectableItems];
89 97
90 ASSERT_EQ(4U, selectable_items.count); 98 ASSERT_EQ(4U, selectable_items.count);
91 99
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 selectedBillingProfile:nil]; 179 selectedBillingProfile:nil];
172 180
173 NSArray<CollectionViewItem*>* selectable_items = 181 NSArray<CollectionViewItem*>* selectable_items =
174 [GetMediator() selectableItems]; 182 [GetMediator() selectableItems];
175 183
176 ASSERT_EQ(4U, selectable_items.count); 184 ASSERT_EQ(4U, selectable_items.count);
177 185
178 // The selected item index must be invalid. 186 // The selected item index must be invalid.
179 EXPECT_EQ(NSUIntegerMax, GetMediator().selectedItemIndex); 187 EXPECT_EQ(NSUIntegerMax, GetMediator().selectedItemIndex);
180 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698