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

Side by Side Diff: ios/chrome/browser/payments/payment_method_selection_coordinator_unittest.mm

Issue 2826713002: [Payment Request] Refactors the remaining selector view controllers (Closed)
Patch Set: Addressed comment Created 3 years, 8 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/payments/payment_method_selection_coordinator.h" 5 #import "ios/chrome/browser/payments/payment_method_selection_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/test/ios/wait_util.h" 9 #include "base/test/ios/wait_util.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_test_utils.h"
11 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/test_personal_data_manager.h" 12 #include "components/autofill/core/browser/test_personal_data_manager.h"
13 #import "ios/chrome/browser/payments/payment_method_selection_view_controller.h"
14 #include "ios/chrome/browser/payments/payment_request.h" 13 #include "ios/chrome/browser/payments/payment_request.h"
14 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h"
15 #include "ios/chrome/browser/payments/payment_request_test_util.h" 15 #include "ios/chrome/browser/payments/payment_request_test_util.h"
16 #include "ios/web/public/payments/payment_request.h" 16 #include "ios/web/public/payments/payment_request.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
19 #include "third_party/ocmock/OCMock/OCMock.h" 19 #include "third_party/ocmock/OCMock/OCMock.h"
20 #include "third_party/ocmock/gtest_support.h" 20 #include "third_party/ocmock/gtest_support.h"
21 21
22 #if !defined(__has_feature) || !__has_feature(objc_arc) 22 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support." 23 #error "This file requires ARC support."
24 #endif 24 #endif
25 25
26 class PaymentRequestPaymentMethodSelectionCoordinatorTest 26 class PaymentRequestPaymentMethodSelectionCoordinatorTest
27 : public PlatformTest { 27 : public PlatformTest {
28 protected: 28 protected:
29 PaymentRequestPaymentMethodSelectionCoordinatorTest() { 29 PaymentRequestPaymentMethodSelectionCoordinatorTest()
30 : credit_card1_(autofill::test::GetCreditCard()),
31 credit_card2_(autofill::test::GetCreditCard2()) {
32 // Add testing credit cards to autofill::TestPersonalDataManager.
33 personal_data_manager_.AddTestingCreditCard(&credit_card1_);
34 personal_data_manager_.AddTestingCreditCard(&credit_card2_);
30 payment_request_ = base::MakeUnique<PaymentRequest>( 35 payment_request_ = base::MakeUnique<PaymentRequest>(
31 payment_request_test_util::CreateTestWebPaymentRequest(), 36 payment_request_test_util::CreateTestWebPaymentRequest(),
32 &personal_data_manager_); 37 &personal_data_manager_);
33 } 38 }
34 39
40 autofill::CreditCard credit_card1_;
41 autofill::CreditCard credit_card2_;
35 autofill::TestPersonalDataManager personal_data_manager_; 42 autofill::TestPersonalDataManager personal_data_manager_;
36 std::unique_ptr<PaymentRequest> payment_request_; 43 std::unique_ptr<PaymentRequest> payment_request_;
37 }; 44 };
38 45
39 // Tests that invoking start and stop on the coordinator presents and dismisses 46 // Tests that invoking start and stop on the coordinator presents and dismisses
40 // the PaymentMethodSelectionViewController, respectively. 47 // the PaymentRequestSelectorViewController, respectively.
41 TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest, StartAndStop) { 48 TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest, StartAndStop) {
42 UIViewController* base_view_controller = [[UIViewController alloc] init]; 49 UIViewController* base_view_controller = [[UIViewController alloc] init];
43 UINavigationController* navigation_controller = 50 UINavigationController* navigation_controller =
44 [[UINavigationController alloc] 51 [[UINavigationController alloc]
45 initWithRootViewController:base_view_controller]; 52 initWithRootViewController:base_view_controller];
46 53
47 PaymentMethodSelectionCoordinator* coordinator = 54 PaymentMethodSelectionCoordinator* coordinator =
48 [[PaymentMethodSelectionCoordinator alloc] 55 [[PaymentMethodSelectionCoordinator alloc]
49 initWithBaseViewController:base_view_controller]; 56 initWithBaseViewController:base_view_controller];
50 [coordinator setPaymentRequest:payment_request_.get()]; 57 [coordinator setPaymentRequest:payment_request_.get()];
51 58
52 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 59 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
53 60
54 [coordinator start]; 61 [coordinator start];
55 // Short delay to allow animation to complete. 62 // Short delay to allow animation to complete.
56 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); 63 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
57 EXPECT_EQ(2u, navigation_controller.viewControllers.count); 64 EXPECT_EQ(2u, navigation_controller.viewControllers.count);
58 65
59 UIViewController* view_controller = 66 UIViewController* view_controller =
60 navigation_controller.visibleViewController; 67 navigation_controller.visibleViewController;
61 EXPECT_TRUE([view_controller 68 EXPECT_TRUE([view_controller
62 isMemberOfClass:[PaymentMethodSelectionViewController class]]); 69 isMemberOfClass:[PaymentRequestSelectorViewController class]]);
63 70
64 [coordinator stop]; 71 [coordinator stop];
65 // Short delay to allow animation to complete. 72 // Short delay to allow animation to complete.
66 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); 73 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
67 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 74 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
68 } 75 }
69 76
70 // Tests that calling the view controller delegate method which notifies the 77 // Tests that calling the view controller delegate method which notifies the
71 // coordinator about selection of a payment method invokes the corresponding 78 // coordinator about selection of a payment method invokes the corresponding
72 // coordinator delegate method. 79 // coordinator delegate method.
73 TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest, 80 TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest,
74 DidSelectPaymentMethod) { 81 DidSelectPaymentMethod) {
75 UIViewController* base_view_controller = [[UIViewController alloc] init]; 82 UIViewController* base_view_controller = [[UIViewController alloc] init];
76 UINavigationController* navigation_controller = 83 UINavigationController* navigation_controller =
77 [[UINavigationController alloc] 84 [[UINavigationController alloc]
78 initWithRootViewController:base_view_controller]; 85 initWithRootViewController:base_view_controller];
79 86
80 PaymentMethodSelectionCoordinator* coordinator = 87 PaymentMethodSelectionCoordinator* coordinator =
81 [[PaymentMethodSelectionCoordinator alloc] 88 [[PaymentMethodSelectionCoordinator alloc]
82 initWithBaseViewController:base_view_controller]; 89 initWithBaseViewController:base_view_controller];
83 [coordinator setPaymentRequest:payment_request_.get()]; 90 [coordinator setPaymentRequest:payment_request_.get()];
84 91
85 // Mock the coordinator delegate. 92 // Mock the coordinator delegate.
86 id delegate = [OCMockObject 93 id delegate = [OCMockObject
87 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)]; 94 mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)];
88 autofill::CreditCard credit_card; 95 autofill::CreditCard* credit_card = payment_request_->credit_cards()[1];
89 [[delegate expect] paymentMethodSelectionCoordinator:coordinator 96 [[delegate expect] paymentMethodSelectionCoordinator:coordinator
90 didSelectPaymentMethod:&credit_card]; 97 didSelectPaymentMethod:credit_card];
91 [coordinator setDelegate:delegate]; 98 [coordinator setDelegate:delegate];
92 99
93 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 100 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
94 101
95 [coordinator start]; 102 [coordinator start];
96 // Short delay to allow animation to complete. 103 // Short delay to allow animation to complete.
97 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); 104 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
98 EXPECT_EQ(2u, navigation_controller.viewControllers.count); 105 EXPECT_EQ(2u, navigation_controller.viewControllers.count);
99 106
100 // Call the controller delegate method. 107 // Call the controller delegate method.
101 PaymentMethodSelectionViewController* view_controller = 108 PaymentRequestSelectorViewController* view_controller =
102 base::mac::ObjCCastStrict<PaymentMethodSelectionViewController>( 109 base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
103 navigation_controller.visibleViewController); 110 navigation_controller.visibleViewController);
104 [coordinator paymentMethodSelectionViewController:view_controller 111 [coordinator paymentRequestSelectorViewController:view_controller
105 didSelectPaymentMethod:&credit_card]; 112 didSelectItemAtIndex:1];
106 113
107 // Wait for the coordinator delegate to be notified. 114 // Wait for the coordinator delegate to be notified.
108 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5)); 115 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
109 116
110 EXPECT_OCMOCK_VERIFY(delegate); 117 EXPECT_OCMOCK_VERIFY(delegate);
111 } 118 }
112 119
113 // Tests that calling the view controller delegate method which notifies the 120 // Tests that calling the view controller delegate method which notifies the
114 // coordinator that the user has chosen to return without making a selection 121 // coordinator that the user has chosen to return without making a selection
115 // invokes the corresponding coordinator delegate method. 122 // invokes the corresponding coordinator delegate method.
(...skipping 15 matching lines...) Expand all
131 [coordinator setDelegate:delegate]; 138 [coordinator setDelegate:delegate];
132 139
133 EXPECT_EQ(1u, navigation_controller.viewControllers.count); 140 EXPECT_EQ(1u, navigation_controller.viewControllers.count);
134 141
135 [coordinator start]; 142 [coordinator start];
136 // Short delay to allow animation to complete. 143 // Short delay to allow animation to complete.
137 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); 144 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
138 EXPECT_EQ(2u, navigation_controller.viewControllers.count); 145 EXPECT_EQ(2u, navigation_controller.viewControllers.count);
139 146
140 // Call the controller delegate method. 147 // Call the controller delegate method.
141 PaymentMethodSelectionViewController* view_controller = 148 PaymentRequestSelectorViewController* view_controller =
142 base::mac::ObjCCastStrict<PaymentMethodSelectionViewController>( 149 base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
143 navigation_controller.visibleViewController); 150 navigation_controller.visibleViewController);
144 [coordinator paymentMethodSelectionViewControllerDidReturn:view_controller]; 151 [coordinator paymentRequestSelectorViewControllerDidFinish:view_controller];
145 152
146 EXPECT_OCMOCK_VERIFY(delegate); 153 EXPECT_OCMOCK_VERIFY(delegate);
147 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698