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/test_personal_data_manager.h" | 14 #include "components/autofill/core/browser/test_personal_data_manager.h" |
15 #include "components/autofill/core/browser/test_region_data_loader.h" | 15 #include "components/autofill/core/browser/test_region_data_loader.h" |
| 16 #include "components/payments/core/payments_profile_comparator.h" |
16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
| 18 #include "ios/chrome/browser/application_context.h" |
17 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 19 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
18 #include "ios/chrome/browser/payments/test_payment_request.h" | 20 #include "ios/chrome/browser/payments/test_payment_request.h" |
19 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" | 21 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
20 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 22 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "testing/platform_test.h" | 25 #include "testing/platform_test.h" |
24 #include "third_party/ocmock/OCMock/OCMock.h" | 26 #include "third_party/ocmock/OCMock/OCMock.h" |
25 #include "third_party/ocmock/gtest_support.h" | 27 #include "third_party/ocmock/gtest_support.h" |
26 | 28 |
27 #if !defined(__has_feature) || !__has_feature(objc_arc) | 29 #if !defined(__has_feature) || !__has_feature(objc_arc) |
28 #error "This file requires ARC support." | 30 #error "This file requires ARC support." |
29 #endif | 31 #endif |
30 | 32 |
31 namespace { | 33 namespace { |
32 class MockTestPersonalDataManager : public autofill::TestPersonalDataManager { | 34 class MockTestPersonalDataManager : public autofill::TestPersonalDataManager { |
33 public: | 35 public: |
34 MockTestPersonalDataManager() : TestPersonalDataManager() {} | 36 MockTestPersonalDataManager() : TestPersonalDataManager() {} |
35 MOCK_METHOD1(AddProfile, void(const autofill::AutofillProfile&)); | 37 MOCK_METHOD1(AddProfile, void(const autofill::AutofillProfile&)); |
36 MOCK_METHOD1(UpdateProfile, void(const autofill::AutofillProfile&)); | 38 MOCK_METHOD1(UpdateProfile, void(const autofill::AutofillProfile&)); |
37 }; | 39 }; |
38 | 40 |
| 41 class MockPaymentsProfileComparator |
| 42 : public payments::PaymentsProfileComparator { |
| 43 public: |
| 44 MockPaymentsProfileComparator(const std::string& app_locale, |
| 45 const payments::PaymentOptionsProvider& options) |
| 46 : PaymentsProfileComparator(app_locale, options) {} |
| 47 MOCK_METHOD1(Invalidate, void(const autofill::AutofillProfile&)); |
| 48 }; |
| 49 |
39 class MockTestPaymentRequest : public TestPaymentRequest { | 50 class MockTestPaymentRequest : public TestPaymentRequest { |
40 public: | 51 public: |
41 MockTestPaymentRequest(web::PaymentRequest web_payment_request, | 52 MockTestPaymentRequest(web::PaymentRequest web_payment_request, |
42 autofill::PersonalDataManager* personal_data_manager) | 53 autofill::PersonalDataManager* personal_data_manager) |
43 : TestPaymentRequest(web_payment_request, personal_data_manager) {} | 54 : TestPaymentRequest(web_payment_request, personal_data_manager) {} |
44 MOCK_METHOD1(AddAutofillProfile, | 55 MOCK_METHOD1(AddAutofillProfile, |
45 autofill::AutofillProfile*(const autofill::AutofillProfile&)); | 56 autofill::AutofillProfile*(const autofill::AutofillProfile&)); |
46 }; | 57 }; |
47 | 58 |
48 MATCHER_P4(ProfileMatches, name, country, state, phone_number, "") { | 59 MATCHER_P4(ProfileMatches, name, country, state, phone_number, "") { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } // namespace | 98 } // namespace |
88 | 99 |
89 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { | 100 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { |
90 protected: | 101 protected: |
91 PaymentRequestAddressEditCoordinatorTest() | 102 PaymentRequestAddressEditCoordinatorTest() |
92 : pref_service_(autofill::test::PrefServiceForTesting()) { | 103 : pref_service_(autofill::test::PrefServiceForTesting()) { |
93 personal_data_manager_.SetTestingPrefService(pref_service_.get()); | 104 personal_data_manager_.SetTestingPrefService(pref_service_.get()); |
94 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( | 105 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( |
95 payment_request_test_util::CreateTestWebPaymentRequest(), | 106 payment_request_test_util::CreateTestWebPaymentRequest(), |
96 &personal_data_manager_); | 107 &personal_data_manager_); |
| 108 |
| 109 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( |
| 110 GetApplicationContext()->GetApplicationLocale(), |
| 111 *payment_request_.get()); |
| 112 payment_request_->SetProfileComparator(profile_comparator_.get()); |
| 113 |
97 test_region_data_loader_.set_synchronous_callback(true); | 114 test_region_data_loader_.set_synchronous_callback(true); |
98 payment_request_->SetRegionDataLoader(&test_region_data_loader_); | 115 payment_request_->SetRegionDataLoader(&test_region_data_loader_); |
99 } | 116 } |
100 | 117 |
101 void TearDown() override { | 118 void TearDown() override { |
102 personal_data_manager_.SetTestingPrefService(nullptr); | 119 personal_data_manager_.SetTestingPrefService(nullptr); |
103 } | 120 } |
104 | 121 |
| 122 std::unique_ptr<PrefService> pref_service_; |
105 MockTestPersonalDataManager personal_data_manager_; | 123 MockTestPersonalDataManager personal_data_manager_; |
106 std::unique_ptr<PrefService> pref_service_; | 124 autofill::TestRegionDataLoader test_region_data_loader_; |
| 125 std::unique_ptr<MockPaymentsProfileComparator> profile_comparator_; |
107 std::unique_ptr<MockTestPaymentRequest> payment_request_; | 126 std::unique_ptr<MockTestPaymentRequest> payment_request_; |
108 autofill::TestRegionDataLoader test_region_data_loader_; | |
109 }; | 127 }; |
110 | 128 |
111 // Tests that invoking start and stop on the coordinator presents and dismisses | 129 // Tests that invoking start and stop on the coordinator presents and dismisses |
112 // the address edit view controller, respectively. | 130 // the address edit view controller, respectively. |
113 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { | 131 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { |
114 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 132 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
115 UINavigationController* navigation_controller = | 133 UINavigationController* navigation_controller = |
116 [[UINavigationController alloc] | 134 [[UINavigationController alloc] |
117 initWithRootViewController:base_view_controller]; | 135 initWithRootViewController:base_view_controller]; |
118 | 136 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 AddAutofillProfile(ProfileMatches("John Doe", "CA" /* Canada */, | 187 AddAutofillProfile(ProfileMatches("John Doe", "CA" /* Canada */, |
170 "Quebec", "16502111111"))) | 188 "Quebec", "16502111111"))) |
171 .Times(1); | 189 .Times(1); |
172 // Expect an autofill profile to be added to the PersonalDataManager. | 190 // Expect an autofill profile to be added to the PersonalDataManager. |
173 EXPECT_CALL(personal_data_manager_, | 191 EXPECT_CALL(personal_data_manager_, |
174 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", | 192 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
175 "16502111111"))) | 193 "16502111111"))) |
176 .Times(1); | 194 .Times(1); |
177 // No autofill profile should get updated in the PersonalDataManager. | 195 // No autofill profile should get updated in the PersonalDataManager. |
178 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); | 196 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); |
| 197 // No autofill profile should get invalidated in PaymentsProfileComparator. |
| 198 EXPECT_CALL(*profile_comparator_, Invalidate(_)).Times(0); |
179 | 199 |
180 // Call the controller delegate method. | 200 // Call the controller delegate method. |
181 PaymentRequestEditViewController* view_controller = | 201 PaymentRequestEditViewController* view_controller = |
182 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 202 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
183 navigation_controller.visibleViewController); | 203 navigation_controller.visibleViewController); |
184 [coordinator paymentRequestEditViewController:view_controller | 204 [coordinator paymentRequestEditViewController:view_controller |
185 didFinishEditingFields:GetEditorFields()]; | 205 didFinishEditingFields:GetEditorFields()]; |
186 | 206 |
187 EXPECT_OCMOCK_VERIFY(delegate); | 207 EXPECT_OCMOCK_VERIFY(delegate); |
188 } | 208 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 244 |
225 // No autofill profile should get added to the PaymentRequest. | 245 // No autofill profile should get added to the PaymentRequest. |
226 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0); | 246 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0); |
227 // No autofill profile should get added to the PersonalDataManager. | 247 // No autofill profile should get added to the PersonalDataManager. |
228 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0); | 248 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0); |
229 // Expect an autofill profile to be updated in the PersonalDataManager. | 249 // Expect an autofill profile to be updated in the PersonalDataManager. |
230 EXPECT_CALL(personal_data_manager_, | 250 EXPECT_CALL(personal_data_manager_, |
231 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, | 251 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, |
232 "Quebec", "16502111111"))) | 252 "Quebec", "16502111111"))) |
233 .Times(1); | 253 .Times(1); |
| 254 // Expect an autofill profile to be invalidated in PaymentsProfileComparator. |
| 255 EXPECT_CALL(*profile_comparator_, |
| 256 Invalidate(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", |
| 257 "16502111111"))) |
| 258 .Times(1); |
234 | 259 |
235 // Call the controller delegate method. | 260 // Call the controller delegate method. |
236 PaymentRequestEditViewController* view_controller = | 261 PaymentRequestEditViewController* view_controller = |
237 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 262 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
238 navigation_controller.visibleViewController); | 263 navigation_controller.visibleViewController); |
239 [coordinator paymentRequestEditViewController:view_controller | 264 [coordinator paymentRequestEditViewController:view_controller |
240 didFinishEditingFields:GetEditorFields()]; | 265 didFinishEditingFields:GetEditorFields()]; |
241 | 266 |
242 EXPECT_OCMOCK_VERIFY(delegate); | 267 EXPECT_OCMOCK_VERIFY(delegate); |
243 } | 268 } |
(...skipping 25 matching lines...) Expand all Loading... |
269 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 294 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
270 | 295 |
271 // Call the controller delegate method. | 296 // Call the controller delegate method. |
272 PaymentRequestEditViewController* view_controller = | 297 PaymentRequestEditViewController* view_controller = |
273 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 298 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
274 navigation_controller.visibleViewController); | 299 navigation_controller.visibleViewController); |
275 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; | 300 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; |
276 | 301 |
277 EXPECT_OCMOCK_VERIFY(delegate); | 302 EXPECT_OCMOCK_VERIFY(delegate); |
278 } | 303 } |
OLD | NEW |