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/ui/alert_coordinator/input_alert_coordinator.h" | 5 #import "ios/chrome/browser/ui/alert_coordinator/input_alert_coordinator.h" |
6 | 6 |
7 #include "testing/platform_test.h" | 7 #include "testing/platform_test.h" |
8 #import "third_party/ocmock/OCMock/OCMock.h" | 8 #import "third_party/ocmock/OCMock/OCMock.h" |
9 #include "third_party/ocmock/gtest_support.h" | 9 #include "third_party/ocmock/gtest_support.h" |
10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
11 TEST(InputAlertCoordinatorTest, AddTextField) { | 15 TEST(InputAlertCoordinatorTest, AddTextField) { |
12 // Setup. | 16 // Setup. |
13 UIViewController* viewController = | 17 UIViewController* viewController = [[UIViewController alloc] init]; |
14 [[[UIViewController alloc] init] autorelease]; | 18 InputAlertCoordinator* alertCoordinator = |
15 InputAlertCoordinator* alertCoordinator = [[[InputAlertCoordinator alloc] | 19 [[InputAlertCoordinator alloc] initWithBaseViewController:viewController |
16 initWithBaseViewController:viewController | 20 title:@"Test" |
17 title:@"Test" | 21 message:nil]; |
18 message:nil] autorelease]; | |
19 | 22 |
20 void (^emptyHandler)(UITextField* textField) = ^(UITextField* textField) { | 23 void (^emptyHandler)(UITextField* textField) = ^(UITextField* textField) { |
21 }; | 24 }; |
22 id alert = | 25 id alert = |
23 [OCMockObject partialMockForObject:alertCoordinator.alertController]; | 26 [OCMockObject partialMockForObject:alertCoordinator.alertController]; |
24 [[alert expect] addTextFieldWithConfigurationHandler:emptyHandler]; | 27 [[alert expect] addTextFieldWithConfigurationHandler:emptyHandler]; |
25 | 28 |
26 // Action. | 29 // Action. |
27 [alertCoordinator addTextFieldWithConfigurationHandler:emptyHandler]; | 30 [alertCoordinator addTextFieldWithConfigurationHandler:emptyHandler]; |
28 | 31 |
29 // Test. | 32 // Test. |
30 EXPECT_OCMOCK_VERIFY(alert); | 33 EXPECT_OCMOCK_VERIFY(alert); |
31 } | 34 } |
32 | 35 |
33 TEST(InputAlertCoordinatorTest, GetTextFields) { | 36 TEST(InputAlertCoordinatorTest, GetTextFields) { |
34 // Setup. | 37 // Setup. |
35 UIViewController* viewController = | 38 UIViewController* viewController = [[UIViewController alloc] init]; |
36 [[[UIViewController alloc] init] autorelease]; | 39 InputAlertCoordinator* alertCoordinator = |
37 InputAlertCoordinator* alertCoordinator = [[[InputAlertCoordinator alloc] | 40 [[InputAlertCoordinator alloc] initWithBaseViewController:viewController |
38 initWithBaseViewController:viewController | 41 title:@"Test" |
39 title:@"Test" | 42 message:nil]; |
40 message:nil] autorelease]; | |
41 | 43 |
42 NSArray<UITextField*>* array = [NSArray array]; | 44 NSArray<UITextField*>* array = [NSArray array]; |
43 id alert = | 45 id alert = |
44 [OCMockObject partialMockForObject:alertCoordinator.alertController]; | 46 [OCMockObject partialMockForObject:alertCoordinator.alertController]; |
45 [[[alert expect] andReturn:array] textFields]; | 47 [[[alert expect] andReturn:array] textFields]; |
46 | 48 |
47 // Action. | 49 // Action. |
48 NSArray<UITextField*>* resultArray = alertCoordinator.textFields; | 50 NSArray<UITextField*>* resultArray = alertCoordinator.textFields; |
49 | 51 |
50 // Test. | 52 // Test. |
51 EXPECT_EQ(array, resultArray); | 53 EXPECT_EQ(array, resultArray); |
52 EXPECT_OCMOCK_VERIFY(alert); | 54 EXPECT_OCMOCK_VERIFY(alert); |
53 } | 55 } |
OLD | NEW |