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

Side by Side Diff: ios/chrome/browser/ui/payments/payment_request_view_controller_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/payment_request_view_controller.h" 5 #import "ios/chrome/browser/ui/payments/payment_request_view_controller.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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/scoped_task_environment.h" 12 #include "base/test/scoped_task_environment.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/autofill_test_utils.h" 14 #include "components/autofill/core/browser/autofill_test_utils.h"
15 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/autofill/core/browser/test_personal_data_manager.h" 16 #include "components/autofill/core/browser/test_personal_data_manager.h"
17 #include "components/strings/grit/components_strings.h" 17 #include "components/strings/grit/components_strings.h"
18 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
18 #include "ios/chrome/browser/payments/payment_request_test_util.h" 19 #include "ios/chrome/browser/payments/payment_request_test_util.h"
19 #include "ios/chrome/browser/payments/test_payment_request.h" 20 #include "ios/chrome/browser/payments/test_payment_request.h"
20 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 21 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
23 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " 24 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h "
24 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" 25 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h"
25 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h" 26 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h"
26 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" 27 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h"
27 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h" 28 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
28 #import "ios/chrome/browser/ui/payments/cells/price_item.h" 29 #import "ios/chrome/browser/ui/payments/cells/price_item.h"
29 #import "ios/chrome/browser/ui/payments/payment_request_view_controller_data_sou rce.h" 30 #import "ios/chrome/browser/ui/payments/payment_request_view_controller_data_sou rce.h"
30 #include "ios/chrome/grit/ios_strings.h" 31 #include "ios/chrome/grit/ios_strings.h"
31 #include "ios/web/public/payments/payment_request.h" 32 #include "ios/web/public/payments/payment_request.h"
33 #import "ios/web/public/test/fakes/test_web_state.h"
32 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
34 36
35 #if !defined(__has_feature) || !__has_feature(objc_arc) 37 #if !defined(__has_feature) || !__has_feature(objc_arc)
36 #error "This file requires ARC support." 38 #error "This file requires ARC support."
37 #endif 39 #endif
38 40
39 @interface TestPaymentRequestMediator 41 @interface TestPaymentRequestMediator
40 : NSObject<PaymentRequestViewControllerDataSource> 42 : NSObject<PaymentRequestViewControllerDataSource>
41 43
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 - (BOOL)canShip { 136 - (BOOL)canShip {
135 return NO; 137 return NO;
136 } 138 }
137 139
138 @end 140 @end
139 141
140 class PaymentRequestViewControllerTest : public CollectionViewControllerTest { 142 class PaymentRequestViewControllerTest : public CollectionViewControllerTest {
141 protected: 143 protected:
142 PaymentRequestViewControllerTest() 144 PaymentRequestViewControllerTest()
143 : autofill_profile_(autofill::test::GetFullProfile()), 145 : autofill_profile_(autofill::test::GetFullProfile()),
144 credit_card_(autofill::test::GetCreditCard()) { 146 credit_card_(autofill::test::GetCreditCard()),
147 chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {
145 // Add testing profile and credit card to autofill::TestPersonalDataManager. 148 // Add testing profile and credit card to autofill::TestPersonalDataManager.
146 personal_data_manager_.AddTestingProfile(&autofill_profile_); 149 personal_data_manager_.AddTestingProfile(&autofill_profile_);
147 personal_data_manager_.AddTestingCreditCard(&credit_card_); 150 personal_data_manager_.AddTestingCreditCard(&credit_card_);
148 151
149 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( 152 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>(
150 payment_request_test_util::CreateTestWebPaymentRequest(), 153 payment_request_test_util::CreateTestWebPaymentRequest(),
151 &personal_data_manager_); 154 chrome_browser_state_.get(), &web_state_, &personal_data_manager_);
152 155
153 mediator_ = [[TestPaymentRequestMediator alloc] init]; 156 mediator_ = [[TestPaymentRequestMediator alloc] init];
154 } 157 }
155 158
156 CollectionViewController* InstantiateController() override { 159 CollectionViewController* InstantiateController() override {
157 PaymentRequestViewController* viewController = 160 PaymentRequestViewController* viewController =
158 [[PaymentRequestViewController alloc] init]; 161 [[PaymentRequestViewController alloc] init];
159 [viewController setDataSource:mediator_]; 162 [viewController setDataSource:mediator_];
160 return viewController; 163 return viewController;
161 } 164 }
162 165
163 PaymentRequestViewController* GetPaymentRequestViewController() { 166 PaymentRequestViewController* GetPaymentRequestViewController() {
164 return base::mac::ObjCCastStrict<PaymentRequestViewController>( 167 return base::mac::ObjCCastStrict<PaymentRequestViewController>(
165 controller()); 168 controller());
166 } 169 }
167 170
168 base::test::ScopedTaskEnvironment scoped_task_evironment_; 171 base::test::ScopedTaskEnvironment scoped_task_evironment_;
169 172
170 autofill::AutofillProfile autofill_profile_; 173 autofill::AutofillProfile autofill_profile_;
171 autofill::CreditCard credit_card_; 174 autofill::CreditCard credit_card_;
175 web::TestWebState web_state_;
172 autofill::TestPersonalDataManager personal_data_manager_; 176 autofill::TestPersonalDataManager personal_data_manager_;
177 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
173 std::unique_ptr<payments::TestPaymentRequest> payment_request_; 178 std::unique_ptr<payments::TestPaymentRequest> payment_request_;
174 TestPaymentRequestMediator* mediator_; 179 TestPaymentRequestMediator* mediator_;
175 }; 180 };
176 181
177 // Tests that the correct items are displayed after loading the model. 182 // Tests that the correct items are displayed after loading the model.
178 TEST_F(PaymentRequestViewControllerTest, TestModel) { 183 TEST_F(PaymentRequestViewControllerTest, TestModel) {
179 CreateController(); 184 CreateController();
180 CheckController(); 185 CheckController();
181 CheckTitleWithId(IDS_PAYMENTS_TITLE); 186 CheckTitleWithId(IDS_PAYMENTS_TITLE);
182 187
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); 347 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0)));
343 348
344 // The first item should be of type PageInfoItem. 349 // The first item should be of type PageInfoItem.
345 id item = GetCollectionViewItem(0, 0); 350 id item = GetCollectionViewItem(0, 0);
346 EXPECT_TRUE([item isMemberOfClass:[PageInfoItem class]]); 351 EXPECT_TRUE([item isMemberOfClass:[PageInfoItem class]]);
347 352
348 // The second item should be of type StatusItem. 353 // The second item should be of type StatusItem.
349 item = GetCollectionViewItem(0, 1); 354 item = GetCollectionViewItem(0, 1);
350 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); 355 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]);
351 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698