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

Side by Side Diff: ios/chrome/browser/ui/payments/address_edit_coordinator_unittest.mm

Issue 2908033002: [Payment Request] Refactors edit view controller (Closed)
Patch Set: Addressed comments Created 3 years, 6 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/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/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
17 #include "ios/chrome/browser/payments/payment_request_test_util.h" 17 #include "ios/chrome/browser/payments/payment_request_test_util.h"
18 #include "ios/chrome/browser/payments/test_payment_request.h" 18 #include "ios/chrome/browser/payments/test_payment_request.h"
19 #import "ios/chrome/browser/ui/payments/address_edit_view_controller.h" 19 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h"
20 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" 20 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
24 #include "third_party/ocmock/OCMock/OCMock.h" 24 #include "third_party/ocmock/OCMock/OCMock.h"
25 #include "third_party/ocmock/gtest_support.h" 25 #include "third_party/ocmock/gtest_support.h"
26 26
27 #if !defined(__has_feature) || !__has_feature(objc_arc) 27 #if !defined(__has_feature) || !__has_feature(objc_arc)
28 #error "This file requires ARC support." 28 #error "This file requires ARC support."
29 #endif 29 #endif
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 .Times(1); 171 .Times(1);
172 // Expect an autofill profile to be added to the PersonalDataManager. 172 // Expect an autofill profile to be added to the PersonalDataManager.
173 EXPECT_CALL(personal_data_manager_, 173 EXPECT_CALL(personal_data_manager_,
174 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec", 174 AddProfile(ProfileMatches("John Doe", "CA" /* Canada */, "Quebec",
175 "16502111111"))) 175 "16502111111")))
176 .Times(1); 176 .Times(1);
177 // No autofill profile should get updated in the PersonalDataManager. 177 // No autofill profile should get updated in the PersonalDataManager.
178 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0); 178 EXPECT_CALL(personal_data_manager_, UpdateProfile(_)).Times(0);
179 179
180 // Call the controller delegate method. 180 // Call the controller delegate method.
181 AddressEditViewController* view_controller = 181 PaymentRequestEditViewController* view_controller =
182 base::mac::ObjCCastStrict<AddressEditViewController>( 182 base::mac::ObjCCastStrict<PaymentRequestEditViewController>(
183 navigation_controller.visibleViewController); 183 navigation_controller.visibleViewController);
184 [coordinator addressEditViewController:view_controller 184 [coordinator paymentRequestEditViewController:view_controller
185 didFinishEditingFields:GetEditorFields()]; 185 didFinishEditingFields:GetEditorFields()];
186 186
187 EXPECT_OCMOCK_VERIFY(delegate); 187 EXPECT_OCMOCK_VERIFY(delegate);
188 } 188 }
189 189
190 // Tests that calling the view controller delegate method which signals that the 190 // Tests that calling the view controller delegate method which signals that the
191 // user has finished editing an address, causes the the corresponding 191 // user has finished editing an address, causes the the corresponding
192 // coordinator delegate method to get called. The address should not get 192 // coordinator delegate method to get called. The address should not get
193 // re-added to the PaymentRequest instance or the PersonalDataManager. However, 193 // re-added to the PaymentRequest instance or the PersonalDataManager. However,
194 // it is expected to get updated in the PersonalDataManager. 194 // it is expected to get updated in the PersonalDataManager.
195 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidFinishEditing) { 195 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidFinishEditing) {
(...skipping 30 matching lines...) Expand all
226 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0); 226 EXPECT_CALL(*payment_request_, AddAutofillProfile(_)).Times(0);
227 // No autofill profile should get added to the PersonalDataManager. 227 // No autofill profile should get added to the PersonalDataManager.
228 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0); 228 EXPECT_CALL(personal_data_manager_, AddProfile(_)).Times(0);
229 // Expect an autofill profile to be updated in the PersonalDataManager. 229 // Expect an autofill profile to be updated in the PersonalDataManager.
230 EXPECT_CALL(personal_data_manager_, 230 EXPECT_CALL(personal_data_manager_,
231 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */, 231 UpdateProfile(ProfileMatches("John Doe", "CA" /* Canada */,
232 "Quebec", "16502111111"))) 232 "Quebec", "16502111111")))
233 .Times(1); 233 .Times(1);
234 234
235 // Call the controller delegate method. 235 // Call the controller delegate method.
236 AddressEditViewController* view_controller = 236 PaymentRequestEditViewController* view_controller =
237 base::mac::ObjCCastStrict<AddressEditViewController>( 237 base::mac::ObjCCastStrict<PaymentRequestEditViewController>(
238 navigation_controller.visibleViewController); 238 navigation_controller.visibleViewController);
239 [coordinator addressEditViewController:view_controller 239 [coordinator paymentRequestEditViewController:view_controller
240 didFinishEditingFields:GetEditorFields()]; 240 didFinishEditingFields:GetEditorFields()];
241 241
242 EXPECT_OCMOCK_VERIFY(delegate); 242 EXPECT_OCMOCK_VERIFY(delegate);
243 } 243 }
244 244
245 // Tests that calling the view controller delegate method which signals that the 245 // Tests that calling the view controller delegate method which signals that the
246 // user has chosen to cancel creating/editing an address, causes the 246 // user has chosen to cancel creating/editing an address, causes the
247 // corresponding coordinator delegate method to get called. 247 // corresponding coordinator delegate method to get called.
248 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidCancel) { 248 TEST_F(PaymentRequestAddressEditCoordinatorTest, DidCancel) {
249 UIViewController* base_view_controller = [[UIViewController alloc] init]; 249 UIViewController* base_view_controller = [[UIViewController alloc] init];
250 UINavigationController* navigation_controller = 250 UINavigationController* navigation_controller =
(...skipping 11 matching lines...) Expand all
262 [coordinator setDelegate:delegate]; 262 [coordinator setDelegate:delegate];
263 263
264 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 264 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
265 265
266 [coordinator start]; 266 [coordinator start];
267 // Short delay to allow animation to complete. 267 // Short delay to allow animation to complete.
268 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); 268 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
269 EXPECT_EQ(2u, navigation_controller.viewControllers.count); 269 EXPECT_EQ(2u, navigation_controller.viewControllers.count);
270 270
271 // Call the controller delegate method. 271 // Call the controller delegate method.
272 AddressEditViewController* view_controller = 272 PaymentRequestEditViewController* view_controller =
273 base::mac::ObjCCastStrict<AddressEditViewController>( 273 base::mac::ObjCCastStrict<PaymentRequestEditViewController>(
274 navigation_controller.visibleViewController); 274 navigation_controller.visibleViewController);
275 [coordinator addressEditViewControllerDidCancel:view_controller]; 275 [coordinator paymentRequestEditViewControllerDidCancel:view_controller];
276 276
277 EXPECT_OCMOCK_VERIFY(delegate); 277 EXPECT_OCMOCK_VERIFY(delegate);
278 } 278 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/payments/address_edit_coordinator.mm ('k') | ios/chrome/browser/ui/payments/address_edit_mediator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698