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/payment_request_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/ios/wait_util.h" | 10 #include "base/test/ios/wait_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #error "This file requires ARC support." | 30 #error "This file requires ARC support." |
31 #endif | 31 #endif |
32 | 32 |
33 @interface PaymentRequestCoordinatorDelegateMock< | 33 @interface PaymentRequestCoordinatorDelegateMock< |
34 PaymentRequestCoordinatorDelegate>:OCMockComplexTypeHelper | 34 PaymentRequestCoordinatorDelegate>:OCMockComplexTypeHelper |
35 @end | 35 @end |
36 | 36 |
37 @implementation PaymentRequestCoordinatorDelegateMock | 37 @implementation PaymentRequestCoordinatorDelegateMock |
38 | 38 |
39 typedef void (^mock_coordinator_cancel)(PaymentRequestCoordinator*); | 39 typedef void (^mock_coordinator_cancel)(PaymentRequestCoordinator*); |
40 typedef void (^mock_coordinator_confirm)(PaymentRequestCoordinator*, | 40 typedef void (^mock_coordinator_complete)(PaymentRequestCoordinator*, |
41 web::PaymentResponse); | 41 PaymentRequest*, |
| 42 const autofill::CreditCard&, |
| 43 const base::string16&); |
42 typedef void (^mock_coordinator_select_shipping_address)( | 44 typedef void (^mock_coordinator_select_shipping_address)( |
43 PaymentRequestCoordinator*, | 45 PaymentRequestCoordinator*, |
44 payments::PaymentAddress); | 46 payments::PaymentAddress); |
45 typedef void (^mock_coordinator_select_shipping_option)( | 47 typedef void (^mock_coordinator_select_shipping_option)( |
46 PaymentRequestCoordinator*, | 48 PaymentRequestCoordinator*, |
47 web::PaymentShippingOption); | 49 web::PaymentShippingOption); |
48 | 50 |
49 - (void)paymentRequestCoordinatorDidCancel: | 51 - (void)paymentRequestCoordinatorDidCancel: |
50 (PaymentRequestCoordinator*)coordinator { | 52 (PaymentRequestCoordinator*)coordinator { |
51 return static_cast<mock_coordinator_cancel>([self blockForSelector:_cmd])( | 53 return static_cast<mock_coordinator_cancel>([self blockForSelector:_cmd])( |
52 coordinator); | 54 coordinator); |
53 } | 55 } |
54 | 56 |
55 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 57 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
56 didConfirmWithPaymentResponse:(web::PaymentResponse)paymentResponse { | 58 didCompletePaymentRequest:(PaymentRequest*)paymentRequest |
57 return static_cast<mock_coordinator_confirm>([self blockForSelector:_cmd])( | 59 card:(const autofill::CreditCard&)card |
58 coordinator, paymentResponse); | 60 verificationCode:(const base::string16&)verificationCode { |
| 61 return static_cast<mock_coordinator_complete>([self blockForSelector:_cmd])( |
| 62 coordinator, paymentRequest, card, verificationCode); |
59 } | 63 } |
60 | 64 |
61 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 65 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
62 didSelectShippingAddress:(payments::PaymentAddress)shippingAddress { | 66 didSelectShippingAddress:(payments::PaymentAddress)shippingAddress { |
63 return static_cast<mock_coordinator_select_shipping_address>( | 67 return static_cast<mock_coordinator_select_shipping_address>( |
64 [self blockForSelector:_cmd])(coordinator, shippingAddress); | 68 [self blockForSelector:_cmd])(coordinator, shippingAddress); |
65 } | 69 } |
66 | 70 |
67 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 71 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
68 didSelectShippingOption:(web::PaymentShippingOption)shippingOption { | 72 didSelectShippingOption:(web::PaymentShippingOption)shippingOption { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 [scoped_key_window_.Get() setRootViewController:base_view_controller]; | 144 [scoped_key_window_.Get() setRootViewController:base_view_controller]; |
141 | 145 |
142 PaymentRequestCoordinator* coordinator = [[PaymentRequestCoordinator alloc] | 146 PaymentRequestCoordinator* coordinator = [[PaymentRequestCoordinator alloc] |
143 initWithBaseViewController:base_view_controller]; | 147 initWithBaseViewController:base_view_controller]; |
144 [coordinator setPaymentRequest:payment_request_.get()]; | 148 [coordinator setPaymentRequest:payment_request_.get()]; |
145 | 149 |
146 id delegate = [OCMockObject | 150 id delegate = [OCMockObject |
147 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)]; | 151 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)]; |
148 id delegate_mock([[PaymentRequestCoordinatorDelegateMock alloc] | 152 id delegate_mock([[PaymentRequestCoordinatorDelegateMock alloc] |
149 initWithRepresentedObject:delegate]); | 153 initWithRepresentedObject:delegate]); |
150 SEL selector = | 154 SEL selector = @selector(paymentRequestCoordinator:didCompletePaymentRequest: |
151 @selector(paymentRequestCoordinator:didConfirmWithPaymentResponse:); | 155 card:verificationCode:); |
152 [delegate_mock onSelector:selector | 156 [delegate_mock onSelector:selector |
153 callBlockExpectation:^(PaymentRequestCoordinator* callerCoordinator, | 157 callBlockExpectation:^(PaymentRequestCoordinator* callerCoordinator, |
154 web::PaymentResponse paymentResponse) { | 158 PaymentRequest* paymentRequest, |
155 EXPECT_EQ(base::ASCIIToUTF16("4111111111111111"), | 159 const autofill::CreditCard& card, |
156 paymentResponse.details.card_number); | 160 const base::string16& verificationCode) { |
157 EXPECT_EQ(base::ASCIIToUTF16("Test User"), | 161 EXPECT_EQ(credit_card_, card); |
158 paymentResponse.details.cardholder_name); | 162 EXPECT_EQ(base::ASCIIToUTF16("123"), verificationCode); |
159 EXPECT_EQ(base::ASCIIToUTF16("11"), | |
160 paymentResponse.details.expiry_month); | |
161 EXPECT_EQ(base::ASCIIToUTF16("2022"), | |
162 paymentResponse.details.expiry_year); | |
163 EXPECT_EQ(base::ASCIIToUTF16("123"), | |
164 paymentResponse.details.card_security_code); | |
165 EXPECT_EQ(coordinator, callerCoordinator); | 163 EXPECT_EQ(coordinator, callerCoordinator); |
166 }]; | 164 }]; |
167 [coordinator setDelegate:delegate_mock]; | 165 [coordinator setDelegate:delegate_mock]; |
168 | 166 |
169 // Call the card unmasking delegate method. | 167 // Call the card unmasking delegate method. |
170 [coordinator fullCardRequestDidSucceedWithCard:credit_card_ | 168 [coordinator fullCardRequestDidSucceedWithCard:credit_card_ |
171 CVC:base::ASCIIToUTF16("123")]; | 169 verificationCode:base::ASCIIToUTF16("123")]; |
172 } | 170 } |
173 | 171 |
174 // Tests that calling the ShippingAddressSelectionCoordinator delegate method | 172 // Tests that calling the ShippingAddressSelectionCoordinator delegate method |
175 // which notifies the coordinator about selection of a shipping address invokes | 173 // which notifies the coordinator about selection of a shipping address invokes |
176 // the corresponding coordinator delegate method with the expected information. | 174 // the corresponding coordinator delegate method with the expected information. |
177 TEST_F(PaymentRequestCoordinatorTest, DidSelectShippingAddress) { | 175 TEST_F(PaymentRequestCoordinatorTest, DidSelectShippingAddress) { |
178 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 176 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
179 ScopedKeyWindow scoped_key_window_; | 177 ScopedKeyWindow scoped_key_window_; |
180 [scoped_key_window_.Get() setRootViewController:base_view_controller]; | 178 [scoped_key_window_.Get() setRootViewController:base_view_controller]; |
181 | 179 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 [coordinator setDelegate:delegate_mock]; | 276 [coordinator setDelegate:delegate_mock]; |
279 [coordinator setBrowserState:browser_state_.get()]; | 277 [coordinator setBrowserState:browser_state_.get()]; |
280 | 278 |
281 [coordinator start]; | 279 [coordinator start]; |
282 // Short delay to allow animation to complete. | 280 // Short delay to allow animation to complete. |
283 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1)); | 281 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1)); |
284 | 282 |
285 // Call the controller delegate method. | 283 // Call the controller delegate method. |
286 [coordinator paymentRequestViewControllerDidCancel:nil]; | 284 [coordinator paymentRequestViewControllerDidCancel:nil]; |
287 } | 285 } |
OLD | NEW |