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" |
11 #include "base/test/ios/wait_util.h" | 11 #include "base/test/ios/wait_util.h" |
12 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
13 #include "components/autofill/core/browser/autofill_test_utils.h" | 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/country_names.h" |
14 #include "components/autofill/core/browser/test_personal_data_manager.h" | 15 #include "components/autofill/core/browser/test_personal_data_manager.h" |
15 #include "components/autofill/core/browser/test_region_data_loader.h" | 16 #include "components/autofill/core/browser/test_region_data_loader.h" |
16 #include "components/payments/core/payments_profile_comparator.h" | 17 #include "components/payments/core/payments_profile_comparator.h" |
17 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
18 #include "ios/chrome/browser/application_context.h" | 19 #include "ios/chrome/browser/application_context.h" |
19 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 20 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
20 #include "ios/chrome/browser/payments/test_payment_request.h" | 21 #include "ios/chrome/browser/payments/test_payment_request.h" |
21 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" | 22 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
22 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 23 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
23 #import "ios/chrome/test/scoped_key_window.h" | 24 #import "ios/chrome/test/scoped_key_window.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 ]; | 96 ]; |
96 } | 97 } |
97 | 98 |
98 using ::testing::_; | 99 using ::testing::_; |
99 } // namespace | 100 } // namespace |
100 | 101 |
101 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { | 102 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { |
102 protected: | 103 protected: |
103 PaymentRequestAddressEditCoordinatorTest() | 104 PaymentRequestAddressEditCoordinatorTest() |
104 : pref_service_(autofill::test::PrefServiceForTesting()) { | 105 : pref_service_(autofill::test::PrefServiceForTesting()) { |
| 106 autofill::CountryNames::SetLocaleString("en-US"); |
105 personal_data_manager_.SetTestingPrefService(pref_service_.get()); | 107 personal_data_manager_.SetTestingPrefService(pref_service_.get()); |
106 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( | 108 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( |
107 payment_request_test_util::CreateTestWebPaymentRequest(), | 109 payment_request_test_util::CreateTestWebPaymentRequest(), |
108 &personal_data_manager_); | 110 &personal_data_manager_); |
109 | 111 |
110 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( | 112 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( |
111 GetApplicationContext()->GetApplicationLocale(), | 113 GetApplicationContext()->GetApplicationLocale(), |
112 *payment_request_.get()); | 114 *payment_request_.get()); |
113 payment_request_->SetProfileComparator(profile_comparator_.get()); | 115 payment_request_->SetProfileComparator(profile_comparator_.get()); |
114 | 116 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_EQ(nil, base_view_controller.presentedViewController); | 188 EXPECT_EQ(nil, base_view_controller.presentedViewController); |
187 | 189 |
188 [coordinator start]; | 190 [coordinator start]; |
189 // Spin the run loop to trigger the animation. | 191 // Spin the run loop to trigger the animation. |
190 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 192 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
191 EXPECT_NE(nil, base_view_controller.presentedViewController); | 193 EXPECT_NE(nil, base_view_controller.presentedViewController); |
192 | 194 |
193 // Expect an autofill profile to be added to the PaymentRequest. | 195 // Expect an autofill profile to be added to the PaymentRequest. |
194 EXPECT_CALL(*payment_request_, | 196 EXPECT_CALL(*payment_request_, |
195 AddAutofillProfile(ProfileMatches("John Doe", "CA" /* Canada */, | 197 AddAutofillProfile(ProfileMatches("John Doe", "CA" /* Canada */, |
196 "Quebec", "16502111111"))) | 198 "Quebec", "1 650-211-1111"))) |
197 .Times(1); | 199 .Times(1); |
198 // Expect an autofill profile to be added to the PersonalDataManager. | 200 // Expect an autofill profile to be added to the PersonalDataManager. |
199 EXPECT_CALL(personal_data_manager_, | 201 EXPECT_CALL(personal_data_manager_, |
200 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", | 202 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
201 "16502111111"))) | 203 "1 650-211-1111"))) |
202 .Times(1); | 204 .Times(1); |
203 // No autofill profile should get updated in the PersonalDataManager. | 205 // No autofill profile should get updated in the PersonalDataManager. |
204 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); | 206 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); |
205 // No autofill profile should get invalidated in PaymentsProfileComparator. | 207 // No autofill profile should get invalidated in PaymentsProfileComparator. |
206 EXPECT_CALL(*profile_comparator_, Invalidate(_)).Times(0); | 208 EXPECT_CALL(*profile_comparator_, Invalidate(_)).Times(0); |
207 | 209 |
208 // Call the controller delegate method. | 210 // Call the controller delegate method. |
209 EXPECT_TRUE([base_view_controller.presentedViewController | 211 EXPECT_TRUE([base_view_controller.presentedViewController |
210 isMemberOfClass:[UINavigationController class]]); | 212 isMemberOfClass:[UINavigationController class]]); |
211 UINavigationController* navigation_controller = | 213 UINavigationController* navigation_controller = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 256 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
255 EXPECT_NE(nil, base_view_controller.presentedViewController); | 257 EXPECT_NE(nil, base_view_controller.presentedViewController); |
256 | 258 |
257 // No autofill profile should get added to the PaymentRequest. | 259 // No autofill profile should get added to the PaymentRequest. |
258 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0); | 260 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0); |
259 // No autofill profile should get added to the PersonalDataManager. | 261 // No autofill profile should get added to the PersonalDataManager. |
260 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0); | 262 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0); |
261 // Expect an autofill profile to be updated in the PersonalDataManager. | 263 // Expect an autofill profile to be updated in the PersonalDataManager. |
262 EXPECT_CALL(personal_data_manager_, | 264 EXPECT_CALL(personal_data_manager_, |
263 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, | 265 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, |
264 "Quebec", "16502111111"))) | 266 "Quebec", "1 650-211-1111"))) |
265 .Times(1); | 267 .Times(1); |
266 // Expect an autofill profile to be invalidated in PaymentsProfileComparator. | 268 // Expect an autofill profile to be invalidated in PaymentsProfileComparator. |
267 EXPECT_CALL(*profile_comparator_, | 269 EXPECT_CALL(*profile_comparator_, |
268 Invalidate(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", | 270 Invalidate(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
269 "16502111111"))) | 271 "1 650-211-1111"))) |
270 .Times(1); | 272 .Times(1); |
271 | 273 |
272 // Call the controller delegate method. | 274 // Call the controller delegate method. |
273 EXPECT_TRUE([base_view_controller.presentedViewController | 275 EXPECT_TRUE([base_view_controller.presentedViewController |
274 isMemberOfClass:[UINavigationController class]]); | 276 isMemberOfClass:[UINavigationController class]]); |
275 UINavigationController* navigation_controller = | 277 UINavigationController* navigation_controller = |
276 base::mac::ObjCCastStrict<UINavigationController>( | 278 base::mac::ObjCCastStrict<UINavigationController>( |
277 base_view_controller.presentedViewController); | 279 base_view_controller.presentedViewController); |
278 PaymentRequestEditViewController* view_controller = | 280 PaymentRequestEditViewController* view_controller = |
279 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 281 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 UINavigationController* navigation_controller = | 317 UINavigationController* navigation_controller = |
316 base::mac::ObjCCastStrict<UINavigationController>( | 318 base::mac::ObjCCastStrict<UINavigationController>( |
317 base_view_controller.presentedViewController); | 319 base_view_controller.presentedViewController); |
318 PaymentRequestEditViewController* view_controller = | 320 PaymentRequestEditViewController* view_controller = |
319 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 321 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
320 navigation_controller.visibleViewController); | 322 navigation_controller.visibleViewController); |
321 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; | 323 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; |
322 | 324 |
323 EXPECT_OCMOCK_VERIFY(delegate); | 325 EXPECT_OCMOCK_VERIFY(delegate); |
324 } | 326 } |
OLD | NEW |