OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/chrome/browser/payments/payment_request_error_coordinator.h" | |
6 | |
7 #include "base/mac/foundation_util.h" | |
8 #include "base/test/ios/wait_util.h" | |
9 #import "ios/chrome/browser/payments/payment_request_error_view_controller.h" | |
10 #import "ios/chrome/test/scoped_key_window.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "testing/platform_test.h" | |
13 #include "third_party/ocmock/OCMock/OCMock.h" | |
14 #include "third_party/ocmock/gtest_support.h" | |
15 | |
16 typedef PlatformTest PaymentRequestErrorCoordinatorTest; | |
17 | |
18 // Tests that invoking start and stop on the coordinator presents and dismisses | |
19 // the payment request error view controller, respectively. | |
20 TEST(PaymentRequestErrorCoordinatorTest, StartAndStop) { | |
21 UIViewController* base_view_controller = | |
22 [[[UIViewController alloc] init] autorelease]; | |
23 ScopedKeyWindow scoped_key_window_; | |
24 [scoped_key_window_.Get() setRootViewController:base_view_controller]; | |
25 | |
26 PaymentRequestErrorCoordinator* coordinator = | |
27 [[[PaymentRequestErrorCoordinator alloc] | |
28 initWithBaseViewController:base_view_controller] autorelease]; | |
29 | |
30 [coordinator start]; | |
31 // Short delay to allow animation to complete. | |
32 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | |
33 id persented_view_controller = | |
lpromero
2017/02/21 16:51:07
*presented
Moe
2017/02/21 22:56:15
Done.
| |
34 [coordinator baseViewController].presentedViewController; | |
35 EXPECT_TRUE([persented_view_controller | |
36 isMemberOfClass:[PaymentRequestErrorViewController class]]); | |
37 | |
38 [coordinator stop]; | |
39 // Delay to allow animation to complete. | |
40 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(2)); | |
41 EXPECT_EQ(nil, [coordinator baseViewController].presentedViewController); | |
42 } | |
43 | |
44 // Tests that calling the view controller delegate method which notifies the | |
45 // coordinator that the user has dismissed the error invokes the corresponding | |
46 // coordinator delegate method. | |
47 TEST(PaymentRequestErrorCoordinatorTest, DidDismiss) { | |
48 UIViewController* base_view_controller = | |
49 [[[UIViewController alloc] init] autorelease]; | |
50 ScopedKeyWindow scoped_key_window_; | |
51 [scoped_key_window_.Get() setRootViewController:base_view_controller]; | |
52 | |
53 PaymentRequestErrorCoordinator* coordinator = | |
54 [[[PaymentRequestErrorCoordinator alloc] | |
55 initWithBaseViewController:base_view_controller] autorelease]; | |
56 | |
57 // Mock the coordinator delegate. | |
58 id delegate = [OCMockObject | |
59 mockForProtocol:@protocol(PaymentRequestErrorCoordinatorDelegate)]; | |
60 [[delegate expect] paymentRequestErrorCoordinatorDidDismiss:coordinator]; | |
61 [coordinator setDelegate:delegate]; | |
62 | |
63 [coordinator start]; | |
64 // Short delay to allow animation to complete. | |
65 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | |
66 | |
67 // Call the controller delegate method. | |
68 id persented_view_controller = | |
69 [coordinator baseViewController].presentedViewController; | |
70 PaymentRequestErrorViewController* view_controller = | |
71 base::mac::ObjCCastStrict<PaymentRequestErrorViewController>( | |
72 persented_view_controller); | |
73 [coordinator paymentRequestErrorViewControllerDidDismiss:view_controller]; | |
74 | |
75 EXPECT_OCMOCK_VERIFY(delegate); | |
76 } | |
OLD | NEW |