OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/shipping_address_selection_coordinator.h" | 5 #import "ios/chrome/browser/payments/shipping_address_selection_coordinator.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/test/ios/wait_util.h" | 8 #include "base/test/ios/wait_util.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
11 #include "ios/chrome/browser/payments/payment_request.h" | 11 #include "ios/chrome/browser/payments/payment_request.h" |
12 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 12 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
13 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller.
h" | 13 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller.
h" |
14 #include "ios/web/public/payments/payment_request.h" | 14 #include "ios/web/public/payments/payment_request.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
17 #include "third_party/ocmock/OCMock/OCMock.h" | 17 #include "third_party/ocmock/OCMock/OCMock.h" |
18 #include "third_party/ocmock/gtest_support.h" | 18 #include "third_party/ocmock/gtest_support.h" |
19 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
20 typedef PlatformTest ShippingAddressSelectionCoordinatorTest; | 24 typedef PlatformTest ShippingAddressSelectionCoordinatorTest; |
21 | 25 |
22 // Tests that invoking start and stop on the coordinator presents and dismisses | 26 // Tests that invoking start and stop on the coordinator presents and dismisses |
23 // the ShippingAddressSelectionViewController, respectively. | 27 // the ShippingAddressSelectionViewController, respectively. |
24 TEST(ShippingAddressSelectionCoordinatorTest, StartAndStop) { | 28 TEST(ShippingAddressSelectionCoordinatorTest, StartAndStop) { |
25 std::unique_ptr<PaymentRequest> payment_request = | 29 std::unique_ptr<PaymentRequest> payment_request = |
26 payment_request_test_util::CreateTestPaymentRequest(); | 30 payment_request_test_util::CreateTestPaymentRequest(); |
27 | 31 |
28 UIViewController* base_view_controller = | 32 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
29 [[[UIViewController alloc] init] autorelease]; | |
30 UINavigationController* navigation_controller = | 33 UINavigationController* navigation_controller = |
31 [[[UINavigationController alloc] | 34 [[UINavigationController alloc] |
32 initWithRootViewController:base_view_controller] autorelease]; | 35 initWithRootViewController:base_view_controller]; |
33 | 36 |
34 ShippingAddressSelectionCoordinator* coordinator = | 37 ShippingAddressSelectionCoordinator* coordinator = |
35 [[[ShippingAddressSelectionCoordinator alloc] | 38 [[ShippingAddressSelectionCoordinator alloc] |
36 initWithBaseViewController:base_view_controller] autorelease]; | 39 initWithBaseViewController:base_view_controller]; |
37 [coordinator setPaymentRequest:payment_request.get()]; | 40 [coordinator setPaymentRequest:payment_request.get()]; |
38 | 41 |
39 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 42 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
40 | 43 |
41 [coordinator start]; | 44 [coordinator start]; |
42 // Short delay to allow animation to complete. | 45 // Short delay to allow animation to complete. |
43 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 46 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
44 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 47 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
45 | 48 |
46 UIViewController* view_controller = | 49 UIViewController* view_controller = |
47 navigation_controller.visibleViewController; | 50 navigation_controller.visibleViewController; |
48 EXPECT_TRUE([view_controller | 51 EXPECT_TRUE([view_controller |
49 isMemberOfClass:[ShippingAddressSelectionViewController class]]); | 52 isMemberOfClass:[ShippingAddressSelectionViewController class]]); |
50 | 53 |
51 [coordinator stop]; | 54 [coordinator stop]; |
52 // Short delay to allow animation to complete. | 55 // Short delay to allow animation to complete. |
53 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 56 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
54 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 57 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
55 } | 58 } |
56 | 59 |
57 // Tests that calling the view controller delegate method which notifies the | 60 // Tests that calling the view controller delegate method which notifies the |
58 // delegate about selection of a shipping address invokes the corresponding | 61 // delegate about selection of a shipping address invokes the corresponding |
59 // coordinator delegate method. | 62 // coordinator delegate method. |
60 TEST(ShippingAddressSelectionCoordinatorTest, SelectedShippingAddress) { | 63 TEST(ShippingAddressSelectionCoordinatorTest, SelectedShippingAddress) { |
61 std::unique_ptr<PaymentRequest> payment_request = | 64 std::unique_ptr<PaymentRequest> payment_request = |
62 payment_request_test_util::CreateTestPaymentRequest(); | 65 payment_request_test_util::CreateTestPaymentRequest(); |
63 | 66 |
64 UIViewController* base_view_controller = | 67 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
65 [[[UIViewController alloc] init] autorelease]; | |
66 UINavigationController* navigation_controller = | 68 UINavigationController* navigation_controller = |
67 [[[UINavigationController alloc] | 69 [[UINavigationController alloc] |
68 initWithRootViewController:base_view_controller] autorelease]; | 70 initWithRootViewController:base_view_controller]; |
69 | 71 |
70 ShippingAddressSelectionCoordinator* coordinator = | 72 ShippingAddressSelectionCoordinator* coordinator = |
71 [[[ShippingAddressSelectionCoordinator alloc] | 73 [[ShippingAddressSelectionCoordinator alloc] |
72 initWithBaseViewController:base_view_controller] autorelease]; | 74 initWithBaseViewController:base_view_controller]; |
73 [coordinator setPaymentRequest:payment_request.get()]; | 75 [coordinator setPaymentRequest:payment_request.get()]; |
74 | 76 |
75 // Mock the coordinator delegate. | 77 // Mock the coordinator delegate. |
76 id delegate = [OCMockObject | 78 id delegate = [OCMockObject |
77 mockForProtocol:@protocol(ShippingAddressSelectionCoordinatorDelegate)]; | 79 mockForProtocol:@protocol(ShippingAddressSelectionCoordinatorDelegate)]; |
78 std::unique_ptr<autofill::AutofillProfile> profile( | 80 std::unique_ptr<autofill::AutofillProfile> profile( |
79 new autofill::AutofillProfile()); | 81 new autofill::AutofillProfile()); |
80 [[delegate expect] shippingAddressSelectionCoordinator:coordinator | 82 [[delegate expect] shippingAddressSelectionCoordinator:coordinator |
81 didSelectShippingAddress:profile.get()]; | 83 didSelectShippingAddress:profile.get()]; |
82 [coordinator setDelegate:delegate]; | 84 [coordinator setDelegate:delegate]; |
(...skipping 18 matching lines...) Expand all Loading... |
101 EXPECT_OCMOCK_VERIFY(delegate); | 103 EXPECT_OCMOCK_VERIFY(delegate); |
102 } | 104 } |
103 | 105 |
104 // Tests that calling the view controller delegate method which notifies the | 106 // Tests that calling the view controller delegate method which notifies the |
105 // delegate that the user has chosen to return without making a selection | 107 // delegate that the user has chosen to return without making a selection |
106 // invokes the corresponding coordinator delegate method. | 108 // invokes the corresponding coordinator delegate method. |
107 TEST(ShippingAddressSelectionCoordinatorTest, DidReturn) { | 109 TEST(ShippingAddressSelectionCoordinatorTest, DidReturn) { |
108 std::unique_ptr<PaymentRequest> payment_request = | 110 std::unique_ptr<PaymentRequest> payment_request = |
109 payment_request_test_util::CreateTestPaymentRequest(); | 111 payment_request_test_util::CreateTestPaymentRequest(); |
110 | 112 |
111 UIViewController* base_view_controller = | 113 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
112 [[[UIViewController alloc] init] autorelease]; | |
113 UINavigationController* navigation_controller = | 114 UINavigationController* navigation_controller = |
114 [[[UINavigationController alloc] | 115 [[UINavigationController alloc] |
115 initWithRootViewController:base_view_controller] autorelease]; | 116 initWithRootViewController:base_view_controller]; |
116 | 117 |
117 ShippingAddressSelectionCoordinator* coordinator = | 118 ShippingAddressSelectionCoordinator* coordinator = |
118 [[[ShippingAddressSelectionCoordinator alloc] | 119 [[ShippingAddressSelectionCoordinator alloc] |
119 initWithBaseViewController:base_view_controller] autorelease]; | 120 initWithBaseViewController:base_view_controller]; |
120 [coordinator setPaymentRequest:payment_request.get()]; | 121 [coordinator setPaymentRequest:payment_request.get()]; |
121 | 122 |
122 // Mock the coordinator delegate. | 123 // Mock the coordinator delegate. |
123 id delegate = [OCMockObject | 124 id delegate = [OCMockObject |
124 mockForProtocol:@protocol(ShippingAddressSelectionCoordinatorDelegate)]; | 125 mockForProtocol:@protocol(ShippingAddressSelectionCoordinatorDelegate)]; |
125 [[delegate expect] shippingAddressSelectionCoordinatorDidReturn:coordinator]; | 126 [[delegate expect] shippingAddressSelectionCoordinatorDidReturn:coordinator]; |
126 [coordinator setDelegate:delegate]; | 127 [coordinator setDelegate:delegate]; |
127 | 128 |
128 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 129 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
129 | 130 |
130 [coordinator start]; | 131 [coordinator start]; |
131 // Short delay to allow animation to complete. | 132 // Short delay to allow animation to complete. |
132 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 133 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
133 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 134 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
134 | 135 |
135 // Call the controller delegate method. | 136 // Call the controller delegate method. |
136 ShippingAddressSelectionViewController* view_controller = | 137 ShippingAddressSelectionViewController* view_controller = |
137 base::mac::ObjCCastStrict<ShippingAddressSelectionViewController>( | 138 base::mac::ObjCCastStrict<ShippingAddressSelectionViewController>( |
138 navigation_controller.visibleViewController); | 139 navigation_controller.visibleViewController); |
139 [coordinator shippingAddressSelectionViewControllerDidReturn:view_controller]; | 140 [coordinator shippingAddressSelectionViewControllerDidReturn:view_controller]; |
140 | 141 |
141 EXPECT_OCMOCK_VERIFY(delegate); | 142 EXPECT_OCMOCK_VERIFY(delegate); |
142 } | 143 } |
OLD | NEW |