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/payment_items_display_coordinator.h" | 5 #import "ios/chrome/browser/payments/payment_items_display_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 "components/autofill/core/browser/test_personal_data_manager.h" | 11 #include "components/autofill/core/browser/test_personal_data_manager.h" |
12 #import "ios/chrome/browser/payments/payment_items_display_view_controller.h" | 12 #import "ios/chrome/browser/payments/payment_items_display_view_controller.h" |
13 #include "ios/chrome/browser/payments/payment_request.h" | 13 #include "ios/chrome/browser/payments/payment_request.h" |
14 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 14 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
15 #include "ios/web/public/payments/payment_request.h" | 15 #include "ios/web/public/payments/payment_request.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
18 #include "third_party/ocmock/OCMock/OCMock.h" | 18 #include "third_party/ocmock/OCMock/OCMock.h" |
19 #include "third_party/ocmock/gtest_support.h" | 19 #include "third_party/ocmock/gtest_support.h" |
20 | 20 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." |
| 23 #endif |
| 24 |
21 typedef PlatformTest PaymentItemsDisplayCoordinatorTest; | 25 typedef PlatformTest PaymentItemsDisplayCoordinatorTest; |
22 | 26 |
23 // Tests that invoking start and stop on the coordinator presents and dismisses | 27 // Tests that invoking start and stop on the coordinator presents and dismisses |
24 // the payment items display view controller, respectively. | 28 // the payment items display view controller, respectively. |
25 TEST(PaymentItemsDisplayCoordinatorTest, StartAndStop) { | 29 TEST(PaymentItemsDisplayCoordinatorTest, StartAndStop) { |
26 std::unique_ptr<PaymentRequest> payment_request = | 30 std::unique_ptr<PaymentRequest> payment_request = |
27 payment_request_test_util::CreateTestPaymentRequest(); | 31 payment_request_test_util::CreateTestPaymentRequest(); |
28 | 32 |
29 UIViewController* base_view_controller = | 33 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
30 [[[UIViewController alloc] init] autorelease]; | |
31 UINavigationController* navigation_controller = | 34 UINavigationController* navigation_controller = |
32 [[[UINavigationController alloc] | 35 [[UINavigationController alloc] |
33 initWithRootViewController:base_view_controller] autorelease]; | 36 initWithRootViewController:base_view_controller]; |
34 | 37 |
35 PaymentItemsDisplayCoordinator* coordinator = | 38 PaymentItemsDisplayCoordinator* coordinator = |
36 [[[PaymentItemsDisplayCoordinator alloc] | 39 [[PaymentItemsDisplayCoordinator alloc] |
37 initWithBaseViewController:base_view_controller] autorelease]; | 40 initWithBaseViewController:base_view_controller]; |
38 [coordinator setPaymentRequest:payment_request.get()]; | 41 [coordinator setPaymentRequest:payment_request.get()]; |
39 | 42 |
40 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 43 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
41 | 44 |
42 [coordinator start]; | 45 [coordinator start]; |
43 // Short delay to allow animation to complete. | 46 // Short delay to allow animation to complete. |
44 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 47 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
45 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 48 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
46 | 49 |
47 [coordinator stop]; | 50 [coordinator stop]; |
48 // Short delay to allow animation to complete. | 51 // Short delay to allow animation to complete. |
49 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 52 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
50 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 53 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
51 } | 54 } |
52 | 55 |
53 // Tests that calling the view controller delegate method which notifies the | 56 // Tests that calling the view controller delegate method which notifies the |
54 // coordinator that the user has confirmed the payment request invokes the | 57 // coordinator that the user has confirmed the payment request invokes the |
55 // the corresponding coordinator delegate method. | 58 // the corresponding coordinator delegate method. |
56 TEST(PaymentItemsDisplayCoordinatorTest, DidConfirm) { | 59 TEST(PaymentItemsDisplayCoordinatorTest, DidConfirm) { |
57 std::unique_ptr<PaymentRequest> payment_request = | 60 std::unique_ptr<PaymentRequest> payment_request = |
58 payment_request_test_util::CreateTestPaymentRequest(); | 61 payment_request_test_util::CreateTestPaymentRequest(); |
59 | 62 |
60 UIViewController* base_view_controller = | 63 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
61 [[[UIViewController alloc] init] autorelease]; | |
62 UINavigationController* navigation_controller = | 64 UINavigationController* navigation_controller = |
63 [[[UINavigationController alloc] | 65 [[UINavigationController alloc] |
64 initWithRootViewController:base_view_controller] autorelease]; | 66 initWithRootViewController:base_view_controller]; |
65 | 67 |
66 PaymentItemsDisplayCoordinator* coordinator = | 68 PaymentItemsDisplayCoordinator* coordinator = |
67 [[[PaymentItemsDisplayCoordinator alloc] | 69 [[PaymentItemsDisplayCoordinator alloc] |
68 initWithBaseViewController:base_view_controller] autorelease]; | 70 initWithBaseViewController:base_view_controller]; |
69 [coordinator setPaymentRequest:payment_request.get()]; | 71 [coordinator setPaymentRequest:payment_request.get()]; |
70 | 72 |
71 // Mock the coordinator delegate. | 73 // Mock the coordinator delegate. |
72 id delegate = [OCMockObject | 74 id delegate = [OCMockObject |
73 mockForProtocol:@protocol(PaymentItemsDisplayCoordinatorDelegate)]; | 75 mockForProtocol:@protocol(PaymentItemsDisplayCoordinatorDelegate)]; |
74 [[delegate expect] paymentItemsDisplayCoordinatorDidConfirm:coordinator]; | 76 [[delegate expect] paymentItemsDisplayCoordinatorDidConfirm:coordinator]; |
75 [coordinator setDelegate:delegate]; | 77 [coordinator setDelegate:delegate]; |
76 | 78 |
77 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 79 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
78 | 80 |
(...skipping 11 matching lines...) Expand all Loading... |
90 EXPECT_OCMOCK_VERIFY(delegate); | 92 EXPECT_OCMOCK_VERIFY(delegate); |
91 } | 93 } |
92 | 94 |
93 // Tests that calling the view controller delegate method which notifies the | 95 // Tests that calling the view controller delegate method which notifies the |
94 // coordinator that the user has chosen to return to the previous screen invokes | 96 // coordinator that the user has chosen to return to the previous screen invokes |
95 // the corresponding coordinator delegate method. | 97 // the corresponding coordinator delegate method. |
96 TEST(PaymentItemsDisplayCoordinatorTest, DidReturn) { | 98 TEST(PaymentItemsDisplayCoordinatorTest, DidReturn) { |
97 std::unique_ptr<PaymentRequest> payment_request = | 99 std::unique_ptr<PaymentRequest> payment_request = |
98 payment_request_test_util::CreateTestPaymentRequest(); | 100 payment_request_test_util::CreateTestPaymentRequest(); |
99 | 101 |
100 UIViewController* base_view_controller = | 102 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
101 [[[UIViewController alloc] init] autorelease]; | |
102 UINavigationController* navigation_controller = | 103 UINavigationController* navigation_controller = |
103 [[[UINavigationController alloc] | 104 [[UINavigationController alloc] |
104 initWithRootViewController:base_view_controller] autorelease]; | 105 initWithRootViewController:base_view_controller]; |
105 | 106 |
106 PaymentItemsDisplayCoordinator* coordinator = | 107 PaymentItemsDisplayCoordinator* coordinator = |
107 [[[PaymentItemsDisplayCoordinator alloc] | 108 [[PaymentItemsDisplayCoordinator alloc] |
108 initWithBaseViewController:base_view_controller] autorelease]; | 109 initWithBaseViewController:base_view_controller]; |
109 [coordinator setPaymentRequest:payment_request.get()]; | 110 [coordinator setPaymentRequest:payment_request.get()]; |
110 | 111 |
111 // Mock the coordinator delegate. | 112 // Mock the coordinator delegate. |
112 id delegate = [OCMockObject | 113 id delegate = [OCMockObject |
113 mockForProtocol:@protocol(PaymentItemsDisplayCoordinatorDelegate)]; | 114 mockForProtocol:@protocol(PaymentItemsDisplayCoordinatorDelegate)]; |
114 [[delegate expect] paymentItemsDisplayCoordinatorDidReturn:coordinator]; | 115 [[delegate expect] paymentItemsDisplayCoordinatorDidReturn:coordinator]; |
115 [coordinator setDelegate:delegate]; | 116 [coordinator setDelegate:delegate]; |
116 | 117 |
117 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 118 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
118 | 119 |
119 [coordinator start]; | 120 [coordinator start]; |
120 // Short delay to allow animation to complete. | 121 // Short delay to allow animation to complete. |
121 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 122 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
122 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 123 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
123 | 124 |
124 // Call the controller delegate method. | 125 // Call the controller delegate method. |
125 PaymentItemsDisplayViewController* view_controller = | 126 PaymentItemsDisplayViewController* view_controller = |
126 base::mac::ObjCCastStrict<PaymentItemsDisplayViewController>( | 127 base::mac::ObjCCastStrict<PaymentItemsDisplayViewController>( |
127 navigation_controller.visibleViewController); | 128 navigation_controller.visibleViewController); |
128 [coordinator paymentItemsDisplayViewControllerDidReturn:view_controller]; | 129 [coordinator paymentItemsDisplayViewControllerDidReturn:view_controller]; |
129 | 130 |
130 EXPECT_OCMOCK_VERIFY(delegate); | 131 EXPECT_OCMOCK_VERIFY(delegate); |
131 } | 132 } |
OLD | NEW |