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/address_edit_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/address_edit_coordinator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 AddressEditCoordinator* coordinator = [[AddressEditCoordinator alloc] | 137 AddressEditCoordinator* coordinator = [[AddressEditCoordinator alloc] |
138 initWithBaseViewController:base_view_controller]; | 138 initWithBaseViewController:base_view_controller]; |
139 [coordinator setPaymentRequest:payment_request_.get()]; | 139 [coordinator setPaymentRequest:payment_request_.get()]; |
140 | 140 |
141 EXPECT_EQ(nil, base_view_controller.presentedViewController); | 141 EXPECT_EQ(nil, base_view_controller.presentedViewController); |
142 | 142 |
143 [coordinator start]; | 143 [coordinator start]; |
144 // Spin the run loop to trigger the animation. | 144 // Spin the run loop to trigger the animation. |
145 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 145 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
146 EXPECT_TRUE([base_view_controller.presentedViewController | 146 EXPECT_TRUE([base_view_controller.presentedViewController |
| 147 isMemberOfClass:[UINavigationController class]]); |
| 148 UINavigationController* navigation_controller = |
| 149 base::mac::ObjCCastStrict<UINavigationController>( |
| 150 base_view_controller.presentedViewController); |
| 151 EXPECT_TRUE([navigation_controller.visibleViewController |
147 isMemberOfClass:[PaymentRequestEditViewController class]]); | 152 isMemberOfClass:[PaymentRequestEditViewController class]]); |
148 | 153 |
149 [coordinator stop]; | 154 [coordinator stop]; |
150 // Wait until the animation completes and the presented view controller is | 155 // Wait until the animation completes and the presented view controller is |
151 // dismissed. | 156 // dismissed. |
152 base::test::ios::WaitUntilCondition(^bool() { | 157 base::test::ios::WaitUntilCondition(^bool() { |
153 return !base_view_controller.presentedViewController; | 158 return !base_view_controller.presentedViewController; |
154 }); | 159 }); |
155 EXPECT_EQ(nil, base_view_controller.presentedViewController); | 160 EXPECT_EQ(nil, base_view_controller.presentedViewController); |
156 } | 161 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 EXPECT_CALL(personal_data_manager_, | 199 EXPECT_CALL(personal_data_manager_, |
195 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", | 200 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
196 "16502111111"))) | 201 "16502111111"))) |
197 .Times(1); | 202 .Times(1); |
198 // No autofill profile should get updated in the PersonalDataManager. | 203 // No autofill profile should get updated in the PersonalDataManager. |
199 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); | 204 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); |
200 // No autofill profile should get invalidated in PaymentsProfileComparator. | 205 // No autofill profile should get invalidated in PaymentsProfileComparator. |
201 EXPECT_CALL(*profile_comparator_, Invalidate(_)).Times(0); | 206 EXPECT_CALL(*profile_comparator_, Invalidate(_)).Times(0); |
202 | 207 |
203 // Call the controller delegate method. | 208 // Call the controller delegate method. |
| 209 EXPECT_TRUE([base_view_controller.presentedViewController |
| 210 isMemberOfClass:[UINavigationController class]]); |
| 211 UINavigationController* navigation_controller = |
| 212 base::mac::ObjCCastStrict<UINavigationController>( |
| 213 base_view_controller.presentedViewController); |
204 PaymentRequestEditViewController* view_controller = | 214 PaymentRequestEditViewController* view_controller = |
205 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 215 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
206 base_view_controller.presentedViewController); | 216 navigation_controller.visibleViewController); |
207 [coordinator paymentRequestEditViewController:view_controller | 217 [coordinator paymentRequestEditViewController:view_controller |
208 didFinishEditingFields:GetEditorFields()]; | 218 didFinishEditingFields:GetEditorFields()]; |
209 | 219 |
210 EXPECT_OCMOCK_VERIFY(delegate); | 220 EXPECT_OCMOCK_VERIFY(delegate); |
211 } | 221 } |
212 | 222 |
213 // Tests that calling the view controller delegate method which signals that the | 223 // Tests that calling the view controller delegate method which signals that the |
214 // user has finished editing an address, causes the the corresponding | 224 // user has finished editing an address, causes the the corresponding |
215 // coordinator delegate method to get called. The address should not get | 225 // coordinator delegate method to get called. The address should not get |
216 // re-added to the PaymentRequest instance or the PersonalDataManager. However, | 226 // re-added to the PaymentRequest instance or the PersonalDataManager. However, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, | 263 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, |
254 "Quebec", "16502111111"))) | 264 "Quebec", "16502111111"))) |
255 .Times(1); | 265 .Times(1); |
256 // Expect an autofill profile to be invalidated in PaymentsProfileComparator. | 266 // Expect an autofill profile to be invalidated in PaymentsProfileComparator. |
257 EXPECT_CALL(*profile_comparator_, | 267 EXPECT_CALL(*profile_comparator_, |
258 Invalidate(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", | 268 Invalidate(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
259 "16502111111"))) | 269 "16502111111"))) |
260 .Times(1); | 270 .Times(1); |
261 | 271 |
262 // Call the controller delegate method. | 272 // Call the controller delegate method. |
| 273 EXPECT_TRUE([base_view_controller.presentedViewController |
| 274 isMemberOfClass:[UINavigationController class]]); |
| 275 UINavigationController* navigation_controller = |
| 276 base::mac::ObjCCastStrict<UINavigationController>( |
| 277 base_view_controller.presentedViewController); |
263 PaymentRequestEditViewController* view_controller = | 278 PaymentRequestEditViewController* view_controller = |
264 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 279 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
265 base_view_controller.presentedViewController); | 280 navigation_controller.visibleViewController); |
266 [coordinator paymentRequestEditViewController:view_controller | 281 [coordinator paymentRequestEditViewController:view_controller |
267 didFinishEditingFields:GetEditorFields()]; | 282 didFinishEditingFields:GetEditorFields()]; |
268 | 283 |
269 EXPECT_OCMOCK_VERIFY(delegate); | 284 EXPECT_OCMOCK_VERIFY(delegate); |
270 } | 285 } |
271 | 286 |
272 // Tests that calling the view controller delegate method which signals that the | 287 // Tests that calling the view controller delegate method which signals that the |
273 // user has chosen to cancel creating/editing an address, causes the | 288 // user has chosen to cancel creating/editing an address, causes the |
274 // corresponding coordinator delegate method to get called. | 289 // corresponding coordinator delegate method to get called. |
275 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidCancel) { | 290 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidCancel) { |
(...skipping 12 matching lines...) Expand all Loading... |
288 [coordinator setDelegate:delegate]; | 303 [coordinator setDelegate:delegate]; |
289 | 304 |
290 EXPECT_EQ(nil, base_view_controller.presentedViewController); | 305 EXPECT_EQ(nil, base_view_controller.presentedViewController); |
291 | 306 |
292 [coordinator start]; | 307 [coordinator start]; |
293 // Spin the run loop to trigger the animation. | 308 // Spin the run loop to trigger the animation. |
294 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 309 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
295 EXPECT_NE(nil, base_view_controller.presentedViewController); | 310 EXPECT_NE(nil, base_view_controller.presentedViewController); |
296 | 311 |
297 // Call the controller delegate method. | 312 // Call the controller delegate method. |
| 313 EXPECT_TRUE([base_view_controller.presentedViewController |
| 314 isMemberOfClass:[UINavigationController class]]); |
| 315 UINavigationController* navigation_controller = |
| 316 base::mac::ObjCCastStrict<UINavigationController>( |
| 317 base_view_controller.presentedViewController); |
298 PaymentRequestEditViewController* view_controller = | 318 PaymentRequestEditViewController* view_controller = |
299 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 319 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
300 base_view_controller.presentedViewController); | 320 navigation_controller.visibleViewController); |
301 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; | 321 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; |
302 | 322 |
303 EXPECT_OCMOCK_VERIFY(delegate); | 323 EXPECT_OCMOCK_VERIFY(delegate); |
304 } | 324 } |
OLD | NEW |