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

Side by Side Diff: ios/chrome/browser/ui/payments/payment_request_coordinator_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/payment_request_coordinator.h" 5 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
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"
(...skipping 13 matching lines...) Expand all
24 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 24 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
25 #include "ios/chrome/browser/payments/payment_request.h" 25 #include "ios/chrome/browser/payments/payment_request.h"
26 #include "ios/chrome/browser/payments/payment_request_test_util.h" 26 #include "ios/chrome/browser/payments/payment_request_test_util.h"
27 #include "ios/chrome/browser/payments/test_payment_request.h" 27 #include "ios/chrome/browser/payments/test_payment_request.h"
28 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h" 28 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h"
29 #include "ios/chrome/browser/signin/signin_manager_factory.h" 29 #include "ios/chrome/browser/signin/signin_manager_factory.h"
30 #import "ios/chrome/browser/ui/payments/payment_request_view_controller.h" 30 #import "ios/chrome/browser/ui/payments/payment_request_view_controller.h"
31 #import "ios/chrome/test/scoped_key_window.h" 31 #import "ios/chrome/test/scoped_key_window.h"
32 #import "ios/testing/ocmock_complex_type_helper.h" 32 #import "ios/testing/ocmock_complex_type_helper.h"
33 #include "ios/web/public/payments/payment_request.h" 33 #include "ios/web/public/payments/payment_request.h"
34 #import "ios/web/public/test/fakes/test_web_state.h"
34 #import "ios/web/public/test/test_web_thread_bundle.h" 35 #import "ios/web/public/test/test_web_thread_bundle.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 #include "testing/platform_test.h" 37 #include "testing/platform_test.h"
37 #include "third_party/ocmock/OCMock/OCMock.h" 38 #include "third_party/ocmock/OCMock/OCMock.h"
38 #include "third_party/ocmock/gtest_support.h" 39 #include "third_party/ocmock/gtest_support.h"
39 40
40 #if !defined(__has_feature) || !__has_feature(objc_arc) 41 #if !defined(__has_feature) || !__has_feature(objc_arc)
41 #error "This file requires ARC support." 42 #error "This file requires ARC support."
42 #endif 43 #endif
43 44
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 : autofill_profile_(autofill::test::GetFullProfile()), 94 : autofill_profile_(autofill::test::GetFullProfile()),
94 credit_card_(autofill::test::GetCreditCard()), 95 credit_card_(autofill::test::GetCreditCard()),
95 pref_service_(payments::test::PrefServiceForTesting()) { 96 pref_service_(payments::test::PrefServiceForTesting()) {
96 // Add testing profile and credit card to autofill::TestPersonalDataManager. 97 // Add testing profile and credit card to autofill::TestPersonalDataManager.
97 personal_data_manager_.AddTestingProfile(&autofill_profile_); 98 personal_data_manager_.AddTestingProfile(&autofill_profile_);
98 personal_data_manager_.AddTestingCreditCard(&credit_card_); 99 personal_data_manager_.AddTestingCreditCard(&credit_card_);
99 100
100 TestChromeBrowserState::Builder test_cbs_builder; 101 TestChromeBrowserState::Builder test_cbs_builder;
101 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(), 102 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(),
102 &ios::BuildFakeSigninManager); 103 &ios::BuildFakeSigninManager);
103 browser_state_ = test_cbs_builder.Build(); 104 chrome_browser_state_ = test_cbs_builder.Build();
104 105
105 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( 106 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>(
106 payment_request_test_util::CreateTestWebPaymentRequest(), 107 payment_request_test_util::CreateTestWebPaymentRequest(),
107 browser_state_.get(), &personal_data_manager_); 108 chrome_browser_state_.get(), &web_state_, &personal_data_manager_);
108 payment_request_->SetPrefService(pref_service_.get()); 109 payment_request_->SetPrefService(pref_service_.get());
109 } 110 }
110 111
111 base::test::ScopedTaskEnvironment scoped_task_evironment_; 112 base::test::ScopedTaskEnvironment scoped_task_evironment_;
112 113
113 autofill::AutofillProfile autofill_profile_; 114 autofill::AutofillProfile autofill_profile_;
114 autofill::CreditCard credit_card_; 115 autofill::CreditCard credit_card_;
116 web::TestWebState web_state_;
115 std::unique_ptr<PrefService> pref_service_; 117 std::unique_ptr<PrefService> pref_service_;
116 autofill::TestPersonalDataManager personal_data_manager_; 118 autofill::TestPersonalDataManager personal_data_manager_;
117 std::unique_ptr<payments::TestPaymentRequest> payment_request_; 119 std::unique_ptr<payments::TestPaymentRequest> payment_request_;
118 std::unique_ptr<ios::ChromeBrowserState> browser_state_; 120 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
119 }; 121 };
120 122
121 // Tests that invoking start and stop on the coordinator presents and 123 // Tests that invoking start and stop on the coordinator presents and
122 // dismisses 124 // dismisses
123 // the PaymentRequestViewController, respectively. 125 // the PaymentRequestViewController, respectively.
124 TEST_F(PaymentRequestCoordinatorTest, StartAndStop) { 126 TEST_F(PaymentRequestCoordinatorTest, StartAndStop) {
125 UIViewController* base_view_controller = [[UIViewController alloc] init]; 127 UIViewController* base_view_controller = [[UIViewController alloc] init];
126 ScopedKeyWindow scoped_key_window_; 128 ScopedKeyWindow scoped_key_window_;
127 [scoped_key_window_.Get() setRootViewController:base_view_controller]; 129 [scoped_key_window_.Get() setRootViewController:base_view_controller];
128 130
129 PaymentRequestCoordinator* coordinator = [[PaymentRequestCoordinator alloc] 131 PaymentRequestCoordinator* coordinator = [[PaymentRequestCoordinator alloc]
130 initWithBaseViewController:base_view_controller]; 132 initWithBaseViewController:base_view_controller];
131 [coordinator setPaymentRequest:payment_request_.get()]; 133 [coordinator setPaymentRequest:payment_request_.get()];
132 [coordinator setBrowserState:browser_state_.get()]; 134 [coordinator setBrowserState:chrome_browser_state_.get()];
133 135
134 [coordinator start]; 136 [coordinator start];
135 // Spin the run loop to trigger the animation. 137 // Spin the run loop to trigger the animation.
136 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1)); 138 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1));
137 EXPECT_TRUE([base_view_controller.presentedViewController 139 EXPECT_TRUE([base_view_controller.presentedViewController
138 isMemberOfClass:[UINavigationController class]]); 140 isMemberOfClass:[UINavigationController class]]);
139 UINavigationController* navigation_controller = 141 UINavigationController* navigation_controller =
140 base::mac::ObjCCastStrict<UINavigationController>( 142 base::mac::ObjCCastStrict<UINavigationController>(
141 base_view_controller.presentedViewController); 143 base_view_controller.presentedViewController);
142 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 144 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 id delegate = [OCMockObject 291 id delegate = [OCMockObject
290 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)]; 292 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)];
291 id delegate_mock([[PaymentRequestCoordinatorDelegateMock alloc] 293 id delegate_mock([[PaymentRequestCoordinatorDelegateMock alloc]
292 initWithRepresentedObject:delegate]); 294 initWithRepresentedObject:delegate]);
293 SEL selector = @selector(paymentRequestCoordinatorDidCancel:); 295 SEL selector = @selector(paymentRequestCoordinatorDidCancel:);
294 [delegate_mock onSelector:selector 296 [delegate_mock onSelector:selector
295 callBlockExpectation:^(PaymentRequestCoordinator* callerCoordinator) { 297 callBlockExpectation:^(PaymentRequestCoordinator* callerCoordinator) {
296 EXPECT_EQ(coordinator, callerCoordinator); 298 EXPECT_EQ(coordinator, callerCoordinator);
297 }]; 299 }];
298 [coordinator setDelegate:delegate_mock]; 300 [coordinator setDelegate:delegate_mock];
299 [coordinator setBrowserState:browser_state_.get()]; 301 [coordinator setBrowserState:chrome_browser_state_.get()];
300 302
301 [coordinator start]; 303 [coordinator start];
302 // Spin the run loop to trigger the animation. 304 // Spin the run loop to trigger the animation.
303 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1)); 305 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1));
304 306
305 // Call the controller delegate method. 307 // Call the controller delegate method.
306 [coordinator paymentRequestViewControllerDidCancel:nil]; 308 [coordinator paymentRequestViewControllerDidCancel:nil];
307 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698